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 a259c3adb..ea1da77e9 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 6282d010f..38a4568d0 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 03420a510..71e598ded 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 04cb5bac0..540b95d95 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 f85ab3665..d04a9c56f 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)