len 8 жил өмнө
parent
commit
3a1699f0b3

+ 7 - 1
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()
+                }
+            }
         }
     }
 

+ 2 - 3
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

+ 2 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt

@@ -8,6 +8,8 @@ import nucleus.view.NucleusAppCompatActivity
 
 abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P>(), ActivityMixin {
 
+    override var resumed = false
+
     init {
         LocaleHelper.updateConfiguration(this)
     }
@@ -25,9 +27,6 @@ abstract class BaseRxActivity<P : BasePresenter<*>> : NucleusAppCompatActivity<P
 
     override fun getActivity() = this
 
-    var resumed = false
-        private set
-
     override fun onResume() {
         super.onResume()
         resumed = true

+ 6 - 3
app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt

@@ -293,9 +293,12 @@ class LibraryPresenter : BasePresenter<LibraryFragment>() {
      *
      * @param mangas the list of manga.
      */
-    fun getCommonCategories(mangas: List<Manga>): Collection<Category> = mangas.toSet()
-            .map { db.getCategoriesForManga(it).executeAsBlocking() }
-            .reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
+    fun getCommonCategories(mangas: List<Manga>): Collection<Category> {
+        if (mangas.isEmpty()) return emptyList()
+        return mangas.toSet()
+                .map { db.getCategoriesForManga(it).executeAsBlocking() }
+                .reduce { set1: Iterable<Category>, set2 -> set1.intersect(set2) }
+    }
 
     /**
      * Remove the selected manga from the library.

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersFragment.kt

@@ -118,7 +118,7 @@ class ChaptersFragment : BaseRxFragment<ChaptersPresenter>(), 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)

+ 13 - 0
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderPresenter.kt

@@ -141,6 +141,11 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
      */
     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<ReaderActivity>() {
         return loader.loadChapter(chapter)
                 .subscribeOn(Schedulers.io())
                 .observeOn(AndroidSchedulers.mainThread())
+                .doOnNext { chapterLoaded = true }
     }
 
     /**
@@ -298,6 +304,7 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
         nextChapter = null
         prevChapter = null
 
+        chapterLoaded = false
         start(LOAD_ACTIVE_CHAPTER)
         getAdjacentChapters(chapter)
     }
@@ -474,6 +481,9 @@ class ReaderPresenter : BasePresenter<ReaderActivity>() {
      * @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<ReaderActivity>() {
      * @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)