Allow feed name changes when adding subscriptions (#114)

This commit is contained in:
Ashinch 2022-06-16 20:54:31 +08:00 committed by GitHub
parent 056f641b13
commit aafdb0a576
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 0 deletions

View File

@ -25,10 +25,12 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import me.ash.reader.R 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.ClipboardTextField
import me.ash.reader.ui.component.base.RYDialog import me.ash.reader.ui.component.base.RYDialog
import me.ash.reader.ui.component.base.TextFieldDialog import me.ash.reader.ui.component.base.TextFieldDialog
import me.ash.reader.ui.ext.collectAsStateValue import me.ash.reader.ui.ext.collectAsStateValue
import me.ash.reader.ui.ext.roundClick
import me.ash.reader.ui.page.home.feeds.FeedOptionView import me.ash.reader.ui.page.home.feeds.FeedOptionView
@OptIn( @OptIn(
@ -76,6 +78,9 @@ fun SubscribeDialog(
}, },
title = { title = {
Text( Text(
modifier = Modifier.roundClick {
subscribeViewModel.showRenameDialog()
},
text = if (subscribeUiState.isSearchPage) { text = if (subscribeUiState.isSearchPage) {
subscribeUiState.title subscribeUiState.title
} else { } 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( TextFieldDialog(
visible = subscribeUiState.newGroupDialogVisible, visible = subscribeUiState.newGroupDialogVisible,
title = stringResource(R.string.create_new_group), title = stringResource(R.string.create_new_group),

View File

@ -189,6 +189,38 @@ class SubscribeViewModel @Inject constructor(
fun switchPage(isSearchPage: Boolean) { fun switchPage(isSearchPage: Boolean) {
_subscribeUiState.update { it.copy(isSearchPage = isSearchPage) } _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( data class SubscribeUiState(
@ -206,4 +238,6 @@ data class SubscribeUiState(
val newGroupContent: String = "", val newGroupContent: String = "",
val groups: Flow<List<Group>> = emptyFlow(), val groups: Flow<List<Group>> = emptyFlow(),
val isSearchPage: Boolean = true, val isSearchPage: Boolean = true,
val newName: String = "",
val renameDialogVisible: Boolean = false,
) )