feat: 优化代码

pull/154/head
kunfei 5 years ago
parent 631ba46986
commit cbffc25d11
  1. 24
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  2. 452
      app/src/main/res/layout/dialog_read_aloud.xml
  3. 2
      app/src/main/res/layout/view_read_menu.xml
  4. 2
      app/src/main/res/values/strings.xml

@ -21,7 +21,6 @@ import io.legado.app.utils.observeEvent
import io.legado.app.utils.putPrefBoolean import io.legado.app.utils.putPrefBoolean
import kotlinx.android.synthetic.main.dialog_read_aloud.* import kotlinx.android.synthetic.main.dialog_read_aloud.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadAloudDialog : BaseDialogFragment() { class ReadAloudDialog : BaseDialogFragment() {
var callBack: CallBack? = null var callBack: CallBack? = null
@ -34,7 +33,7 @@ class ReadAloudDialog : BaseDialogFragment() {
it.windowManager?.defaultDisplay?.getMetrics(dm) it.windowManager?.defaultDisplay?.getMetrics(dm)
} }
dialog?.window?.let { dialog?.window?.let {
it.setBackgroundDrawableResource(R.color.transparent) it.setBackgroundDrawableResource(R.color.background)
it.decorView.setPadding(0, 0, 0, 0) it.decorView.setPadding(0, 0, 0, 0)
val attr = it.attributes val attr = it.attributes
attr.dimAmount = 0.0f attr.dimAmount = 0.0f
@ -54,10 +53,10 @@ class ReadAloudDialog : BaseDialogFragment() {
} }
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
ll_bottom_bg.setBackgroundColor(requireContext().bottomBackground) root_view.setBackgroundColor(requireContext().bottomBackground)
initOnChange() initOnChange()
initData() initData()
initOnClick() initEvent()
} }
private fun initData() { private fun initData() {
@ -101,22 +100,19 @@ class ReadAloudDialog : BaseDialogFragment() {
}) })
} }
private fun initOnClick() { private fun initEvent() {
iv_menu.onClick { callBack?.showMenuBar(); dismiss() } ll_main_menu.onClick { callBack?.showMenuBar(); dismiss() }
iv_other_config.onClick { ll_setting.onClick {
ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog") ReadAloudConfigDialog().show(childFragmentManager, "readAloudConfigDialog")
} }
tv_pre.onClick { ReadBook.moveToPrevChapter(upContent = true, toLast = false) }
tv_next.onClick { ReadBook.moveToNextChapter(true) }
iv_stop.onClick { ReadAloud.stop(requireContext()); dismiss() } iv_stop.onClick { ReadAloud.stop(requireContext()); dismiss() }
iv_play_pause.onClick { callBack?.onClickReadAloud() } iv_play_pause.onClick { callBack?.onClickReadAloud() }
iv_play_prev.onClick { ReadAloud.prevParagraph(requireContext()) } iv_play_prev.onClick { ReadAloud.prevParagraph(requireContext()) }
iv_play_prev.onLongClick {
ReadBook.moveToPrevChapter(upContent = true, toLast = false)
true
}
iv_play_next.onClick { ReadAloud.nextParagraph(requireContext()) } iv_play_next.onClick { ReadAloud.nextParagraph(requireContext()) }
iv_play_next.onLongClick { ReadBook.moveToNextChapter(true); true } ll_catalog.onClick { callBack?.openChapterList() }
fabToc.onClick { callBack?.openChapterList() } ll_to_backstage.onClick { callBack?.finish() }
fabBack.onClick { callBack?.finish() }
} }
private fun upPlayState() { private fun upPlayState() {

@ -1,245 +1,333 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/root_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto" android:background="@color/background_menu"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="6dp"
android:paddingBottom="6dp"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal">
<Space <TextView
android:layout_width="0dp" android:id="@+id/tv_pre"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="@string/previous_chapter"
android:textColor="@color/tv_text_default"
android:textSize="14sp" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" /> android:layout_weight="1" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <ImageView
android:id="@+id/fabToc" android:id="@+id/iv_play_prev"
android:layout_width="wrap_content" android:layout_width="30dp"
android:layout_height="wrap_content" android:layout_height="30dp"
android:layout_margin="10dp" android:layout_marginLeft="8dp"
android:contentDescription="@string/chapter_list" android:layout_marginRight="8dp"
android:src="@drawable/ic_toc" android:background="?android:attr/selectableItemBackgroundBorderless"
android:tooltipText="@string/prev_sentence"
android:contentDescription="@string/prev_sentence"
android:src="@drawable/ic_skip_previous"
android:tint="@color/tv_text_default" android:tint="@color/tv_text_default"
android:tooltipText="@string/chapter_list"
app:backgroundTint="@color/background_menu"
app:elevation="2dp"
app:fabSize="mini"
app:pressedTranslationZ="2dp"
tools:ignore="UnusedAttribute" /> tools:ignore="UnusedAttribute" />
<Space <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:tooltipText="@string/audio_play"
android:contentDescription="@string/audio_play"
android:src="@drawable/ic_play_24dp"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<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:tooltipText="@string/stop"
android:src="@drawable/ic_stop_black_24dp"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<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="@string/next_sentence"
android:tooltipText="@string/next_sentence"
android:src="@drawable/ic_skip_next"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="1dp"
android:layout_weight="1" /> android:layout_weight="1" />
<com.google.android.material.floatingactionbutton.FloatingActionButton <TextView
android:id="@+id/fabBack" android:id="@+id/tv_next"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_margin="10dp" android:layout_marginStart="10dp"
android:contentDescription="@string/to_backstage" android:layout_marginEnd="10dp"
android:src="@drawable/ic_visibility_off" android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:focusable="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:text="@string/next_chapter"
android:textColor="@color/tv_text_default"
android:textSize="14sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="6dp">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:tooltipText="@string/set_timer"
android:contentDescription="@string/set_timer"
android:src="@drawable/ic_time_add_24dp"
android:tint="@color/tv_text_default" android:tint="@color/tv_text_default"
android:tooltipText="@string/to_backstage"
app:backgroundTint="@color/background_menu"
app:elevation="2dp"
app:fabSize="mini"
app:pressedTranslationZ="2dp"
tools:ignore="UnusedAttribute" /> tools:ignore="UnusedAttribute" />
<Space <io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_timer"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_weight="1"
android:max="60" />
</LinearLayout> <TextView
android:id="@+id/tv_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/timer_m" />
<View style="@style/Style.Shadow.Bottom" /> </LinearLayout>
<LinearLayout <LinearLayout
android:id="@+id/ll_bottom_bg"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@color/background_menu"
android:padding="16dp"
android:orientation="vertical"> android:orientation="vertical">
<LinearLayout <LinearLayout
android:id="@+id/ll_tts_SpeechRate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:layout_gravity="center_vertical"
android:orientation="horizontal"> android:orientation="horizontal"
android:padding="8dp">
<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:tooltipText="@string/menu"
android:contentDescription="@string/menu"
android:src="@drawable/ic_menu"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<View <TextView
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<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:tooltipText="@string/prev_sentence"
android:contentDescription="@string/prev_sentence"
android:src="@drawable/ic_skip_previous"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<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:tooltipText="@string/audio_play"
android:contentDescription="@string/audio_play"
android:src="@drawable/ic_play_24dp"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<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:tooltipText="@string/stop"
android:src="@drawable/ic_stop_black_24dp"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<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="@string/next_sentence"
android:tooltipText="@string/next_sentence"
android:src="@drawable/ic_skip_next"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<View
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="1dp" android:layout_height="wrap_content"
android:layout_weight="1" /> android:layout_gravity="center"
android:layout_weight="1"
<ImageView android:text="@string/read_aloud_speed"
android:id="@+id/iv_other_config" android:textColor="@color/tv_text_default"
android:layout_width="30dp" android:textSize="14sp" />
android:layout_height="30dp"
android:layout_marginLeft="8dp" <io.legado.app.lib.theme.view.ATESwitch
android:layout_marginRight="8dp" android:id="@+id/cb_tts_follow_sys"
android:background="?android:attr/selectableItemBackgroundBorderless" android:layout_width="wrap_content"
android:tooltipText="@string/other_aloud_setting" android:layout_height="wrap_content"
android:contentDescription="@string/other_aloud_setting" android:layout_gravity="center_vertical"
android:src="@drawable/ic_settings" android:contentDescription="@string/flow_sys"
android:tint="@color/tv_text_default" android:text="@string/flow_sys"
tools:ignore="UnusedAttribute" /> tools:ignore="RtlHardcoded" />
</LinearLayout> </LinearLayout>
<LinearLayout <io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_tts_SpeechRate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="center" android:layout_marginStart="15dp"
android:orientation="horizontal" android:layout_marginEnd="15dp"
android:padding="8dp"> android:max="45" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_marginTop="8dp"
android:baselineAligned="false"
android:orientation="horizontal">
<!--目录按钮-->
<LinearLayout
android:id="@+id/ll_catalog"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/chapter_list"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="7dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:layout_width="30dp" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="0dp"
android:tooltipText="@string/set_timer"
android:contentDescription="@string/set_timer"
android:src="@drawable/ic_time_add_24dp"
android:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_timer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="1"
android:max="60" /> android:contentDescription="@string/chapter_list"
android:src="@drawable/ic_toc"
app:tint="@color/tv_text_default"
tools:ignore="NestedWeights" />
<TextView <TextView
android:id="@+id/tv_timer"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/timer_m" /> android:layout_gravity="center_horizontal"
android:layout_marginTop="3dp"
android:text="@string/chapter_list"
android:textColor="@color/tv_text_default"
android:textSize="12sp" />
</LinearLayout> </LinearLayout>
<View <View
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="0.8dp" android:layout_height="match_parent"
android:background="@color/divider" /> android:layout_weight="2" />
<!--调节按钮-->
<LinearLayout
android:id="@+id/ll_main_menu"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/read_aloud"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="7dp">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/main_menu"
android:src="@drawable/ic_menu"
app:tint="@color/tv_text_default"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dp"
android:text="@string/main_menu"
android:textColor="@color/tv_text_default"
android:textSize="12sp" />
</LinearLayout>
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2" />
<!--界面按钮-->
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:id="@+id/ll_to_backstage"
android:layout_height="wrap_content" android:layout_width="50dp"
android:orientation="vertical"> android:layout_height="50dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:clickable="true"
android:contentDescription="@string/interface_setting"
android:focusable="true"
android:orientation="vertical"
android:paddingBottom="7dp">
<LinearLayout <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/ll_tts_SpeechRate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:contentDescription="@string/to_backstage"
android:src="@drawable/ic_visibility_off"
app:tint="@color/tv_text_default"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_horizontal"
android:orientation="horizontal" android:layout_marginTop="3dp"
android:padding="8dp"> android:text="@string/to_backstage"
android:textColor="@color/tv_text_default"
<TextView android:textSize="12sp" />
android:layout_width="0dp" </LinearLayout>
android:layout_height="wrap_content"
android:layout_gravity="center" <View
android:layout_weight="1" android:layout_width="0dp"
android:text="@string/read_aloud_speed" android:layout_height="match_parent"
android:textColor="@color/tv_text_default" android:layout_weight="2" />
android:textSize="14sp" /> <!--设置按钮-->
<LinearLayout
<io.legado.app.lib.theme.view.ATESwitch android:id="@+id/ll_setting"
android:id="@+id/cb_tts_follow_sys" android:layout_width="50dp"
android:layout_width="wrap_content" android:layout_height="50dp"
android:layout_height="wrap_content" android:background="?android:attr/selectableItemBackgroundBorderless"
android:layout_gravity="center_vertical" android:clickable="true"
android:contentDescription="@string/flow_sys" android:contentDescription="@string/setting"
android:text="@string/flow_sys" android:focusable="true"
tools:ignore="RtlHardcoded" /> android:orientation="vertical"
android:paddingBottom="7dp">
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
<io.legado.app.lib.theme.view.ATESeekBar
android:id="@+id/seek_tts_SpeechRate"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="30dp" android:layout_height="0dp"
android:layout_marginStart="15dp" android:layout_weight="1"
android:layout_marginEnd="15dp" android:contentDescription="@string/aloud_config"
android:max="45" /> android:src="@drawable/ic_settings"
app:tint="@color/tv_text_default"
tools:ignore="NestedWeights" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="3dp"
android:text="@string/aloud_config"
android:textColor="@color/tv_text_default"
android:textSize="12sp" />
</LinearLayout> </LinearLayout>
</LinearLayout> </LinearLayout>

@ -210,7 +210,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="50dp" android:layout_height="wrap_content"
android:baselineAligned="false" android:baselineAligned="false"
android:orientation="horizontal"> android:orientation="horizontal">

@ -628,7 +628,6 @@
<string name="more_menu">更多菜单</string> <string name="more_menu">更多菜单</string>
<string name="reduce"></string> <string name="reduce"></string>
<string name="plus"></string> <string name="plus"></string>
<string name="other_aloud_setting">其它朗读设置</string>
<string name="system_typeface">系统内置字体样式</string> <string name="system_typeface">系统内置字体样式</string>
<string name="delete_book_file">删除源文件</string> <string name="delete_book_file">删除源文件</string>
<string name="default1">预设一</string> <string name="default1">预设一</string>
@ -646,5 +645,6 @@
<string name="bar_elevation">导航栏阴影</string> <string name="bar_elevation">导航栏阴影</string>
<string name="bar_elevation_s">当前阴影大小(elevation): %s</string> <string name="bar_elevation_s">当前阴影大小(elevation): %s</string>
<string name="btn_default_s">默认</string> <string name="btn_default_s">默认</string>
<string name="main_menu">主菜单</string>
</resources> </resources>

Loading…
Cancel
Save