Skip to content

Commit

Permalink
Fix scroll for Library TV layout (#695)
Browse files Browse the repository at this point in the history
* Fix scroll for Library TV layout

* Fixed without NestedScrollView
  • Loading branch information
KingLucius authored Nov 2, 2023
1 parent 6f40d27 commit 908f83c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -137,6 +138,10 @@ class LibraryFragment : Fragment() {

binding?.libraryRoot?.findViewById<TextView>(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
Expand Down Expand Up @@ -342,6 +347,7 @@ class LibraryFragment : Fragment() {
binding?.apply {
viewpager.offscreenPageLimit = 2
viewpager.reduceDragSensitivity()
searchBar.setExpanded(true)
}

val startLoading = Runnable {
Expand Down Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -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<AppBarLayout>(R.id.search_bar)
.apply {
if (diff <= 0)
setExpanded(true)
else
setExpanded(false)
}
}
if (diff == 0) return@setOnScrollChangeListener

scrollCallback.invoke(diff > 0)
Expand All @@ -80,8 +95,6 @@ class ViewpagerAdapter(
}
}
}


}
}

Expand Down
25 changes: 13 additions & 12 deletions app/src/main/res/layout/fragment_library_tv.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<ImageView
android:id="@+id/provider_selector"
Expand Down Expand Up @@ -108,6 +109,7 @@
</androidx.appcompat.widget.SearchView>
</FrameLayout>
</LinearLayout>

<com.google.android.material.tabs.TabLayout
android:id="@+id/library_tab_layout"
style="@style/Theme.Widget.Tabs"
Expand All @@ -117,7 +119,7 @@
android:nextFocusDown="@id/search_result_root"
android:background="?attr/primaryGrayBackground"
android:paddingHorizontal="5dp"
app:layout_scrollFlags="noScroll"
android:focusable="true"
app:tabGravity="center"
app:tabIndicator="@drawable/indicator_background"
app:tabIndicatorColor="?attr/white"
Expand All @@ -134,15 +136,15 @@
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="40dp"
android:focusable="true"
android:tag="@string/tv_no_focus_tag"
tools:listitem="@layout/library_viewpager_page" />
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="40dp"
android:focusable="true"
android:tag="@string/tv_no_focus_tag"
tools:listitem="@layout/library_viewpager_page" />

<LinearLayout
android:id="@+id/library_loading_overlay"
Expand Down Expand Up @@ -182,7 +184,6 @@
tools:listitem="@layout/loading_poster_dynamic" />
</com.facebook.shimmer.ShimmerFrameLayout>
</LinearLayout>

</FrameLayout>

<FrameLayout
Expand Down

0 comments on commit 908f83c

Please sign in to comment.