Fix issue with counters

This commit is contained in:
stom79 2019-01-10 12:00:14 +01:00
parent dc6c595186
commit c95d7045fa
3 changed files with 21 additions and 15 deletions

View File

@ -1750,6 +1750,7 @@ public class API {
try {
Status status1 = parseStatuses(context, new JSONObject(resp));
b.putParcelable("status", status1);
b.putSerializable("action", statusAction);
} catch (JSONException ignored) {}
b.putSerializable("action", statusAction);
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);

View File

@ -2700,17 +2700,27 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
}
public void notifyStatusWithActionChanged(Status status){
public void notifyStatusWithActionChanged(API.StatusAction statusAction, Status status){
for (int i = 0; i < statusListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (statusListAdapter.getItemAt(i) != null && statusListAdapter.getItemAt(i).getId().equals(status.getId())) {
try {
int countFav = statuses.get(i).getFavourites_count() -1;
if( countFav < 0)
countFav = 0;
int countReblog = statuses.get(i).getReblogs_count() -1;
if( countReblog < 0)
countReblog = 0;
int j;
int countFav = statuses.get(i).getFavourites_count();
int countReblog = statuses.get(i).getReblogs_count();
if( statusAction == API.StatusAction.UNFAVOURITE){
countFav--;
if( countFav < 0)
countFav = 0;
}else if( statusAction == API.StatusAction.FAVOURITE){
countFav++;
}else if( statusAction == API.StatusAction.UNREBLOG){
countReblog--;
if( countReblog < 0)
countReblog = 0;
}else if( statusAction == API.StatusAction.REBLOG){
countReblog++;
}
statuses.get(i).setFavourited(status.isFavourited());
statuses.get(i).setFavourites_count(countFav);
statuses.get(i).setReblogged(status.isReblogged());

View File

@ -51,6 +51,7 @@ import fr.gouv.etalab.mastodon.asynctasks.RetrieveFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrieveMissingFeedsAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.RetrievePeertubeSearchAsyncTask;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoAsyncTask;
import fr.gouv.etalab.mastodon.client.API;
import fr.gouv.etalab.mastodon.client.APIResponse;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Conversation;
@ -216,8 +217,9 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
API.StatusAction statusAction = (API.StatusAction)b.getSerializable("action");
if( status != null) {
applyAction(status);
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
}
}
};
@ -426,7 +428,6 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
super.onDestroy();
if(asyncTask != null && asyncTask.getStatus() == AsyncTask.Status.RUNNING)
asyncTask.cancel(true);
Log.v(Helper.TAG,type + " - destroy: " + receive_action);
if( receive_action != null)
LocalBroadcastManager.getInstance(context).unregisterReceiver(receive_action);
}
@ -938,10 +939,4 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
}
}
public void applyAction(Status status){
if( statusListAdapter != null && this.statuses != null && this.statuses.contains(status)){
statusListAdapter.notifyStatusWithActionChanged(status);
}
}
}