From 2a9d537b6e458a774309fcb314d0d5966606d9c7 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 11 Sep 2019 21:07:33 +0800 Subject: [PATCH] up --- .../app/ui/readbook/ReadBookActivity.kt | 6 +- .../io/legado/app/ui/readbook/ReadMenu.kt | 7 +- .../ui/readbook/config/MoreConfigDialog.kt | 39 ++++++++ .../readbook/config/ReadAloudConfigDialog.kt | 92 +++++++++++++++++++ .../app/ui/readbook/config/ReadAloudDialog.kt | 10 +- .../readbook/config/ReadPreferenceFragment.kt | 41 --------- app/src/main/res/layout/dialog_read_aloud.xml | 39 +++++--- app/src/main/res/values/strings.xml | 3 +- app/src/main/res/xml/pref_config_aloud.xml | 12 +++ 9 files changed, 183 insertions(+), 66 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt delete mode 100644 app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt create mode 100644 app/src/main/res/xml/pref_config_aloud.xml diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index e8652e0a3..448f1cbe3 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -402,12 +402,16 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_rea override fun clickCenter() { if (readAloudStatus != Status.STOP) { - ReadAloudDialog().show(supportFragmentManager, "readAloud") + showReadAloudDialog() } else { read_menu.runMenuIn() } } + override fun showReadAloudDialog() { + ReadAloudDialog().show(supportFragmentManager, "readAloud") + } + override fun autoPage() { } diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt index 2d42e0d70..b0b79603e 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt @@ -16,6 +16,7 @@ import io.legado.app.lib.theme.buttonDisabledColor import io.legado.app.utils.* import kotlinx.android.synthetic.main.view_read_menu.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.sdk27.listeners.onLongClick class ReadMenu : FrameLayout { var cnaShowMenu: Boolean = false @@ -170,7 +171,10 @@ class ReadMenu : FrameLayout { postEvent(Bus.READ_ALOUD_BUTTON, true) } } - + ll_read_aloud.onLongClick { + runMenuOut { callBack?.showReadAloudDialog() } + true + } //界面 ll_font.onClick { runMenuOut { @@ -252,6 +256,7 @@ class ReadMenu : FrameLayout { fun openChapterList() fun showReadStyle() fun showMoreSetting() + fun showReadAloudDialog() fun upSystemUiVisibility() } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt index 3e1652645..ba7aca78f 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt @@ -1,5 +1,6 @@ package io.legado.app.ui.readbook.config +import android.content.SharedPreferences import android.os.Bundle import android.util.DisplayMetrics import android.view.Gravity @@ -8,8 +9,12 @@ import android.view.View import android.view.ViewGroup import android.widget.LinearLayout import androidx.fragment.app.DialogFragment +import androidx.preference.PreferenceFragmentCompat import io.legado.app.R +import io.legado.app.constant.Bus +import io.legado.app.lib.theme.ATH import io.legado.app.ui.readbook.Help +import io.legado.app.utils.postEvent class MoreConfigDialog : DialogFragment() { @@ -53,4 +58,38 @@ class MoreConfigDialog : DialogFragment() { .replace(view.id, preferenceFragment, readPreferTag) .commit() } + + class ReadPreferenceFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_config_read) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + ATH.applyEdgeEffectColor(listView) + } + + override fun onResume() { + super.onResume() + preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + super.onPause() + } + + override fun onSharedPreferenceChanged( + sharedPreferences: SharedPreferences?, + key: String? + ) { + when (key) { + "hideStatusBar" -> postEvent(Bus.UP_CONFIG, true) + "hideNavigationBar" -> postEvent(Bus.UP_CONFIG, true) + } + } + + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt new file mode 100644 index 000000000..a56c1572c --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt @@ -0,0 +1,92 @@ +package io.legado.app.ui.readbook.config + +import android.content.SharedPreferences +import android.os.Bundle +import android.util.DisplayMetrics +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import androidx.fragment.app.DialogFragment +import androidx.preference.PreferenceFragmentCompat +import io.legado.app.R +import io.legado.app.constant.Bus +import io.legado.app.lib.theme.ATH +import io.legado.app.ui.readbook.Help +import io.legado.app.utils.postEvent + +class ReadAloudConfigDialog : DialogFragment() { + private val readAloudPreferTag = "readAloudPreferTag" + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = LinearLayout(context) + view.setBackgroundResource(R.color.background) + view.id = R.id.tag1 + container?.addView(view) + return view + } + + 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.transparent) + it.decorView.setPadding(0, 0, 0, 0) + val attr = it.attributes + attr.dimAmount = 0.0f + it.attributes = attr + it.setLayout((dm.widthPixels * 0.9).toInt(), ViewGroup.LayoutParams.WRAP_CONTENT) + } + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + var preferenceFragment = childFragmentManager.findFragmentByTag(readAloudPreferTag) + if (preferenceFragment == null) preferenceFragment = ReadAloudPreferenceFragment() + childFragmentManager.beginTransaction() + .replace(view.id, preferenceFragment, readAloudPreferTag) + .commit() + } + + class ReadAloudPreferenceFragment : PreferenceFragmentCompat(), + SharedPreferences.OnSharedPreferenceChangeListener { + + override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { + addPreferencesFromResource(R.xml.pref_config_aloud) + } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + ATH.applyEdgeEffectColor(listView) + } + + override fun onResume() { + super.onResume() + preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) + } + + override fun onPause() { + preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) + super.onPause() + } + + override fun onSharedPreferenceChanged( + sharedPreferences: SharedPreferences?, + key: String? + ) { + when (key) { + "readAloudByPage" -> postEvent(Bus.READ_ALOUD_BUTTON, false) + + } + } + + } +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index 31f07a645..90f2d9415 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -65,19 +65,12 @@ class ReadAloudDialog : DialogFragment() { seek_timer.progress = BaseReadAloudService.timeMinute tv_timer.text = requireContext().getString(R.string.timer_m, BaseReadAloudService.timeMinute) - cb_by_page.isChecked = requireContext().getPrefBoolean("readAloudByPage") cb_tts_follow_sys.isChecked = requireContext().getPrefBoolean("ttsFollowSys", true) seek_tts_SpeechRate.isEnabled = !cb_tts_follow_sys.isChecked seek_tts_SpeechRate.progress = requireContext().getPrefInt("ttsSpeechRate", 5) } private fun initOnChange() { - cb_by_page.setOnCheckedChangeListener { buttonView, isChecked -> - if (buttonView.isPressed) { - requireContext().putPrefBoolean("readAloudByPage", isChecked) - postEvent(Bus.READ_ALOUD_BUTTON, false) - } - } cb_tts_follow_sys.setOnCheckedChangeListener { buttonView, isChecked -> if (buttonView.isPressed) { requireContext().putPrefBoolean("ttsFollowSys", isChecked) @@ -112,6 +105,9 @@ class ReadAloudDialog : DialogFragment() { private fun initOnClick() { iv_menu.onClick { callBack?.showMenu(); dismiss() } + iv_other_config.onClick { + ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") + } iv_menu.onLongClick { callBack?.openChapterList(); true } iv_stop.onClick { ReadAloud.stop(requireContext()); dismiss() } iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt deleted file mode 100644 index 47b27bf33..000000000 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt +++ /dev/null @@ -1,41 +0,0 @@ -package io.legado.app.ui.readbook.config - -import android.content.SharedPreferences -import android.os.Bundle -import android.view.View -import androidx.preference.PreferenceFragmentCompat -import io.legado.app.R -import io.legado.app.constant.Bus -import io.legado.app.lib.theme.ATH -import io.legado.app.utils.postEvent - -class ReadPreferenceFragment : PreferenceFragmentCompat(), - SharedPreferences.OnSharedPreferenceChangeListener { - - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - addPreferencesFromResource(R.xml.pref_config_read) - } - - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - ATH.applyEdgeEffectColor(listView) - } - - override fun onResume() { - super.onResume() - preferenceManager.sharedPreferences.registerOnSharedPreferenceChangeListener(this) - } - - override fun onPause() { - preferenceManager.sharedPreferences.unregisterOnSharedPreferenceChangeListener(this) - super.onPause() - } - - override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { - when (key) { - "hideStatusBar" -> postEvent(Bus.UP_CONFIG, true) - "hideNavigationBar" -> postEvent(Bus.UP_CONFIG, true) - } - } - -} \ 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 68c0282e4..c1816be96 100644 --- a/app/src/main/res/layout/dialog_read_aloud.xml +++ b/app/src/main/res/layout/dialog_read_aloud.xml @@ -1,10 +1,10 @@ - @@ -29,43 +30,47 @@ android:layout_height="1dp" android:layout_weight="1" /> - - - - @@ -74,21 +79,25 @@ android:layout_height="1dp" android:layout_weight="1" /> - + + android:padding="8dp"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b4a44b681..d0000ebfb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -487,7 +487,7 @@ %d%% %d分钟 自动亮度%s - 按页 + 按页朗读 背景图片 背景颜色 文字颜色 @@ -499,5 +499,6 @@ 分组 启用所选 禁用所选 + TTS diff --git a/app/src/main/res/xml/pref_config_aloud.xml b/app/src/main/res/xml/pref_config_aloud.xml new file mode 100644 index 000000000..638cb16c5 --- /dev/null +++ b/app/src/main/res/xml/pref_config_aloud.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file