mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Possible fix for viewpager focus
This commit is contained in:
parent
548f390026
commit
5a548b227f
2 changed files with 22 additions and 4 deletions
|
@ -10,11 +10,14 @@ import android.os.Looper
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.ViewGroup.FOCUS_AFTER_DESCENDANTS
|
||||||
|
import android.view.ViewGroup.FOCUS_BLOCK_DESCENDANTS
|
||||||
import android.view.animation.AlphaAnimation
|
import android.view.animation.AlphaAnimation
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
import androidx.appcompat.widget.SearchView
|
import androidx.appcompat.widget.SearchView
|
||||||
|
import androidx.core.view.allViews
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
|
@ -35,6 +38,7 @@ import com.lagradost.cloudstream3.mvvm.logError
|
||||||
import com.lagradost.cloudstream3.mvvm.observe
|
import com.lagradost.cloudstream3.mvvm.observe
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
import com.lagradost.cloudstream3.syncproviders.SyncAPI
|
||||||
import com.lagradost.cloudstream3.syncproviders.SyncIdName
|
import com.lagradost.cloudstream3.syncproviders.SyncIdName
|
||||||
|
import com.lagradost.cloudstream3.ui.AutofitRecyclerView
|
||||||
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
|
import com.lagradost.cloudstream3.ui.quicksearch.QuickSearchFragment
|
||||||
import com.lagradost.cloudstream3.ui.result.txt
|
import com.lagradost.cloudstream3.ui.result.txt
|
||||||
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
|
import com.lagradost.cloudstream3.ui.search.SEARCH_ACTION_LOAD
|
||||||
|
@ -441,9 +445,22 @@ class LibraryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding?.viewpager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
binding?.viewpager?.registerOnPageChangeCallback(object :
|
||||||
|
ViewPager2.OnPageChangeCallback() {
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
libraryViewModel.currentPage = position
|
val all = binding?.viewpager?.allViews?.toList()
|
||||||
|
?.filterIsInstance<AutofitRecyclerView>()
|
||||||
|
|
||||||
|
all?.forEach { view ->
|
||||||
|
view.isVisible = view.tag == position
|
||||||
|
view.isFocusable = view.tag == position
|
||||||
|
|
||||||
|
if (view.tag == position)
|
||||||
|
view.descendantFocusability = FOCUS_AFTER_DESCENDANTS
|
||||||
|
else
|
||||||
|
view.descendantFocusability = FOCUS_BLOCK_DESCENDANTS
|
||||||
|
}
|
||||||
|
super.onPageSelected(position)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ class ViewpagerAdapter(
|
||||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||||
when (holder) {
|
when (holder) {
|
||||||
is PageViewHolder -> {
|
is PageViewHolder -> {
|
||||||
holder.bind(pages[position], unbound.remove(position))
|
holder.bind(pages[position], position, unbound.remove(position))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,8 @@ class ViewpagerAdapter(
|
||||||
|
|
||||||
inner class PageViewHolder(private val binding: LibraryViewpagerPageBinding) :
|
inner class PageViewHolder(private val binding: LibraryViewpagerPageBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
fun bind(page: SyncAPI.Page, rebind: Boolean) {
|
fun bind(page: SyncAPI.Page, position: Int, rebind: Boolean) {
|
||||||
|
binding.pageRecyclerview.tag = position
|
||||||
binding.pageRecyclerview.apply {
|
binding.pageRecyclerview.apply {
|
||||||
spanCount =
|
spanCount =
|
||||||
this@PageViewHolder.itemView.context.getSpanCount() ?: 3
|
this@PageViewHolder.itemView.context.getSpanCount() ?: 3
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue