Convert drawer list item to view binding

This commit is contained in:
FooIbar authored and tarsin committed 2023-03-06 23:27:23 +08:00
1 parent 39681dcb8a
commit 595147bacc
3 files changed
+37 -50

No files matched your search

@@ -27,7 +27,6 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
@@ -56,6 +55,7 @@ import com.hippo.ehviewer.Settings
import com.hippo.ehviewer.client.EhUtils
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.databinding.ItemDownloadBinding
import com.hippo.ehviewer.databinding.ItemDrawerListBinding
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener
import com.hippo.ehviewer.download.DownloadService
@@ -675,23 +675,14 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
// TODO
}
private class DownloadLabelHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val label: TextView
val edit: ImageView
val option: ImageView
init {
label = ViewUtils.`$$`(itemView, R.id.tv_key) as TextView
edit = ViewUtils.`$$`(itemView, R.id.iv_edit) as ImageView
option = ViewUtils.`$$`(itemView, R.id.iv_option) as ImageView
}
}
private class DownloadLabelHolder(val binding: ItemDrawerListBinding) :
RecyclerView.ViewHolder(binding.root)
private inner class DownloadLabelAdapter(private val mInflater: LayoutInflater) :
RecyclerView.Adapter<DownloadLabelHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DownloadLabelHolder {
val holder =
DownloadLabelHolder(mInflater.inflate(R.layout.item_drawer_list, parent, false))
DownloadLabelHolder(ItemDrawerListBinding.inflate(mInflater, parent, false))
holder.itemView.setOnClickListener {
val position = holder.bindingAdapterPosition
val label1: String? = if (position == 0) {
@@ -706,7 +697,7 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
closeDrawer(GravityCompat.END)
}
}
holder.edit.setOnClickListener {
holder.binding.edit.setOnClickListener {
val context = context
val label = mLabels[holder.bindingAdapterPosition]
if (context != null) {
@@ -747,17 +738,19 @@ class DownloadsScene : BaseToolbarScene(), DownloadInfoListener, OnClickFabListe
}
}
}
if (list != null) {
holder.label.text = label + " [" + list.size + "]"
} else {
holder.label.text = label
}
if (position < LABEL_OFFSET) {
holder.edit.visibility = View.GONE
holder.option.visibility = View.GONE
} else {
holder.edit.visibility = View.VISIBLE
holder.option.visibility = View.VISIBLE
holder.binding.run {
if (list != null) {
text.text = label + " [" + list.size + "]"
} else {
text.text = label
}
if (position < LABEL_OFFSET) {
edit.visibility = View.GONE
option.visibility = View.GONE
} else {
edit.visibility = View.VISIBLE
option.visibility = View.VISIBLE
}
}
}
@@ -34,7 +34,6 @@ import android.view.View
import android.view.ViewConfiguration
import android.view.ViewGroup
import android.view.ViewPropertyAnimator
import android.widget.ImageView
import android.widget.TextView
import androidx.activity.OnBackPressedCallback
import androidx.activity.result.PickVisualMediaRequest
@@ -86,6 +85,7 @@ import com.hippo.ehviewer.client.parser.GalleryPageUrlParser
import com.hippo.ehviewer.dao.DownloadInfo
import com.hippo.ehviewer.dao.QuickSearch
import com.hippo.ehviewer.databinding.DrawerListRvBinding
import com.hippo.ehviewer.databinding.ItemDrawerListBinding
import com.hippo.ehviewer.databinding.SceneGalleryListBinding
import com.hippo.ehviewer.download.DownloadManager
import com.hippo.ehviewer.download.DownloadManager.DownloadInfoListener
@@ -1113,15 +1113,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
override fun onCancel() {}
}
private class QsDrawerHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
val key: TextView
val option: ImageView
init {
key = ViewUtils.`$$`(itemView, R.id.tv_key) as TextView
option = ViewUtils.`$$`(itemView, R.id.iv_option) as ImageView
}
}
private class QsDrawerHolder(val binding: ItemDrawerListBinding) : RecyclerView.ViewHolder(binding.root)
private inner class MoveDialogHelper(
private val mLabels: Array<String>,
@@ -1141,7 +1133,7 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
private inner class QsDrawerAdapter(private val mInflater: LayoutInflater) :
RecyclerView.Adapter<QsDrawerHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): QsDrawerHolder {
val holder = QsDrawerHolder(mInflater.inflate(R.layout.item_drawer_list, parent, false))
val holder = QsDrawerHolder(ItemDrawerListBinding.inflate(mInflater, parent, false))
if (!mIsTopList) {
holder.itemView.setOnClickListener {
if (null == mHelper) {
@@ -1174,17 +1166,19 @@ class GalleryListScene : SearchBarScene(), OnDragHandlerListener, SearchLayout.H
}
override fun onBindViewHolder(holder: QsDrawerHolder, position: Int) {
if (!mIsTopList) {
holder.key.text = mQuickSearchList[position].name
} else {
val toplists = intArrayOf(
R.string.toplist_alltime,
R.string.toplist_pastyear,
R.string.toplist_pastmonth,
R.string.toplist_yesterday
)
holder.key.text = getString(toplists[position])
holder.option.visibility = View.GONE
holder.binding.run {
if (!mIsTopList) {
text.text = mQuickSearchList[position].name
} else {
val toplists = intArrayOf(
R.string.toplist_alltime,
R.string.toplist_pastyear,
R.string.toplist_pastmonth,
R.string.toplist_yesterday
)
text.text = getString(toplists[position])
option.visibility = View.GONE
}
}
}
+3 -3
View File
@@ -24,7 +24,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/tv_key"
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
@@ -34,7 +34,7 @@
android:textColor="?android:attr/textColorPrimary" />
<ImageView
android:id="@+id/iv_edit"
android:id="@+id/edit"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
@@ -44,7 +44,7 @@
app:srcCompat="@drawable/v_pencil_dark_x24" />
<ImageView
android:id="@+id/iv_option"
android:id="@+id/option"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"