pull/34/head
kunfei 5 years ago
parent d85db50d03
commit 2a9d537b6e
  1. 6
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 7
      app/src/main/java/io/legado/app/ui/readbook/ReadMenu.kt
  3. 39
      app/src/main/java/io/legado/app/ui/readbook/config/MoreConfigDialog.kt
  4. 92
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudConfigDialog.kt
  5. 10
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  6. 41
      app/src/main/java/io/legado/app/ui/readbook/config/ReadPreferenceFragment.kt
  7. 39
      app/src/main/res/layout/dialog_read_aloud.xml
  8. 3
      app/src/main/res/values/strings.xml
  9. 12
      app/src/main/res/xml/pref_config_aloud.xml

@ -402,12 +402,16 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(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() {
}

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

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

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

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

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

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background_menu"
android:orientation="vertical"
android:padding="10dp">
<LinearLayout
@ -14,13 +14,14 @@
android:orientation="horizontal"
android:padding="8dp">
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/iv_menu"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/menu"
android:src="@drawable/ic_chapter_list"
android:tint="@color/tv_text_default" />
@ -29,43 +30,47 @@
android:layout_height="1dp"
android:layout_weight="1" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/iv_play_prev"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="上一句"
android:src="@drawable/ic_skip_previous"
android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/iv_play_pause"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="播放/暂停"
android:src="@drawable/ic_play_24dp"
android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/iv_stop"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/stop"
android:src="@drawable/ic_stop_black_24dp"
android:tint="@color/tv_text_default" />
<androidx.appcompat.widget.AppCompatImageView
<ImageView
android:id="@+id/iv_play_next"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="下一句"
android:src="@drawable/ic_skip_next"
android:tint="@color/tv_text_default" />
@ -74,21 +79,25 @@
android:layout_height="1dp"
android:layout_weight="1" />
<io.legado.app.lib.theme.view.ATESwitch
android:id="@+id/cb_by_page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/byPage"
tools:ignore="RtlHardcoded" />
<ImageView
android:id="@+id/iv_other_config"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="其它设置"
android:src="@drawable/ic_settings"
android:tint="@color/tv_text_default" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="8dp"
android:gravity="center">
android:padding="8dp">
<androidx.appcompat.widget.AppCompatImageView
@ -144,8 +153,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/flow_sys"
android:contentDescription="@string/flow_sys"
android:text="@string/flow_sys"
tools:ignore="RtlHardcoded" />
</LinearLayout>

@ -487,7 +487,7 @@
<string name="battery_show">%d%%</string>
<string name="timer_m">%d分钟</string>
<string name="brightness_auto">自动亮度%s</string>
<string name="byPage">按页</string>
<string name="read_aloud_by_page">按页朗读</string>
<string name="bg_image">背景图片</string>
<string name="bg_color">背景颜色</string>
<string name="text_color">文字颜色</string>
@ -499,5 +499,6 @@
<string name="group">分组</string>
<string name="enable_selection">启用所选</string>
<string name="disable_selection">禁用所选</string>
<string name="tts">TTS</string>
</resources>

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<io.legado.app.lib.theme.prefs.ATESwitchPreference
android:defaultValue="false"
android:title="@string/read_aloud_by_page"
android:key="readAloudByPage"
app:iconSpaceReserved="false" />
</androidx.preference.PreferenceScreen>
Loading…
Cancel
Save