mirror of
https://github.com/atsunatsu/Look4Sat.git
synced 2026-10-08 21:47:23 +00:00
Added SatEntry data class and SatEntryAdapter
This commit is contained in:
1 parent
753ddee7df
commit
f9039d670f
3 files changed
+62
-1
No files matched your search
@@ -0,0 +1,3 @@
|
|||||||
|
package com.rtbishop.look4sat.repo
|
||||||
|
|
||||||
|
data class SatEntry(val id: Int, val name: String, var isSelected: Boolean = false)
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.rtbishop.look4sat.ui.adapters
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.widget.CheckBox
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.rtbishop.look4sat.R
|
||||||
|
import com.rtbishop.look4sat.repo.SatEntry
|
||||||
|
import com.rtbishop.look4sat.ui.SatEntryDialog
|
||||||
|
|
||||||
|
internal class SatEntryAdapter(private var entriesList: MutableList<SatEntry>) :
|
||||||
|
RecyclerView.Adapter<SatEntryAdapter.SatEntryHolder>() {
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SatEntryHolder {
|
||||||
|
val view = LayoutInflater
|
||||||
|
.from(parent.context)
|
||||||
|
.inflate(R.layout.sat_entry_item, parent, false)
|
||||||
|
return SatEntryHolder(view)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: SatEntryHolder, position: Int) {
|
||||||
|
holder.bind(entriesList[position])
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount(): Int {
|
||||||
|
return entriesList.size
|
||||||
|
}
|
||||||
|
|
||||||
|
fun setEntries(entries: MutableList<SatEntry>) {
|
||||||
|
entriesList = entries
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
internal inner class SatEntryHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||||
|
private val satEntryItem: CheckBox = itemView.findViewById(R.id.sat_entry_item)
|
||||||
|
|
||||||
|
fun bind(satEntry: SatEntry) {
|
||||||
|
satEntryItem.text = satEntry.name
|
||||||
|
satEntryItem.isChecked = SatEntryDialog.tempSelectionList.contains(satEntry.id)
|
||||||
|
|
||||||
|
itemView.setOnClickListener {
|
||||||
|
if (satEntryItem.isChecked) {
|
||||||
|
if (!SatEntryDialog.tempSelectionList.contains(satEntry.id)) {
|
||||||
|
SatEntryDialog.tempSelectionList.add(satEntry.id)
|
||||||
|
satEntry.isSelected = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (SatEntryDialog.tempSelectionList.contains(satEntry.id)) {
|
||||||
|
SatEntryDialog.tempSelectionList.remove(satEntry.id)
|
||||||
|
satEntry.isSelected = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/dialog_title"
|
android:id="@+id/dialog_title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="8dp"
|
android:layout_marginStart="8dp"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
android:id="@+id/dialog_recycler"
|
android:id="@+id/dialog_recycler"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginTop="4dp"
|
||||||
android:layout_marginBottom="8dp"
|
android:layout_marginBottom="8dp"
|
||||||
app:layout_constraintBottom_toTopOf="@+id/dialog_btn_negative"
|
app:layout_constraintBottom_toTopOf="@+id/dialog_btn_negative"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|||||||
Reference in new issue
Block a user