Maintaining a Favorites List in Firebase

Viewed 268

In my app, the user can add an item to their Favorite list by pressing a checkbox. A new node (Favorites) is created in the database for each user. Just like this:-
Firebase Structure

User can view their favorite list under "Favorites" activity. Like this:- Favorites Activity

The "Home Activity" displays all the hacks from the "Hacks" list.

My question is how to combine the "Hacks" and the "Favorites" list for a particular user so that the user can see his/her favorite item highlighted (like button being active ie red in color) in the Home Activity. What logic or any firebase technique should I use? User should be able to see his/her item highlighted in the Home Activity and also can add or remove an item from their favorites list by clicking on the like button from both Favorites and Home Activity.

1 Answers

Since i don't know, how you get your data, this is the only thing i can suggest

I would load bot lists (Hacks and Favourites) and display the Hacks. Locally, you can check, if the Hack you are handling currently is a favourite, by checking if its Identifier is contained in the favourites-list. If so, you can add your styling for highlighting.

Whenever the user favourites or unfavourites a hack, the logic should trigger for this specific item

Related