mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fix visibility
This commit is contained in:
parent
f98ce0558d
commit
6d51c59b18
2 changed files with 34 additions and 23 deletions
|
@ -385,7 +385,6 @@ class LibraryFragment : Fragment() {
|
||||||
val pages = resource.value
|
val pages = resource.value
|
||||||
val showNotice = pages.all { it.items.isEmpty() }
|
val showNotice = pages.all { it.items.isEmpty() }
|
||||||
|
|
||||||
|
|
||||||
binding?.apply {
|
binding?.apply {
|
||||||
emptyListTextview.isVisible = showNotice
|
emptyListTextview.isVisible = showNotice
|
||||||
if (showNotice) {
|
if (showNotice) {
|
||||||
|
@ -408,7 +407,10 @@ class LibraryFragment : Fragment() {
|
||||||
0,
|
0,
|
||||||
viewpager.adapter?.itemCount ?: 0
|
viewpager.adapter?.itemCount ?: 0
|
||||||
)
|
)
|
||||||
binding?.viewpager?.setCurrentItem(libraryViewModel.currentPage, false)
|
|
||||||
|
libraryViewModel.currentPage.value?.let { page ->
|
||||||
|
binding?.viewpager?.setCurrentItem(page, false)
|
||||||
|
}
|
||||||
|
|
||||||
// Only stop loading after 300ms to hide the fade effect the viewpager produces when updating
|
// Only stop loading after 300ms to hide the fade effect the viewpager produces when updating
|
||||||
// Without this there would be a flashing effect:
|
// Without this there would be a flashing effect:
|
||||||
|
@ -449,27 +451,26 @@ class LibraryFragment : Fragment() {
|
||||||
tab.view.nextFocusDownId = R.id.search_result_root
|
tab.view.nextFocusDownId = R.id.search_result_root
|
||||||
|
|
||||||
tab.view.setOnClickListener {
|
tab.view.setOnClickListener {
|
||||||
libraryViewModel.currentPage = position // updating selected library tab position
|
|
||||||
|
|
||||||
val currentItem =
|
val currentItem =
|
||||||
binding?.viewpager?.currentItem ?: return@setOnClickListener
|
binding?.viewpager?.currentItem ?: return@setOnClickListener
|
||||||
val distance = abs(position - currentItem)
|
val distance = abs(position - currentItem)
|
||||||
hideViewpager(distance)
|
hideViewpager(distance)
|
||||||
}
|
}
|
||||||
//Expand the appBar on tab focus
|
//Expand the appBar on tab focus
|
||||||
tab.view.setOnFocusChangeListener { view, b ->
|
tab.view.setOnFocusChangeListener { _, _ ->
|
||||||
binding?.searchBar?.setExpanded(true)
|
binding?.searchBar?.setExpanded(true)
|
||||||
}
|
}
|
||||||
}.attach()
|
}.attach()
|
||||||
|
|
||||||
binding?.libraryTabLayout?.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
binding?.libraryTabLayout?.addOnTabSelectedListener(object: TabLayout.OnTabSelectedListener {
|
||||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
override fun onTabSelected(tab: TabLayout.Tab?) {
|
||||||
libraryViewModel.currentPage = binding?.libraryTabLayout?.selectedTabPosition ?:0
|
binding?.libraryTabLayout?.selectedTabPosition?.let { page ->
|
||||||
|
libraryViewModel.switchPage(page)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) {}
|
override fun onTabUnselected(tab: TabLayout.Tab?) = Unit
|
||||||
override fun onTabReselected(tab: TabLayout.Tab?) {}
|
override fun onTabReselected(tab: TabLayout.Tab?) = Unit
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,24 +486,29 @@ class LibraryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
binding?.viewpager?.registerOnPageChangeCallback(object :
|
|
||||||
|
observe(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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*binding?.viewpager?.registerOnPageChangeCallback(object :
|
||||||
ViewPager2.OnPageChangeCallback() {
|
ViewPager2.OnPageChangeCallback() {
|
||||||
override fun onPageSelected(position: Int) {
|
override fun onPageSelected(position: Int) {
|
||||||
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)
|
super.onPageSelected(position)
|
||||||
}
|
}
|
||||||
})
|
})*/
|
||||||
}
|
}
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
(binding?.viewpager?.adapter as? ViewpagerAdapter)?.rebind()
|
(binding?.viewpager?.adapter as? ViewpagerAdapter)?.rebind()
|
||||||
|
|
|
@ -28,7 +28,12 @@ enum class ListSorting(@StringRes val stringRes: Int) {
|
||||||
const val LAST_SYNC_API_KEY = "last_sync_api"
|
const val LAST_SYNC_API_KEY = "last_sync_api"
|
||||||
|
|
||||||
class LibraryViewModel : ViewModel() {
|
class LibraryViewModel : ViewModel() {
|
||||||
var currentPage: Int = 0
|
fun switchPage(page : Int) {
|
||||||
|
_currentPage.postValue(page)
|
||||||
|
}
|
||||||
|
|
||||||
|
private val _currentPage: MutableLiveData<Int> = MutableLiveData(0)
|
||||||
|
val currentPage: LiveData<Int> = _currentPage
|
||||||
|
|
||||||
private val _pages: MutableLiveData<Resource<List<SyncAPI.Page>>> = MutableLiveData(null)
|
private val _pages: MutableLiveData<Resource<List<SyncAPI.Page>>> = MutableLiveData(null)
|
||||||
val pages: LiveData<Resource<List<SyncAPI.Page>>> = _pages
|
val pages: LiveData<Resource<List<SyncAPI.Page>>> = _pages
|
||||||
|
|
Loading…
Reference in a new issue