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. 18
      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),
PageView.CallBack,
ReadMenu.CallBack,
ReadAloudDialog.CallBack,
ChangeSourceDialog.CallBack,
ReadBookViewModel.CallBack,
ColorPickerDialogListener {
@ -63,7 +64,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_rea
private val requestCodeEditSource = 111
private var changeSourceDialog: ChangeSourceDialog? = null
private var timeElectricityReceiver: TimeElectricityReceiver? = null
var readAloudStatus = Status.STOP
override var readAloudStatus = Status.STOP
override fun onActivityCreated(savedInstanceState: Bundle?) {
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 {
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.ReadBookActivity
import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_read_book.*
import kotlinx.android.synthetic.main.dialog_read_aloud.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class ReadAloudDialog : DialogFragment() {
var callBack: CallBack? = null
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
callBack = activity as? CallBack
return inflater.inflate(R.layout.dialog_read_aloud, container)
}
@ -111,12 +112,10 @@ class ReadAloudDialog : DialogFragment() {
private fun initOnClick() {
iv_menu.onClick {
val activity = activity
if (activity is ReadBookActivity) {
activity.read_menu.runMenuIn()
callBack?.showMenu()
dismiss()
}
}
iv_menu.onLongClick { callBack?.openChapterList(); true }
iv_stop.onClick { ReadAloudService.stop(requireContext()); dismiss() }
iv_play_pause.onClick { postEvent(Bus.READ_ALOUD_BUTTON, true) }
iv_play_prev.onClick { ReadAloudService.prevParagraph(requireContext()) }
@ -134,13 +133,16 @@ class ReadAloudDialog : DialogFragment() {
}
private fun upTtsSpeechRate() {
val activity = activity
ReadAloudService.upTtsSpeechRate(requireContext())
if (activity is ReadBookActivity) {
if (activity.readAloudStatus == Status.PLAY) {
if (callBack?.readAloudStatus == Status.PLAY) {
ReadAloudService.pause(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.MenuItem
import android.view.SubMenu
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData
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.help.ItemTouchCallback
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.splitNotBlank
import kotlinx.android.synthetic.main.activity_replace_rule.*
import kotlinx.android.synthetic.main.view_search.*
import org.jetbrains.anko.doAsync
class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activity_replace_rule),
SearchView.OnQueryTextListener,
ReplaceRuleAdapter.CallBack {
override val viewModel: ReplaceRuleViewModel
get() = getViewModel(ReplaceRuleViewModel::class.java)
@ -37,6 +41,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
initSearchView()
initDataObservers()
}
@ -78,6 +83,14 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
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() {
rulesLiveData?.removeObservers(this)
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) {
viewModel.update(rule)
}

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

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

Loading…
Cancel
Save