Make emoji clickable

This commit is contained in:
Lucas Lima 2020-03-08 11:52:02 -03:00
parent 87a2fbde04
commit fb4a439f43
3 changed files with 20 additions and 7 deletions

View file

@ -53,15 +53,26 @@ class EndGameDialogFragment : DaggerAppCompatDialogFragment() {
.from(context)
.inflate(R.layout.dialog_end_game, null, false)
.apply {
val title = if (isVictory)
endGameViewModel.randomVictoryEmoji() else endGameViewModel.randomGameOverEmoji()
val title = when {
isVictory -> endGameViewModel.randomVictoryEmoji()
else -> endGameViewModel.randomGameOverEmoji()
}
val titleRes =
if (isVictory) R.string.you_won else R.string.you_lost
val message = endGameViewModel.messageTo(context, rightMines, totalMines, time, isVictory)
findViewById<TextView>(R.id.title_emoji).text = title
findViewById<TextView>(R.id.title).text = context.getString(titleRes)
findViewById<TextView>(R.id.subtitle).text = message
findViewById<TextView>(R.id.title_emoji).apply {
text = title
setOnClickListener {
text = when {
isVictory -> endGameViewModel.randomVictoryEmoji(text.toString())
else -> endGameViewModel.randomGameOverEmoji(text.toString())
}
}
}
}
setView(view)

View file

@ -5,14 +5,14 @@ import androidx.lifecycle.ViewModel
import dev.lucasnlm.antimine.R
class EngGameDialogViewModel : ViewModel() {
fun randomVictoryEmoji() = listOf(
fun randomVictoryEmoji(except: String? = null) = listOf(
"\uD83D\uDE00", "\uD83D\uDE0E", "\uD83D\uDE1D", "\uD83E\uDD73", "\uD83D\uDE06"
).random()
).filter { it != except }.random()
fun randomGameOverEmoji() = listOf(
fun randomGameOverEmoji(except: String? = null) = listOf(
"\uD83D\uDE10", "\uD83D\uDE44", "\uD83D\uDE25", "\uD83D\uDE13", "\uD83D\uDE31",
"\uD83E\uDD2C", "\uD83E\uDD15", "\uD83D\uDE16", "\uD83D\uDCA3", "\uD83D\uDE05"
).random()
).filter { it != except }.random()
fun messageTo(context: Context, rightMines: Int, totalMines: Int, time: Long, isVictory: Boolean) =
when {

View file

@ -13,6 +13,8 @@
android:layout_height="wrap_content"
android:textColor="#FF000000"
android:textSize="52sp"
android:background="?selectableItemBackgroundBorderless"
android:clickable="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"