From 3a1699f0b379febf529bb2b8e13d0c079a904667 Mon Sep 17 00:00:00 2001 From: len Date: Sat, 31 Dec 2016 16:19:32 +0100 Subject: [PATCH] Fix #373 and a few crashes --- .../tachiyomi/ui/base/activity/ActivityMixin.kt | 8 +++++++- .../tachiyomi/ui/base/activity/BaseActivity.kt | 5 ++--- .../tachiyomi/ui/base/activity/BaseRxActivity.kt | 5 ++--- .../kanade/tachiyomi/ui/library/LibraryPresenter.kt | 9 ++++++--- .../tachiyomi/ui/manga/chapter/ChaptersFragment.kt | 2 +- .../kanade/tachiyomi/ui/reader/ReaderPresenter.kt | 13 +++++++++++++ 6 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt index a259c3adb7..ea1da77e92 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/ActivityMixin.kt @@ -15,11 +15,17 @@ import uy.kohesive.injekt.api.get interface ActivityMixin { + var resumed: Boolean + fun setupToolbar(toolbar: Toolbar, backNavigation: Boolean = true) { setSupportActionBar(toolbar) getSupportActionBar()?.setDisplayHomeAsUpEnabled(true) if (backNavigation) { - toolbar.setNavigationOnClickListener { onBackPressed() } + toolbar.setNavigationOnClickListener { + if (resumed) { + onBackPressed() + } + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index 6282d010fa..38a4568d06 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -5,15 +5,14 @@ import eu.kanade.tachiyomi.util.LocaleHelper abstract class BaseActivity : AppCompatActivity(), ActivityMixin { + override var resumed = false + init { LocaleHelper.updateConfiguration(this) } override fun getActivity() = this - var resumed = false - private set - override fun onResume() { super.onResume() resumed = true diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 03420a510b..71e598dedc 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -8,6 +8,8 @@ import nucleus.view.NucleusAppCompatActivity abstract class BaseRxActivity

> : NucleusAppCompatActivity

(), ActivityMixin { + override var resumed = false + init { LocaleHelper.updateConfiguration(this) } @@ -25,9 +27,6 @@ abstract class BaseRxActivity

> : NucleusAppCompatActivity

() { * * @param mangas the list of manga. */ - fun getCommonCategories(mangas: List): Collection = mangas.toSet() - .map { db.getCategoriesForManga(it).executeAsBlocking() } - .reduce { set1: Iterable, set2 -> set1.intersect(set2) } + fun getCommonCategories(mangas: List): Collection { + if (mangas.isEmpty()) return emptyList() + return mangas.toSet() + .map { db.getCategoriesForManga(it).executeAsBlocking() } + .reduce { set1: Iterable, set2 -> set1.intersect(set2) } + } /** * Remove the selected manga from the library. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt index 04cb5bac0f..540b95d950 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt @@ -118,7 +118,7 @@ class ChaptersFragment : BaseRxFragment(), ActionMode.Callbac override fun onPrepareOptionsMenu(menu: Menu) { // Initialize menu items. - val menuFilterRead = menu.findItem(R.id.action_filter_read) + val menuFilterRead = menu.findItem(R.id.action_filter_read) ?: return val menuFilterUnread = menu.findItem(R.id.action_filter_unread) val menuFilterDownloaded = menu.findItem(R.id.action_filter_downloaded) val menuFilterBookmarked = menu.findItem(R.id.action_filter_bookmarked) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt index f85ab36654..d04a9c56fe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt @@ -141,6 +141,11 @@ class ReaderPresenter : BasePresenter() { */ private var adjacentChaptersSubscription: Subscription? = null + /** + * Whether the active chapter has been loaded. + */ + private var chapterLoaded = false + companion object { /** * Id of the restartable that loads the active chapter. @@ -211,6 +216,7 @@ class ReaderPresenter : BasePresenter() { return loader.loadChapter(chapter) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) + .doOnNext { chapterLoaded = true } } /** @@ -298,6 +304,7 @@ class ReaderPresenter : BasePresenter() { nextChapter = null prevChapter = null + chapterLoaded = false start(LOAD_ACTIVE_CHAPTER) getAdjacentChapters(chapter) } @@ -474,6 +481,9 @@ class ReaderPresenter : BasePresenter() { * @return true if the next chapter is being loaded, false if there is no next chapter. */ fun loadNextChapter(): Boolean { + // Avoid skipping chapters. + if (!chapterLoaded) return true + nextChapter?.let { onChapterLeft() loadChapter(it, 0) @@ -488,6 +498,9 @@ class ReaderPresenter : BasePresenter() { * @return true if the previous chapter is being loaded, false if there is no previous chapter. */ fun loadPreviousChapter(): Boolean { + // Avoid skipping chapters. + if (!chapterLoaded) return true + prevChapter?.let { onChapterLeft() loadChapter(it, if (it.read) -1 else 0)