From 065cd6ee49dd4ace709e9284a4cabfa9fc1a459a Mon Sep 17 00:00:00 2001 From: kunfei Date: Sun, 24 May 2020 19:45:59 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=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 | 1 + .../java/io/legado/app/help/ReadBookConfig.kt | 5 + .../app/ui/book/read/ReadBookActivity.kt | 17 +- .../app/ui/book/read/config/AutoReadDialog.kt | 97 +++++++++ app/src/main/res/layout/dialog_auto_read.xml | 198 ++++++++++++++++++ app/src/main/res/layout/dialog_read_aloud.xml | 2 +- app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 316 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt create mode 100644 app/src/main/res/layout/dialog_auto_read.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 6542640c8..4387f8b2a 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -44,4 +44,5 @@ object PreferKey { const val systemTypefaces = "system_typefaces" const val readBodyToLh = "readBodyToLh" const val textFullJustify = "textFullJustify" + const val autoReadSpeed = "autoReadSpeed" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt index 6bc3bd5af..cbc9fbd77 100644 --- a/app/src/main/java/io/legado/app/help/ReadBookConfig.kt +++ b/app/src/main/java/io/legado/app/help/ReadBookConfig.kt @@ -103,6 +103,11 @@ object ReadBookConfig { } //配置写入读取 + var autoReadSpeed + get() = App.INSTANCE.getPrefInt(PreferKey.autoReadSpeed, 46) + set(value) { + App.INSTANCE.putPrefInt(PreferKey.autoReadSpeed, value) + } var styleSelect = App.INSTANCE.getPrefInt(PreferKey.readStyleSelect) set(value) { field = value 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 dd2e765c5..3027b34c9 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 @@ -69,6 +69,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, ReadBook.CallBack, + AutoReadDialog.CallBack, TocRegexDialog.CallBack, ReplaceEditDialog.CallBack, ColorPickerDialogListener { @@ -547,10 +548,16 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo } override fun clickCenter() { - if (BaseReadAloudService.isRun) { - showReadAloudDialog() - } else { - read_menu.runMenuIn() + when { + BaseReadAloudService.isRun -> { + showReadAloudDialog() + } + isAutoPage -> { + AutoReadDialog().show(supportFragmentManager, "autoRead") + } + else -> { + read_menu.runMenuIn() + } } } @@ -576,7 +583,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo read_menu.setAutoPage(isAutoPage) } - private fun autoPageStop() { + override fun autoPageStop() { isAutoPage = false mHandler.removeCallbacks(autoPageRunnable) page_view.upContent() diff --git a/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt new file mode 100644 index 000000000..37364721f --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/book/read/config/AutoReadDialog.kt @@ -0,0 +1,97 @@ +package io.legado.app.ui.book.read.config + +import android.os.Bundle +import android.util.DisplayMetrics +import android.view.Gravity +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.SeekBar +import io.legado.app.R +import io.legado.app.base.BaseDialogFragment +import io.legado.app.help.ReadBookConfig +import io.legado.app.lib.theme.bottomBackground +import io.legado.app.service.BaseReadAloudService +import io.legado.app.service.help.ReadAloud +import io.legado.app.ui.book.read.Help +import kotlinx.android.synthetic.main.dialog_auto_read.* +import org.jetbrains.anko.sdk27.listeners.onClick + +class AutoReadDialog : BaseDialogFragment() { + var callBack: CallBack? = null + + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.let { + Help.upSystemUiVisibility(it) + it.windowManager?.defaultDisplay?.getMetrics(dm) + } + dialog?.window?.let { + it.setBackgroundDrawableResource(R.color.background) + it.decorView.setPadding(0, 0, 0, 0) + val attr = it.attributes + attr.dimAmount = 0.0f + attr.gravity = Gravity.BOTTOM + it.attributes = attr + it.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) + } + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + callBack = activity as? CallBack + return inflater.inflate(R.layout.dialog_auto_read, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + root_view.setBackgroundColor(requireContext().bottomBackground) + initOnChange() + initData() + initEvent() + } + + private fun initData() { + seek_auto_read.progress = ReadBookConfig.autoReadSpeed + } + + private fun initOnChange() { + seek_auto_read.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) { + } + + override fun onStartTrackingTouch(seekBar: SeekBar?) = Unit + + override fun onStopTrackingTouch(seekBar: SeekBar?) { + ReadBookConfig.autoReadSpeed = seek_auto_read.progress + upTtsSpeechRate() + } + }) + } + + private fun initEvent() { + ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() } + ll_setting.onClick { + ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") + } + ll_catalog.onClick { callBack?.openChapterList() } + ll_auto_page_stop.onClick { callBack?.autoPageStop() } + } + + private fun upTtsSpeechRate() { + ReadAloud.upTtsSpeechRate(requireContext()) + if (!BaseReadAloudService.pause) { + ReadAloud.pause(requireContext()) + ReadAloud.resume(requireContext()) + } + } + + interface CallBack { + fun showMenuBar() + fun openChapterList() + fun autoPageStop() + } +} \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_auto_read.xml b/app/src/main/res/layout/dialog_auto_read.xml new file mode 100644 index 000000000..420bfe61f --- /dev/null +++ b/app/src/main/res/layout/dialog_auto_read.xml @@ -0,0 +1,198 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_read_aloud.xml b/app/src/main/res/layout/dialog_read_aloud.xml index 504865171..422c1932b 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -273,7 +273,7 @@ android:layout_height="50dp" android:background="?android:attr/selectableItemBackgroundBorderless" android:clickable="true" - android:contentDescription="@string/interface_setting" + android:contentDescription="@string/to_backstage" android:focusable="true" android:orientation="vertical" android:paddingBottom="7dp"> diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index edcfe8a08..90d34f2c3 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -692,4 +692,5 @@ 自動換源 置底 文字兩端對齊 + 自動翻頁速度 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 124663532..457c42de7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -694,5 +694,6 @@ 夜间,底栏色 自动换源 文字两端对齐 + 自动翻页速度