mirror of
https://github.com/gedoor/legado.git
synced 2024-07-17 00:58:29 +08:00
优化
This commit is contained in:
parent
65161f1b4f
commit
56fcdd6d92
@ -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) {
|
||||
|
||||
|
||||
|
||||
}
|
27
app/src/main/res/layout/item_server_select.xml
Normal file
27
app/src/main/res/layout/item_server_select.xml
Normal file
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/background"
|
||||
android:padding="8dp"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<io.legado.app.lib.theme.view.ThemeRadioButton
|
||||
android:id="@+id/rb_server"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_weight="1"
|
||||
android:singleLine="true"
|
||||
android:textColor="@color/primaryText" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:padding="8dp"
|
||||
android:text="@string/edit" />
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user