Skip to content

Commit

Permalink
Created loading state for Create Master Key screen and Login Screen
Browse files Browse the repository at this point in the history
  • Loading branch information
aritra-tech committed Nov 9, 2024
1 parent 9267832 commit 6f4a326
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ fun LoginContent(
UCButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.login),
isLoading = isLoading,
loadingText = "Logging you in..",
onClick = {
isLoading = true
viewModel.logIn(email, password)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.aritradas.uncrack.domain.model.Key
import com.aritradas.uncrack.domain.repository.KeyRepository
import com.aritradas.uncrack.util.runIO
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import javax.inject.Inject

@HiltViewModel
Expand All @@ -34,6 +35,10 @@ class KeyViewModel @Inject constructor(
private val _hasSymbol = MutableLiveData(false)
val hasSymbol: LiveData<Boolean> = _hasSymbol

private val _isLoading = MutableLiveData<Boolean>()
val isLoading: LiveData<Boolean> = _isLoading


fun setMasterKey(masterKey: String) {
_masterKeyLiveData.value = masterKey
validatePassword(masterKey)
Expand All @@ -60,7 +65,10 @@ class KeyViewModel @Inject constructor(
}

fun saveMasterKey(key: Key) = runIO {
delay(2000L)
_isLoading.postValue(true)
repository.setMasterKey(key)
_isLoading.postValue(false)
}

fun getMasterKey() = runIO {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ fun CreateMasterKeyContent(
val enableButtonObserver by masterKeyViewModel.enableButtonLiveData.observeAsState(false)
var passwordVisibility by remember { mutableStateOf(false) }
var confirmPasswordVisibility by remember { mutableStateOf(false) }
val isLoading by masterKeyViewModel.isLoading.observeAsState(false)

Scaffold(
modifier.fillMaxSize()
Expand Down Expand Up @@ -169,6 +170,8 @@ fun CreateMasterKeyContent(
UCButton(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.save),
isLoading = isLoading,
loadingText = "Creating you Master Key",
onClick = {
val key = Key(0, masterKeyObserver)
masterKeyViewModel.saveMasterKey(key)
Expand Down

0 comments on commit 6f4a326

Please sign in to comment.