Add counter for group view
This commit is contained in:
parent
71a33c4db7
commit
968f4206cc
@ -4,6 +4,7 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import androidx.fragment.app.FragmentActivity
|
import androidx.fragment.app.FragmentActivity
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
@ -34,18 +35,28 @@ class GroupListAdapter(private val activity: FragmentActivity, private val selec
|
|||||||
|
|
||||||
inner class GroupViewHolder(itemView: View, private val activity: FragmentActivity, private val selectDialog: DialogFragment?) : RecyclerView.ViewHolder(itemView) {
|
inner class GroupViewHolder(itemView: View, private val activity: FragmentActivity, private val selectDialog: DialogFragment?) : RecyclerView.ViewHolder(itemView) {
|
||||||
private val color: Button = itemView.findViewById(R.id.group_color)
|
private val color: Button = itemView.findViewById(R.id.group_color)
|
||||||
|
private val entries: TextView = itemView.findViewById(R.id.name)
|
||||||
|
|
||||||
fun bind(entry: Pair<Int, Groups.Group>) {
|
fun bind(entry: Pair<Int, Groups.Group>) {
|
||||||
color.text = entry.second.name
|
color.text = entry.second.name
|
||||||
color.setBackgroundColor(entry.second.color.color)
|
val entryColor = entry.second.color.color
|
||||||
color.setTextColor(getContrastColor(entry.second.color.color))
|
val contrastEntryColor = getContrastColor(entryColor)
|
||||||
|
color.setBackgroundColor(entryColor)
|
||||||
|
color.setTextColor(contrastEntryColor)
|
||||||
|
entries.setTextColor(contrastEntryColor)
|
||||||
|
entries.text = visits!!.countVisited(entry.first).toString()
|
||||||
|
|
||||||
color.setOnClickListener {
|
color.setOnClickListener {
|
||||||
if (selectDialog == null) {
|
if (selectDialog == null) {
|
||||||
val dialogFragment = EditGroupAddFragment(entry.first) {
|
val dialogFragment = EditGroupAddFragment(entry.first) {
|
||||||
val newEntry = groups!!.getGroupFromKey(entry.first)!!
|
val newEntry = groups!!.getGroupFromKey(entry.first)!!
|
||||||
color.text = newEntry.name
|
color.text = newEntry.name
|
||||||
color.setBackgroundColor(newEntry.color.color)
|
val newEntryColor = newEntry.color.color
|
||||||
color.setTextColor(getContrastColor(newEntry.color.color))
|
val contrastNewEntryColor = getContrastColor(newEntryColor)
|
||||||
|
color.setBackgroundColor(newEntryColor)
|
||||||
|
color.setTextColor(contrastNewEntryColor)
|
||||||
|
entries.setTextColor(contrastNewEntryColor)
|
||||||
|
entries.text = "0"
|
||||||
}
|
}
|
||||||
dialogFragment.show(
|
dialogFragment.show(
|
||||||
activity.supportFragmentManager,
|
activity.supportFragmentManager,
|
||||||
|
@ -28,6 +28,10 @@ class Visits(val id: Int, private val locs: HashMap<String,Int>) {
|
|||||||
return locs.getOrDefault(key.code,0)
|
return locs.getOrDefault(key.code,0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun countVisited(key: Int): Int {
|
||||||
|
return locs.filter { it.value == key }.size
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalSerializationApi::class)
|
@OptIn(ExperimentalSerializationApi::class)
|
||||||
@Serializer(Visits::class)
|
@Serializer(Visits::class)
|
||||||
class VisitsSerializer {
|
class VisitsSerializer {
|
||||||
|
@ -16,11 +16,25 @@
|
|||||||
android:layout_marginTop="2dp"
|
android:layout_marginTop="2dp"
|
||||||
android:layout_marginEnd="32dp"
|
android:layout_marginEnd="32dp"
|
||||||
android:layout_marginBottom="2dp"
|
android:layout_marginBottom="2dp"
|
||||||
|
android:textAlignment="textStart"
|
||||||
|
android:textColor="?attr/colorOnPrimary"
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="50dp"
|
||||||
|
android:gravity="start|center_vertical"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:textColor="?attr/colorOnPrimary"
|
||||||
|
app:layout_constraintTop_toTopOf="@id/group_color"
|
||||||
|
app:layout_constraintBottom_toBottomOf="@id/group_color"
|
||||||
|
app:layout_constraintEnd_toEndOf="@id/group_color" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user