Fix: last digit of send amount always lingers when returning to home screen

This commit is contained in:
Kevin Gorham 2020-03-26 09:38:52 -04:00
parent 3d4ae2ae63
commit f724a74993
No known key found for this signature in database
GPG Key ID: CCA55602DF49FC38
1 changed files with 9 additions and 3 deletions

View File

@ -21,8 +21,7 @@ class HomeViewModel @Inject constructor() : ViewModel() {
lateinit var uiModels: Flow<UiModel> lateinit var uiModels: Flow<UiModel>
private val _typedChars = ConflatedBroadcastChannel<Char>() lateinit var _typedChars: ConflatedBroadcastChannel<Char>
private val typedChars = _typedChars.asFlow()
var initialized = false var initialized = false
@ -32,12 +31,19 @@ class HomeViewModel @Inject constructor() : ViewModel() {
twig("Warning already initialized HomeViewModel. Ignoring call to initialize.") twig("Warning already initialized HomeViewModel. Ignoring call to initialize.")
return return
} }
if (::_typedChars.isInitialized) {
_typedChars.close()
}
_typedChars = ConflatedBroadcastChannel()
val typedChars = _typedChars.asFlow()
val zec = typedChars.scan("0") { acc, c -> val zec = typedChars.scan("0") { acc, c ->
when { when {
// no-op cases // no-op cases
acc == "0" && c == '0' acc == "0" && c == '0'
|| (c == '<' && acc == "0") || (c == '<' && acc == "0")
|| (c == '.' && acc.contains('.')) -> {twig("triggered: 1 acc: $acc c: $c $typedChars ") || (c == '.' && acc.contains('.')) -> {twig("triggered: 1 acc: $acc c: $c")
acc acc
} }
c == '<' && acc.length <= 1 -> {twig("triggered: 2 $typedChars") c == '<' && acc.length <= 1 -> {twig("triggered: 2 $typedChars")