From 6ee493d8ea35381da53db32f6a2720681ffb8060 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Fri, 21 Aug 2020 18:51:05 +0200 Subject: [PATCH] fix notifications sometimes not rendering (#1905) * fix notifications sometimes not rendering * fix empty timeline fragment as well * add link to github issue as explanation --- .../keylesspalace/tusky/fragment/NotificationsFragment.java | 5 +++-- .../com/keylesspalace/tusky/fragment/TimelineFragment.java | 4 +++- 2 files changed, 6 insertions(+), 3 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 9a5cbbb6e..6014ac9bc 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -79,7 +79,6 @@ import com.keylesspalace.tusky.util.ListUtils; import com.keylesspalace.tusky.util.NotificationTypeConverterKt; import com.keylesspalace.tusky.util.PairedList; import com.keylesspalace.tusky.util.StatusDisplayOptions; -import com.keylesspalace.tusky.util.ThemeUtils; import com.keylesspalace.tusky.util.ViewDataUtils; import com.keylesspalace.tusky.view.BackgroundMessageView; import com.keylesspalace.tusky.view.EndlessOnScrollListener; @@ -1205,7 +1204,9 @@ public class NotificationsFragment extends SFragment implements if (isAdded()) { adapter.notifyItemRangeInserted(position, count); Context context = getContext(); - if (position == 0 && context != null) { + // scroll up when new items at the top are loaded while being at the start + // https://github.com/tuskyapp/Tusky/pull/1905#issuecomment-677819724 + if (position == 0 && context != null && adapter.getItemCount() != count) { recyclerView.scrollBy(0, Utils.dpToPx(context, -30)); } } diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java index 0a6162c14..71cc11812 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/TimelineFragment.java @@ -1405,7 +1405,9 @@ public class TimelineFragment extends SFragment implements if (isAdded()) { adapter.notifyItemRangeInserted(position, count); Context context = getContext(); - if (position == 0 && context != null) { + // scroll up when new items at the top are loaded while being in the first position + // https://github.com/tuskyapp/Tusky/pull/1905#issuecomment-677819724 + if (position == 0 && context != null && adapter.getItemCount() != count) { if (isSwipeToRefreshEnabled) recyclerView.scrollBy(0, Utils.dpToPx(context, -30)); else