Update history item

This commit is contained in:
Lucas Lima 2020-04-03 18:16:17 -03:00 committed by Lucas Lima
parent 2431718ce2
commit 40ae21102f
4 changed files with 27 additions and 10 deletions

View file

@ -7,6 +7,7 @@ import dev.lucasnlm.antimine.R
import dev.lucasnlm.antimine.common.level.database.models.Save
import dev.lucasnlm.antimine.common.level.models.Difficulty
import dev.lucasnlm.antimine.common.level.viewmodel.GameViewModel
import java.text.DateFormat
class HistoryAdapter(
private val saveHistory: List<Save>,
@ -21,7 +22,7 @@ class HistoryAdapter(
override fun getItemCount(): Int = saveHistory.size
override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) = with (saveHistory[position]) {
override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) = with(saveHistory[position]) {
holder.difficulty.text = holder.itemView.context.getString(when (difficulty) {
Difficulty.Beginner -> R.string.beginner
Difficulty.Intermediate -> R.string.intermediate
@ -31,7 +32,8 @@ class HistoryAdapter(
})
holder.minefieldSize.text = String.format("%d x %d", minefield.width, minefield.height)
//holder.minesCount.text = holder.itemView.context.getString(R.string.mines_remaining, minefield.mines)
holder.minesCount.text = holder.itemView.context.getString(R.string.mines_remaining, minefield.mines)
holder.date.text = DateFormat.getDateInstance().format(startDate)
holder.itemView.setOnClickListener {
gameViewModel.resumeGameFromSave(this)

View file

@ -4,7 +4,6 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProviders
import androidx.recyclerview.widget.DividerItemDecoration

View file

@ -9,4 +9,5 @@ class HistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val difficulty: TextView = view.findViewById(R.id.difficulty)
val minefieldSize: TextView = view.findViewById(R.id.minefieldSize)
val minesCount: TextView = view.findViewById(R.id.minesCount)
val date: TextView = view.findViewById(R.id.date)
}

View file

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
@ -9,13 +10,25 @@
android:focusable="true"
android:padding="16dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/badge"
android:layout_width="32dp"
android:layout_height="32dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:tint="@color/text_color"
app:srcCompat="@drawable/flag" />
<TextView
android:id="@+id/difficulty"
android:textColor="@color/black"
android:textColor="@color/text_color"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toEndOf="@id/badge"
app:layout_constraintTop_toTopOf="parent"
tools:text="Difficulty" />
@ -24,7 +37,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
app:layout_constraintStart_toEndOf="@id/badge"
app:layout_constraintTop_toBottomOf="@id/difficulty"
tools:text="9 x 9" />
@ -37,7 +52,8 @@
android:layout_marginTop="4dp"
android:text="-"
app:layout_constraintStart_toEndOf="@id/minefieldSize"
app:layout_constraintTop_toBottomOf="@id/difficulty" />
app:layout_constraintTop_toBottomOf="@id/difficulty"
tools:ignore="HardcodedText" />
<TextView
android:id="@+id/minesCount"
@ -51,11 +67,10 @@
tools:text="9 mines" />
<TextView
android:id="@+id/open"
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />