mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
优化
This commit is contained in:
parent
00d5643e8c
commit
ca3d901996
@ -1,9 +1,13 @@
|
||||
package io.legado.app.ui.book.read
|
||||
|
||||
import android.content.Context
|
||||
import android.content.DialogInterface
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import io.legado.app.R
|
||||
import io.legado.app.base.BaseDialogFragment
|
||||
@ -14,6 +18,7 @@ import io.legado.app.databinding.DialogRecyclerViewBinding
|
||||
import io.legado.app.databinding.Item1lineTextBinding
|
||||
import io.legado.app.lib.theme.primaryColor
|
||||
import io.legado.app.model.ReadBook
|
||||
import io.legado.app.ui.replace.edit.ReplaceEditActivity
|
||||
import io.legado.app.utils.setLayout
|
||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
|
||||
@ -23,8 +28,18 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||
class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view) {
|
||||
|
||||
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
|
||||
private val viewModel by activityViewModels<ReadBookViewModel>()
|
||||
private val adapter by lazy { ReplaceAdapter(requireContext()) }
|
||||
|
||||
private var isEdit = false
|
||||
|
||||
private val editActivity =
|
||||
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) {
|
||||
if (it.resultCode == AppCompatActivity.RESULT_OK) {
|
||||
isEdit = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
setLayout(0.9f, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
@ -42,6 +57,12 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDismiss(dialog: DialogInterface) {
|
||||
super.onDismiss(dialog)
|
||||
if (isEdit) {
|
||||
viewModel.replaceRuleChanged()
|
||||
}
|
||||
}
|
||||
|
||||
private inner class ReplaceAdapter(context: Context) :
|
||||
RecyclerAdapter<ReplaceRule, Item1lineTextBinding>(context) {
|
||||
@ -52,7 +73,9 @@ class EffectiveReplacesDialog : BaseDialogFragment(R.layout.dialog_recycler_view
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: Item1lineTextBinding) {
|
||||
binding.root.setOnClickListener {
|
||||
|
||||
getItem(holder.layoutPosition)?.let { item ->
|
||||
editActivity.launch(ReplaceEditActivity.startIntent(requireContext(), item.id))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user