From d7d2ab4585a797e76fddf2a79503040b0b0b0e27 Mon Sep 17 00:00:00 2001 From: Matt Vaughn Date: Tue, 3 May 2022 13:26:30 -0400 Subject: [PATCH] Allow feed URL to be edited Pops up a dialog with an text field allowing editing of the feed url. Identical approach to editing feed name --- .../feeds/option/feed/FeedOptionDrawer.kt | 21 +++++++++ .../feeds/option/feed/FeedOptionViewModel.kt | 47 +++++++++++++++++++ .../page/home/feeds/subscribe/ResultView.kt | 14 ++---- app/src/main/res/values-zh-rCN/strings.xml | 1 + app/src/main/res/values/strings.xml | 2 + 5 files changed, 76 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt index 3b13b6f..fbdbab4 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionDrawer.kt @@ -97,6 +97,9 @@ fun FeedOptionDrawer( }, onAddNewGroup = { feedOptionViewModel.dispatch(FeedOptionViewAction.ShowNewGroupDialog) + }, + onFeedUrlClick = { + feedOptionViewModel.dispatch(FeedOptionViewAction.ShowChangeUrlDialog) } ) } @@ -142,4 +145,22 @@ fun FeedOptionDrawer( context.showToast(toastString) } ) + + TextFieldDialog( + visible = viewState.changeUrlDialogVisible, + title = stringResource(R.string.change_url), + icon = Icons.Outlined.Edit, + value = viewState.newUrl, + placeholder = stringResource(R.string.feed_url_placeholder), + onValueChange = { + feedOptionViewModel.dispatch(FeedOptionViewAction.InputNewUrl(it)) + }, + onDismissRequest = { + feedOptionViewModel.dispatch(FeedOptionViewAction.HideChangeUrlDialog) + }, + onConfirm = { + feedOptionViewModel.dispatch(FeedOptionViewAction.ChangeUrl) + feedOptionViewModel.dispatch(FeedOptionViewAction.Hide(scope)) + } + ) } \ No newline at end of file diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionViewModel.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionViewModel.kt index e555cc3..e2656f1 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionViewModel.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/option/feed/FeedOptionViewModel.kt @@ -61,6 +61,10 @@ class FeedOptionViewModel @Inject constructor( is FeedOptionViewAction.Rename -> rename() is FeedOptionViewAction.ShowRenameDialog -> changeRenameDialogVisible(true) is FeedOptionViewAction.HideRenameDialog -> changeRenameDialogVisible(false) + is FeedOptionViewAction.InputNewUrl -> inputNewUrl(action.content) + is FeedOptionViewAction.ChangeUrl -> changeFeedUrl() + is FeedOptionViewAction.HideChangeUrlDialog -> changeFeedUrlDialogVisible(false) + is FeedOptionViewAction.ShowChangeUrlDialog -> changeFeedUrlDialogVisible(true) } } @@ -212,6 +216,40 @@ class FeedOptionViewModel @Inject constructor( ) } } + + private fun changeFeedUrlDialogVisible(visible: Boolean) { + _viewState.update { + it.copy( + changeUrlDialogVisible = visible, + newUrl = if (visible) _viewState.value.feed?.url ?: "" else "", + ) + } + } + + private fun inputNewUrl(content: String) { + _viewState.update { + it.copy( + newUrl = content + ) + } + } + + private fun changeFeedUrl() { + _viewState.value.feed?.let { + viewModelScope.launch { + rssRepository.get().updateFeed( + it.copy( + url = _viewState.value.newUrl + ) + ) + _viewState.update { + it.copy( + changeUrlDialogVisible = false, + ) + } + } + } + } } @OptIn(ExperimentalMaterialApi::class) @@ -225,6 +263,8 @@ data class FeedOptionViewState( val deleteDialogVisible: Boolean = false, val newName: String = "", val renameDialogVisible: Boolean = false, + val newUrl: String = "", + val changeUrlDialogVisible: Boolean = false, ) sealed class FeedOptionViewAction { @@ -265,4 +305,11 @@ sealed class FeedOptionViewAction { data class InputNewName( val content: String ) : FeedOptionViewAction() + + object ShowChangeUrlDialog : FeedOptionViewAction() + object HideChangeUrlDialog : FeedOptionViewAction() + object ChangeUrl : FeedOptionViewAction() + data class InputNewUrl( + val content: String + ) : FeedOptionViewAction() } diff --git a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/ResultView.kt b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/ResultView.kt index 3c7eb02..ecdd5a4 100644 --- a/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/ResultView.kt +++ b/app/src/main/java/me/ash/reader/ui/page/home/feeds/subscribe/ResultView.kt @@ -1,7 +1,5 @@ package me.ash.reader.ui.page.home.feeds.subscribe -import android.content.Intent -import android.net.Uri import androidx.compose.animation.animateContentSize import androidx.compose.foundation.background import androidx.compose.foundation.clickable @@ -24,7 +22,6 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip -import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.unit.dp @@ -53,6 +50,7 @@ fun ResultView( unsubscribeOnClick: () -> Unit = {}, onGroupClick: (groupId: String) -> Unit = {}, onAddNewGroup: () -> Unit = {}, + onFeedUrlClick: () -> Unit = {} ) { LaunchedEffect(Unit) { if (groups.isNotEmpty() && selectedGroupId.isEmpty()) onGroupClick(groups.first().id) @@ -61,7 +59,7 @@ fun ResultView( Column( modifier = modifier.verticalScroll(rememberScrollState()) ) { - Link(text = link) + EditableUrl(text = link, onFeedUrlClick) Spacer(modifier = Modifier.height(26.dp)) Preset( @@ -86,10 +84,10 @@ fun ResultView( } @Composable -private fun Link( +private fun EditableUrl( text: String, + onClick: () -> Unit ) { - val context = LocalContext.current Row( modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center @@ -97,9 +95,7 @@ private fun Link( SelectionContainer { Text( modifier = Modifier.roundClick { - context.startActivity( - Intent(Intent.ACTION_VIEW, Uri.parse(text)) - ) + onClick() }, text = text, color = MaterialTheme.colorScheme.outline.copy(alpha = 0.7f), diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml index bea1e53..2beeee0 100644 --- a/app/src/main/res/values-zh-rCN/strings.xml +++ b/app/src/main/res/values-zh-rCN/strings.xml @@ -43,6 +43,7 @@ 将 \"%1$s\" 分组中的所有订阅源移动至 \"%2$s\" 分组。 已全部移动至 \"%1$s\" 分组 重命名 + Change URL 已重命名为 \"%1$s\" 新建分组 名称 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 6e0a66d..8376cc5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -43,6 +43,8 @@ Move all feeds in the \"%1$s\" group to the \"%2$s\" group. Moved all to \"%1$s\" group Rename + Change URL + http://example.com/feed.rss Renamed to \"%1$s\" Create New Group Name