Procházet zdrojové kódy

Toggle reader menu with the menu button, closes #286. Fix incorrect drawer selected item when using back button

len před 9 roky
rodič
revize
1d1e5f1f99

+ 2 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt

@@ -76,7 +76,8 @@ class MainActivity : BaseActivity() {
     override fun onBackPressed() {
         supportFragmentManager.findFragmentById(R.id.frame_container)?.let {
             if (it !is LibraryFragment) {
-                setFragment(LibraryFragment.newInstance())
+                nav_view.setCheckedItem(R.id.nav_drawer_library)
+                nav_view.menu.performIdentifierAction(R.id.nav_drawer_library, 0)
             } else {
                 super.onBackPressed()
             }

+ 12 - 11
app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt

@@ -201,21 +201,22 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
                         return true
                     }
                 }
-                KeyEvent.KEYCODE_DPAD_RIGHT -> {
-                    if (event.action == KeyEvent.ACTION_UP) {
-                        viewer?.moveToNext()
-                    }
-                }
-                KeyEvent.KEYCODE_DPAD_LEFT -> {
-                    if (event.action == KeyEvent.ACTION_UP) {
-                        viewer?.moveToPrevious()
-                    }
-                }
             }
         }
         return super.dispatchKeyEvent(event)
     }
 
+    override fun onKeyUp(keyCode: Int, event: KeyEvent): Boolean {
+        if (!isFinishing) {
+            when (keyCode) {
+                KeyEvent.KEYCODE_DPAD_RIGHT -> viewer?.moveToNext()
+                KeyEvent.KEYCODE_DPAD_LEFT -> viewer?.moveToPrevious()
+                KeyEvent.KEYCODE_MENU -> toggleMenu()
+            }
+        }
+        return super.onKeyUp(keyCode, event)
+    }
+
     fun onChapterError(error: Throwable) {
         Timber.e(error, error.message)
         finish()
@@ -318,7 +319,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
         }
     }
 
-    fun onCenterSingleTap() {
+    fun toggleMenu() {
         setMenuVisibility(reader_menu.visibility == View.GONE)
     }
 

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/pager/PagerReader.kt

@@ -168,7 +168,7 @@ abstract class PagerReader : BaseReader() {
                 } else if (positionX > pager.width * RIGHT_REGION) {
                     if (tappingEnabled) onRightSideTap()
                 } else {
-                    readerActivity.onCenterSingleTap()
+                    readerActivity.toggleMenu()
                 }
                 return true
             }

+ 1 - 1
app/src/main/java/eu/kanade/tachiyomi/ui/reader/viewer/webtoon/WebtoonReader.kt

@@ -130,7 +130,7 @@ class WebtoonReader : BaseReader() {
                 } else if (positionX > recycler.width * RIGHT_REGION) {
                     if (tappingEnabled) moveToNext()
                 } else {
-                    readerActivity.onCenterSingleTap()
+                    readerActivity.toggleMenu()
                 }
                 return true
             }