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 47732dde..e8f8fd6a 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/BaseStatusListFragment.java @@ -56,7 +56,7 @@ import me.grishka.appkit.utils.BindableViewHolder; import me.grishka.appkit.utils.V; import me.grishka.appkit.views.UsableRecyclerView; -public abstract class BaseStatusListFragment extends BaseRecyclerFragment implements PhotoViewerHost{ +public abstract class BaseStatusListFragment extends BaseRecyclerFragment implements PhotoViewerHost, ScrollableToTop{ protected ArrayList displayItems=new ArrayList<>(); protected DisplayItemsAdapter adapter; protected String accountID; @@ -377,22 +377,7 @@ public abstract class BaseStatusListFragment exten Toolbar toolbar=getToolbar(); if(toolbar==null) return; - toolbar.setOnClickListener(v->{ - if(list.getChildCount()>0 && list.getChildAdapterPosition(list.getChildAt(0))>10){ - list.scrollToPosition(0); - list.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ - @Override - public boolean onPreDraw(){ - list.getViewTreeObserver().removeOnPreDrawListener(this); - list.scrollBy(0, V.dp(300)); - list.smoothScrollToPosition(0); - return true; - } - }); - }else{ - list.smoothScrollToPosition(0); - } - }); + toolbar.setOnClickListener(v->scrollToTop()); } protected int getMainAdapterOffset(){ @@ -552,6 +537,24 @@ public abstract class BaseStatusListFragment exten return holders; } + @Override + public void scrollToTop(){ + if(list.getChildCount()>0 && list.getChildAdapterPosition(list.getChildAt(0))>10){ + list.scrollToPosition(0); + list.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ + @Override + public boolean onPreDraw(){ + list.getViewTreeObserver().removeOnPreDrawListener(this); + list.scrollBy(0, V.dp(300)); + list.smoothScrollToPosition(0); + return true; + } + }); + }else{ + list.smoothScrollToPosition(0); + } + } + protected class DisplayItemsAdapter extends UsableRecyclerView.Adapter> implements ImageLoaderRecyclerAdapter{ public DisplayItemsAdapter(){ diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index b18d5279..1e021e3f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -158,6 +158,11 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene private void onTabSelected(@IdRes int tab){ Fragment newFragment=fragmentForTab(tab); + if(tab==currentTab){ + if(newFragment instanceof ScrollableToTop) + ((ScrollableToTop) newFragment).scrollToTop(); + return; + } getChildFragmentManager().beginTransaction().hide(fragmentForTab(currentTab)).show(newFragment).commit(); if(newFragment instanceof LoaderFragment){ LoaderFragment lf=(LoaderFragment) newFragment; 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 0d01f2a0..b1d47d7b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -83,7 +83,7 @@ import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; import me.grishka.appkit.utils.CubicBezierInterpolator; import me.grishka.appkit.utils.V; -public class ProfileFragment extends LoaderFragment implements OnBackPressedListener{ +public class ProfileFragment extends LoaderFragment implements OnBackPressedListener, ScrollableToTop{ private static final int AVATAR_RESULT=722; private static final int COVER_RESULT=343; @@ -430,10 +430,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList toolbarTitleView.setTranslationY(titleTransY); toolbarSubtitleView.setTranslationY(titleTransY); } - getToolbar().setOnClickListener(v->{ - getScrollableRecyclerView().scrollToPosition(0); - scrollView.smoothScrollTo(0, 0); - }); + getToolbar().setOnClickListener(v->scrollToTop()); } @Override @@ -798,6 +795,12 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList } } + @Override + public void scrollToTop(){ + getScrollableRecyclerView().scrollToPosition(0); + scrollView.smoothScrollTo(0, 0); + } + private class ProfilePagerAdapter extends RecyclerView.Adapter{ @NonNull @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ScrollableToTop.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScrollableToTop.java new file mode 100644 index 00000000..0eaf3adf --- /dev/null +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ScrollableToTop.java @@ -0,0 +1,5 @@ +package org.joinmastodon.android.fragments; + +/*package*/ interface ScrollableToTop{ + void scrollToTop(); +} diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Poll.java b/mastodon/src/main/java/org/joinmastodon/android/model/Poll.java index bdd2e262..0ac58002 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Poll.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Poll.java @@ -1,25 +1,27 @@ package org.joinmastodon.android.model; -import org.joinmastodon.android.api.AllFieldsAreRequired; import org.joinmastodon.android.api.ObjectValidationException; +import org.joinmastodon.android.api.RequiredField; import org.parceler.Parcel; import java.time.Instant; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; -@AllFieldsAreRequired @Parcel public class Poll extends BaseModel{ + @RequiredField public String id; public Instant expiresAt; public boolean expired; public boolean multiple; public int votersCount; public boolean voted; + @RequiredField public List ownVotes; + @RequiredField public List