From 4befcf3819139c61495828282d51634cbbae90d9 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 23 Apr 2016 15:39:41 +0200 Subject: [PATCH] Fix #277, library not updating --- .../tachiyomi/event/LibraryMangaEvent.kt | 2 +- .../ui/library/LibraryCategoryFragment.kt | 27 ++++---------- .../tachiyomi/ui/library/LibraryFragment.kt | 5 +++ .../tachiyomi/ui/library/LibraryPresenter.kt | 37 +++++++++---------- 4 files changed, 30 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/event/LibraryMangaEvent.kt b/app/src/main/java/eu/kanade/tachiyomi/event/LibraryMangaEvent.kt index 8c6c55cde..ce4a21219 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/event/LibraryMangaEvent.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/event/LibraryMangaEvent.kt @@ -5,7 +5,7 @@ import eu.kanade.tachiyomi.data.database.models.Manga class LibraryMangaEvent(val mangas: Map>) { - fun getMangasForCategory(category: Category): List? { + fun getMangaForCategory(category: Category): List? { return mangas[category.id] } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt index 0c4819083..b130b9850 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryCategoryFragment.kt @@ -15,7 +15,6 @@ import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment import eu.kanade.tachiyomi.ui.manga.MangaActivity import kotlinx.android.synthetic.main.fragment_library_category.* import rx.Subscription -import java.util.* /** * Fragment containing the library manga for a certain category. @@ -34,14 +33,6 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli */ private var position: Int = 0 - /** - * Manga in this category. - */ - private var mangas: List? = null - set(value) { - field = value ?: ArrayList() - } - /** * Subscription for the library manga. */ @@ -119,7 +110,7 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli override fun onResume() { super.onResume() libraryMangaSubscription = libraryPresenter.libraryMangaSubject - .subscribe { if (it != null) onNextLibraryManga(it) } + .subscribe { onNextLibraryManga(it) } } 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 - * and refresh the content of the adapter. + * Subscribe to [LibraryMangaEvent]. When an event is received, it updates the content of the + * adapter. * * @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. if (position >= categories.size) return - // Get the manga list for this category - val mangaForCategory = event.getMangasForCategory(categories[position]) + // Get the manga list for this category. + val mangaForCategory = event.getMangaForCategory(categories[position]) ?: emptyList() - // Update the list only if the reference to the list is different, avoiding reseting the - // adapter after every onResume. - if (mangas !== mangaForCategory) { - mangas = mangaForCategory - adapter.setItems(mangas ?: emptyList()) - } + // Update the category with its manga. + adapter.setItems(mangaForCategory) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt index d3a145380..fe7e02212 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryFragment.kt @@ -125,6 +125,11 @@ class LibraryFragment : BaseRxFragment(), ActionMode.Callback } } + override fun onResume() { + super.onResume() + presenter.subscribeLibrary() + } + override fun onDestroyView() { tabs.visibility = View.GONE super.onDestroyView() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 34b6d8798..e92e9128f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -44,7 +44,7 @@ class LibraryPresenter : BasePresenter() { /** * Subject to notify the library's viewpager for updates. */ - val libraryMangaSubject = BehaviorSubject.create() + val libraryMangaSubject = BehaviorSubject.create() /** * Database. @@ -91,18 +91,6 @@ class LibraryPresenter : BasePresenter() { } - 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. * @@ -114,13 +102,6 @@ class LibraryPresenter : BasePresenter() { .observeOn(AndroidSchedulers.mainThread()) } - /** - * Update the library information - */ - fun updateLibrary() { - start(GET_LIBRARY) - } - /** * Get the categories from the database. * @@ -151,6 +132,22 @@ class LibraryPresenter : BasePresenter() { } } + /** + * 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 *