mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
fixes (library): reverted and updated currentPage logic (#802)
Co-authored-by: Funny-Pen-7005 <Funny-Pen-7005>
This commit is contained in:
parent
3ef8f3030c
commit
530619c8d0
2 changed files with 4 additions and 24 deletions
|
@ -25,7 +25,6 @@ import androidx.fragment.app.Fragment
|
||||||
import androidx.fragment.app.activityViewModels
|
import androidx.fragment.app.activityViewModels
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import androidx.viewpager2.widget.ViewPager2
|
import androidx.viewpager2.widget.ViewPager2
|
||||||
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
|
||||||
import com.lagradost.cloudstream3.APIHolder.allProviders
|
import com.lagradost.cloudstream3.APIHolder.allProviders
|
||||||
|
@ -398,7 +397,7 @@ class LibraryFragment : Fragment() {
|
||||||
0,
|
0,
|
||||||
viewpager.adapter?.itemCount ?: 0
|
viewpager.adapter?.itemCount ?: 0
|
||||||
)
|
)
|
||||||
binding?.viewpager?.setCurrentItem(libraryViewModel.getTabPosition().value ?: 0, false)
|
binding?.viewpager?.setCurrentItem(libraryViewModel.currentPage, 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:
|
||||||
|
@ -439,6 +438,8 @@ 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)
|
||||||
|
@ -450,19 +451,6 @@ class LibraryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
}.attach()
|
}.attach()
|
||||||
|
|
||||||
binding?.libraryTabLayout?.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
|
|
||||||
override fun onTabSelected(tab: TabLayout.Tab?) {
|
|
||||||
val position = tab?.position ?: 0
|
|
||||||
libraryViewModel.setTabPosition(position)
|
|
||||||
}
|
|
||||||
override fun onTabUnselected(tab: TabLayout.Tab?) = Unit
|
|
||||||
override fun onTabReselected(tab: TabLayout.Tab?) = Unit
|
|
||||||
})
|
|
||||||
|
|
||||||
libraryViewModel.getTabPosition().observe(viewLifecycleOwner) { position ->
|
|
||||||
binding?.libraryTabLayout?.getTabAt(position)?.select()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,15 +28,7 @@ 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() {
|
||||||
private val tabPositionLiveData = MutableLiveData<Int>()
|
var currentPage: Int = 0
|
||||||
|
|
||||||
fun setTabPosition(position: Int) {
|
|
||||||
tabPositionLiveData.value = position
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getTabPosition(): LiveData<Int> {
|
|
||||||
return tabPositionLiveData
|
|
||||||
}
|
|
||||||
|
|
||||||
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