Merge pull request #36 from mattttvaughn/Feature/Add-Editor-For-Feed-Url

Allow feed URL to be edited
This commit is contained in:
Ashinch 2022-05-04 03:39:12 +08:00 committed by GitHub
commit 1aa6e28300
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 76 additions and 9 deletions

View File

@ -97,6 +97,9 @@ fun FeedOptionDrawer(
}, },
onAddNewGroup = { onAddNewGroup = {
feedOptionViewModel.dispatch(FeedOptionViewAction.ShowNewGroupDialog) feedOptionViewModel.dispatch(FeedOptionViewAction.ShowNewGroupDialog)
},
onFeedUrlClick = {
feedOptionViewModel.dispatch(FeedOptionViewAction.ShowChangeUrlDialog)
} }
) )
} }
@ -142,4 +145,22 @@ fun FeedOptionDrawer(
context.showToast(toastString) 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))
}
)
} }

View File

@ -61,6 +61,10 @@ class FeedOptionViewModel @Inject constructor(
is FeedOptionViewAction.Rename -> rename() is FeedOptionViewAction.Rename -> rename()
is FeedOptionViewAction.ShowRenameDialog -> changeRenameDialogVisible(true) is FeedOptionViewAction.ShowRenameDialog -> changeRenameDialogVisible(true)
is FeedOptionViewAction.HideRenameDialog -> changeRenameDialogVisible(false) 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) @OptIn(ExperimentalMaterialApi::class)
@ -225,6 +263,8 @@ data class FeedOptionViewState(
val deleteDialogVisible: Boolean = false, val deleteDialogVisible: Boolean = false,
val newName: String = "", val newName: String = "",
val renameDialogVisible: Boolean = false, val renameDialogVisible: Boolean = false,
val newUrl: String = "",
val changeUrlDialogVisible: Boolean = false,
) )
sealed class FeedOptionViewAction { sealed class FeedOptionViewAction {
@ -265,4 +305,11 @@ sealed class FeedOptionViewAction {
data class InputNewName( data class InputNewName(
val content: String val content: String
) : FeedOptionViewAction() ) : FeedOptionViewAction()
object ShowChangeUrlDialog : FeedOptionViewAction()
object HideChangeUrlDialog : FeedOptionViewAction()
object ChangeUrl : FeedOptionViewAction()
data class InputNewUrl(
val content: String
) : FeedOptionViewAction()
} }

View File

@ -1,7 +1,5 @@
package me.ash.reader.ui.page.home.feeds.subscribe 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.animation.animateContentSize
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
@ -24,7 +22,6 @@ import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
@ -53,6 +50,7 @@ fun ResultView(
unsubscribeOnClick: () -> Unit = {}, unsubscribeOnClick: () -> Unit = {},
onGroupClick: (groupId: String) -> Unit = {}, onGroupClick: (groupId: String) -> Unit = {},
onAddNewGroup: () -> Unit = {}, onAddNewGroup: () -> Unit = {},
onFeedUrlClick: () -> Unit = {}
) { ) {
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
if (groups.isNotEmpty() && selectedGroupId.isEmpty()) onGroupClick(groups.first().id) if (groups.isNotEmpty() && selectedGroupId.isEmpty()) onGroupClick(groups.first().id)
@ -61,7 +59,7 @@ fun ResultView(
Column( Column(
modifier = modifier.verticalScroll(rememberScrollState()) modifier = modifier.verticalScroll(rememberScrollState())
) { ) {
Link(text = link) EditableUrl(text = link, onFeedUrlClick)
Spacer(modifier = Modifier.height(26.dp)) Spacer(modifier = Modifier.height(26.dp))
Preset( Preset(
@ -86,10 +84,10 @@ fun ResultView(
} }
@Composable @Composable
private fun Link( private fun EditableUrl(
text: String, text: String,
onClick: () -> Unit
) { ) {
val context = LocalContext.current
Row( Row(
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.Center horizontalArrangement = Arrangement.Center
@ -97,9 +95,7 @@ private fun Link(
SelectionContainer { SelectionContainer {
Text( Text(
modifier = Modifier.roundClick { modifier = Modifier.roundClick {
context.startActivity( onClick()
Intent(Intent.ACTION_VIEW, Uri.parse(text))
)
}, },
text = text, text = text,
color = MaterialTheme.colorScheme.outline.copy(alpha = 0.7f), color = MaterialTheme.colorScheme.outline.copy(alpha = 0.7f),

View File

@ -43,6 +43,7 @@
<string name="all_move_to_group_tip">将 \"%1$s\" 分组中的所有订阅源移动至 \"%2$s\" 分组。</string> <string name="all_move_to_group_tip">将 \"%1$s\" 分组中的所有订阅源移动至 \"%2$s\" 分组。</string>
<string name="all_move_to_group_toast">已全部移动至 \"%1$s\" 分组</string> <string name="all_move_to_group_toast">已全部移动至 \"%1$s\" 分组</string>
<string name="rename">重命名</string> <string name="rename">重命名</string>
<string name="change_url">Change URL</string>
<string name="rename_toast">已重命名为 \"%1$s\"</string> <string name="rename_toast">已重命名为 \"%1$s\"</string>
<string name="create_new_group">新建分组</string> <string name="create_new_group">新建分组</string>
<string name="name">名称</string> <string name="name">名称</string>

View File

@ -43,6 +43,8 @@
<string name="all_move_to_group_tip">Move all feeds in the \"%1$s\" group to the \"%2$s\" group.</string> <string name="all_move_to_group_tip">Move all feeds in the \"%1$s\" group to the \"%2$s\" group.</string>
<string name="all_move_to_group_toast">Moved all to \"%1$s\" group</string> <string name="all_move_to_group_toast">Moved all to \"%1$s\" group</string>
<string name="rename">Rename</string> <string name="rename">Rename</string>
<string name="change_url">Change URL</string>
<string name="feed_url_placeholder" translatable="false">http://example.com/feed.rss</string>
<string name="rename_toast">Renamed to \"%1$s\"</string> <string name="rename_toast">Renamed to \"%1$s\"</string>
<string name="create_new_group">Create New Group</string> <string name="create_new_group">Create New Group</string>
<string name="name">Name</string> <string name="name">Name</string>