mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-02 03:15:37 +00:00
Minor refactoring of EntriesAdapter.kt
This commit is contained in:
1 parent
46f1ea9880
commit
0ddd0286a5
2 files changed
+14
-11
No files matched your search
File renamed without changes.
@@ -84,28 +84,31 @@ class EntriesAdapter : RecyclerView.Adapter<EntriesAdapter.SatItemHolder>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int {
|
override fun getItemCount(): Int = currentItems.size
|
||||||
return currentItems.size
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatItemHolder {
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatItemHolder {
|
||||||
val binding = ItemSatEntryBinding
|
return SatItemHolder.from(parent)
|
||||||
.inflate(LayoutInflater.from(parent.context), parent, false)
|
|
||||||
return SatItemHolder(binding)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBindViewHolder(holder: SatItemHolder, position: Int) {
|
override fun onBindViewHolder(holder: SatItemHolder, position: Int) {
|
||||||
holder.bind(currentItems[position])
|
holder.bind(currentItems[position])
|
||||||
}
|
}
|
||||||
|
|
||||||
inner class SatItemHolder(private val binding: ItemSatEntryBinding) :
|
class SatItemHolder private constructor(private val binding: ItemSatEntryBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
|
|
||||||
fun bind(satItem: SatItem) {
|
fun bind(item: SatItem) {
|
||||||
binding.satEntryCheckbox.text = satItem.name
|
binding.satEntryCheckbox.text = item.name
|
||||||
binding.satEntryCheckbox.isChecked = satItem.isSelected
|
binding.satEntryCheckbox.isChecked = item.isSelected
|
||||||
itemView.setOnClickListener {
|
itemView.setOnClickListener {
|
||||||
satItem.isSelected = binding.satEntryCheckbox.isChecked
|
item.isSelected = binding.satEntryCheckbox.isChecked
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
fun from(parent: ViewGroup): SatItemHolder {
|
||||||
|
val inflater = LayoutInflater.from(parent.context)
|
||||||
|
return SatItemHolder(ItemSatEntryBinding.inflate(inflater, parent, false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user