pull/32/head
kunfei 5 years ago
parent 17ca8ad645
commit 1d61c72515
  1. 1
      app/src/main/AndroidManifest.xml
  2. 6
      app/src/main/java/io/legado/app/data/dao/ReplaceRuleDao.kt
  3. 33
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditActivity.kt
  4. 61
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt
  5. 26
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt
  6. 3
      app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt
  7. 7
      app/src/main/res/layout/activity_replace_edit.xml
  8. 83
      app/src/main/res/layout/dialog_replace_edit.xml

@ -61,7 +61,6 @@
<activity android:name=".ui.chapterlist.ChapterListActivity" /> <activity android:name=".ui.chapterlist.ChapterListActivity" />
<activity android:name=".ui.readrss.ReadRssActivity" /> <activity android:name=".ui.readrss.ReadRssActivity" />
<activity android:name=".ui.audio.AudioPlayActivity" /> <activity android:name=".ui.audio.AudioPlayActivity" />
<activity android:name=".ui.replacerule.ReplaceEditActivity" />
<service android:name=".service.CheckSourceService" /> <service android:name=".service.CheckSourceService" />
<service android:name=".service.DownloadService" /> <service android:name=".service.DownloadService" />

@ -13,7 +13,7 @@ interface ReplaceRuleDao {
fun observeAll(): DataSource.Factory<Int, ReplaceRule> fun observeAll(): DataSource.Factory<Int, ReplaceRule>
@Query("SELECT id FROM replace_rules ORDER BY sortOrder ASC") @Query("SELECT id FROM replace_rules ORDER BY sortOrder ASC")
fun observeAllIds(): LiveData<List<Int>> fun observeAllIds(): LiveData<List<Long>>
@get:Query("SELECT MAX(sortOrder) FROM replace_rules") @get:Query("SELECT MAX(sortOrder) FROM replace_rules")
val maxOrder: Int val maxOrder: Int
@ -25,10 +25,10 @@ interface ReplaceRuleDao {
val allEnabled: List<ReplaceRule> val allEnabled: List<ReplaceRule>
@Query("SELECT * FROM replace_rules WHERE id = :id") @Query("SELECT * FROM replace_rules WHERE id = :id")
fun findById(id: Int): ReplaceRule? fun findById(id: Long): ReplaceRule?
@Query("SELECT * FROM replace_rules WHERE id in (:ids)") @Query("SELECT * FROM replace_rules WHERE id in (:ids)")
fun findByIds(vararg ids: Int): List<ReplaceRule> fun findByIds(vararg ids: Long): List<ReplaceRule>
@Query( @Query(
"""SELECT * FROM replace_rules WHERE isEnabled = 1 """SELECT * FROM replace_rules WHERE isEnabled = 1

@ -1,33 +0,0 @@
package io.legado.app.ui.replacerule
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.utils.getViewModel
class ReplaceEditActivity :
VMBaseActivity<ReplaceEditViewModel>(R.layout.activity_replace_edit, false) {
override val viewModel: ReplaceEditViewModel
get() = getViewModel(ReplaceEditViewModel::class.java)
override fun onActivityCreated(savedInstanceState: Bundle?) {
}
override fun onCompatCreateOptionsMenu(menu: Menu): Boolean {
menuInflater.inflate(R.menu.replace_edit, menu)
return super.onCompatCreateOptionsMenu(menu)
}
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_save -> {
}
}
return super.onCompatOptionsItemSelected(item)
}
}

@ -0,0 +1,61 @@
package io.legado.app.ui.replacerule
import android.os.Bundle
import android.util.DisplayMetrics
import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.view.ViewGroup.LayoutParams.WRAP_CONTENT
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.DialogFragment
import androidx.lifecycle.Observer
import io.legado.app.R
import io.legado.app.data.entities.ReplaceRule
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.dialog_replace_edit.*
class ReplaceEditDialog : DialogFragment(),
Toolbar.OnMenuItemClickListener {
private lateinit var viewModel: ReplaceEditViewModel
override fun onStart() {
super.onStart()
val dm = DisplayMetrics()
activity?.windowManager?.defaultDisplay?.getMetrics(dm)
dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), WRAP_CONTENT)
}
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
viewModel = getViewModel(ReplaceEditViewModel::class.java)
return inflater.inflate(R.layout.dialog_replace_edit, container)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
tool_bar.inflateMenu(R.menu.replace_edit)
tool_bar.menu.applyTint(requireContext(), false)
tool_bar.setOnMenuItemClickListener(this)
viewModel.replaceRuleData.observe(this, Observer {
upReplaceView(it)
})
}
override fun onMenuItemClick(item: MenuItem?): Boolean {
when (item?.itemId) {
R.id.menu_save -> {
}
}
return true
}
private fun upReplaceView(replaceRule: ReplaceRule) {
}
}

@ -1,9 +1,35 @@
package io.legado.app.ui.replacerule package io.legado.app.ui.replacerule
import android.app.Application 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.base.BaseViewModel
import io.legado.app.data.entities.ReplaceRule
class ReplaceEditViewModel(application: Application) : BaseViewModel(application) { class ReplaceEditViewModel(application: Application) : BaseViewModel(application) {
val replaceRuleData = MutableLiveData<ReplaceRule>()
fun initData(intent: Intent) {
execute {
replaceRuleData.value ?: let {
val id = intent.getLongExtra("data", -1)
if (id > 0) {
App.db.replaceRuleDao().findById(id)?.let {
replaceRuleData.postValue(it)
}
}
}
}
}
fun save(replaceRule: ReplaceRule, success: () -> Unit) {
execute {
App.db.replaceRuleDao().insert(replaceRule)
}.onSuccess {
success()
}
}
} }

@ -44,7 +44,8 @@ class ReplaceRuleActivity : VMBaseActivity<ReplaceRuleViewModel>(R.layout.activi
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) { when (item.itemId) {
R.id.menu_add_replace_rule ->
ReplaceEditDialog().show(supportFragmentManager, "replaceNew")
} }
return super.onCompatOptionsItemSelected(item) return super.onCompatOptionsItemSelected(item)
} }

@ -1,7 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:id="@+id/tool_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="@string/replace_rule_edit" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background">
<LinearLayout
android:id="@+id/ll_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dp">
<io.legado.app.lib.theme.view.ATETextInputLayout
android:id="@+id/til_replace_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/replace_rule_summary">
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/tie_replace_summary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.lib.theme.view.ATETextInputLayout>
<io.legado.app.lib.theme.view.ATETextInputLayout
android:id="@+id/til_replace_rule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/replace_rule">
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/tie_replace_rule"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.lib.theme.view.ATETextInputLayout>
<io.legado.app.lib.theme.view.ATECheckBox
android:id="@+id/cb_use_regex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/use_regex" />
<io.legado.app.lib.theme.view.ATETextInputLayout
android:id="@+id/til_replace_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/replace_to">
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/tie_replace_to"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.lib.theme.view.ATETextInputLayout>
<io.legado.app.lib.theme.view.ATETextInputLayout
android:id="@+id/til_use_to"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/use_to">
<io.legado.app.lib.theme.view.ATEEditText
android:id="@+id/tie_use_to"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</io.legado.app.lib.theme.view.ATETextInputLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
Loading…
Cancel
Save