commit 23b681db2b2b18dddae0b26e8cb55957eda0157a
parent aa0a3d953018d3f3c8b46ce5496f824aab2c1164
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date: Tue, 13 Aug 2024 15:27:24 +0200
feat(ui/add_friend_dialogs): support more pinned ids
Diffstat:
2 files changed, 30 insertions(+), 28 deletions(-)
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/social/SocialRootSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/social/SocialRootSection.kt
@@ -45,27 +45,6 @@ class SocialRootSection : Routes.Route() {
}
}
- private val addFriendDialog by lazy {
- AddFriendDialog(context, AddFriendDialog.Actions(
- onFriendState = { friend, state ->
- if (state) {
- context.bridgeService?.triggerScopeSync(SocialScope.FRIEND, friend.userId)
- } else {
- context.database.deleteFriend(friend.userId)
- }
- },
- onGroupState = { group, state ->
- if (state) {
- context.bridgeService?.triggerScopeSync(SocialScope.GROUP, group.conversationId)
- } else {
- context.database.deleteGroup(group.conversationId)
- }
- },
- getFriendState = { friend -> context.database.getFriendInfo(friend.userId) != null },
- getGroupState = { group -> context.database.getGroupInfo(group.conversationId) != null }
- ))
- }
-
@Composable
private fun ScopeList(scope: SocialScope) {
val remainingHours = remember { context.config.root.streaksReminder.remainingHours.get() }
@@ -211,11 +190,11 @@ class SocialRootSection : Routes.Route() {
}
val coroutineScope = rememberCoroutineScope()
val pagerState = rememberPagerState { titles.size }
- var showAddFriendDialog by remember { mutableStateOf(false) }
+ var addFriendDialog by remember { mutableStateOf(null as AddFriendDialog?) }
- if (showAddFriendDialog) {
- addFriendDialog.Content {
- showAddFriendDialog = false
+ if (addFriendDialog != null) {
+ addFriendDialog?.Content {
+ addFriendDialog = null
}
DisposableEffect(Unit) {
onDispose {
@@ -232,7 +211,28 @@ class SocialRootSection : Routes.Route() {
floatingActionButton = {
FloatingActionButton(
onClick = {
- showAddFriendDialog = true
+ addFriendDialog = AddFriendDialog(
+ context,
+ AddFriendDialog.Actions(
+ onFriendState = { friend, state ->
+ if (state) {
+ context.bridgeService?.triggerScopeSync(SocialScope.FRIEND, friend.userId)
+ } else {
+ context.database.deleteFriend(friend.userId)
+ }
+ },
+ onGroupState = { group, state ->
+ if (state) {
+ context.bridgeService?.triggerScopeSync(SocialScope.GROUP, group.conversationId)
+ } else {
+ context.database.deleteGroup(group.conversationId)
+ }
+ },
+ getFriendState = { friend -> context.database.getFriendInfo(friend.userId) != null },
+ getGroupState = { group -> context.database.getGroupInfo(group.conversationId) != null }
+ ),
+ pinnedIds = (friendList.map { it.userId } + groupList.map { it.conversationId }).reversed(),
+ )
},
modifier = Modifier.padding(10.dp),
containerColor = MaterialTheme.colorScheme.primary,
diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/tracker/EditRule.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/pages/tracker/EditRule.kt
@@ -255,7 +255,8 @@ class EditRule : Routes.Route() {
currentScopeType = TrackerScopeType.WHITELIST
addFriendDialog = AddFriendDialog(
context,
- friendDialogActions
+ friendDialogActions,
+ pinnedIds = scopes,
)
}) {
Row(
@@ -274,7 +275,8 @@ class EditRule : Routes.Route() {
currentScopeType = TrackerScopeType.BLACKLIST
addFriendDialog = AddFriendDialog(
context,
- friendDialogActions
+ friendDialogActions,
+ pinnedIds = scopes,
)
}) {
Row(