替换界面添加正则帮助链接

pull/462/head
gedoor 4 years ago
parent 9021eaae22
commit 8ce3ff401a
  1. 12
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  2. 41
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt
  3. 23
      app/src/main/res/layout/activity_replace_edit.xml

@ -17,9 +17,11 @@ import io.legado.app.constant.EventBus
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.ui.widget.KeyboardToolPop
import io.legado.app.utils.getViewModel
import io.legado.app.utils.openUrl
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.activity_replace_edit.*
import org.jetbrains.anko.displayMetrics
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.toast
import kotlin.math.abs
@ -58,10 +60,12 @@ class ReplaceEditActivity :
override fun onActivityCreated(savedInstanceState: Bundle?) {
mSoftKeyboardTool = KeyboardToolPop(this, AppConst.keyboardToolChars, this)
window.decorView.viewTreeObserver.addOnGlobalLayoutListener(this)
viewModel.replaceRuleData.observe(this, {
viewModel.initData(intent) {
upReplaceView(it)
})
viewModel.initData(intent)
}
iv_help.onClick {
openUrl("https://www.runoob.com/regexp/regexp-syntax.html")
}
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
@ -96,7 +100,7 @@ class ReplaceEditActivity :
}
private fun getReplaceRule(): ReplaceRule {
val replaceRule: ReplaceRule = viewModel.replaceRuleData.value ?: ReplaceRule()
val replaceRule: ReplaceRule = viewModel.replaceRule ?: ReplaceRule()
replaceRule.name = et_name.text.toString()
replaceRule.group = et_group.text.toString()
replaceRule.pattern = et_replace_rule.text.toString()

@ -2,35 +2,36 @@ package io.legado.app.ui.replace.edit
import android.app.Application
import android.content.Intent
import androidx.lifecycle.MutableLiveData
import io.legado.app.App
import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule
class ReplaceEditViewModel(application: Application) : BaseViewModel(application) {
val replaceRuleData = MutableLiveData<ReplaceRule>()
var replaceRule: ReplaceRule? = null
fun initData(intent: Intent) {
fun initData(intent: Intent, finally: (replaceRule: ReplaceRule) -> Unit) {
execute {
replaceRuleData.value ?: let {
val id = intent.getLongExtra("id", -1)
if (id > 0) {
App.db.replaceRuleDao().findById(id)?.let {
replaceRuleData.postValue(it)
}
} else {
val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false)
val scope = intent.getStringExtra("scope")
val rule = ReplaceRule(
name = pattern,
pattern = pattern,
isRegex = isRegex,
scope = scope
)
replaceRuleData.postValue(rule)
val id = intent.getLongExtra("id", -1)
if (id > 0) {
App.db.replaceRuleDao().findById(id)?.let {
replaceRule = it
}
} else {
val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false)
val scope = intent.getStringExtra("scope")
val rule = ReplaceRule(
name = pattern,
pattern = pattern,
isRegex = isRegex,
scope = scope
)
replaceRule = rule
}
}.onFinally {
replaceRule?.let {
finally(it)
}
}
}

@ -62,11 +62,28 @@
android:layout_height="wrap_content" />
</io.legado.app.ui.widget.text.TextInputLayout>
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_use_regex"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_regex" />
android:orientation="horizontal"
android:gravity="center_vertical">
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_use_regex"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/use_regex" />
<ImageView
android:id="@+id/iv_help"
android:layout_width="24dp"
android:layout_height="24dp"
android:src="@drawable/ic_help"
app:tint="@color/secondaryText"
android:contentDescription="@string/help" />
</LinearLayout>
<io.legado.app.ui.widget.text.TextInputLayout
android:id="@+id/til_replace_to"

Loading…
Cancel
Save