From 9a4dfc632f9a67aad809e9df6d287c2f308750f6 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 3 May 2019 20:42:13 +0200 Subject: [PATCH] fix poll voting in NotificationFragment (#1234) --- .../tusky/fragment/NotificationsFragment.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index e10b9c94..834548c4 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -267,7 +267,7 @@ public class NotificationsFragment extends SFragment implements findReplyPosition(event.getStatusId()); if (posAndNotification == null) return; //noinspection ConstantConditions - setFavovouriteForStatus(posAndNotification.first, + setFavouriteForStatus(posAndNotification.first, posAndNotification.second.getStatus(), event.getFavourite()); } @@ -295,7 +295,7 @@ public class NotificationsFragment extends SFragment implements hideFab = preferences.getBoolean("fabHide", false); scrollListener = new EndlessOnScrollListener(layoutManager) { @Override - public void onScrolled(RecyclerView view, int dx, int dy) { + public void onScrolled(@NonNull RecyclerView view, int dx, int dy) { super.onScrolled(view, dx, dy); ActionButtonActivity activity = (ActionButtonActivity) getActivity(); @@ -401,13 +401,13 @@ public class NotificationsFragment extends SFragment implements .observeOn(AndroidSchedulers.mainThread()) .as(autoDisposable(from(this))) .subscribe( - (newStatus) -> setFavovouriteForStatus(position, status, favourite), + (newStatus) -> setFavouriteForStatus(position, status, favourite), (t) -> Log.d(getClass().getSimpleName(), "Failed to favourite status: " + status.getId(), t) ); } - private void setFavovouriteForStatus(int position, Status status, boolean favourite) { + private void setFavouriteForStatus(int position, Status status, boolean favourite) { status.setFavourited(favourite); if (status.getReblog() != null) { @@ -442,7 +442,18 @@ public class NotificationsFragment extends SFragment implements } private void setVoteForPoll(int position, Poll poll) { - // TODO + + NotificationViewData.Concrete viewdata = (NotificationViewData.Concrete) notifications.getPairedItem(position); + + StatusViewData.Builder viewDataBuilder = new StatusViewData.Builder(viewdata.getStatusViewData()); + viewDataBuilder.setPoll(poll); + + NotificationViewData.Concrete newViewData = new NotificationViewData.Concrete( + viewdata.getType(), viewdata.getId(), viewdata.getAccount(), + viewDataBuilder.createStatusViewData(), viewdata.isExpanded()); + + notifications.setPairedItem(position, newViewData); + updateAdapter(); } @Override @@ -452,7 +463,7 @@ public class NotificationsFragment extends SFragment implements } @Override - public void onViewMedia(int position, int attachmentIndex, @NonNull View view) { + public void onViewMedia(int position, int attachmentIndex, @Nullable View view) { Notification notification = notifications.get(position).asRightOrNull(); if (notification == null || notification.getStatus() == null) return; super.viewMedia(attachmentIndex, notification.getStatus(), view); @@ -1099,7 +1110,7 @@ public class NotificationsFragment extends SFragment implements } @Override - public boolean areContentsTheSame(NotificationViewData oldItem, NotificationViewData newItem) { + public boolean areContentsTheSame(@NonNull NotificationViewData oldItem, @NonNull NotificationViewData newItem) { return false; }