pull/909/head
gedoor 4 years ago
parent b035a44658
commit 1ceda567dc
  1. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 13
      app/src/main/java/io/legado/app/ui/replace/ReplaceRuleActivity.kt
  3. 16
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt

@ -490,8 +490,9 @@ class ReadBookActivity : ReadBookBaseActivity(),
ReadBook.bookSource?.bookSourceUrl?.let {
scopes.add(it)
}
ReplaceEditActivity.show(
ReplaceEditActivity.startForResult(
this,
requestCodeReplace,
pattern = selectedText,
scope = scopes.joinToString(";")
)
@ -955,9 +956,6 @@ class ReadBookActivity : ReadBookBaseActivity(),
observeEvent<String>(PreferKey.showBrightnessView) {
readMenu.upBrightnessState()
}
observeEvent<String>(EventBus.REPLACE_RULE_SAVE) {
viewModel.replaceRuleChanged()
}
}
private fun upScreenTimeOut() {

@ -54,6 +54,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
private val importRequestCode = 132
private val importRequestCodeQr = 133
private val exportRequestCode = 234
private val requestCodeEdit = 213
private lateinit var adapter: ReplaceRuleAdapter
private lateinit var searchView: SearchView
private var groups = hashSetOf<String>()
@ -179,7 +180,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_add_replace_rule ->
ReplaceEditActivity.show(this)
ReplaceEditActivity.startForResult(this, requestCodeEdit)
R.id.menu_group_manage ->
GroupManageDialog().show(supportFragmentManager, "groupManage")
@ -260,8 +261,10 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode != RESULT_OK) return
when (requestCode) {
importRequestCode -> if (resultCode == Activity.RESULT_OK) {
requestCodeEdit -> setResult(RESULT_OK)
importRequestCode -> {
data?.data?.let { uri ->
kotlin.runCatching {
uri.readText(this)?.let {
@ -275,14 +278,14 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
}
}
}
importRequestCodeQr -> if (resultCode == Activity.RESULT_OK) {
importRequestCodeQr -> {
data?.getStringExtra("result")?.let {
startActivity<ImportReplaceRuleActivity> {
putExtra("source", it)
}
}
}
exportRequestCode -> if (resultCode == RESULT_OK) {
exportRequestCode -> {
data?.data?.let { uri ->
if (uri.isContentScheme()) {
DocumentFile.fromTreeUri(this, uri)?.let {
@ -322,7 +325,7 @@ class ReplaceRuleActivity : VMBaseActivity<ActivityReplaceRuleBinding, ReplaceRu
override fun edit(rule: ReplaceRule) {
setResult(RESULT_OK)
ReplaceEditActivity.show(this, rule.id)
ReplaceEditActivity.startForResult(this, requestCodeEdit, rule.id)
}
override fun toTop(rule: ReplaceRule) {

@ -1,6 +1,6 @@
package io.legado.app.ui.replace.edit
import android.content.Context
import android.app.Activity
import android.content.Intent
import android.graphics.Rect
import android.os.Bundle
@ -14,15 +14,12 @@ import androidx.activity.viewModels
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.AppConst
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.databinding.ActivityReplaceEditBinding
import io.legado.app.lib.dialogs.selector
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.ui.widget.dialog.TextDialog
import io.legado.app.utils.getSize
import io.legado.app.utils.postEvent
import io.legado.app.utils.toastOnUi
import kotlin.math.abs
@ -36,19 +33,20 @@ class ReplaceEditActivity :
companion object {
fun show(
context: Context,
fun startForResult(
activity: Activity,
requestCode: Int,
id: Long = -1,
pattern: String? = null,
isRegex: Boolean = false,
scope: String? = null
) {
val intent = Intent(context, ReplaceEditActivity::class.java)
val intent = Intent(activity, ReplaceEditActivity::class.java)
intent.putExtra("id", id)
intent.putExtra("pattern", pattern)
intent.putExtra("isRegex", isRegex)
intent.putExtra("scope", scope)
context.startActivity(intent)
activity.startActivityForResult(intent, requestCode)
}
}
@ -86,7 +84,7 @@ class ReplaceEditActivity :
toastOnUi(R.string.replace_rule_invalid)
} else {
viewModel.save(rule) {
postEvent(EventBus.REPLACE_RULE_SAVE, "")
setResult(RESULT_OK)
finish()
}
}

Loading…
Cancel
Save