Merge branch 'main' of https://github.com/vitorpamplona/amethyst
* 'main' of https://github.com/vitorpamplona/amethyst: Remove delay, and implement custom moving function that updates the list in one event, rather than two with the previous approach. Increase delay time in moveBookmark. Need to find a better alternative to delay. String resources. Re-introduce display stats for bookmark list, focusing on total bookmarks size per category. Support moving articles/posts from private to public and vice versa.
This commit is contained in:
+17
@@ -265,6 +265,23 @@ class LabeledBookmarkListsState(
|
||||
account.sendMyPublicAndPrivateOutbox(updatedList)
|
||||
}
|
||||
|
||||
suspend fun moveBookmarkInList(
|
||||
bookmark: BookmarkIdTag,
|
||||
bookmarkListIdentifier: String,
|
||||
isBookmarkCurrentlyPrivate: Boolean,
|
||||
account: Account,
|
||||
) {
|
||||
val bookmarkList = getLabeledBookmarkListEvent(bookmarkListIdentifier)
|
||||
val updatedList =
|
||||
LabeledBookmarkListEvent.moveBookmark(
|
||||
earlierVersion = bookmarkList,
|
||||
bookmarkIdTag = bookmark,
|
||||
isCurrentlyPrivate = isBookmarkCurrentlyPrivate,
|
||||
signer = account.signer,
|
||||
)
|
||||
account.sendMyPublicAndPrivateOutbox(updatedList)
|
||||
}
|
||||
|
||||
suspend fun removeBookmarkFromList(
|
||||
bookmark: BookmarkIdTag,
|
||||
bookmarkListIdentifier: String,
|
||||
|
||||
+15
@@ -43,6 +43,7 @@ fun RenderArticleList(
|
||||
bookmarkGroupViewModel: BookmarkGroupViewModel,
|
||||
pagerState: PagerState,
|
||||
accountViewModel: AccountViewModel,
|
||||
moveArticleBookmark: (articleAddress: Address, fromPrivate: Boolean) -> Unit,
|
||||
deleteArticleBookmark: (articleAddress: Address, isPrivate: Boolean) -> Unit,
|
||||
nav: INav,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -56,6 +57,10 @@ fun RenderArticleList(
|
||||
ArticleList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
articles = publicArticles,
|
||||
isArticleBookmarkPrivate = false,
|
||||
onMoveBookmarkToPrivate = { articleAddress ->
|
||||
moveArticleBookmark(articleAddress, false)
|
||||
},
|
||||
onDeleteArticleBookmark = { articleAddress ->
|
||||
deleteArticleBookmark(articleAddress, false)
|
||||
},
|
||||
@@ -66,6 +71,10 @@ fun RenderArticleList(
|
||||
ArticleList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
articles = privateArticles,
|
||||
isArticleBookmarkPrivate = true,
|
||||
onMoveBookmarkToPublic = { articleAddress ->
|
||||
moveArticleBookmark(articleAddress, true)
|
||||
},
|
||||
onDeleteArticleBookmark = { articleAddress ->
|
||||
deleteArticleBookmark(articleAddress, true)
|
||||
},
|
||||
@@ -80,6 +89,9 @@ fun RenderArticleList(
|
||||
fun ArticleList(
|
||||
modifier: Modifier = Modifier,
|
||||
articles: List<AddressableNote>,
|
||||
isArticleBookmarkPrivate: Boolean,
|
||||
onMoveBookmarkToPublic: (articleAddress: Address) -> Unit = {},
|
||||
onMoveBookmarkToPrivate: (articleAddress: Address) -> Unit = {},
|
||||
onDeleteArticleBookmark: (Address) -> Unit,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
@@ -101,6 +113,9 @@ fun ArticleList(
|
||||
moreOptions = {
|
||||
BookmarkGroupItemOptions(
|
||||
baseNote = item,
|
||||
isBookmarkItemPrivate = isArticleBookmarkPrivate,
|
||||
onMoveBookmarkToPublic = { onMoveBookmarkToPublic(item.address) },
|
||||
onMoveBookmarkToPrivate = { onMoveBookmarkToPrivate(item.address) },
|
||||
onDeleteBookmarkItem = {
|
||||
onDeleteArticleBookmark(item.address)
|
||||
},
|
||||
|
||||
+13
-5
@@ -60,6 +60,9 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun BookmarkGroupItemOptions(
|
||||
baseNote: Note,
|
||||
isBookmarkItemPrivate: Boolean,
|
||||
onMoveBookmarkToPublic: () -> Unit,
|
||||
onMoveBookmarkToPrivate: () -> Unit,
|
||||
onDeleteBookmarkItem: () -> Unit,
|
||||
editState: State<GenericLoadable<EditState>>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -76,7 +79,10 @@ fun BookmarkGroupItemOptions(
|
||||
if (popupExpanded.value) {
|
||||
BookmarkGroupItemOptionsMenu(
|
||||
note = baseNote,
|
||||
isBookmarkItemPrivate = isBookmarkItemPrivate,
|
||||
onDismiss = { popupExpanded.value = false },
|
||||
onMoveBookmarkToPublic = onMoveBookmarkToPublic,
|
||||
onMoveBookmarkToPrivate = onMoveBookmarkToPrivate,
|
||||
onDeleteBookmarkItem = onDeleteBookmarkItem,
|
||||
editState = editState,
|
||||
accountViewModel = accountViewModel,
|
||||
@@ -89,7 +95,10 @@ fun BookmarkGroupItemOptions(
|
||||
@Composable
|
||||
fun BookmarkGroupItemOptionsMenu(
|
||||
note: Note,
|
||||
isBookmarkItemPrivate: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
onMoveBookmarkToPublic: () -> Unit,
|
||||
onMoveBookmarkToPrivate: () -> Unit,
|
||||
onDeleteBookmarkItem: () -> Unit,
|
||||
editState: State<GenericLoadable<EditState>>? = null,
|
||||
accountViewModel: AccountViewModel,
|
||||
@@ -149,6 +158,10 @@ fun BookmarkGroupItemOptionsMenu(
|
||||
}
|
||||
|
||||
val scope = rememberCoroutineScope()
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringRes(if (isBookmarkItemPrivate) R.string.move_bookmark_to_public_label else R.string.move_bookmark_to_private_label)) },
|
||||
onClick = if (isBookmarkItemPrivate) onMoveBookmarkToPublic else onMoveBookmarkToPrivate,
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringRes(R.string.bookmark_remove_action_label)) },
|
||||
onClick = {
|
||||
@@ -156,11 +169,6 @@ fun BookmarkGroupItemOptionsMenu(
|
||||
onDismiss()
|
||||
},
|
||||
)
|
||||
// TODO: Work on moving feature below
|
||||
// DropdownMenuItem(
|
||||
// text = { Text("Move to Public") },
|
||||
// onClick =
|
||||
// )
|
||||
HorizontalDivider(thickness = DividerThickness)
|
||||
|
||||
if (!state.isFollowingAuthor) {
|
||||
|
||||
+18
@@ -162,6 +162,15 @@ fun BookmarkGroupScreenView(
|
||||
bookmarkGroupViewModel,
|
||||
pagerState,
|
||||
accountViewModel,
|
||||
movePostBookmark = { postId, isPrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
bookmarkGroupViewModel.movePostBookmark(
|
||||
groupIdentifier = bookmarkGroupViewModel.bookmarkGroupIdentifier,
|
||||
postId = postId,
|
||||
isCurrentlyPrivate = isPrivate,
|
||||
)
|
||||
}
|
||||
},
|
||||
deletePostBookmark = { postId, isPrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
bookmarkGroupViewModel.removePostBookmark(
|
||||
@@ -178,6 +187,15 @@ fun BookmarkGroupScreenView(
|
||||
bookmarkGroupViewModel,
|
||||
pagerState,
|
||||
accountViewModel,
|
||||
moveArticleBookmark = { articleAddress, isPrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
bookmarkGroupViewModel.moveArticleBookmark(
|
||||
groupIdentifier = bookmarkGroupViewModel.bookmarkGroupIdentifier,
|
||||
articleAddress = articleAddress,
|
||||
isCurrentlyPrivate = isPrivate,
|
||||
)
|
||||
}
|
||||
},
|
||||
deleteArticleBookmark = { articleAddress, isPrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
bookmarkGroupViewModel.removeArticleBookmark(
|
||||
|
||||
+31
-2
@@ -69,8 +69,6 @@ class BookmarkGroupViewModel(
|
||||
.map { group -> group.privateArticleBookmarks.map { account.cache.getOrCreateAddressableNote(it.address) } }
|
||||
.stateIn(viewModelScope, SharingStarted.Eagerly, emptyList())
|
||||
|
||||
// TODO: Add implementations for Hashtag and Link bookmarks
|
||||
|
||||
suspend fun deleteBookmarkGroup(groupIdentifier: String) {
|
||||
account.labeledBookmarkLists.deleteBookmarkList(groupIdentifier, account)
|
||||
}
|
||||
@@ -88,6 +86,37 @@ class BookmarkGroupViewModel(
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun movePostBookmark(
|
||||
groupIdentifier: String = bookmarkGroupIdentifier,
|
||||
postId: String,
|
||||
isCurrentlyPrivate: Boolean,
|
||||
) {
|
||||
val eventBookmark = EventBookmark(postId)
|
||||
moveBookmark(groupIdentifier, eventBookmark, isCurrentlyPrivate)
|
||||
}
|
||||
|
||||
suspend fun moveArticleBookmark(
|
||||
groupIdentifier: String = bookmarkGroupIdentifier,
|
||||
articleAddress: Address,
|
||||
isCurrentlyPrivate: Boolean,
|
||||
) {
|
||||
val eventBookmark = AddressBookmark(articleAddress)
|
||||
moveBookmark(groupIdentifier, eventBookmark, isCurrentlyPrivate)
|
||||
}
|
||||
|
||||
suspend fun moveBookmark(
|
||||
groupIdentifier: String = bookmarkGroupIdentifier,
|
||||
bookmark: BookmarkIdTag,
|
||||
isCurrentlyPrivate: Boolean,
|
||||
) {
|
||||
account.labeledBookmarkLists.moveBookmarkInList(
|
||||
bookmark,
|
||||
groupIdentifier,
|
||||
isCurrentlyPrivate,
|
||||
account,
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun removePostBookmark(
|
||||
groupIdentifier: String = bookmarkGroupIdentifier,
|
||||
bookmarkPostId: String,
|
||||
|
||||
+15
@@ -42,6 +42,7 @@ fun RenderPostList(
|
||||
bookmarkGroupViewModel: BookmarkGroupViewModel,
|
||||
pagerState: PagerState,
|
||||
accountViewModel: AccountViewModel,
|
||||
movePostBookmark: (postId: String, fromPrivate: Boolean) -> Unit,
|
||||
deletePostBookmark: (postId: String, isPrivate: Boolean) -> Unit,
|
||||
nav: INav,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -55,6 +56,10 @@ fun RenderPostList(
|
||||
PostList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
posts = publicPosts,
|
||||
isPostBookmarkPrivate = false,
|
||||
onMoveBookmarkToPrivate = { postId ->
|
||||
movePostBookmark(postId, false)
|
||||
},
|
||||
onDeletePostBookmark = { postId ->
|
||||
deletePostBookmark(postId, false)
|
||||
},
|
||||
@@ -65,6 +70,10 @@ fun RenderPostList(
|
||||
PostList(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
posts = privatePosts,
|
||||
isPostBookmarkPrivate = true,
|
||||
onMoveBookmarkToPublic = { postId ->
|
||||
movePostBookmark(postId, true)
|
||||
},
|
||||
onDeletePostBookmark = { postId ->
|
||||
deletePostBookmark(postId, true)
|
||||
},
|
||||
@@ -79,6 +88,9 @@ fun RenderPostList(
|
||||
private fun PostList(
|
||||
modifier: Modifier = Modifier,
|
||||
posts: List<Note>,
|
||||
isPostBookmarkPrivate: Boolean,
|
||||
onMoveBookmarkToPublic: (postId: String) -> Unit = {},
|
||||
onMoveBookmarkToPrivate: (postId: String) -> Unit = {},
|
||||
onDeletePostBookmark: (postId: String) -> Unit,
|
||||
accountViewModel: AccountViewModel,
|
||||
nav: INav,
|
||||
@@ -100,6 +112,9 @@ private fun PostList(
|
||||
moreOptions = {
|
||||
BookmarkGroupItemOptions(
|
||||
baseNote = item,
|
||||
isBookmarkItemPrivate = isPostBookmarkPrivate,
|
||||
onMoveBookmarkToPublic = { onMoveBookmarkToPublic(item.idHex) },
|
||||
onMoveBookmarkToPrivate = { onMoveBookmarkToPrivate(item.idHex) },
|
||||
onDeleteBookmarkItem = { onDeletePostBookmark(item.idHex) },
|
||||
accountViewModel = accountViewModel,
|
||||
nav = nav,
|
||||
|
||||
+17
-19
@@ -32,8 +32,6 @@ import androidx.compose.foundation.layout.offset
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.outlined.Article
|
||||
import androidx.compose.material.icons.outlined.CollectionsBookmark
|
||||
import androidx.compose.material.icons.outlined.Lock
|
||||
import androidx.compose.material.icons.outlined.Public
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
@@ -70,6 +68,7 @@ import com.vitorpamplona.amethyst.ui.theme.Size40Modifier
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size5dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.SpacedBy2dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@Composable
|
||||
fun BookmarkGroupItem(
|
||||
@@ -135,13 +134,12 @@ fun BookmarkGroupItem(
|
||||
contentDescription = stringRes(R.string.bookmark_list_icon_label),
|
||||
modifier = Size40Modifier,
|
||||
)
|
||||
// TODO: Fix the component below, with per-category stats
|
||||
// Spacer(StdVertSpacer)
|
||||
// BookmarkMembershipStatusAndNumberDisplay(
|
||||
// modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
// privateBookmarksSize = bookmarkList.privateBookmarks.size,
|
||||
// publicBookmarksSize = bookmarkList.publicBookmarks.size,
|
||||
// )
|
||||
Spacer(StdVertSpacer)
|
||||
BookmarkMembershipStatusAndNumberDisplay(
|
||||
modifier = Modifier.align(Alignment.CenterHorizontally),
|
||||
postBookmarksSize = bookmarkList.publicPostBookmarks.size + bookmarkList.privatePostBookmarks.size,
|
||||
articleBookmarksSize = bookmarkList.publicArticleBookmarks.size + bookmarkList.privateArticleBookmarks.size,
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
@@ -193,49 +191,49 @@ private fun BookmarkGroupActions(
|
||||
|
||||
@Composable
|
||||
fun BookmarkMembershipStatusAndNumberDisplay(
|
||||
modifier: Modifier,
|
||||
privateBookmarksSize: Int,
|
||||
publicBookmarksSize: Int,
|
||||
modifier: Modifier = Modifier,
|
||||
postBookmarksSize: Int,
|
||||
articleBookmarksSize: Int,
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier.offset(y = (-5).dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = SpacedBy5dp,
|
||||
) {
|
||||
if (privateBookmarksSize <= 0 && publicBookmarksSize <= 0) {
|
||||
if (postBookmarksSize <= 0 && articleBookmarksSize <= 0) {
|
||||
Text(
|
||||
text = stringRes(R.string.follow_set_empty_label2),
|
||||
fontSize = Font10SP,
|
||||
)
|
||||
} else {
|
||||
if (privateBookmarksSize > 0) {
|
||||
if (postBookmarksSize > 0) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = SpacedBy2dp,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Lock,
|
||||
painter = painterResource(R.drawable.post),
|
||||
modifier = Size10Modifier,
|
||||
contentDescription = null,
|
||||
)
|
||||
Text(
|
||||
text = privateBookmarksSize.toString(),
|
||||
text = postBookmarksSize.toString(),
|
||||
fontSize = Font10SP,
|
||||
)
|
||||
}
|
||||
}
|
||||
if (publicBookmarksSize > 0) {
|
||||
if (articleBookmarksSize > 0) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = SpacedBy2dp,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.Public,
|
||||
imageVector = Icons.AutoMirrored.Outlined.Article,
|
||||
modifier = Size10Modifier,
|
||||
contentDescription = null,
|
||||
)
|
||||
Text(
|
||||
text = publicBookmarksSize.toString(),
|
||||
text = articleBookmarksSize.toString(),
|
||||
fontSize = Font10SP,
|
||||
)
|
||||
}
|
||||
|
||||
+2
@@ -110,6 +110,8 @@ private fun ListManagementView(
|
||||
listTitle = bookmarkList.title,
|
||||
isPublicMemberBookmark = maybePublicBookmark != null,
|
||||
isPrivateMemberBookmark = maybePrivateBookmark != null,
|
||||
totalPostBookmarkSize = bookmarkList.publicPostBookmarks.size + bookmarkList.privatePostBookmarks.size,
|
||||
totalArticleBookmarkSize = bookmarkList.publicArticleBookmarks.size + bookmarkList.privateArticleBookmarks.size,
|
||||
onClick = { nav.nav(Route.BookmarkGroupView(bookmarkList.identifier, BookmarkType.ArticleBookmark)) },
|
||||
onAddBookmarkToGroup = { shouldBePrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
|
||||
+13
-3
@@ -23,9 +23,9 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarkgroups.membershipM
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.BookmarkAdd
|
||||
@@ -48,11 +48,13 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.bookmarkgroups.list.BookmarkMembershipStatusAndNumberDisplay
|
||||
import com.vitorpamplona.amethyst.ui.stringRes
|
||||
import com.vitorpamplona.amethyst.ui.theme.HalfHalfVertPadding
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size15Modifier
|
||||
import com.vitorpamplona.amethyst.ui.theme.Size50Modifier
|
||||
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
|
||||
@Composable
|
||||
fun BookmarkGroupManagementItem(
|
||||
@@ -60,6 +62,8 @@ fun BookmarkGroupManagementItem(
|
||||
listTitle: String,
|
||||
isPrivateMemberBookmark: Boolean,
|
||||
isPublicMemberBookmark: Boolean,
|
||||
totalPostBookmarkSize: Int,
|
||||
totalArticleBookmarkSize: Int,
|
||||
onClick: () -> Unit,
|
||||
onAddBookmarkToGroup: (shouldBookmarkBePrivate: Boolean) -> Unit,
|
||||
onRemoveBookmarkFromGroup: () -> Unit,
|
||||
@@ -77,14 +81,20 @@ fun BookmarkGroupManagementItem(
|
||||
BookmarkStatusInList(isPublicMemberBookmark, isPrivateMemberBookmark)
|
||||
},
|
||||
leadingContent = {
|
||||
Box(
|
||||
contentAlignment = Alignment.Center,
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
Icon(
|
||||
imageVector = Icons.Outlined.CollectionsBookmark,
|
||||
contentDescription = stringRes(R.string.bookmark_list_icon_label),
|
||||
modifier = Size50Modifier,
|
||||
)
|
||||
Spacer(StdVertSpacer)
|
||||
BookmarkMembershipStatusAndNumberDisplay(
|
||||
postBookmarksSize = totalPostBookmarkSize,
|
||||
articleBookmarksSize = totalArticleBookmarkSize,
|
||||
)
|
||||
}
|
||||
},
|
||||
trailingContent = {
|
||||
|
||||
+2
@@ -109,6 +109,8 @@ private fun ListManagementView(
|
||||
listTitle = bookmarkList.title,
|
||||
isPublicMemberBookmark = maybePublicBookmark != null,
|
||||
isPrivateMemberBookmark = maybePrivateBookmark != null,
|
||||
totalPostBookmarkSize = bookmarkList.publicPostBookmarks.size + bookmarkList.privatePostBookmarks.size,
|
||||
totalArticleBookmarkSize = bookmarkList.publicArticleBookmarks.size + bookmarkList.privateArticleBookmarks.size,
|
||||
onClick = { nav.nav(Route.BookmarkGroupView(bookmarkList.identifier, BookmarkType.PostBookmark)) },
|
||||
onAddBookmarkToGroup = { shouldBePrivate ->
|
||||
accountViewModel.launchSigner {
|
||||
|
||||
@@ -422,6 +422,8 @@
|
||||
<string name="private_bookmark_add_action_label">Add as private bookmark</string>
|
||||
<string name="bookmark_remove_action_label">Remove from Bookmark List</string>
|
||||
<string name="bookmark_list_explainer">Bookmark lists metadata can be seen by anyone on Nostr. Only your private members are encrypted.</string>
|
||||
<string name="move_bookmark_to_public_label">Move to Public</string>
|
||||
<string name="move_bookmark_to_private_label">Move to Private</string>
|
||||
|
||||
<string name="wallet_connect_service">Wallet Connect Service</string>
|
||||
<string name="wallet_connect_service_explainer">Authorizes a Nostr Secret to pay zaps without leaving the app. Keep the secret safe and use a private relay if possible</string>
|
||||
|
||||
Reference in New Issue
Block a user