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
import android.os.Bundle
import android.view.View
import androidx.fragment.app.DialogFragment
import io.legado.app.help.coroutine.Coroutine
import kotlinx.coroutines.CoroutineScope
@ -18,6 +19,14 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope {
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() {
super.onDestroy()
job.cancel()
@ -30,4 +39,7 @@ abstract class BaseDialogFragment : DialogFragment(), CoroutineScope {
): Coroutine<T> {
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)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
ll_bottom_bg.setBackgroundColor(requireContext().bottomBackground)
initOnChange()
initData()
initOnClick()
observeLiveBusEvent()
}
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.TTS_DS) { seek_timer.progress = it }
}

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

Loading…
Cancel
Save