Skip to content

Commit 6656090

Browse files
bmc08gtjeffyanta
authored andcommitted
chore(backupkey): reset button state after saving photo
Signed-off-by: Brandon McAnsh <git@bmcreations.dev>
1 parent 01b7b33 commit 6656090

3 files changed

Lines changed: 26 additions & 10 deletions

File tree

app/src/main/java/com/getcode/view/login/AccessKeyViewModel.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import android.annotation.SuppressLint
55
import android.os.Build
66
import com.getcode.analytics.Action
77
import com.getcode.analytics.ActionSource
8-
import com.getcode.analytics.AnalyticsManager
98
import com.getcode.analytics.AnalyticsService
109
import com.getcode.manager.AuthManager
11-
import com.getcode.media.MediaScanner
1210
import com.getcode.manager.MnemonicManager
11+
import com.getcode.media.MediaScanner
1312
import com.getcode.navigation.core.CodeNavigator
1413
import com.getcode.navigation.screens.CodeLoginPermission
1514
import com.getcode.navigation.screens.HomeScreen

app/src/main/java/com/getcode/view/main/account/AccountAccessKeyViewModel.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.getcode.view.main.account
22

33
import android.annotation.SuppressLint
4+
import androidx.lifecycle.viewModelScope
45
import com.getcode.media.MediaScanner
56
import com.getcode.manager.MnemonicManager
67
import com.getcode.navigation.core.CodeNavigator
@@ -10,7 +11,11 @@ import dagger.hilt.android.lifecycle.HiltViewModel
1011
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
1112
import io.reactivex.rxjava3.core.Completable
1213
import io.reactivex.rxjava3.schedulers.Schedulers
14+
import kotlinx.coroutines.delay
15+
import kotlinx.coroutines.flow.update
16+
import kotlinx.coroutines.launch
1317
import javax.inject.Inject
18+
import kotlin.time.Duration.Companion.seconds
1419

1520

1621
@HiltViewModel
@@ -20,23 +25,36 @@ class AccountAccessKeyViewModel @Inject constructor(
2025
mediaScanner: MediaScanner,
2126
) : BaseAccessKeyViewModel(resources, mnemonicManager, mediaScanner) {
2227
@SuppressLint("CheckResult")
23-
fun onSubmit(navigator: CodeNavigator) {
28+
fun onSubmit() {
2429
Completable.create {
2530
val result = saveBitmapToFile()
2631
if (result) it.onComplete() else it.onError(IllegalStateException())
2732
}
2833
.observeOn(AndroidSchedulers.mainThread())
2934
.subscribeOn(Schedulers.computation())
3035
.doOnSubscribe {
31-
uiFlow.value = uiFlow.value.copy(isLoading = true, isEnabled = false)
36+
uiFlow.update {
37+
it.copy(isLoading = true, isEnabled = false)
38+
}
3239
}
3340
.doOnComplete {
34-
uiFlow.value =
35-
uiFlow.value.copy(isLoading = false, isEnabled = false, isSuccess = true)
41+
viewModelScope.launch {
42+
uiFlow.update {
43+
it.copy(isLoading = false, isEnabled = false, isSuccess = true)
44+
}
45+
// wait 2s and reset button state
46+
delay(2.seconds)
47+
48+
uiFlow.update {
49+
it.copy(isSuccess = false, isEnabled = true)
50+
}
51+
52+
}
3653
}
3754
.doOnError {
38-
uiFlow.value =
39-
uiFlow.value.copy(isLoading = false, isEnabled = true, isSuccess = false)
55+
uiFlow.update {
56+
it.copy(isLoading = false, isEnabled = true, isSuccess = false)
57+
}
4058
}
4159
.subscribe({}, ::onSubmitError)
4260
}

app/src/main/java/com/getcode/view/main/account/BackupKey.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import com.getcode.util.launchAppSettings
5656
fun BackupKey(
5757
viewModel: AccountAccessKeyViewModel,
5858
) {
59-
val navigator = LocalCodeNavigator.current
6059
val dataState by viewModel.uiFlow.collectAsState()
6160

6261
val context = LocalContext.current
@@ -83,7 +82,7 @@ fun BackupKey(
8382
val launcher = getPermissionLauncher(onPermissionResult)
8483

8584
if (isExportSeedRequested && isStoragePermissionGranted) {
86-
viewModel.onSubmit(navigator)
85+
viewModel.onSubmit()
8786
isExportSeedRequested = false
8887
}
8988

0 commit comments

Comments
 (0)