mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Fix #277, library not updating
This commit is contained in:
parent
cb58145361
commit
4befcf3819
4 changed files with 30 additions and 41 deletions
|
@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga
|
||||||
|
|
||||||
class LibraryMangaEvent(val mangas: Map<Int, List<Manga>>) {
|
class LibraryMangaEvent(val mangas: Map<Int, List<Manga>>) {
|
||||||
|
|
||||||
fun getMangasForCategory(category: Category): List<Manga>? {
|
fun getMangaForCategory(category: Category): List<Manga>? {
|
||||||
return mangas[category.id]
|
return mangas[category.id]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
import eu.kanade.tachiyomi.ui.manga.MangaActivity
|
||||||
import kotlinx.android.synthetic.main.fragment_library_category.*
|
import kotlinx.android.synthetic.main.fragment_library_category.*
|
||||||
import rx.Subscription
|
import rx.Subscription
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fragment containing the library manga for a certain category.
|
* Fragment containing the library manga for a certain category.
|
||||||
|
@ -34,14 +33,6 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||||
*/
|
*/
|
||||||
private var position: Int = 0
|
private var position: Int = 0
|
||||||
|
|
||||||
/**
|
|
||||||
* Manga in this category.
|
|
||||||
*/
|
|
||||||
private var mangas: List<Manga>? = null
|
|
||||||
set(value) {
|
|
||||||
field = value ?: ArrayList()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscription for the library manga.
|
* Subscription for the library manga.
|
||||||
*/
|
*/
|
||||||
|
@ -119,7 +110,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
||||||
.subscribe { if (it != null) onNextLibraryManga(it) }
|
.subscribe { onNextLibraryManga(it) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPause() {
|
override fun onPause() {
|
||||||
|
@ -134,8 +125,8 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subscribe to [LibraryMangaEvent]. When an event is received, it updates [mangas] if needed
|
* Subscribe to [LibraryMangaEvent]. When an event is received, it updates the content of the
|
||||||
* and refresh the content of the adapter.
|
* adapter.
|
||||||
*
|
*
|
||||||
* @param event the event received.
|
* @param event the event received.
|
||||||
*/
|
*/
|
||||||
|
@ -146,15 +137,11 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
||||||
// When a category is deleted, the index can be greater than the number of categories.
|
// When a category is deleted, the index can be greater than the number of categories.
|
||||||
if (position >= categories.size) return
|
if (position >= categories.size) return
|
||||||
|
|
||||||
// Get the manga list for this category
|
// Get the manga list for this category.
|
||||||
val mangaForCategory = event.getMangasForCategory(categories[position])
|
val mangaForCategory = event.getMangaForCategory(categories[position]) ?: emptyList()
|
||||||
|
|
||||||
// Update the list only if the reference to the list is different, avoiding reseting the
|
// Update the category with its manga.
|
||||||
// adapter after every onResume.
|
adapter.setItems(mangaForCategory)
|
||||||
if (mangas !== mangaForCategory) {
|
|
||||||
mangas = mangaForCategory
|
|
||||||
adapter.setItems(mangas ?: emptyList())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -125,6 +125,11 @@ class LibraryFragment : BaseRxFragment<LibraryPresenter>(), ActionMode.Callback
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onResume() {
|
||||||
|
super.onResume()
|
||||||
|
presenter.subscribeLibrary()
|
||||||
|
}
|
||||||
|
|
||||||
override fun onDestroyView() {
|
override fun onDestroyView() {
|
||||||
tabs.visibility = View.GONE
|
tabs.visibility = View.GONE
|
||||||
super.onDestroyView()
|
super.onDestroyView()
|
||||||
|
|
|
@ -44,7 +44,7 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||||
/**
|
/**
|
||||||
* Subject to notify the library's viewpager for updates.
|
* Subject to notify the library's viewpager for updates.
|
||||||
*/
|
*/
|
||||||
val libraryMangaSubject = BehaviorSubject.create<LibraryMangaEvent?>()
|
val libraryMangaSubject = BehaviorSubject.create<LibraryMangaEvent>()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database.
|
* Database.
|
||||||
|
@ -91,18 +91,6 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDropView() {
|
|
||||||
libraryMangaSubject.onNext(null)
|
|
||||||
super.onDropView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTakeView(libraryFragment: LibraryFragment) {
|
|
||||||
super.onTakeView(libraryFragment)
|
|
||||||
if (isUnsubscribed(GET_LIBRARY)) {
|
|
||||||
start(GET_LIBRARY)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the categories and all its manga from the database.
|
* Get the categories and all its manga from the database.
|
||||||
*
|
*
|
||||||
|
@ -114,13 +102,6 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||||
.observeOn(AndroidSchedulers.mainThread())
|
.observeOn(AndroidSchedulers.mainThread())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the library information
|
|
||||||
*/
|
|
||||||
fun updateLibrary() {
|
|
||||||
start(GET_LIBRARY)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the categories from the database.
|
* Get the categories from the database.
|
||||||
*
|
*
|
||||||
|
@ -151,6 +132,22 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resubscribes to library if needed.
|
||||||
|
*/
|
||||||
|
fun subscribeLibrary() {
|
||||||
|
if (isUnsubscribed(GET_LIBRARY)) {
|
||||||
|
start(GET_LIBRARY)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resubscribes to library.
|
||||||
|
*/
|
||||||
|
fun updateLibrary() {
|
||||||
|
start(GET_LIBRARY)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Filter library by preference
|
* Filter library by preference
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue