From 8900ab391db5eb2a61174d05f12e2743136993e1 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 9 May 2023 16:08:29 +1000 Subject: [PATCH 1/7] Add pending state to button --- .../accountsettings/components/FlatButtons.kt | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt index 9580cecea0d2..bf87ea77bc34 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt @@ -1,8 +1,11 @@ package org.wordpress.android.ui.prefs.accountsettings.components +import androidx.compose.foundation.layout.size import androidx.compose.material.Button import androidx.compose.material.ButtonColors import androidx.compose.material.ButtonDefaults +import androidx.compose.material.CircularProgressIndicator +import androidx.compose.material.LocalContentColor import androidx.compose.material.OutlinedButton import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -40,6 +43,7 @@ fun FlatOutlinedButton( modifier: Modifier = Modifier, colors: ButtonColors = ButtonDefaults.buttonColors(), enabled: Boolean = true, + isPending: Boolean = false, ) = OutlinedButton( modifier = modifier, onClick = onClick, @@ -48,7 +52,14 @@ fun FlatOutlinedButton( defaultElevation = 0.dp, pressedElevation = 0.dp, ), - enabled = enabled, + enabled = enabled && !isPending, ) { - Text(text) + if (isPending) { + CircularProgressIndicator( + strokeWidth = 2.dp, + modifier = Modifier.size(20.dp), + ) + } else { + Text(text) + } } From 0fc22ea04fc12d5eaa02e16d7d0cec50351547da Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 9 May 2023 16:11:32 +1000 Subject: [PATCH 2/7] Add pending flag to dialog state --- .../ui/prefs/accountsettings/AccountSettingsViewModel.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt index 679528bb3477..a5bb205adb46 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt @@ -297,7 +297,8 @@ class AccountSettingsViewModel @Inject constructor( object Dismissed: AccountClosureUiState() sealed class Opened: AccountClosureUiState() { - data class Default(val username: String?): Opened() + data class Default(val username: String?, val isPending: Boolean = false): Opened() + object Atomic: Opened() } } From 99c8a6c785e836c9acc9e37fa4c5ba6a68864bcf Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 9 May 2023 16:11:53 +1000 Subject: [PATCH 3/7] Add fake account closure implementation This resumes the normal dialog after a three second delay for the purpose of testing the ui, and will be wired up to the real implementation after the FluxC changes are available. --- .../accountsettings/AccountSettingsViewModel.kt | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt index a5bb205adb46..d5380da504fc 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt @@ -5,6 +5,7 @@ import androidx.lifecycle.viewModelScope import com.google.android.material.snackbar.Snackbar import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.Job +import kotlinx.coroutines.delay import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow @@ -316,6 +317,19 @@ class AccountSettingsViewModel @Inject constructor( _accountClosureUiState.value = Dismissed } + fun closeAccount() { + (accountClosureUiState.value as? Default)?.let { uiState -> + _accountClosureUiState.value = uiState.copy(isPending = true) + + launch { + delay(3000) + (accountClosureUiState.value as? Default)?.let { uiState -> + _accountClosureUiState.value = uiState.copy(isPending = false) + } + } + } + } + override fun onCleared() { pushAccountSettingsUseCase.onCleared() super.onCleared() From 1eca8a0bdac408cd73b83862c24dc6e8a2a3d8c7 Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Tue, 9 May 2023 16:14:47 +1000 Subject: [PATCH 4/7] Wire up the confirm button to the close account function --- .../accountsettings/components/AccountClosureDialog.kt | 8 ++++++-- .../prefs/accountsettings/components/AccountClosureUi.kt | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureDialog.kt index 7d612242ca86..c715425e2737 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureDialog.kt @@ -12,7 +12,6 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.ButtonDefaults import androidx.compose.material.MaterialTheme -import androidx.compose.material.OutlinedButton import androidx.compose.material.Text import androidx.compose.material.TextField import androidx.compose.runtime.Composable @@ -36,6 +35,8 @@ import org.wordpress.android.ui.compose.theme.AppTheme fun AccountClosureDialog( onDismissRequest: () -> Unit, currentUsername: String, + onConfirm: () -> Unit, + isPending: Boolean, ) { var username by remember { mutableStateOf("") } val padding = 10.dp @@ -82,7 +83,8 @@ fun AccountClosureDialog( text = stringResource(R.string.confirm), modifier = Modifier.weight(1f), enabled = username.isNotEmpty() && username == currentUsername, - onClick = {}, + isPending = isPending, + onClick = onConfirm, colors = ButtonDefaults.buttonColors( contentColor = MaterialTheme.colors.error, backgroundColor = Color.Transparent, @@ -101,6 +103,8 @@ fun PreviewAccountClosureDialog() { AccountClosureDialog( onDismissRequest = {}, currentUsername = "previewUser", + onConfirm = {}, + isPending = false, ) } } diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureUi.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureUi.kt index 817fbb614f91..a53b8347b8bb 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureUi.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/AccountClosureUi.kt @@ -17,6 +17,8 @@ fun AccountClosureUi(viewModel: AccountSettingsViewModel, onHelpRequested: () -> AccountClosureDialog( onDismissRequest = { viewModel.dismissAccountClosureDialog() }, currentUsername, + onConfirm = { viewModel.closeAccount() }, + isPending = it.isPending, ) } From 05634366447c0a0e571a4dad1d9f06ed48c87b1e Mon Sep 17 00:00:00 2001 From: Matthew Kevins Date: Wed, 10 May 2023 06:30:31 +1000 Subject: [PATCH 5/7] Remove unnecessary type-guard in fake closeAccount function --- .../ui/prefs/accountsettings/AccountSettingsViewModel.kt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt index d5380da504fc..8dfb88e34683 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt @@ -323,9 +323,7 @@ class AccountSettingsViewModel @Inject constructor( launch { delay(3000) - (accountClosureUiState.value as? Default)?.let { uiState -> - _accountClosureUiState.value = uiState.copy(isPending = false) - } + _accountClosureUiState.value = uiState.copy(isPending = false) } } } From f478167260753de9a9d1be7db37c70ff33aec038 Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 9 May 2023 22:31:30 +0200 Subject: [PATCH 6/7] Refactor: remove unused imports --- .../android/ui/prefs/accountsettings/components/FlatButtons.kt | 2 -- .../prefs/accountsettings/components/IneligibleClosureDialog.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt index bf87ea77bc34..654e91273f1c 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/FlatButtons.kt @@ -5,12 +5,10 @@ import androidx.compose.material.Button import androidx.compose.material.ButtonColors import androidx.compose.material.ButtonDefaults import androidx.compose.material.CircularProgressIndicator -import androidx.compose.material.LocalContentColor import androidx.compose.material.OutlinedButton import androidx.compose.material.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.dp import org.wordpress.android.ui.compose.theme.AppColor diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/IneligibleClosureDialog.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/IneligibleClosureDialog.kt index c5e8fbc8e4c0..a94a11894e74 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/IneligibleClosureDialog.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/components/IneligibleClosureDialog.kt @@ -2,9 +2,7 @@ package org.wordpress.android.ui.prefs.accountsettings.components import android.content.res.Configuration import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding From 8bb341fda3faba16e199e8c6880dd133a3f7cacf Mon Sep 17 00:00:00 2001 From: Ovi Trif Date: Tue, 9 May 2023 22:32:00 +0200 Subject: [PATCH 7/7] Update: add inline magic number detekt suppression temporarily --- .../android/ui/prefs/accountsettings/AccountSettingsViewModel.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt index 8dfb88e34683..5e708de1edd3 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/prefs/accountsettings/AccountSettingsViewModel.kt @@ -322,6 +322,7 @@ class AccountSettingsViewModel @Inject constructor( _accountClosureUiState.value = uiState.copy(isPending = true) launch { + @Suppress("MagicNumber") delay(3000) _accountClosureUiState.value = uiState.copy(isPending = false) }