From aafdb0a57641306798ce8be00a43fe8f16ffba50 Mon Sep 17 00:00:00 2001 From: Ashinch Date: Thu, 16 Jun 2022 20:54:31 +0800 Subject: [PATCH] Allow feed name changes when adding subscriptions (#114) --- .../home/feeds/subscribe/SubscribeDialog.kt | 20 +++++++++++ .../feeds/subscribe/SubscribeViewModel.kt | 34 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeDialog.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeDialog.kt index 0564224..ab1309d 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeDialog.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeDialog.kt @@ -25,10 +25,12 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.DialogProperties import androidx.hilt.navigation.compose.hiltViewModel import me.ash.reader.R +import me.ash.reader.ui.component.RenameDialog import me.ash.reader.ui.component.base.ClipboardTextField import me.ash.reader.ui.component.base.RYDialog import me.ash.reader.ui.component.base.TextFieldDialog import me.ash.reader.ui.ext.collectAsStateValue +import me.ash.reader.ui.ext.roundClick import me.ash.reader.ui.page.home.feeds.FeedOptionView @OptIn( @@ -76,6 +78,9 @@ fun SubscribeDialog( }, title = { Text( + modifier = Modifier.roundClick { + subscribeViewModel.showRenameDialog() + }, text = if (subscribeUiState.isSearchPage) { subscribeUiState.title } else { @@ -185,6 +190,21 @@ fun SubscribeDialog( }, ) + RenameDialog( + visible = subscribeUiState.renameDialogVisible, + value = subscribeUiState.newName, + onValueChange = { + subscribeViewModel.inputNewName(it) + }, + onDismissRequest = { + subscribeViewModel.hideRenameDialog() + }, + onConfirm = { + subscribeViewModel.renameFeed() + subscribeViewModel.hideRenameDialog() + } + ) + TextFieldDialog( visible = subscribeUiState.newGroupDialogVisible, title = stringResource(R.string.create_new_group), diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt index 6901719..81b39e0 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/SubscribeViewModel.kt @@ -189,6 +189,38 @@ class SubscribeViewModel @Inject constructor( fun switchPage(isSearchPage: Boolean) { _subscribeUiState.update { it.copy(isSearchPage = isSearchPage) } } + + fun showRenameDialog() { + _subscribeUiState.update { + it.copy( + renameDialogVisible = true, + newName = _subscribeUiState.value.feed?.name ?: "", + ) + } + } + + fun hideRenameDialog() { + _subscribeUiState.update { + it.copy( + renameDialogVisible = false, + newName = "", + ) + } + } + + fun inputNewName(content: String) { + _subscribeUiState.update { it.copy(newName = content) } + } + + fun renameFeed() { + _subscribeUiState.value.feed?.let { + _subscribeUiState.update { + it.copy( + feed = it.feed?.copy(name = _subscribeUiState.value.newName), + ) + } + } + } } data class SubscribeUiState( @@ -206,4 +238,6 @@ data class SubscribeUiState( val newGroupContent: String = "", val groups: Flow> = emptyFlow(), val isSearchPage: Boolean = true, + val newName: String = "", + val renameDialogVisible: Boolean = false, )