From 908f83c50ea960b939ab2d7561a66eff180e0c6e Mon Sep 17 00:00:00 2001 From: KingLucius Date: Thu, 2 Nov 2023 22:03:00 +0200 Subject: [PATCH] Fix scroll for Library TV layout (#695) * Fix scroll for Library TV layout * Fixed without NestedScrollView --- .../ui/library/LibraryFragment.kt | 10 ++++++++ .../ui/library/ViewpagerAdapter.kt | 17 +++++++++++-- .../main/res/layout/fragment_library_tv.xml | 25 ++++++++++--------- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt index 7cc57f5d..864ca065 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/LibraryFragment.kt @@ -27,6 +27,7 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.activityViewModels import androidx.viewpager2.widget.ViewPager2 import androidx.recyclerview.widget.RecyclerView +import com.google.android.material.appbar.AppBarLayout import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayoutMediator import com.lagradost.cloudstream3.APIHolder @@ -137,6 +138,10 @@ class LibraryFragment : Fragment() { binding?.libraryRoot?.findViewById(R.id.search_src_text)?.apply { tag = "tv_no_focus_tag" + //Expand the Appbar when search bar is focused, fixing scroll up issue + setOnFocusChangeListener { _, _ -> + binding?.searchBar?.setExpanded(true) + } } // Set the color for the search exit icon to the correct theme text color @@ -342,6 +347,7 @@ class LibraryFragment : Fragment() { binding?.apply { viewpager.offscreenPageLimit = 2 viewpager.reduceDragSensitivity() + searchBar.setExpanded(true) } val startLoading = Runnable { @@ -441,6 +447,10 @@ class LibraryFragment : Fragment() { val distance = abs(position - currentItem) hideViewpager(distance) } + //Expand the appBar on tab focus + tab.view.setOnFocusChangeListener { view, b -> + binding?.searchBar?.setExpanded(true) + } }.attach() } } diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt index 76028487..6731eae2 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/library/ViewpagerAdapter.kt @@ -1,14 +1,18 @@ package com.lagradost.cloudstream3.ui.library import android.os.Build +import android.util.Log import android.view.LayoutInflater import android.view.ViewGroup import androidx.core.view.doOnAttach import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.OnFlingListener +import com.google.android.material.appbar.AppBarLayout +import com.lagradost.cloudstream3.R import com.lagradost.cloudstream3.databinding.LibraryViewpagerPageBinding import com.lagradost.cloudstream3.syncproviders.SyncAPI import com.lagradost.cloudstream3.ui.search.SearchClickCallback +import com.lagradost.cloudstream3.ui.settings.SettingsFragment import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount class ViewpagerAdapter( @@ -67,6 +71,17 @@ class ViewpagerAdapter( if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { setOnScrollChangeListener { _, _, scrollY, _, oldScrollY -> val diff = scrollY - oldScrollY + + //Expand the top Appbar based on scroll direction up/down, simulate phone behavior + if (SettingsFragment.isTvSettings()) { + binding.root.rootView.findViewById(R.id.search_bar) + .apply { + if (diff <= 0) + setExpanded(true) + else + setExpanded(false) + } + } if (diff == 0) return@setOnScrollChangeListener scrollCallback.invoke(diff > 0) @@ -80,8 +95,6 @@ class ViewpagerAdapter( } } } - - } } diff --git a/app/src/main/res/layout/fragment_library_tv.xml b/app/src/main/res/layout/fragment_library_tv.xml index 22b9feb1..6d2198e9 100644 --- a/app/src/main/res/layout/fragment_library_tv.xml +++ b/app/src/main/res/layout/fragment_library_tv.xml @@ -27,7 +27,8 @@ android:id="@+id/search_status_bar_padding" android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="horizontal" + app:layout_scrollFlags="scroll|enterAlways"> + - + -