pull/436/head
gedoor 4 years ago
parent b0f740dc82
commit cfa8460e1d
  1. 4
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  3. 38
      app/src/main/java/io/legado/app/ui/book/read/config/PageKeyDialog.kt
  4. 7
      app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt
  5. 2
      app/src/main/java/io/legado/app/utils/ContextExtensions.kt

@ -12,8 +12,8 @@ object PreferKey {
const val speakEngine = "speakEngine"
const val readAloudByPage = "readAloudByPage"
const val ttsSpeechRate = "ttsSpeechRate"
const val prevKey = "prevKeyCode"
const val nextKey = "nextKeyCode"
const val prevKeys = "prevKeyCodes"
const val nextKeys = "nextKeyCodes"
const val showRss = "showRss"
const val bookshelfLayout = "bookshelfLayout"
const val bookshelfSort = "bookshelfSort"

@ -314,13 +314,13 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
*/
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
when (keyCode) {
getPrefInt(PreferKey.prevKey) -> {
getPrefInt(PreferKey.prevKeys) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.PREV)
return true
}
}
getPrefInt(PreferKey.nextKey) -> {
getPrefInt(PreferKey.nextKeys) -> {
if (keyCode != KeyEvent.KEYCODE_UNKNOWN) {
page_view.pageDelegate?.keyTurnPage(PageDelegate.Direction.NEXT)
return true

@ -6,10 +6,9 @@ import android.view.KeyEvent
import io.legado.app.R
import io.legado.app.constant.PreferKey
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getPrefString
import io.legado.app.utils.hideSoftInput
import io.legado.app.utils.putPrefInt
import io.legado.app.utils.removePref
import io.legado.app.utils.putPrefString
import kotlinx.android.synthetic.main.dialog_page_key.*
import org.jetbrains.anko.sdk27.listeners.onClick
@ -19,21 +18,11 @@ class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDi
init {
setContentView(R.layout.dialog_page_key)
content_view.setBackgroundColor(context.backgroundColor)
et_prev.setText(context.getPrefInt(PreferKey.prevKey).toString())
et_next.setText(context.getPrefInt(PreferKey.nextKey).toString())
et_prev.setText(context.getPrefString(PreferKey.prevKeys))
et_next.setText(context.getPrefString(PreferKey.nextKeys))
tv_ok.onClick {
val prevKey = et_prev.text?.toString()
if (prevKey.isNullOrEmpty()) {
context.removePref(PreferKey.prevKey)
} else {
context.putPrefInt(PreferKey.prevKey, prevKey.toInt())
}
val nextKey = et_next.text?.toString()
if (nextKey.isNullOrEmpty()) {
context.removePref(PreferKey.nextKey)
} else {
context.putPrefInt(PreferKey.nextKey, nextKey.toInt())
}
context.putPrefString(PreferKey.prevKeys, et_prev.text?.toString())
context.putPrefString(PreferKey.nextKeys, et_next.text?.toString())
dismiss()
}
}
@ -41,11 +30,20 @@ class PageKeyDialog(context: Context) : Dialog(context, R.style.AppTheme_AlertDi
override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
if (keyCode != KeyEvent.KEYCODE_BACK) {
if (et_prev.hasFocus()) {
et_prev.setText(keyCode.toString())
val editableText = et_prev.editableText
if (editableText.isEmpty() or editableText.endsWith(",")) {
editableText.append(keyCode.toString())
} else {
editableText.append(",").append(keyCode.toString())
}
} else if (et_next.hasFocus()) {
et_next.setText(keyCode.toString())
val editableText = et_next.editableText
if (editableText.isEmpty() or editableText.endsWith(",")) {
editableText.append(keyCode.toString())
} else {
editableText.append(",").append(keyCode.toString())
}
}
return true
}
return super.onKeyDown(keyCode, event)
}

@ -20,11 +20,11 @@ import java.lang.reflect.Method
class VerticalSeekBar @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyle: Int = 0
defStyleAttr: Int = androidx.appcompat.R.attr.seekBarStyle
) : AppCompatSeekBar(
context,
attrs,
defStyle
defStyleAttr
) {
private var mIsDragging: Boolean = false
@ -67,7 +67,8 @@ class VerticalSeekBar @JvmOverloads constructor(
ViewCompat.setLayoutDirection(this, ViewCompat.LAYOUT_DIRECTION_LTR)
if (attrs != null) {
val a = context.obtainStyledAttributes(attrs, R.styleable.VerticalSeekBar, defStyle, 0)
val a =
context.obtainStyledAttributes(attrs, R.styleable.VerticalSeekBar, defStyleAttr, 0)
val rotationAngle = a.getInteger(R.styleable.VerticalSeekBar_seekBarRotation, 0)
if (isValidRotationAngle(rotationAngle)) {
mRotationAngle = rotationAngle

@ -56,7 +56,7 @@ fun Context.getPrefString(key: String, defValue: String? = null) =
fun Context.getPrefString(@StringRes keyId: Int, defValue: String? = null) =
defaultSharedPreferences.getString(getString(keyId), defValue)
fun Context.putPrefString(key: String, value: String) =
fun Context.putPrefString(key: String, value: String?) =
defaultSharedPreferences.edit { putString(key, value) }
fun Context.getPrefStringSet(

Loading…
Cancel
Save