Fix library not being updated
Cette révision appartient à :
Parent
297fed6aef
révision
d94dc68830
3 fichiers modifiés avec 18 ajouts et 3 suppressions
|
@ -26,6 +26,8 @@ class LibraryAdapter(private val controller: LibraryController) : RecyclerViewPa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var boundViews = arrayListOf<View>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new view for this adapter.
|
* Creates a new view for this adapter.
|
||||||
*
|
*
|
||||||
|
@ -45,6 +47,7 @@ class LibraryAdapter(private val controller: LibraryController) : RecyclerViewPa
|
||||||
*/
|
*/
|
||||||
override fun bindView(view: View, position: Int) {
|
override fun bindView(view: View, position: Int) {
|
||||||
(view as LibraryCategoryView).onBind(categories[position])
|
(view as LibraryCategoryView).onBind(categories[position])
|
||||||
|
boundViews.add(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +58,7 @@ class LibraryAdapter(private val controller: LibraryController) : RecyclerViewPa
|
||||||
*/
|
*/
|
||||||
override fun recycleView(view: View, position: Int) {
|
override fun recycleView(view: View, position: Int) {
|
||||||
(view as LibraryCategoryView).onRecycle()
|
(view as LibraryCategoryView).onRecycle()
|
||||||
|
boundViews.remove(view)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -85,4 +89,15 @@ class LibraryAdapter(private val controller: LibraryController) : RecyclerViewPa
|
||||||
return if (index == -1) POSITION_NONE else index
|
return if (index == -1) POSITION_NONE else index
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when the view of this adapter is being destroyed.
|
||||||
|
*/
|
||||||
|
fun onDestroy() {
|
||||||
|
for (view in boundViews) {
|
||||||
|
if (view is LibraryCategoryView) {
|
||||||
|
view.unsubscribe()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -124,12 +124,11 @@ class LibraryCategoryView @JvmOverloads constructor(context: Context, attrs: Att
|
||||||
fun onRecycle() {
|
fun onRecycle() {
|
||||||
adapter.setItems(emptyList())
|
adapter.setItems(emptyList())
|
||||||
adapter.clearSelection()
|
adapter.clearSelection()
|
||||||
subscriptions.clear()
|
unsubscribe()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDetachedFromWindow() {
|
fun unsubscribe() {
|
||||||
subscriptions.clear()
|
subscriptions.clear()
|
||||||
super.onDetachedFromWindow()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -164,6 +164,7 @@ class LibraryController(
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroyView(view: View) {
|
override fun onDestroyView(view: View) {
|
||||||
|
adapter?.onDestroy()
|
||||||
adapter = null
|
adapter = null
|
||||||
actionMode = null
|
actionMode = null
|
||||||
tabsVisibilitySubscription?.unsubscribe()
|
tabsVisibilitySubscription?.unsubscribe()
|
||||||
|
|
Référencer dans un nouveau ticket