This commit is contained in:
LagradOst 2023-10-07 01:54:34 +02:00
parent 77294dc68e
commit f14557fe6a
2 changed files with 10 additions and 0 deletions

View file

@ -15,6 +15,7 @@ import androidx.appcompat.widget.SearchView
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
import androidx.viewpager2.widget.ViewPager2
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
@ -229,6 +230,7 @@ class LibraryFragment : Fragment() {
} }
binding?.viewpager?.setPageTransformer(LibraryScrollTransformer()) binding?.viewpager?.setPageTransformer(LibraryScrollTransformer())
binding?.viewpager?.adapter = binding?.viewpager?.adapter =
binding?.viewpager?.adapter ?: ViewpagerAdapter( binding?.viewpager?.adapter ?: ViewpagerAdapter(
mutableListOf(), mutableListOf(),
@ -357,6 +359,7 @@ class LibraryFragment : Fragment() {
0, 0,
viewpager.adapter?.itemCount ?: 0 viewpager.adapter?.itemCount ?: 0
) )
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:
@ -415,6 +418,11 @@ class LibraryFragment : Fragment() {
} }
} }
} }
binding?.viewpager?.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
libraryViewModel.currentPage = position
}
})
} }
override fun onConfigurationChanged(newConfig: Configuration) { override fun onConfigurationChanged(newConfig: Configuration) {

View file

@ -30,6 +30,8 @@ class LibraryViewModel : ViewModel() {
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
var currentPage : Int = 0
private val _currentApiName: MutableLiveData<String> = MutableLiveData("") private val _currentApiName: MutableLiveData<String> = MutableLiveData("")
val currentApiName: LiveData<String> = _currentApiName val currentApiName: LiveData<String> = _currentApiName