Fix issue #324 & #325 - Error messages with action on Friendica

This commit is contained in:
Thomas 2022-09-20 16:11:55 +02:00
parent f4bfe12abe
commit bd43af4ab8

View file

@ -224,42 +224,64 @@ public class StatusAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
Status statusReturned, Status statusReturned,
boolean remote) { boolean remote) {
if (statusReturned == null) { if (statusReturned == null) {
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show(); switch (typeOfAction) {
return; case BOOKMARK_ACTION:
} statusToDeal.bookmarked = true;
boolean isOK = true; break;
switch (typeOfAction) { case REBLOG_ACTION:
case BOOKMARK_ACTION: statusToDeal.reblogged = true;
isOK = statusReturned.bookmarked; statusToDeal.reblogs_count++;
break; break;
case REBLOG_ACTION: case FAVOURITE_ACTION:
isOK = statusReturned.reblogged; statusToDeal.favourited = true;
break; statusToDeal.favourites_count++;
case FAVOURITE_ACTION: break;
isOK = statusReturned.favourited; case UNBOOKMARK_ACTION:
break; statusToDeal.bookmarked = false;
case UNBOOKMARK_ACTION: break;
isOK = !statusReturned.bookmarked; case UNREBLOG_ACTION:
break; statusToDeal.reblogged = false;
case UNREBLOG_ACTION: statusToDeal.reblogs_count--;
isOK = !statusReturned.reblogged; break;
break; case UNFAVOURITE_ACTION:
case UNFAVOURITE_ACTION: statusToDeal.favourited = false;
isOK = !statusReturned.favourited; statusToDeal.favourites_count--;
break; break;
} }
} else {
boolean isOK = true;
switch (typeOfAction) {
case BOOKMARK_ACTION:
isOK = statusReturned.bookmarked;
break;
case REBLOG_ACTION:
isOK = statusReturned.reblogged;
break;
case FAVOURITE_ACTION:
isOK = statusReturned.favourited;
break;
case UNBOOKMARK_ACTION:
isOK = !statusReturned.bookmarked;
break;
case UNREBLOG_ACTION:
isOK = !statusReturned.reblogged;
break;
case UNFAVOURITE_ACTION:
isOK = !statusReturned.favourited;
break;
}
if (!isOK) {
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return;
}
//Update elements
statusToDeal.favourited = statusReturned.favourited;
statusToDeal.reblogged = statusReturned.reblogged;
statusToDeal.bookmarked = statusReturned.bookmarked;
statusToDeal.reblogs_count = statusReturned.reblogs_count;
statusToDeal.favourites_count = statusReturned.favourites_count;
if (!isOK) {
Toasty.error(context, context.getString(R.string.toast_error), Toasty.LENGTH_SHORT).show();
return;
} }
//Update elements
statusToDeal.favourited = statusReturned.favourited;
statusToDeal.reblogged = statusReturned.reblogged;
statusToDeal.bookmarked = statusReturned.bookmarked;
statusToDeal.reblogs_count = statusReturned.reblogs_count;
statusToDeal.favourites_count = statusReturned.favourites_count;
//Update status in cache if not a remote instance //Update status in cache if not a remote instance
if (!remote) { if (!remote) {
new Thread(() -> { new Thread(() -> {