Refresh statuses after an action

This commit is contained in:
tom79 2019-03-30 18:48:38 +01:00
parent 4067b3e40f
commit 250e052b8f
9 changed files with 15 additions and 102 deletions

View File

@ -129,9 +129,8 @@ public class ShowConversationActivity extends BaseActivity implements OnRetriev
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
if( status != null) {
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
if( status != null && statusListAdapter != null) {
statusListAdapter.notifyStatusWithActionChanged(status);
}
}
};

View File

@ -2065,7 +2065,6 @@ public class API {
try {
Status status1 = parseStatuses(context, new JSONObject(resp));
b.putParcelable("status", status1);
b.putSerializable("action", statusAction);
} catch (JSONException ignored) {}
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
intentBC.putExtras(b);
@ -2223,9 +2222,8 @@ public class API {
String response = httpsConnection.get(getAbsoluteUrl(String.format("/polls/%s", status.getPoll().getId())), 60, null, prefKeyOauthTokenT);
Poll poll = parsePoll(context, new JSONObject(response));
Bundle b = new Bundle();
b.putParcelable("poll", poll);
status.setPoll(poll);
b.putParcelable("status", status);
b.putSerializable("action", REFRESHPOLL);
Intent intentBC = new Intent(Helper.RECEIVE_ACTION);
intentBC.putExtras(b);
LocalBroadcastManager.getInstance(context).sendBroadcast(intentBC);

View File

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

View File

@ -316,29 +316,12 @@ public class ArtListAdapter extends RecyclerView.Adapter implements OnPostAction
}
}
public void notifyStatusWithActionChanged(API.StatusAction statusAction, Status status){
public void notifyStatusWithActionChanged(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 favCount = statuses.get(i).getFavourites_count();
int boostCount = statuses.get(i).getReblogs_count();
if( statusAction == API.StatusAction.REBLOG)
boostCount++;
else if( statusAction == API.StatusAction.UNREBLOG)
boostCount--;
else if( statusAction == API.StatusAction.FAVOURITE)
favCount++;
else if( statusAction == API.StatusAction.UNFAVOURITE)
favCount--;
if( boostCount < 0 )
boostCount = 0;
if( favCount < 0 )
favCount = 0;
statuses.get(i).setFavourited(status.isFavourited());
statuses.get(i).setFavourites_count(favCount);
statuses.get(i).setReblogged(status.isReblogged());
statuses.get(i).setReblogs_count(boostCount);
statuses.set(i, status);
statusListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}

View File

@ -1081,33 +1081,12 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
}
public void notifyNotificationWithActionChanged(API.StatusAction statusAction, Status status){
public void notifyNotificationWithActionChanged(Status status){
for (int i = 0; i < notificationsListAdapter.getItemCount(); i++) {
if (notificationsListAdapter.getItemAt(i) != null && notificationsListAdapter.getItemAt(i).getStatus() != null && notificationsListAdapter.getItemAt(i).getStatus().getId().equals(status.getId())) {
try {
if( notifications.get(i).getStatus() != null){
int favCount = notifications.get(i).getStatus().getFavourites_count();
int boostCount = notifications.get(i).getStatus().getReblogs_count();
if( statusAction == API.StatusAction.REBLOG)
boostCount++;
else if( statusAction == API.StatusAction.UNREBLOG)
boostCount--;
else if( statusAction == API.StatusAction.FAVOURITE)
favCount++;
else if( statusAction == API.StatusAction.UNFAVOURITE)
favCount--;
else if( statusAction == API.StatusAction.REFRESHPOLL){
if( status.getPoll() != null)
notifications.get(i).getStatus().setPoll(status.getPoll());
}
if( boostCount < 0 )
boostCount = 0;
if( favCount < 0 )
favCount = 0;
notifications.get(i).getStatus().setFavourited(status.isFavourited());
notifications.get(i).getStatus().setFavourites_count(favCount);
notifications.get(i).getStatus().setReblogged(status.isReblogged());
notifications.get(i).getStatus().setReblogs_count(boostCount);
notifications.get(i).setStatus(status);
notificationsListAdapter.notifyItemChanged(i);
break;
}
@ -1345,7 +1324,7 @@ public class NotificationsListAdapter extends RecyclerView.Adapter implements On
@Override
public void onPoll(Status status, Poll poll) {
status.setPoll(poll);
notifyNotificationWithActionChanged(API.StatusAction.REFRESHPOLL, status);
notifyNotificationWithActionChanged(status);
}
class ViewHolder extends RecyclerView.ViewHolder {

View File

@ -460,29 +460,12 @@ public class PixelfedListAdapter extends RecyclerView.Adapter implements OnPostA
}
}
public void notifyStatusWithActionChanged(API.StatusAction statusAction, Status status){
public void notifyStatusWithActionChanged(Status status){
for (int i = 0; i < pixelfedListAdapter.getItemCount(); i++) {
//noinspection ConstantConditions
if (pixelfedListAdapter.getItemAt(i) != null && pixelfedListAdapter.getItemAt(i).getId().equals(status.getId())) {
try {
int favCount = statuses.get(i).getFavourites_count();
int boostCount = statuses.get(i).getReblogs_count();
if( statusAction == API.StatusAction.REBLOG)
boostCount++;
else if( statusAction == API.StatusAction.UNREBLOG)
boostCount--;
else if( statusAction == API.StatusAction.FAVOURITE)
favCount++;
else if( statusAction == API.StatusAction.UNFAVOURITE)
favCount--;
if( boostCount < 0 )
boostCount = 0;
if( favCount < 0 )
favCount = 0;
statuses.get(i).setFavourited(status.isFavourited());
statuses.get(i).setFavourites_count(favCount);
statuses.get(i).setReblogged(status.isReblogged());
statuses.get(i).setReblogs_count(boostCount);
statuses.set(i, status);
pixelfedListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}

View File

@ -3025,29 +3025,12 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct
}
}
public void notifyStatusWithActionChanged(API.StatusAction statusAction, Status status){
public void notifyStatusWithActionChanged(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 favCount = statuses.get(i).getFavourites_count();
int boostCount = statuses.get(i).getReblogs_count();
if( statusAction == API.StatusAction.REBLOG)
boostCount++;
else if( statusAction == API.StatusAction.UNREBLOG)
boostCount--;
else if( statusAction == API.StatusAction.FAVOURITE)
favCount++;
else if( statusAction == API.StatusAction.UNFAVOURITE)
favCount--;
if( boostCount < 0 )
boostCount = 0;
if( favCount < 0 )
favCount = 0;
statuses.get(i).setFavourited(status.isFavourited());
statuses.get(i).setFavourites_count(favCount);
statuses.get(i).setReblogged(status.isReblogged());
statuses.get(i).setReblogs_count(boostCount);
statuses.set(i, status);
statusListAdapter.notifyItemChanged(i);
} catch (Exception ignored) {
}

View File

@ -157,14 +157,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
Poll poll = b.getParcelable("poll");
if (poll != null && status != null){
status.setPoll(poll);
}
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
if (status != null) {
notificationsListAdapter.notifyNotificationWithActionChanged(statusAction, status);
}
if( notificationsListAdapter != null && status != null)
notificationsListAdapter.notifyNotificationWithActionChanged(status);
}
};
LocalBroadcastManager.getInstance(context).registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_ACTION));

View File

@ -245,13 +245,8 @@ public class DisplayStatusFragment extends Fragment implements OnRetrieveFeedsIn
Bundle b = intent.getExtras();
assert b != null;
Status status = b.getParcelable("status");
Poll poll = b.getParcelable("poll");
if (poll != null && status != null){
status.setPoll(poll);
}
API.StatusAction statusAction = (API.StatusAction) b.getSerializable("action");
if( status != null && statusListAdapter != null) {
statusListAdapter.notifyStatusWithActionChanged(statusAction, status);
statusListAdapter.notifyStatusWithActionChanged(status);
}
}
};