|
@@ -9,13 +9,11 @@ import com.f2prateek.rx.preferences.Preference
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
|
import eu.kanade.tachiyomi.R
|
|
import eu.kanade.tachiyomi.R
|
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
import eu.kanade.tachiyomi.data.database.models.Manga
|
|
-import eu.kanade.tachiyomi.event.LibraryMangasEvent
|
|
|
|
|
|
+import eu.kanade.tachiyomi.event.LibraryMangaEvent
|
|
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
|
import eu.kanade.tachiyomi.ui.base.adapter.FlexibleViewHolder
|
|
import eu.kanade.tachiyomi.ui.base.fragment.BaseFragment
|
|
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 org.greenrobot.eventbus.Subscribe
|
|
|
|
-import org.greenrobot.eventbus.ThreadMode
|
|
|
|
import rx.Subscription
|
|
import rx.Subscription
|
|
import java.util.*
|
|
import java.util.*
|
|
|
|
|
|
@@ -44,6 +42,11 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
field = value ?: ArrayList()
|
|
field = value ?: ArrayList()
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Subscription for the library manga.
|
|
|
|
+ */
|
|
|
|
+ private var libraryMangaSubscription: Subscription? = null
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* Subscription of the number of manga per row.
|
|
* Subscription of the number of manga per row.
|
|
*/
|
|
*/
|
|
@@ -115,11 +118,12 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
|
|
|
|
override fun onResume() {
|
|
override fun onResume() {
|
|
super.onResume()
|
|
super.onResume()
|
|
- registerForEvents()
|
|
|
|
|
|
+ libraryMangaSubscription = libraryPresenter.libraryMangaSubject
|
|
|
|
+ .subscribe({ onNextLibraryManga(it) })
|
|
}
|
|
}
|
|
|
|
|
|
override fun onPause() {
|
|
override fun onPause() {
|
|
- unregisterForEvents()
|
|
|
|
|
|
+ libraryMangaSubscription?.unsubscribe()
|
|
super.onPause()
|
|
super.onPause()
|
|
}
|
|
}
|
|
|
|
|
|
@@ -130,13 +134,12 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
- * Subscribe to [LibraryMangasEvent]. When an event is received, it updates [mangas] if needed
|
|
|
|
|
|
+ * Subscribe to [LibraryMangaEvent]. When an event is received, it updates [mangas] if needed
|
|
* and refresh the content of the adapter.
|
|
* and refresh the content of the adapter.
|
|
*
|
|
*
|
|
* @param event the event received.
|
|
* @param event the event received.
|
|
*/
|
|
*/
|
|
- @Subscribe(sticky = true, threadMode = ThreadMode.MAIN)
|
|
|
|
- fun onEvent(event: LibraryMangasEvent) {
|
|
|
|
|
|
+ fun onNextLibraryManga(event: LibraryMangaEvent?) {
|
|
// Get the categories from the parent fragment.
|
|
// Get the categories from the parent fragment.
|
|
val categories = libraryFragment.adapter.categories ?: return
|
|
val categories = libraryFragment.adapter.categories ?: return
|
|
|
|
|
|
@@ -144,13 +147,13 @@ class LibraryCategoryFragment : BaseFragment(), FlexibleViewHolder.OnListItemCli
|
|
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?.getMangasForCategory(categories[position])
|
|
|
|
|
|
// Update the list only if the reference to the list is different, avoiding reseting the
|
|
// Update the list only if the reference to the list is different, avoiding reseting the
|
|
// adapter after every onResume.
|
|
// adapter after every onResume.
|
|
if (mangas !== mangaForCategory) {
|
|
if (mangas !== mangaForCategory) {
|
|
mangas = mangaForCategory
|
|
mangas = mangaForCategory
|
|
- mangas?.let { adapter.setItems(it) }
|
|
|
|
|
|
+ adapter.setItems(mangas ?: emptyList())
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|