pull/32/head
parent
17ca8ad645
commit
1d61c72515
@ -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 |
||||
|
||||
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>() |
||||
|
||||
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() |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
@ -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…
Reference in new issue