pull/464/head
Robot 4 years ago
commit db3785d64e
  1. 12
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditActivity.kt
  2. 40
      app/src/main/java/io/legado/app/ui/replace/edit/ReplaceEditViewModel.kt
  3. 14
      app/src/main/res/drawable/ic_cancel.xml
  4. 23
      app/src/main/res/layout/activity_replace_edit.xml
  5. 18
      app/src/main/res/menu/read_book.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,33 @@ 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) {
replaceRule = App.db.replaceRuleDao().findById(id)
} else {
val pattern = intent.getStringExtra("pattern") ?: ""
val isRegex = intent.getBooleanExtra("isRegex", false)
val scope = intent.getStringExtra("scope")
replaceRule = ReplaceRule(
name = pattern,
pattern = pattern,
isRegex = isRegex,
scope = scope
)
}
}.onFinally {
replaceRule?.let {
finally(it)
}
}
}

@ -1,14 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#595757"
android:pathData="M12,4c-4.412,0-8,3.588-8,8s3.588,8,8,8c4.41,0,8-3.588,8-8S16.41,4,12,4z M12,18.545 c-3.608,0-6.546-2.936-6.546-6.545S8.392,5.455,12,5.455c3.607,0,6.545,2.936,6.545,6.545S15.607,18.545,12,18.545z" />
<path
android:fillColor="#595757"
android:pathData="M 13.426 9.546 L 12.002 10.972 L 10.576 9.546 L 9.547 10.575 L 10.973 12 L 9.547 13.425 L 10.576 14.454 L 12.002 13.028 L 13.426 14.454 L 14.454 13.425 L 13.029 12 L 14.454 10.575 Z" />
</vector>

@ -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"

@ -7,7 +7,8 @@
android:id="@+id/menu_add_bookmark"
android:icon="@drawable/ic_bookmark"
android:title="@string/bookmark_add"
app:showAsAction="ifRoom" />
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<group android:id="@+id/menu_group_on_line">
<item
@ -20,17 +21,15 @@
android:id="@+id/menu_refresh"
android:icon="@drawable/ic_refresh_black_24dp"
android:title="@string/refresh"
app:showAsAction="ifRoom" />
app:showAsAction="always" />
<item
android:id="@+id/menu_download"
android:icon="@drawable/ic_download_line"
android:title="@string/offline_cache"
app:showAsAction="never" />
<item
android:id="@+id/menu_disable_book_source"
android:icon="@drawable/ic_cancel"
android:title="@string/disable_book_source"
app:showAsAction="never" />
@ -39,7 +38,6 @@
<group android:id="@+id/menu_group_login">
<item
android:id="@+id/menu_login"
android:icon="@drawable/ic_toc"
android:visible="false"
android:title="@string/login"
app:showAsAction="never" />
@ -60,25 +58,22 @@
android:id="@+id/menu_set_charset"
android:icon="@drawable/ic_translate"
android:title="@string/set_charset"
app:showAsAction="ifRoom" />
app:showAsAction="always" />
</group>
<item
android:id="@+id/menu_copy_text"
android:icon="@drawable/ic_copy"
android:title="@string/copy_text"
app:showAsAction="ifRoom" />
app:showAsAction="never" />
<item
android:id="@+id/menu_page_anim"
android:icon="@drawable/ic_auto_page"
android:title="@string/page_anim"
app:showAsAction="never" />
<item
android:id="@+id/menu_enable_replace"
android:icon="@drawable/ic_find_replace"
android:title="@string/replace_rule_title"
android:checkable="true"
android:checked="true"
@ -86,7 +81,6 @@
<item
android:id="@+id/menu_re_segment"
android:icon="@drawable/ic_toc"
android:title="@string/re_segment"
android:checkable="true"
android:checked="false"
@ -94,13 +88,11 @@
<item
android:id="@+id/menu_update_toc"
android:icon="@drawable/ic_update"
android:title="@string/update_toc"
app:showAsAction="never" />
<item
android:id="@+id/menu_book_info"
android:icon="@drawable/ic_toc"
android:title="@string/book_info"
app:showAsAction="never" />

Loading…
Cancel
Save