diff --git a/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt b/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt index 55d270c1..cb0b16ac 100644 --- a/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt +++ b/app/src/main/java/com/readrops/app/feeds/FeedScreenModel.kt @@ -144,13 +144,14 @@ class FeedScreenModel( it.copy( value = "", textFieldError = null, - exception = null + exception = null, + isLoading = false ) } } is DialogState.UpdateFeed -> { - _updateFeedDialogState.update { it.copy(exception = null) } + _updateFeedDialogState.update { it.copy(exception = null, isLoading = false) } } else -> {} @@ -337,7 +338,7 @@ class FeedScreenModel( } else -> { - _updateFeedDialogState.update { it.copy(exception = null) } + _updateFeedDialogState.update { it.copy(exception = null, isLoading = true) } screenModelScope.launch(dispatcher) { with(_updateFeedDialogState.value) { @@ -355,12 +356,12 @@ class FeedScreenModel( ) ) } catch (e: Exception) { - _updateFeedDialogState.update { it.copy(exception = e) } + _updateFeedDialogState.update { it.copy(exception = e, isLoading = false) } return@launch } } - closeDialog() + closeDialog(_feedState.value.dialog) } } } @@ -378,10 +379,16 @@ class FeedScreenModel( } fun folderValidate(updateFolder: Boolean = false) { + _folderState.update { it.copy(isLoading = true) } val name = _folderState.value.value if (name.isEmpty()) { - _folderState.update { it.copy(textFieldError = TextFieldError.EmptyField) } + _folderState.update { + it.copy( + textFieldError = TextFieldError.EmptyField, + isLoading = false + ) + } return } @@ -394,11 +401,11 @@ class FeedScreenModel( repository?.addFolder(Folder(name = name, accountId = currentAccount!!.id)) } } catch (e: Exception) { - _folderState.update { it.copy(exception = e) } + _folderState.update { it.copy(exception = e, isLoading = false) } return@launch } - closeDialog(DialogState.AddFolder) + closeDialog(_feedState.value.dialog) } } diff --git a/app/src/main/java/com/readrops/app/feeds/FeedState.kt b/app/src/main/java/com/readrops/app/feeds/FeedState.kt index f901f39f..b2ee0e50 100644 --- a/app/src/main/java/com/readrops/app/feeds/FeedState.kt +++ b/app/src/main/java/com/readrops/app/feeds/FeedState.kt @@ -50,7 +50,8 @@ data class UpdateFeedDialogState( val folders: List = listOf(), val isAccountDropDownExpanded: Boolean = false, val isFeedUrlReadOnly: Boolean = true, - val exception: Exception? = null + val exception: Exception? = null, + val isLoading: Boolean = false ) { val isFeedNameError get() = feedNameError != null @@ -59,14 +60,4 @@ data class UpdateFeedDialogState( get() = feedUrlError != null val hasFolders = folders.isNotEmpty() -} - -data class FolderState( - val folder: Folder = Folder(), - val nameError: TextFieldError? = null, - val exception: Exception? = null -) { - val name = folder.name - - val isTextFieldError = nameError != null } \ No newline at end of file diff --git a/app/src/main/java/com/readrops/app/feeds/dialogs/UpdateFeedDialog.kt b/app/src/main/java/com/readrops/app/feeds/dialogs/UpdateFeedDialog.kt index e9c24c81..aa042d7e 100644 --- a/app/src/main/java/com/readrops/app/feeds/dialogs/UpdateFeedDialog.kt +++ b/app/src/main/java/com/readrops/app/feeds/dialogs/UpdateFeedDialog.kt @@ -8,7 +8,6 @@ import androidx.compose.material3.Icon import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier @@ -19,6 +18,7 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.readrops.app.R import com.readrops.app.feeds.FeedScreenModel import com.readrops.app.util.ErrorMessage +import com.readrops.app.util.components.LoadingTextButton import com.readrops.app.util.components.dialog.BaseDialog import com.readrops.app.util.theme.LargeSpacer import com.readrops.app.util.theme.MediumSpacer @@ -133,10 +133,10 @@ fun UpdateFeedDialog( LargeSpacer() - TextButton( + LoadingTextButton( + text = stringResource(R.string.validate), + isLoading = state.isLoading, onClick = { viewModel.updateFeedDialogValidate() }, - ) { - Text(text = stringResource(R.string.validate)) - } + ) } } diff --git a/app/src/main/java/com/readrops/app/util/components/LoadingTextButton.kt b/app/src/main/java/com/readrops/app/util/components/LoadingTextButton.kt new file mode 100644 index 00000000..ea3b255f --- /dev/null +++ b/app/src/main/java/com/readrops/app/util/components/LoadingTextButton.kt @@ -0,0 +1,29 @@ +package com.readrops.app.util.components + +import androidx.compose.foundation.layout.size +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.Text +import androidx.compose.material3.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp + +@Composable +fun LoadingTextButton( + text: String, + isLoading: Boolean, + onClick: () -> Unit +) { + TextButton( + onClick = onClick + ) { + if (isLoading) { + CircularProgressIndicator( + strokeWidth = 2.dp, + modifier = Modifier.size(16.dp) + ) + } else { + Text(text = text) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/readrops/app/util/components/dialog/TextFieldDialog.kt b/app/src/main/java/com/readrops/app/util/components/dialog/TextFieldDialog.kt index d0a3f505..c79af6de 100644 --- a/app/src/main/java/com/readrops/app/util/components/dialog/TextFieldDialog.kt +++ b/app/src/main/java/com/readrops/app/util/components/dialog/TextFieldDialog.kt @@ -7,7 +7,6 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text -import androidx.compose.material3.TextButton import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.painter.Painter @@ -15,13 +14,15 @@ import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import com.readrops.app.R import com.readrops.app.util.ErrorMessage +import com.readrops.app.util.components.LoadingTextButton import com.readrops.app.util.components.TextFieldError import com.readrops.app.util.theme.LargeSpacer data class TextFieldDialogState( val value: String = "", val textFieldError: TextFieldError? = null, - val exception: Exception? = null + val exception: Exception? = null, + val isLoading: Boolean = false ) { val isTextFieldError get() = textFieldError != null @@ -36,12 +37,12 @@ fun TextFieldDialog( onValueChange: (String) -> Unit, onValidate: () -> Unit, onDismiss: () -> Unit, - modifier: Modifier = Modifier + modifier: Modifier = Modifier, ) { BaseDialog( title = title, icon = icon, - onDismiss = onDismiss, + onDismiss = { if (!state.isLoading) onDismiss() }, modifier = modifier ) { OutlinedTextField( @@ -74,10 +75,10 @@ fun TextFieldDialog( LargeSpacer() - TextButton( + LoadingTextButton( + text = stringResource(R.string.validate), + isLoading = state.isLoading, onClick = { onValidate() }, - ) { - Text(text = stringResource(R.string.validate)) - } + ) } } \ No newline at end of file