From f80e3771d1458ac08a5808d3c37c683ec39b89c0 Mon Sep 17 00:00:00 2001 From: Grishka Date: Fri, 25 Oct 2024 04:46:09 +0300 Subject: [PATCH] Make toolbar scroll away in home timeline (AND-208) --- .../fragments/HomeTimelineFragment.java | 17 +++++++ .../layout/fragment_loader_hiding_toolbar.xml | 47 +++++++++++++++++++ .../src/main/res/layout/fragment_timeline.xml | 45 ++++++++++-------- 3 files changed, 89 insertions(+), 20 deletions(-) create mode 100644 mastodon/src/main/res/layout/fragment_loader_hiding_toolbar.xml diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java index 8aef7868..08d52ead 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTimelineFragment.java @@ -61,6 +61,7 @@ import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper; import org.joinmastodon.android.ui.viewcontrollers.HomeTimelineMenuController; import org.joinmastodon.android.ui.viewcontrollers.ToolbarDropdownMenuController; import org.joinmastodon.android.ui.views.FixedAspectRatioImageView; +import org.joinmastodon.android.ui.views.NestedRecyclerScrollView; import org.joinmastodon.android.ui.views.NewPostsButtonContainer; import org.joinmastodon.android.updater.GithubSelfUpdater; import org.parceler.Parcels; @@ -109,6 +110,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD private BottomSheet donationSheet; public HomeTimelineFragment(){ + setLayout(R.layout.fragment_loader_hiding_toolbar); setListLayoutId(R.layout.fragment_timeline); } @@ -279,6 +281,21 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD } } }); + View bottomOverlays=view.findViewById(R.id.bottom_overlays); + NestedRecyclerScrollView scroller=view.findViewById(R.id.scroller); + scroller.setScrollableChildSupplier(()->list); + scroller.setTakePriorityOverChildViews(true); + scroller.setOnScrollChangeListener((v, scrollX, scrollY, oldScrollX, oldScrollY)->{ + bottomOverlays.setTranslationY(scrollY-getToolbar().getHeight()); + }); + scroller.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener(){ + @Override + public boolean onPreDraw(){ + scroller.getViewTreeObserver().removeOnPreDrawListener(this); + bottomOverlays.setTranslationY(scroller.getScrollY()-getToolbar().getHeight()); + return true; + } + }); if(GithubSelfUpdater.needSelfUpdating()){ updateUpdateState(GithubSelfUpdater.getInstance().getState()); diff --git a/mastodon/src/main/res/layout/fragment_loader_hiding_toolbar.xml b/mastodon/src/main/res/layout/fragment_loader_hiding_toolbar.xml new file mode 100644 index 00000000..96e05f99 --- /dev/null +++ b/mastodon/src/main/res/layout/fragment_loader_hiding_toolbar.xml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/mastodon/src/main/res/layout/fragment_timeline.xml b/mastodon/src/main/res/layout/fragment_timeline.xml index 8f44ecec..e2f3692a 100644 --- a/mastodon/src/main/res/layout/fragment_timeline.xml +++ b/mastodon/src/main/res/layout/fragment_timeline.xml @@ -20,19 +20,31 @@ android:layout_height="match_parent" android:id="@+id/empty"/> - + + + + + - - \ No newline at end of file