mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fix scroll for Library TV layout (#695)
* Fix scroll for Library TV layout * Fixed without NestedScrollView
This commit is contained in:
parent
6f40d2750f
commit
908f83c50e
3 changed files with 38 additions and 14 deletions
|
@ -27,6 +27,7 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
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.TabLayout
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
import com.google.android.material.tabs.TabLayoutMediator
|
||||||
import com.lagradost.cloudstream3.APIHolder
|
import com.lagradost.cloudstream3.APIHolder
|
||||||
|
@ -137,6 +138,10 @@ class LibraryFragment : Fragment() {
|
||||||
|
|
||||||
binding?.libraryRoot?.findViewById<TextView>(R.id.search_src_text)?.apply {
|
binding?.libraryRoot?.findViewById<TextView>(R.id.search_src_text)?.apply {
|
||||||
tag = "tv_no_focus_tag"
|
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
|
// Set the color for the search exit icon to the correct theme text color
|
||||||
|
@ -342,6 +347,7 @@ class LibraryFragment : Fragment() {
|
||||||
binding?.apply {
|
binding?.apply {
|
||||||
viewpager.offscreenPageLimit = 2
|
viewpager.offscreenPageLimit = 2
|
||||||
viewpager.reduceDragSensitivity()
|
viewpager.reduceDragSensitivity()
|
||||||
|
searchBar.setExpanded(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
val startLoading = Runnable {
|
val startLoading = Runnable {
|
||||||
|
@ -441,6 +447,10 @@ class LibraryFragment : Fragment() {
|
||||||
val distance = abs(position - currentItem)
|
val distance = abs(position - currentItem)
|
||||||
hideViewpager(distance)
|
hideViewpager(distance)
|
||||||
}
|
}
|
||||||
|
//Expand the appBar on tab focus
|
||||||
|
tab.view.setOnFocusChangeListener { view, b ->
|
||||||
|
binding?.searchBar?.setExpanded(true)
|
||||||
|
}
|
||||||
}.attach()
|
}.attach()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
package com.lagradost.cloudstream3.ui.library
|
package com.lagradost.cloudstream3.ui.library
|
||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.core.view.doOnAttach
|
import androidx.core.view.doOnAttach
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.recyclerview.widget.RecyclerView.OnFlingListener
|
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.databinding.LibraryViewpagerPageBinding
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
|
import com.lagradost.cloudstream3.ui.search.SearchClickCallback
|
||||||
|
import com.lagradost.cloudstream3.ui.settings.SettingsFragment
|
||||||
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
|
import com.lagradost.cloudstream3.utils.UIHelper.getSpanCount
|
||||||
|
|
||||||
class ViewpagerAdapter(
|
class ViewpagerAdapter(
|
||||||
|
@ -67,6 +71,17 @@ class ViewpagerAdapter(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||||
setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
setOnScrollChangeListener { _, _, scrollY, _, oldScrollY ->
|
||||||
val diff = 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<AppBarLayout>(R.id.search_bar)
|
||||||
|
.apply {
|
||||||
|
if (diff <= 0)
|
||||||
|
setExpanded(true)
|
||||||
|
else
|
||||||
|
setExpanded(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
if (diff == 0) return@setOnScrollChangeListener
|
if (diff == 0) return@setOnScrollChangeListener
|
||||||
|
|
||||||
scrollCallback.invoke(diff > 0)
|
scrollCallback.invoke(diff > 0)
|
||||||
|
@ -80,8 +95,6 @@ class ViewpagerAdapter(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,8 @@
|
||||||
android:id="@+id/search_status_bar_padding"
|
android:id="@+id/search_status_bar_padding"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal">
|
android:orientation="horizontal"
|
||||||
|
app:layout_scrollFlags="scroll|enterAlways">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/provider_selector"
|
android:id="@+id/provider_selector"
|
||||||
|
@ -108,6 +109,7 @@
|
||||||
</androidx.appcompat.widget.SearchView>
|
</androidx.appcompat.widget.SearchView>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.tabs.TabLayout
|
<com.google.android.material.tabs.TabLayout
|
||||||
android:id="@+id/library_tab_layout"
|
android:id="@+id/library_tab_layout"
|
||||||
style="@style/Theme.Widget.Tabs"
|
style="@style/Theme.Widget.Tabs"
|
||||||
|
@ -117,7 +119,7 @@
|
||||||
android:nextFocusDown="@id/search_result_root"
|
android:nextFocusDown="@id/search_result_root"
|
||||||
android:background="?attr/primaryGrayBackground"
|
android:background="?attr/primaryGrayBackground"
|
||||||
android:paddingHorizontal="5dp"
|
android:paddingHorizontal="5dp"
|
||||||
app:layout_scrollFlags="noScroll"
|
android:focusable="true"
|
||||||
app:tabGravity="center"
|
app:tabGravity="center"
|
||||||
app:tabIndicator="@drawable/indicator_background"
|
app:tabIndicator="@drawable/indicator_background"
|
||||||
app:tabIndicatorColor="?attr/white"
|
app:tabIndicatorColor="?attr/white"
|
||||||
|
@ -182,7 +184,6 @@
|
||||||
tools:listitem="@layout/loading_poster_dynamic" />
|
tools:listitem="@layout/loading_poster_dynamic" />
|
||||||
</com.facebook.shimmer.ShimmerFrameLayout>
|
</com.facebook.shimmer.ShimmerFrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
|
Loading…
Reference in a new issue