From 40ae21102fbcbda3510c8200ced45403d743f27b Mon Sep 17 00:00:00 2001 From: Lucas Lima Date: Fri, 3 Apr 2020 18:16:17 -0300 Subject: [PATCH] Update history item --- .../antimine/history/views/HistoryAdapter.kt | 6 ++-- .../antimine/history/views/HistoryFragment.kt | 1 - .../history/views/HistoryViewHolder.kt | 1 + app/src/main/res/layout/view_history_item.xml | 29 ++++++++++++++----- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt index 68f26922..23d25583 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryAdapter.kt @@ -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, @@ -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) diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryFragment.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryFragment.kt index ddc00358..7dc073fa 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryFragment.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryFragment.kt @@ -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 diff --git a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt index 21c70d97..432140b0 100644 --- a/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt +++ b/app/src/main/java/dev/lucasnlm/antimine/history/views/HistoryViewHolder.kt @@ -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) } diff --git a/app/src/main/res/layout/view_history_item.xml b/app/src/main/res/layout/view_history_item.xml index 7eb910fc..a6f9f8db 100644 --- a/app/src/main/res/layout/view_history_item.xml +++ b/app/src/main/res/layout/view_history_item.xml @@ -1,5 +1,6 @@ - + + @@ -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" />