feat: 优化代码

pull/111/head
kunfei 5 years ago
parent 7f192df83f
commit f0ce910944
  1. 11
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/read/TextActionMenu.kt
  3. 4
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  4. 8
      app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditDialog.kt
  5. 6
      app/src/main/java/io/legado/app/ui/replacerule/edit/ReplaceEditViewModel.kt

@ -385,12 +385,15 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
}
}
override fun getSelectedText(): String {
return page_view.selectedText
}
override val selectedText: String get() = page_view.selectedText
override fun onMenuItemSelected(item: MenuItemImpl): Boolean {
when (item.itemId) {
R.id.menu_replace -> ReplaceEditDialog.show(
supportFragmentManager,
pattern = selectedText
)
}
return false
}

@ -68,13 +68,13 @@ class TextActionMenu(private val context: Context, private val callBack: CallBac
private fun onMenuItemSelected(item: MenuItemImpl) {
when (item.itemId) {
R.id.menu_copy -> context.sendToClip(callBack.getSelectedText())
R.id.menu_copy -> context.sendToClip(callBack.selectedText)
}
}
interface CallBack {
fun onMenuItemSelected(item: MenuItemImpl): Boolean
fun getSelectedText(): String
val selectedText: String
}
}

@ -306,9 +306,7 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
}
override fun edit(rule: ReplaceRule) {
ReplaceEditDialog
.newInstance(rule.id)
.show(supportFragmentManager, "editReplace")
ReplaceEditDialog.show(supportFragmentManager, rule.id)
}
override fun toTop(rule: ReplaceRule) {

@ -9,6 +9,7 @@ import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Observer
import io.legado.app.R
import io.legado.app.constant.Theme
@ -22,14 +23,15 @@ class ReplaceEditDialog : DialogFragment(),
companion object {
fun newInstance(id: Long? = null): ReplaceEditDialog {
fun show(fragmentManager: FragmentManager, id: Long? = null, pattern: String? = null) {
val dialog = ReplaceEditDialog()
id?.let {
val bundle = Bundle()
bundle.putLong("id", id)
bundle.putString("pattern", pattern)
dialog.arguments = bundle
}
return dialog
dialog.show(fragmentManager, "editReplace")
}
}
@ -56,7 +58,7 @@ class ReplaceEditDialog : DialogFragment(),
tool_bar.inflateMenu(R.menu.replace_edit)
tool_bar.menu.applyTint(requireContext(), Theme.getTheme())
tool_bar.setOnMenuItemClickListener(this)
viewModel.replaceRuleData.observe(this, Observer {
viewModel.replaceRuleData.observe(viewLifecycleOwner, Observer {
upReplaceView(it)
})
arguments?.let {

@ -19,6 +19,12 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application
App.db.replaceRuleDao().findById(id)?.let {
replaceRuleData.postValue(it)
}
} else {
bundle.getString("pattern")?.let { pattern ->
replaceRuleData.postValue(
ReplaceRule(pattern = pattern)
)
}
}
}
}

Loading…
Cancel
Save