pull/32/head
kunfei 5 years ago
parent 47d93aea7e
commit 01f953ccaa
  1. 7
      app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt
  2. 26
      app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt
  3. 21
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  4. 1
      app/src/main/res/layout/activity_replace_rule.xml
  5. 2
      app/src/main/res/values/strings.xml

@ -54,6 +54,7 @@ import org.jetbrains.anko.toast
class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book), class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_read_book),
PageView.CallBack, PageView.CallBack,
ReadMenu.CallBack, ReadMenu.CallBack,
ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack, ChangeSourceDialog.CallBack,
ReadBookViewModel.CallBack, ReadBookViewModel.CallBack,
ColorPickerDialogListener { ColorPickerDialogListener {
@ -63,7 +64,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
private val requestCodeEditSource = 111 private val requestCodeEditSource = 111
private var changeSourceDialog: ChangeSourceDialog? = null private var changeSourceDialog: ChangeSourceDialog? = null
private var timeElectricityReceiver: TimeElectricityReceiver? = null private var timeElectricityReceiver: TimeElectricityReceiver? = null
var readAloudStatus = Status.STOP override var readAloudStatus = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@ -317,6 +318,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
} }
} }
override fun showMenu() {
read_menu.runMenuIn()
}
override fun chapterSize(): Int { override fun chapterSize(): Int {
return viewModel.chapterSize return viewModel.chapterSize
} }

@ -15,18 +15,19 @@ import io.legado.app.service.ReadAloudService
import io.legado.app.ui.readbook.Help import io.legado.app.ui.readbook.Help
import io.legado.app.ui.readbook.ReadBookActivity import io.legado.app.ui.readbook.ReadBookActivity
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_read_book.*
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 import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadAloudDialog : DialogFragment() { class ReadAloudDialog : DialogFragment() {
var callBack: CallBack? = null
override fun onCreateView( override fun onCreateView(
inflater: LayoutInflater, inflater: LayoutInflater,
container: ViewGroup?, container: ViewGroup?,
savedInstanceState: Bundle? savedInstanceState: Bundle?
): View? { ): View? {
callBack = activity as? CallBack
return inflater.inflate(R.layout.dialog_read_aloud, container) return inflater.inflate(R.layout.dialog_read_aloud, container)
} }
@ -111,12 +112,10 @@ class ReadAloudDialog : DialogFragment() {
private fun initOnClick() { private fun initOnClick() {
iv_menu.onClick { iv_menu.onClick {
val activity = activity callBack?.showMenu()
if (activity is ReadBookActivity) { dismiss()
activity.read_menu.runMenuIn()
dismiss()
}
} }
iv_menu.onLongClick { callBack?.openChapterList(); true }
iv_stop.onClick { ReadAloudService.stop(requireContext()); dismiss() } iv_stop.onClick { ReadAloudService.stop(requireContext()); dismiss() }
iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) } iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) }
iv_play_prev.onClick { ReadAloudService.prevParagraph(requireContext()) } iv_play_prev.onClick { ReadAloudService.prevParagraph(requireContext()) }
@ -134,13 +133,16 @@ class ReadAloudDialog : DialogFragment() {
} }
private fun upTtsSpeechRate() { private fun upTtsSpeechRate() {
val activity = activity
ReadAloudService.upTtsSpeechRate(requireContext()) ReadAloudService.upTtsSpeechRate(requireContext())
if (activity is ReadBookActivity) { if (callBack?.readAloudStatus == Status.PLAY) {
if (activity.readAloudStatus == Status.PLAY) { ReadAloudService.pause(requireContext())
ReadAloudService.pause(requireContext()) ReadAloudService.resume(requireContext())
ReadAloudService.resume(requireContext())
}
} }
} }
interface CallBack {
fun showMenu()
fun openChapterList()
var readAloudStatus: Int
}
} }

@ -4,6 +4,7 @@ import android.os.Bundle
import android.view.Menu import android.view.Menu
import android.view.MenuItem import android.view.MenuItem
import android.view.SubMenu import android.view.SubMenu
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -18,13 +19,16 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
import io.legado.app.help.ItemTouchCallback import io.legado.app.help.ItemTouchCallback
import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.utils.getViewModel import io.legado.app.utils.getViewModel
import io.legado.app.utils.splitNotBlank import io.legado.app.utils.splitNotBlank
import kotlinx.android.synthetic.main.activity_replace_rule.* import kotlinx.android.synthetic.main.activity_replace_rule.*
import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.doAsync import org.jetbrains.anko.doAsync
class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule), class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule),
SearchView.OnQueryTextListener,
ReplaceRuleAdapter.CallBack { ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel override val viewModel: ReplaceRuleViewModel
get() = getViewModel(ReplaceRuleViewModel::class.java) get() = getViewModel(ReplaceRuleViewModel::class.java)
@ -37,6 +41,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
override fun onActivityCreated(savedInstanceState: Bundle?) { override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView() initRecyclerView()
initSearchView()
initDataObservers() initDataObservers()
} }
@ -78,6 +83,14 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view) ItemTouchHelper(itemTouchCallback).attachToRecyclerView(recycler_view)
} }
private fun initSearchView() {
ATH.setTint(search_view, primaryTextColor)
search_view.onActionViewExpanded()
search_view.queryHint = getString(R.string.replace_purify_search)
search_view.clearFocus()
search_view.setOnQueryTextListener(this)
}
private fun initDataObservers() { private fun initDataObservers() {
rulesLiveData?.removeObservers(this) rulesLiveData?.removeObservers(this)
rulesLiveData = LivePagedListBuilder(App.db.replaceRuleDao().observeAll(), 30).build() rulesLiveData = LivePagedListBuilder(App.db.replaceRuleDao().observeAll(), 30).build()
@ -107,6 +120,14 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
} }
} }
override fun onQueryTextChange(newText: String?): Boolean {
return false
}
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
override fun update(rule: ReplaceRule) { override fun update(rule: ReplaceRule) {
viewModel.update(rule) viewModel.update(rule)
} }

@ -10,6 +10,7 @@
android:id="@+id/title_bar" android:id="@+id/title_bar"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:contentLayout="@layout/view_search"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:title="@string/replace_purify" /> app:title="@string/replace_purify" />

@ -32,7 +32,7 @@
<string name="replace_purify">替换净化</string> <string name="replace_purify">替换净化</string>
<string name="not_available">暂无</string> <string name="not_available">暂无</string>
<string name="enable">启用</string> <string name="enable">启用</string>
<string name="replace_purify_search">替换净化-搜索</string>
<string name="bookshelf">书架</string> <string name="bookshelf">书架</string>
<string name="rss">订阅</string> <string name="rss">订阅</string>
<string name="recent_reading">最近阅读</string> <string name="recent_reading">最近阅读</string>

Loading…
Cancel
Save