Unify the underlying implementation for follow sets and use it in both profile actions and CustomListsScreen.
This commit is contained in:
+14
-4
@@ -226,8 +226,14 @@ fun CustomListItem(
|
||||
)
|
||||
}
|
||||
|
||||
followSet.isPrivate.let {
|
||||
val text by derivedStateOf { if (it) "Private" else "Public" }
|
||||
followSet.type.let {
|
||||
val text by derivedStateOf {
|
||||
when (it) {
|
||||
ListType.Public -> "Public"
|
||||
ListType.Private -> "Private"
|
||||
ListType.Mixed -> "Mixed"
|
||||
}
|
||||
}
|
||||
Column(
|
||||
// modifier = modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
@@ -236,7 +242,11 @@ fun CustomListItem(
|
||||
Icon(
|
||||
painter =
|
||||
painterResource(
|
||||
if (followSet.isPrivate) R.drawable.incognito else R.drawable.ic_public,
|
||||
when (it) {
|
||||
ListType.Public -> R.drawable.ic_public
|
||||
ListType.Private -> R.drawable.incognito
|
||||
ListType.Mixed -> R.drawable.format_list_bulleted_type
|
||||
},
|
||||
),
|
||||
contentDescription = "Icon for $text List",
|
||||
)
|
||||
@@ -251,7 +261,7 @@ fun CustomListItem(
|
||||
private fun ListItemPreview() {
|
||||
val sampleFollowSet =
|
||||
FollowSet(
|
||||
isPrivate = false,
|
||||
type = ListType.Mixed,
|
||||
title = "Sample List Title",
|
||||
description = "Sample List Description",
|
||||
emptySet(),
|
||||
|
||||
+4
-4
@@ -25,8 +25,8 @@ import com.vitorpamplona.quartz.nip01Core.signers.NostrSigner
|
||||
import com.vitorpamplona.quartz.nip51Lists.PeopleListEvent
|
||||
|
||||
@Stable
|
||||
class FollowSet(
|
||||
val isPrivate: Boolean,
|
||||
data class FollowSet(
|
||||
val type: ListType,
|
||||
val title: String,
|
||||
val description: String?,
|
||||
val profileList: Set<String>,
|
||||
@@ -44,14 +44,14 @@ class FollowSet(
|
||||
event.privateTaggedUsers(signer) { userList -> privateFollows.addAll(userList) }
|
||||
return if (publicFollows.isEmpty() && privateFollows.isNotEmpty()) {
|
||||
FollowSet(
|
||||
isPrivate = true,
|
||||
type = ListType.Public,
|
||||
title = listTitle,
|
||||
description = listDescription,
|
||||
profileList = privateFollows.toSet(),
|
||||
)
|
||||
} else if (publicFollows.isNotEmpty() && privateFollows.isEmpty()) {
|
||||
FollowSet(
|
||||
isPrivate = false,
|
||||
type = ListType.Private,
|
||||
title = listTitle,
|
||||
description = listDescription,
|
||||
profileList = publicFollows.toSet(),
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Copyright (c) 2024 Vitor Pamplona
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to use,
|
||||
* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||
* Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
package com.vitorpamplona.amethyst.ui.screen.loggedIn.lists
|
||||
|
||||
enum class ListType {
|
||||
Public,
|
||||
Private,
|
||||
Mixed,
|
||||
}
|
||||
+36
-22
@@ -61,6 +61,8 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.PopupProperties
|
||||
import com.vitorpamplona.amethyst.R
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.FollowSet
|
||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.lists.ListType
|
||||
import com.vitorpamplona.amethyst.ui.theme.ButtonBorder
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdHorzSpacer
|
||||
import com.vitorpamplona.amethyst.ui.theme.StdVertSpacer
|
||||
@@ -70,9 +72,9 @@ import kotlinx.coroutines.launch
|
||||
@Composable
|
||||
fun FollowSetsActionMenu(
|
||||
userHex: String,
|
||||
followLists: List<FollowInfo>,
|
||||
followLists: List<FollowSet>,
|
||||
modifier: Modifier = Modifier,
|
||||
addUser: (followListItemIndex: Int, list: FollowInfo) -> Unit,
|
||||
addUser: (followListItemIndex: Int, list: FollowSet) -> Unit,
|
||||
removeUser: (followListItemIndex: Int) -> Unit,
|
||||
) {
|
||||
val (isMenuOpen, setMenuValue) = remember { mutableStateOf(false) }
|
||||
@@ -130,17 +132,17 @@ fun FollowSetsActionMenu(
|
||||
text = {
|
||||
FollowSetItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
listHeader = list.name,
|
||||
listIsPublic = !list.isPrivate,
|
||||
isUserInList = list.memberList.contains(userHex),
|
||||
listHeader = list.title,
|
||||
listType = list.type,
|
||||
isUserInList = list.profileList.contains(userHex),
|
||||
onRemoveUser = {
|
||||
removeUser(index)
|
||||
},
|
||||
onAddUser = {
|
||||
println("List contains user -> ${list.memberList.contains(userHex)}")
|
||||
println("Adding user to List -> ${list.name}")
|
||||
println("List contains user -> ${list.profileList.contains(userHex)}")
|
||||
println("Adding user to List -> ${list.title}")
|
||||
addUser(index, list)
|
||||
println("List contains user -> ${list.memberList.contains(userHex)}")
|
||||
println("List contains user -> ${list.profileList.contains(userHex)}")
|
||||
},
|
||||
)
|
||||
},
|
||||
@@ -169,17 +171,18 @@ private fun DropDownMenuHeader(
|
||||
}
|
||||
}
|
||||
|
||||
data class FollowInfo(
|
||||
val name: String,
|
||||
val isPrivate: Boolean,
|
||||
val memberList: List<String> = listOf(),
|
||||
)
|
||||
|
||||
fun generateFollowLists(): List<FollowInfo> =
|
||||
fun generateFollowLists(): List<FollowSet> =
|
||||
List(10) { index: Int ->
|
||||
FollowInfo(
|
||||
name = "List No $index",
|
||||
isPrivate = index % 2 == 0,
|
||||
FollowSet(
|
||||
type =
|
||||
when {
|
||||
index % 2 == 0 -> ListType.Private
|
||||
index in listOf(3, 7, 9) -> ListType.Mixed
|
||||
else -> ListType.Public
|
||||
},
|
||||
title = "List No $index",
|
||||
description = null,
|
||||
profileList = emptySet(),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -187,7 +190,7 @@ fun generateFollowLists(): List<FollowInfo> =
|
||||
fun FollowSetItem(
|
||||
modifier: Modifier = Modifier,
|
||||
listHeader: String,
|
||||
listIsPublic: Boolean,
|
||||
listType: ListType,
|
||||
isUserInList: Boolean,
|
||||
onAddUser: () -> Unit,
|
||||
onRemoveUser: () -> Unit,
|
||||
@@ -278,8 +281,15 @@ fun FollowSetItem(
|
||||
}
|
||||
}
|
||||
|
||||
listIsPublic.let {
|
||||
val text by derivedStateOf { if (!it) "Private" else "Public" }
|
||||
listType.let {
|
||||
val text by derivedStateOf {
|
||||
when (it) {
|
||||
ListType.Public -> "Public"
|
||||
ListType.Private -> "Private"
|
||||
ListType.Mixed -> "Mixed"
|
||||
}
|
||||
}
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
@@ -287,7 +297,11 @@ fun FollowSetItem(
|
||||
Icon(
|
||||
painter =
|
||||
painterResource(
|
||||
if (!it) R.drawable.incognito else R.drawable.ic_public,
|
||||
when (it) {
|
||||
ListType.Public -> R.drawable.ic_public
|
||||
ListType.Private -> R.drawable.incognito
|
||||
ListType.Mixed -> R.drawable.format_list_bulleted_type
|
||||
},
|
||||
),
|
||||
contentDescription = "Icon for $text List",
|
||||
)
|
||||
|
||||
+6
-6
@@ -59,15 +59,15 @@ fun ProfileActions(
|
||||
followLists = tempFollowLists,
|
||||
addUser = { index, list ->
|
||||
Log.d("Amethyst", "ProfileActions: Updating list ...")
|
||||
val newList = tempFollowLists[index].memberList + baseUser.pubkeyHex
|
||||
tempFollowLists[index] = tempFollowLists[index].copy(memberList = newList)
|
||||
println("Updated List. New size: ${tempFollowLists[index].memberList.size}")
|
||||
val newList = tempFollowLists[index].profileList + baseUser.pubkeyHex
|
||||
tempFollowLists[index] = tempFollowLists[index].copy(profileList = newList)
|
||||
println("Updated List. New size: ${tempFollowLists[index].profileList.size}")
|
||||
},
|
||||
removeUser = { index ->
|
||||
Log.d("Amethyst", "ProfileActions: Updating list ...")
|
||||
val newList = tempFollowLists[index].memberList - baseUser.pubkeyHex
|
||||
tempFollowLists[index] = tempFollowLists[index].copy(memberList = newList)
|
||||
println("Updated List. New size: ${tempFollowLists[index].memberList.size}")
|
||||
val newList = tempFollowLists[index].profileList - baseUser.pubkeyHex
|
||||
tempFollowLists[index] = tempFollowLists[index].copy(profileList = newList)
|
||||
println("Updated List. New size: ${tempFollowLists[index].profileList.size}")
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user