mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fixed rotation and loading delay
This commit is contained in:
parent
7512dbcbf8
commit
ef7e0ecf0d
3 changed files with 16 additions and 6 deletions
|
@ -360,6 +360,7 @@ class LibraryFragment : Fragment() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
(viewpager.adapter as? ViewpagerAdapter)?.rebind()
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,7 +97,6 @@ class LibraryViewModel : ViewModel() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
delay(5000)
|
|
||||||
_pages.postValue(Resource.Success(pages))
|
_pages.postValue(Resource.Success(pages))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,18 +28,28 @@ 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])
|
holder.bind(pages[position], unbound.remove(position))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val unbound = mutableSetOf<Int>()
|
||||||
|
/**
|
||||||
|
* Used to mark all pages for re-binding and forces all items to be refreshed
|
||||||
|
* Without this the pages will still use the same adapters
|
||||||
|
**/
|
||||||
|
fun rebind() {
|
||||||
|
unbound.addAll(0..pages.size)
|
||||||
|
this.notifyItemRangeChanged(0, pages.size)
|
||||||
|
}
|
||||||
|
|
||||||
inner class PageViewHolder(private val itemViewTest: View) :
|
inner class PageViewHolder(private val itemViewTest: View) :
|
||||||
RecyclerView.ViewHolder(itemViewTest) {
|
RecyclerView.ViewHolder(itemViewTest) {
|
||||||
fun bind(page: SyncAPI.Page) {
|
fun bind(page: SyncAPI.Page, rebind: Boolean) {
|
||||||
if (itemViewTest.page_recyclerview?.adapter == null) {
|
|
||||||
itemView.page_recyclerview?.spanCount =
|
itemView.page_recyclerview?.spanCount =
|
||||||
this@PageViewHolder.itemView.context.getSpanCount() ?: 3
|
this@PageViewHolder.itemView.context.getSpanCount() ?: 3
|
||||||
|
|
||||||
|
if (itemViewTest.page_recyclerview?.adapter == null || rebind) {
|
||||||
// Only add the items after it has been attached since the items rely on ItemWidth
|
// Only add the items after it has been attached since the items rely on ItemWidth
|
||||||
// Which is only determined after the recyclerview is attached.
|
// Which is only determined after the recyclerview is attached.
|
||||||
// If this fails then item height becomes 0 when there is only one item
|
// If this fails then item height becomes 0 when there is only one item
|
||||||
|
|
Loading…
Reference in a new issue