From 8e1af9cc1648c4a672051e7dc291f96ffd4f73ca Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 15 Nov 2019 20:25:48 +0800 Subject: [PATCH] up --- .../java/io/legado/app/constant/PreferKey.kt | 2 + .../app/ui/book/read/ReadBookActivity.kt | 1 + .../app/ui/book/read/config/PageKeyDialog.kt | 45 +++++++++++++++++++ app/src/main/res/layout/dialog_page_key.xml | 44 ++++++++++++++++++ app/src/main/res/menu/read_book.xml | 5 +++ app/src/main/res/values/strings.xml | 1 + 6 files changed, 98 insertions(+) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt create mode 100644 app/src/main/res/layout/dialog_page_key.xml diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 1bf8e9a30..ba75dea1f 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -6,4 +6,6 @@ object PreferKey { const val hideStatusBar = "hideStatusBar" const val hideNavigationBar = "hideNavigationBar" const val precisionSearch = "precisionSearch" + const val prevKey = "prevKeyCode" + const val nextKey = "nextKeyCode" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index 95b2151c3..c532d3af3 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -152,6 +152,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo viewModel.refreshContent(it) } } + R.id.menu_page_key -> PageKeyDialog(this).show() } return super.onCompatOptionsItemSelected(item) } diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt new file mode 100644 index 000000000..74933fef6 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt @@ -0,0 +1,45 @@ +package io.legado.app.ui.book.read.config + +import android.app.Dialog +import android.content.Context +import android.view.KeyEvent +import io.legado.app.R +import io.legado.app.constant.PreferKey +import io.legado.app.utils.hideSoftInput +import io.legado.app.utils.putPrefInt +import kotlinx.android.synthetic.main.dialog_page_key.* +import org.jetbrains.anko.sdk27.listeners.onClick + + +class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDialog) { + + init { + setContentView(R.layout.dialog_page_key) + tv_ok.onClick { + et_prev.text?.let { + context.putPrefInt(PreferKey.prevKey, it.toString().toInt()) + } + et_next.text?.let { + context.putPrefInt(PreferKey.nextKey, it.toString().toInt()) + } + dismiss() + } + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { + if (keyCode != KeyEvent.KEYCODE_BACK) { + if (et_prev.hasFocus()) { + et_prev.setText(keyCode.toString()) + } else if (et_next.hasFocus()) { + et_next.setText(keyCode.toString()) + } + } + return super.onKeyDown(keyCode, event) + } + + override fun dismiss() { + super.dismiss() + currentFocus?.hideSoftInput() + } + +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_page_key.xml b/app/src/main/res/layout/dialog_page_key.xml new file mode 100644 index 000000000..4dbe01c61 --- /dev/null +++ b/app/src/main/res/layout/dialog_page_key.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/read_book.xml b/app/src/main/res/menu/read_book.xml index d8ea10f3d..cbf8ad3dc 100644 --- a/app/src/main/res/menu/read_book.xml +++ b/app/src/main/res/menu/read_book.xml @@ -81,6 +81,11 @@ android:icon="@drawable/ic_toc" android:title="@string/book_info" app:showAsAction="never" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index d54b7c30e..53a7e924b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -556,5 +556,6 @@ 音频 转到后台 正在导入 + 定义翻页按键