-1

I'm currently working on an app. There are three fragments. One is the home page fragment where there's a list of some popular locations of the world listed in a RecyclerView. And the other one is the favourite page fragment where favourited locations are listed in the RecyclerView as well. And the last one is the details page fragment where the information of the selected location is shown.

Favourited locations are stored in the room database. I have an entity class for the database and a model class for locations that are listed on the home page. I can navigate to the details fragment from both the favourites fragment and the home fragment.

Each list item has a fav icon. If the location is added to the favourites, the icon should be filled. So my question here is, where/how do I save/check the state of the icon? in the model class or in the database?

And also, how do I pass the selected location info data from the favourites page to the details page? Like with a bundle? If so, then don't I have to implement Parcelable in the entity class? Is it against the MVVM architecture?

2
  • 1
    You should never check the state of a button. Your model class should drive the UI and be its source of truth, not the other way around Commented Apr 20 at 15:54
  • @GabeSechan so should i add a boolean variable to my model class? Commented Apr 20 at 17:13

1 Answer 1

0

You can add a parameter in your model class as isFavourite of boolean type and set the default value to false. Then when any one clicks on the like button change the value of isFavourite, and save it into database. That will do what you want.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.