From d16e199dd12a4f96aa74d9c9d77082627f44a307 Mon Sep 17 00:00:00 2001 From: sk Date: Mon, 5 Jun 2023 11:48:40 +0200 Subject: [PATCH] scroll up when posting on profile fragment closes sk22#546 --- .../android/fragments/AccountTimelineFragment.java | 4 +++- .../android/fragments/BaseStatusListFragment.java | 7 ++++++- .../joinmastodon/android/fragments/ProfileFragment.java | 1 - .../android/fragments/discover/DiscoverPostsFragment.java | 8 +------- .../android/fragments/discover/SearchFragment.java | 8 +------- 5 files changed, 11 insertions(+), 17 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java index 1db365282..67cd4df72 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/AccountTimelineFragment.java @@ -20,6 +20,7 @@ import org.parceler.Parcels; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; @@ -95,10 +96,11 @@ public class AccountTimelineFragment extends StatusListFragment{ if(ev.status.inReplyToAccountId!=null && !ev.status.inReplyToAccountId.equals(AccountSessionManager.getInstance().getAccount(accountID).self.id)) return; }else if(filter==GetAccountStatuses.Filter.MEDIA){ - if(ev.status.mediaAttachments.isEmpty()) + if(Optional.ofNullable(ev.status.mediaAttachments).map(List::isEmpty).orElse(true)) return; } prependItems(Collections.singletonList(ev.status), true); + if (isOnTop()) scrollToTop(); } protected void onStatusUnpinned(StatusUnpinnedEvent ev){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java index 96480351e..5ae8a2d0f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -71,7 +71,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public abstract class BaseStatusListFragment extends RecyclerFragment implements PhotoViewerHost, ScrollableToTop, HasFab, ProvidesAssistContent.ProvidesWebUri { +public abstract class BaseStatusListFragment extends RecyclerFragment implements PhotoViewerHost, ScrollableToTop, IsOnTop, HasFab, ProvidesAssistContent.ProvidesWebUri { protected ArrayList displayItems=new ArrayList<>(); protected DisplayItemsAdapter adapter; protected String accountID; @@ -680,6 +680,11 @@ public abstract class BaseStatusListFragment exten smoothScrollRecyclerViewToTop(list); } + @Override + public boolean isOnTop() { + return isRecyclerViewOnTop(list); + } + protected int getListWidthForMediaLayout(){ return list.getWidth(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index 9c706a3e7..d8ccc4c30 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -58,7 +58,6 @@ import org.joinmastodon.android.fragments.report.ReportReasonChoiceFragment; import org.joinmastodon.android.model.Account; import org.joinmastodon.android.model.AccountField; import org.joinmastodon.android.model.Attachment; -import org.joinmastodon.android.model.Instance; import org.joinmastodon.android.model.Relationship; import org.joinmastodon.android.ui.BetterItemAnimator; import org.joinmastodon.android.ui.SimpleViewHolder; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java index e6d7c4a4c..4130b16a3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/DiscoverPostsFragment.java @@ -5,7 +5,6 @@ import android.os.Bundle; import android.view.View; import org.joinmastodon.android.api.requests.trends.GetTrendingStatuses; -import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.StatusListFragment; import org.joinmastodon.android.model.Filter; import org.joinmastodon.android.model.Status; @@ -17,7 +16,7 @@ import java.util.stream.Collectors; import me.grishka.appkit.api.SimpleCallback; -public class DiscoverPostsFragment extends StatusListFragment implements IsOnTop { +public class DiscoverPostsFragment extends StatusListFragment { private DiscoverInfoBannerHelper bannerHelper=new DiscoverInfoBannerHelper(DiscoverInfoBannerHelper.BannerType.TRENDING_POSTS); @Override @@ -39,11 +38,6 @@ public class DiscoverPostsFragment extends StatusListFragment implements IsOnTop bannerHelper.maybeAddBanner(contentWrap); } - @Override - public boolean isOnTop() { - return isRecyclerViewOnTop(list); - } - @Override protected Filter.FilterContext getFilterContext() { return Filter.FilterContext.PUBLIC; diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java index e4a375e83..741149c35 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/discover/SearchFragment.java @@ -12,7 +12,6 @@ import org.joinmastodon.android.R; import org.joinmastodon.android.api.requests.search.GetSearchResults; import org.joinmastodon.android.api.session.AccountSessionManager; import org.joinmastodon.android.fragments.BaseStatusListFragment; -import org.joinmastodon.android.fragments.IsOnTop; import org.joinmastodon.android.fragments.ProfileFragment; import org.joinmastodon.android.fragments.ThreadFragment; import org.joinmastodon.android.model.Account; @@ -43,7 +42,7 @@ import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.utils.MergeRecyclerAdapter; import me.grishka.appkit.utils.V; -public class SearchFragment extends BaseStatusListFragment implements IsOnTop { +public class SearchFragment extends BaseStatusListFragment { private String currentQuery; private List prevDisplayItems; private EnumSet currentFilter=EnumSet.allOf(SearchResult.Type.class); @@ -312,11 +311,6 @@ public class SearchFragment extends BaseStatusListFragment impleme } } - @Override - public boolean isOnTop() { - return isRecyclerViewOnTop(list); - } - @Override public Uri getWebUri(Uri.Builder base) { Uri.Builder searchUri = base.path("/search");