# android-architecture


04/01/2022, 2:59 PM
Hi 👋 , Perhaps one of you can be of assistance to me. In my ViewModel I would like to be able to query my local database with LiveData and observe it. For each page in the app I would need to change the query. This works just fine with:
Copy code
val observableActionsFilteredByPageId = Transformations.switchMap(filterPageId)
However, now I want to filter that data with different values. Meaning that for each page I would need multiple lists filtered by some other parameter... Something like this:
Copy code
val contentView = { actions ->
    actions?.filter { it.actionType == "action_contentView" }

val notifications = { actions ->
    actions?.filter { it.actionType == "action_notification" }
Would this be a proper way to do it or am I using the APIs wrongly? Thanks for your time!


04/02/2022, 12:40 PM
You can follow the clean architecture. To do that: 1. you can have a domain layer where you can request for each query which then call the repository. You can also modify your data that you will show in the UI 2. then you can have a repository where you will query from your local database and map the data as you required for the page 3. Viewmodel will just call the domain class, observe the data and update the ui You can do this way for each page.