Add retry button
This commit is contained in:
parent
dcd73f36f6
commit
19b91aa432
7 changed files with 94 additions and 20 deletions
|
@ -1,15 +1,18 @@
|
|||
package dev.lucasnlm.antimine.history.views
|
||||
|
||||
import android.content.Intent
|
||||
import android.graphics.PorterDuff
|
||||
import android.net.Uri
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.lucasnlm.antimine.DeepLink
|
||||
import dev.lucasnlm.antimine.R
|
||||
import dev.lucasnlm.antimine.common.level.database.models.Save
|
||||
import dev.lucasnlm.antimine.common.level.database.models.SaveStatus
|
||||
import dev.lucasnlm.antimine.common.level.models.Difficulty
|
||||
import java.text.DateFormat
|
||||
|
||||
class HistoryAdapter(
|
||||
private val saveHistory: List<Save>
|
||||
|
@ -34,20 +37,60 @@ 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.date.text = DateFormat.getDateInstance().format(startDate)
|
||||
val context = holder.itemView.context
|
||||
holder.flag.setColorFilter(
|
||||
when (status) {
|
||||
SaveStatus.VICTORY -> ContextCompat.getColor(context, R.color.victory)
|
||||
SaveStatus.ON_GOING -> ContextCompat.getColor(context, R.color.ongoing)
|
||||
SaveStatus.DEFEAT -> ContextCompat.getColor(context, R.color.lose)
|
||||
}, PorterDuff.Mode.SRC_IN
|
||||
)
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
data = Uri.Builder()
|
||||
.scheme(DeepLink.SCHEME)
|
||||
.authority(DeepLink.RETRY_HOST_AUTHORITY)
|
||||
.appendPath(uid.toString())
|
||||
.build()
|
||||
holder.minefieldSize.text = String.format("%d x %d", minefield.width, minefield.height)
|
||||
holder.minesCount.text = context.getString(R.string.mines_remaining, minefield.mines)
|
||||
|
||||
if (status != SaveStatus.VICTORY) {
|
||||
holder.replay.setImageResource(R.drawable.replay)
|
||||
holder.replay.setOnClickListener {
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
data = Uri.Builder()
|
||||
.scheme(DeepLink.SCHEME)
|
||||
.authority(DeepLink.RETRY_HOST_AUTHORITY)
|
||||
.appendPath(uid.toString())
|
||||
.build()
|
||||
}
|
||||
it.context.startActivity(intent)
|
||||
}
|
||||
it.context.startActivity(intent)
|
||||
} else {
|
||||
holder.replay.setImageResource(R.drawable.play)
|
||||
holder.replay.setOnClickListener { replayGame(it, uid) }
|
||||
}
|
||||
|
||||
holder.itemView.setOnClickListener { loadGame(it, uid) }
|
||||
}
|
||||
|
||||
private fun replayGame(view: View, uid: Int) {
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
data = Uri.Builder()
|
||||
.scheme(DeepLink.SCHEME)
|
||||
.authority(DeepLink.RETRY_HOST_AUTHORITY)
|
||||
.appendPath(uid.toString())
|
||||
.build()
|
||||
}
|
||||
view.context.startActivity(intent)
|
||||
}
|
||||
|
||||
private fun loadGame(view: View, uid: Int) {
|
||||
val intent = Intent(Intent.ACTION_VIEW).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
data = Uri.Builder()
|
||||
.scheme(DeepLink.SCHEME)
|
||||
.authority(DeepLink.LOAD_GAME_AUTHORITY)
|
||||
.appendPath(uid.toString())
|
||||
.build()
|
||||
}
|
||||
view.context.startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,12 +2,14 @@ package dev.lucasnlm.antimine.history.views
|
|||
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import dev.lucasnlm.antimine.R
|
||||
|
||||
class HistoryViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val flag: AppCompatImageView = view.findViewById(R.id.badge)
|
||||
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)
|
||||
val replay: AppCompatImageView = view.findViewById(R.id.replay)
|
||||
}
|
||||
|
|
9
app/src/main/res/drawable/play.xml
Normal file
9
app/src/main/res/drawable/play.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M8,6.82v10.36c0,0.79 0.87,1.27 1.54,0.84l8.14,-5.18c0.62,-0.39 0.62,-1.29 0,-1.69L9.54,5.98C8.87,5.55 8,6.03 8,6.82z"/>
|
||||
</vector>
|
9
app/src/main/res/drawable/retry.xml
Normal file
9
app/src/main/res/drawable/retry.xml
Normal file
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,5V2.21c0,-0.45 -0.54,-0.67 -0.85,-0.35l-3.8,3.79c-0.2,0.2 -0.2,0.51 0,0.71l3.79,3.79c0.32,0.31 0.86,0.09 0.86,-0.36V7c3.73,0 6.68,3.42 5.86,7.29 -0.47,2.27 -2.31,4.1 -4.57,4.57 -3.57,0.75 -6.75,-1.7 -7.23,-5.01 -0.07,-0.48 -0.49,-0.85 -0.98,-0.85 -0.6,0 -1.08,0.53 -1,1.13 0.62,4.39 4.8,7.64 9.53,6.72 3.12,-0.61 5.63,-3.12 6.24,-6.24C20.84,9.48 16.94,5 12,5z"/>
|
||||
</vector>
|
|
@ -66,13 +66,16 @@
|
|||
app:layout_constraintTop_toBottomOf="@id/difficulty"
|
||||
tools:text="9 mines" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/date"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/open"
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/replay"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="32dp"
|
||||
android:contentDescription="@string/retry"
|
||||
android:background="?selectableItemBackgroundBorderless"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="@color/text_color"
|
||||
app:srcCompat="@drawable/retry" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -6,6 +6,10 @@
|
|||
<color name="primary">#212121</color>
|
||||
<color name="primary_dark">#212121</color>
|
||||
|
||||
<color name="victory">#FFFFFF</color>
|
||||
<color name="ongoing">#616161</color>
|
||||
<color name="lose">#616161</color>
|
||||
|
||||
<color name="mines_around_1">#d5d2cc</color>
|
||||
<color name="mines_around_2">#d5d2cc</color>
|
||||
<color name="mines_around_3">#d5d2cc</color>
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
<color name="primary">#FFFFFF</color>
|
||||
<color name="primary_dark">#9E9E9E</color>
|
||||
|
||||
<color name="victory">#4CAF50</color>
|
||||
<color name="ongoing">#455a64</color>
|
||||
<color name="lose">#F44336</color>
|
||||
|
||||
<color name="mines_around_1">#527F8D</color>
|
||||
<color name="mines_around_2">#2B8D43</color>
|
||||
<color name="mines_around_3">#E65100</color>
|
||||
|
|
Loading…
Reference in a new issue