pull/48/head
kunfei 5 years ago
parent b5399c4041
commit 8e1af9cc16
  1. 2
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 1
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 45
      app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt
  4. 44
      app/src/main/res/layout/dialog_page_key.xml
  5. 5
      app/src/main/res/menu/read_book.xml
  6. 1
      app/src/main/res/values/strings.xml

@ -6,4 +6,6 @@ object PreferKey {
const val hideStatusBar = "hideStatusBar" const val hideStatusBar = "hideStatusBar"
const val hideNavigationBar = "hideNavigationBar" const val hideNavigationBar = "hideNavigationBar"
const val precisionSearch = "precisionSearch" const val precisionSearch = "precisionSearch"
const val prevKey = "prevKeyCode"
const val nextKey = "nextKeyCode"
} }

@ -152,6 +152,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
viewModel.refreshContent(it) viewModel.refreshContent(it)
} }
} }
R.id.menu_page_key -> PageKeyDialog(this).show()
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -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()
}
}

@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp" />
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/et_prev"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:completionThreshold="0"
android:inputType="number"
android:singleLine="true" />
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/et_next"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:completionThreshold="0"
android:inputType="number"
android:singleLine="true" />
<TextView
android:id="@+id/tv_ok"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@drawable/selector_fillet_btn_bg"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:text="@string/ok"
android:textColor="@color/tv_text_default" />
</LinearLayout>

@ -81,6 +81,11 @@
android:icon="@drawable/ic_toc" android:icon="@drawable/ic_toc"
android:title="@string/book_info" android:title="@string/book_info"
app:showAsAction="never" /> app:showAsAction="never" />
<item
android:id="@+id/menu_page_key"
android:title="@string/custom_page_key"
app:showAsAction="never" />
</group> </group>
<group android:id="@+id/menu_group_login"> <group android:id="@+id/menu_group_login">

@ -556,5 +556,6 @@
<string name="book_type_audio">音频</string> <string name="book_type_audio">音频</string>
<string name="to_backstage">转到后台</string> <string name="to_backstage">转到后台</string>
<string name="importing">正在导入</string> <string name="importing">正在导入</string>
<string name="custom_page_key">定义翻页按键</string>
</resources> </resources>

Loading…
Cancel
Save