diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt index 3bec6c67e..8cbab8ce6 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookActivity.kt @@ -54,6 +54,7 @@ import org.jetbrains.anko.toast class ReadBookActivity : VMBaseActivity(R.layout.activity_read_book), PageView.CallBack, ReadMenu.CallBack, + ReadAloudDialog.CallBack, ChangeSourceDialog.CallBack, ReadBookViewModel.CallBack, ColorPickerDialogListener { @@ -63,7 +64,7 @@ class ReadBookActivity : VMBaseActivity(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(R.layout.activity_rea } } + override fun showMenu() { + read_menu.runMenuIn() + } + override fun chapterSize(): Int { return viewModel.chapterSize } diff --git a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt index e3f26e37c..a48544363 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/config/ReadAloudDialog.kt @@ -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() - dismiss() - } + 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) { - ReadAloudService.pause(requireContext()) - ReadAloudService.resume(requireContext()) - } + if (callBack?.readAloudStatus == Status.PLAY) { + ReadAloudService.pause(requireContext()) + ReadAloudService.resume(requireContext()) } } + + interface CallBack { + fun showMenu() + fun openChapterList() + var readAloudStatus: Int + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index b2b9b0b8c..c839da8bf 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -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(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(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { initRecyclerView() + initSearchView() initDataObservers() } @@ -78,6 +83,14 @@ class ReplaceRuleActivity : VMBaseActivity(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(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) } diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index 4c3ceff0f..cefeba9d0 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -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" /> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c849417a..8799447c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,7 +32,7 @@ 替换净化 暂无 启用 - + 替换净化-搜索 书架 订阅 最近阅读