0

I have online music application.

My Application has 1 listview and 1 fragment player page.

player page has like button (2 state):

  • is like (red heart icon)
  • no like (white heart icon)

my method is check like from mysqli database server using by send post request to server and get json response include (0-> false or 1->true). false means no like and true means liked.

now, for every request and open player fragment this request post to server for checking. number of requests too much and my server Does not rest :\

my method Not worth it :|

Methods and Facebook apps like Instagram likes to check out what is?

frzdno
  • 172
  • 9

1 Answers1

0

You don't have to do that. The thing Facebook or other big social media company do is they include like state while they request JSON from the server. So you need to add JOIN logic to your sql query. Every time you request JSON data for your listView your JSON data will be something like this:

{
    .... //all of yours json data
    likeState : "true"
}

Then you need to pass those data into intent if your using activity for display the detail from that current list item or if your using fragment you can follow this link on how to send data from activity to fragment. Check wether likeState is true then you know what else to do rather than keep request data from the server every time you open up your fragment.

Community
  • 1
  • 1
teck wei
  • 1,375
  • 11
  • 22
  • your answer is helpful, thank you. In your opinion, useing `JOIN` in query (join music table with likes table) To get the list of songs, is difficult and expensive? OR this way is better? --> i not use JOIN for get listview data, and only in fragment player page i do check like with post request for every time open fragment? – frzdno Dec 30 '16 at 18:09
  • `JOIN` is not Expensive? – frzdno Dec 30 '16 at 18:16
  • Not at all. My friend work in a big tech company their query about 100 lines code most of it is JOIN and subquery. By the way join is very easy to use when u get familiar with it but you need to have associate column in both table you need to join eg. MUSIC TABLE id, LIKE TABLE music_id then you can get reference one another to know which music have been like. If it is really that expensive mysql won't even built in this function for us. – teck wei Dec 30 '16 at 18:41
  • As you say if you request every time when user open up fragment your will use up your bandwidth and that will cost you a lot when you reach million of user. What if you have more page to request like comment? detail? So you need to really reuse the data that already available on your last request. – teck wei Dec 30 '16 at 18:45
  • Thank you so much from the guide, So useing by `JOIN` is the best way for this issue. **A request and reuse it for ever**. Thank you **teck wei** – frzdno Dec 30 '16 at 19:29