Q
Q
qqweer2020-10-20 21:21:38
Android
qqweer, 2020-10-20 21:21:38

How to implement adding to favorites?

I have a player. There are 2 fragments. One shows the entire list with music - it's called SongsFragment. Another one of her plays is called the SongPlayFragment.
How to implement adding to favorites? The button "to favorites" is in the SongPlayFragment. At first I thought of creating an array of data, to which, when the user clicks on the button, the position of the song is added, but this is a bad solution. I would like to know something sensible and useful. Perhaps a solution on the surface, but nothing comes to mind. I'm waiting for help, thanks.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis Zagaevsky, 2020-10-21
@hawkkiller

Well, in general, there is such a Repository pattern, you need to use it. Inside you need to keep the database, no options. Imagine if I add 1000 songs to my favorites. All these dumb options with files and preferences will slow down.
There is also an option to keep the database on the server, and make requests to it transparently via http api through the same repository.

D
DiSay, 2020-10-20
@DiSay

Why not just take the song title and add it to your favorites list? For example, in a json file and then read it.
Xs is the vario correct, but I think it's a worker.

A
Aleksandr Chuyko, 2020-10-21
@Byleopold

If I understand you correctly, saving data using SharedPreferences can help you.
Just save the position of the song in an SP file. And then play the one you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question