diff --git a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt index 24822211d..1a8ed67f6 100644 --- a/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/bookshelf/BookshelfAdapter.kt @@ -11,7 +11,6 @@ import io.legado.app.data.entities.Book import io.legado.app.help.ImageLoader import io.legado.app.lib.theme.ATH import kotlinx.android.synthetic.main.item_bookshelf_list.view.* -import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name class BookshelfAdapter : PagedListAdapter(DIFF_CALLBACK) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index f7d9cda78..bfd23569c 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -14,7 +14,6 @@ import io.legado.app.lib.theme.ThemeStore import io.legado.app.utils.getCompatColor import io.legado.app.utils.invisible import kotlinx.android.synthetic.main.item_bookshelf_list.view.* -import kotlinx.android.synthetic.main.item_relace_rule.view.tv_name import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onLongClick diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt index 1d8843b19..64a84744f 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditDialog.kt @@ -18,6 +18,20 @@ import kotlinx.android.synthetic.main.dialog_replace_edit.* class ReplaceEditDialog : DialogFragment(), Toolbar.OnMenuItemClickListener { + + companion object { + + fun newInstance(id: Long? = null): ReplaceEditDialog { + val dialog = ReplaceEditDialog() + id?.let { + val bundle = Bundle() + bundle.putLong("data", id) + dialog.arguments = bundle + } + return dialog + } + } + private lateinit var viewModel: ReplaceEditViewModel override fun onStart() { @@ -44,6 +58,9 @@ class ReplaceEditDialog : DialogFragment(), viewModel.replaceRuleData.observe(this, Observer { upReplaceView(it) }) + arguments?.let { + viewModel.initData(it) + } } override fun onMenuItemClick(item: MenuItem?): Boolean { diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt index aa09b0003..a13502fa4 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceEditViewModel.kt @@ -1,7 +1,7 @@ package io.legado.app.ui.replacerule import android.app.Application -import android.content.Intent +import android.os.Bundle import androidx.lifecycle.MutableLiveData import io.legado.app.App import io.legado.app.base.BaseViewModel @@ -11,10 +11,10 @@ class ReplaceEditViewModel(application: Application) : BaseViewModel(application val replaceRuleData = MutableLiveData() - fun initData(intent: Intent) { + fun initData(bundle: Bundle) { execute { replaceRuleData.value ?: let { - val id = intent.getLongExtra("data", -1) + val id = bundle.getLong("data") if (id > 0) { App.db.replaceRuleDao().findById(id)?.let { replaceRuleData.postValue(it) diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt index 41a83d31f..2579cf387 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleActivity.kt @@ -91,6 +91,8 @@ class ReplaceRuleActivity : VMBaseActivity(R.layout.activi } override fun edit(rule: ReplaceRule) { - + ReplaceEditDialog + .newInstance(rule.id) + .show(supportFragmentManager, "editReplace") } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt index b34f6202f..4ab569beb 100644 --- a/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/replacerule/ReplaceRuleAdapter.kt @@ -2,16 +2,17 @@ package io.legado.app.ui.replacerule import android.content.Context import android.view.LayoutInflater +import android.view.Menu import android.view.View import android.view.ViewGroup -import androidx.core.view.isGone +import android.widget.PopupMenu import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.data.entities.ReplaceRule import io.legado.app.help.ItemTouchCallback -import kotlinx.android.synthetic.main.item_relace_rule.view.* +import kotlinx.android.synthetic.main.item_replace_rule.view.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -45,7 +46,13 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { - return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_relace_rule, parent, false)) + return MyViewHolder( + LayoutInflater.from(parent.context).inflate( + R.layout.item_replace_rule, + parent, + false + ) + ) } override fun onBindViewHolder(holder: MyViewHolder, pos: Int) { @@ -53,14 +60,26 @@ class ReplaceRuleAdapter(context: Context, var callBack: CallBack) : } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { - fun bind(rule: ReplaceRule, listener: CallBack?) = with(itemView) { - tv_name.text = rule.name + + fun bind(rule: ReplaceRule, callBack: CallBack) = with(itemView) { + cb_name.text = rule.name swt_enabled.isChecked = rule.isEnabled - iv_delete.isGone = true - iv_edit.isGone = true swt_enabled.onClick { rule.isEnabled = swt_enabled.isChecked - listener?.update(rule) + callBack.update(rule) + } + iv_menu_more.onClick { + val popupMenu = PopupMenu(context, it) + popupMenu.menu.add(Menu.NONE, R.id.menu_edit, Menu.NONE, R.string.edit) + popupMenu.menu.add(Menu.NONE, R.id.menu_del, Menu.NONE, R.string.delete) + popupMenu.setOnMenuItemClickListener { item -> + when (item.itemId) { + R.id.menu_edit -> callBack.edit(rule) + R.id.menu_del -> callBack.delete(rule) + } + true + } + popupMenu.show() } } } diff --git a/app/src/main/res/layout/activity_replace_rule.xml b/app/src/main/res/layout/activity_replace_rule.xml index b703b0371..24e331018 100644 --- a/app/src/main/res/layout/activity_replace_rule.xml +++ b/app/src/main/res/layout/activity_replace_rule.xml @@ -17,9 +17,6 @@ android:id="@+id/rv_replace_rule" android:layout_width="match_parent" android:layout_height="0dp" - android:paddingStart="16dp" - android:paddingEnd="16dp" - android:layout_marginBottom="8dp" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@+id/title_bar" diff --git a/app/src/main/res/layout/item_relace_rule.xml b/app/src/main/res/layout/item_relace_rule.xml deleted file mode 100644 index 87d714997..000000000 --- a/app/src/main/res/layout/item_relace_rule.xml +++ /dev/null @@ -1,86 +0,0 @@ - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/item_replace_rule.xml b/app/src/main/res/layout/item_replace_rule.xml new file mode 100644 index 000000000..a2a476dff --- /dev/null +++ b/app/src/main/res/layout/item_replace_rule.xml @@ -0,0 +1,34 @@ + + + + + + + + +