This commit is contained in:
kunfei
2023-03-07 20:00:29 +08:00
parent 0949b776cc
commit c88b21e197
4 changed files with 99 additions and 3 deletions
@@ -45,7 +45,7 @@ class GroupSelectDialog() : BaseDialogFragment(R.layout.dialog_book_group_picker
private var requestCode: Int = -1
private val viewModel: GroupViewModel by viewModels()
private val adapter by lazy { GroupAdapter(requireContext()) }
private var callBack: CallBack? = null
private var callBack = (activity as? CallBack)
private var groupId: Long = 0
override fun onStart() {
@@ -55,7 +55,6 @@ class GroupSelectDialog() : BaseDialogFragment(R.layout.dialog_book_group_picker
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor)
callBack = activity as? CallBack
arguments?.let {
groupId = it.getLong("groupId")
requestCode = it.getInt("requestCode", -1)
@@ -1,17 +1,30 @@
package io.legado.app.ui.book.import.remote
import android.content.Context
import android.content.DialogInterface
import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.data.entities.Server
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemServerSelectBinding
import io.legado.app.lib.theme.backgroundColor
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.setLayout
import io.legado.app.utils.viewbindingdelegate.viewBinding
class ServersDialog:BaseDialogFragment(R.layout.dialog_recycler_view) {
class ServersDialog : BaseDialogFragment(R.layout.dialog_recycler_view) {
val binding by viewBinding(DialogRecyclerViewBinding::bind)
val viewModel by viewModels<ServersViewModel>()
private val callback get() = (activity as? Callback)
private val adapter by lazy { ServersAdapter(requireContext()) }
override fun onStart() {
super.onStart()
@@ -20,8 +33,55 @@ class ServersDialog:BaseDialogFragment(R.layout.dialog_recycler_view) {
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.toolBar.setBackgroundColor(primaryColor)
}
private fun initView() {
}
private fun initData() {
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
callback?.onDialogDismiss("serversDialog")
}
class ServersAdapter(context: Context) :
RecyclerAdapter<Server, ItemServerSelectBinding>(context) {
private var selectServerId: Long? = null
override fun getViewBinding(parent: ViewGroup): ItemServerSelectBinding {
return ItemServerSelectBinding.inflate(inflater, parent, false)
}
override fun registerListener(holder: ItemViewHolder, binding: ItemServerSelectBinding) {
}
override fun convert(
holder: ItemViewHolder,
binding: ItemServerSelectBinding,
item: Server,
payloads: MutableList<Any>
) {
binding.run {
root.setBackgroundColor(context.backgroundColor)
rbServer.text = item.name
rbServer.isChecked = item.id == selectServerId
}
}
}
interface Callback {
fun onDialogDismiss(tag: String)
}
}
@@ -0,0 +1,10 @@
package io.legado.app.ui.book.import.remote
import android.app.Application
import io.legado.app.base.BaseViewModel
class ServersViewModel(application: Application): BaseViewModel(application) {
}