feat: 优化代码

pull/133/head
kunfei 5 years ago
parent 25409cf109
commit 5de79bc316
  1. 12
      app/src/main/java/io/legado/app/base/BaseDialogFragment.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/config/ReadAloudDialog.kt
  3. 3
      app/src/main/java/io/legado/app/ui/book/read/config/TocRegexDialog.kt
  4. 2
      app/src/main/java/io/legado/app/ui/widget/font/FontSelectDialog.kt

@ -1,6 +1,7 @@
package io.legado.app.base package io.legado.app.base
import android.os.Bundle import android.os.Bundle
import android.view.View
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import io.legado.app.help.coroutine.Coroutine import io.legado.app.help.coroutine.Coroutine
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -18,6 +19,14 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope {
job = Job() job = Job()
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
onFragmentCreated(view, savedInstanceState)
observeLiveBus()
}
abstract fun onFragmentCreated(view: View, savedInstanceState: Bundle?)
override fun onDestroy() { override fun onDestroy() {
super.onDestroy() super.onDestroy()
job.cancel() job.cancel()
@ -30,4 +39,7 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope {
): Coroutine<T> { ): Coroutine<T> {
return Coroutine.async(scope, context) { block() } return Coroutine.async(scope, context) { block() }
} }
open fun observeLiveBus() {
}
} }

@ -53,13 +53,11 @@ class ReadAloudDialog : BaseDialogFragment() {
return inflater.inflate(R.layout.dialog_read_aloud, container) return inflater.inflate(R.layout.dialog_read_aloud, container)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
ll_bottom_bg.setBackgroundColor(requireContext().bottomBackground) ll_bottom_bg.setBackgroundColor(requireContext().bottomBackground)
initOnChange() initOnChange()
initData() initData()
initOnClick() initOnClick()
observeLiveBusEvent()
} }
private fun initData() { private fun initData() {
@ -136,7 +134,7 @@ class ReadAloudDialog : BaseDialogFragment() {
} }
} }
private fun observeLiveBusEvent() { override fun observeLiveBus() {
observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() } observeEvent<Int>(EventBus.ALOUD_STATE) { upPlayState() }
observeEvent<Int>(EventBus.TTS_DS) { seek_timer.progress = it } observeEvent<Int>(EventBus.TTS_DS) { seek_timer.progress = it }
} }

@ -61,8 +61,7 @@ class TocRegexDialog : BaseDialogFragment(), Toolbar.OnMenuItemClickListener {
return inflater.inflate(R.layout.dialog_toc_regex, container) return inflater.inflate(R.layout.dialog_toc_regex, container)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
durRegex = arguments?.getString("tocRegex") durRegex = arguments?.getString("tocRegex")
tool_bar.setTitle(R.string.txt_toc_regex) tool_bar.setTitle(R.string.txt_toc_regex)
tool_bar.inflateMenu(R.menu.txt_toc_regex) tool_bar.inflateMenu(R.menu.txt_toc_regex)

@ -60,7 +60,7 @@ class FontSelectDialog : BaseDialogFragment(),
return inflater.inflate(R.layout.dialog_font_select, container) return inflater.inflate(R.layout.dialog_font_select, container)
} }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
tool_bar.setTitle(R.string.select_font) tool_bar.setTitle(R.string.select_font)
tool_bar.inflateMenu(R.menu.font_select) tool_bar.inflateMenu(R.menu.font_select)

Loading…
Cancel
Save