Skip to content

Commit

Permalink
Display toast when copying to clipboard (closes #17)
Browse files Browse the repository at this point in the history
  • Loading branch information
opatry committed Jan 17, 2022
1 parent e12116e commit 86825e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ class WordleViewModel(inDictionary: List<String>, private val repository: Wordle
updateAlphabet()
}
InputState.NOT_IN_DICTIONARY -> {
_userFeedback += "Not in word list"
userFeedback = _userFeedback.toList()
pushMessage("Not in word list")
updateGrid()
}
InputState.TOO_SHORT -> {
_userFeedback += "Not enough letters"
userFeedback = _userFeedback.toList()
pushMessage("Not enough letters")
updateGrid()
}
else -> Unit
Expand Down Expand Up @@ -222,16 +220,14 @@ class WordleViewModel(inDictionary: List<String>, private val repository: Wordle
// notify user
victory = rules.state is State.Won
if (victory && !oldVictory) {
_userFeedback += rules.state.message
userFeedback = _userFeedback.toList()
pushMessage(rules.state.message)
}
}

fun restart() {
val availableWords = availableWords
if (availableWords.isEmpty()) {
_userFeedback += "All known words were already played."
userFeedback = _userFeedback.toList()
pushMessage("All known words were already played.")
return
}

Expand All @@ -251,7 +247,12 @@ class WordleViewModel(inDictionary: List<String>, private val repository: Wordle
updateAnswer()
}

fun consumed(message: String) {
fun pushMessage(message: String) {
_userFeedback += message
userFeedback = _userFeedback.toList()
}

fun consumeMessage(message: String) {
_userFeedback -= message
userFeedback = _userFeedback.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,14 +235,6 @@ fun GameScreen(settings: Settings, viewModel: WordleViewModel) {
}
}

Column(Modifier.padding(top = 80.dp)) {
userFeedback.forEach { message ->
Toast(message, Modifier.padding(bottom = 4.dp)) {
viewModel.consumed(message)
}
}
}

PopupOverlay(
showRulesPanel,
"How to play",
Expand Down Expand Up @@ -281,11 +273,16 @@ fun GameScreen(settings: Settings, viewModel: WordleViewModel) {
if (lastRecord.isVictory) {
val lastRecordString = lastRecord.resultString
clipboard.setText(AnnotatedString(lastRecordString))
// TODO how to display toast in combination of view model provided ones
//userFeedback += "Copied results to clipboard"
viewModel.pushMessage("Copied results to clipboard")
}
}
}

Column(Modifier.padding(top = 80.dp)) {
userFeedback.forEach { message ->
Toast(message, Modifier.padding(bottom = 4.dp), viewModel::consumeMessage)
}
}
}

@Composable
Expand Down

0 comments on commit 86825e3

Please sign in to comment.