From cfa8460e1d23206c61029732ac10877472a751dd Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 20 Oct 2020 22:40:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/io/legado/app/constant/PreferKey.kt | 4 +- .../app/ui/book/read/ReadBookActivity.kt | 4 +- .../app/ui/book/read/config/PageKeyDialog.kt | 38 +++++++++---------- .../app/ui/widget/seekbar/VerticalSeekBar.kt | 7 ++-- .../io/legado/app/utils/ContextExtensions.kt | 2 +- 5 files changed, 27 insertions(+), 28 deletions(-) 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 0dbd518af..b55f35d57 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.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" 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 c7f860697..6b518f89a 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 @@ -314,13 +314,13 @@ class ReadBookActivity : VMBaseActivity(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 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 index cfd632453..04c5dabfa 100644 --- 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 @@ -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) } diff --git a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt index c700f4794..61f509e32 100644 --- a/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt +++ b/app/src/main/java/io/legado/app/ui/widget/seekbar/VerticalSeekBar.kt @@ -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 diff --git a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt index b99f935eb..7366cb602 100644 --- a/app/src/main/java/io/legado/app/utils/ContextExtensions.kt +++ b/app/src/main/java/io/legado/app/utils/ContextExtensions.kt @@ -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(