Weekly Questions Thread - August 27, 2018

I have a fragment that contains a RecyclerView that displays search results of users. Each user row in the RecyclerView contains a Follow/Unfollow button, which upon clicking, causing the hosting fragment to execute the appropriate RxJava network call in its Presenter (using MVP). I should also note that each button will be linked to the same network call function in the Presenter (by this I mean it isn't the case that each ViewHolder has its own RxJava network call).

The problem that I'm looking to solve, is how to make sure that if a User is hammering away at a follow/unfollow button on a given row, that a network call is only executed once (I know this particular problem could be solved with switchmap if there was only one button). However, since each row has a button, I do not want prior network calls to be cancelled if for example the user clicks Follow on one user, and then right away clicks Follow on a different user.

Here is an example of what the Fragment looks like: https://imgur.com/a/4EkJI01

Any ideas on how to tackle this?

One thought I had was, since every row has a unique ID (User ID), in the presenter each time a "follow/unfollow" network call is made, the disposable is added to a hashmap with the User ID as the key. If a button is clicked again and the given user who's follow button was clicked is already in the HashMap, then it is disposed and removed from the map.

/r/androiddev Thread