feat: show online and rest friends in friends screen

Signed-off-by: Infi <infi@infi.sh>
This commit is contained in:
Infi 2023-12-01 16:42:45 +01:00
parent f8af5e4abd
commit 6a7a82636d
3 changed files with 83 additions and 10 deletions

View File

@ -10,27 +10,27 @@ object FriendRequests {
}
}
fun getIncomingCount(): Int {
return getIncoming().size
}
fun getOutgoing(): List<User> {
return RevoltAPI.userCache.values.filter { user ->
user.relationship == "Outgoing"
}
}
fun getOutgoingCount(): Int {
return getOutgoing().size
}
fun getBlocked(): List<User> {
return RevoltAPI.userCache.values.filter { user ->
user.relationship == "Blocked"
}
}
fun getBlockedCount(): Int {
return getBlocked().size
fun getOnlineFriends(): List<User> {
return RevoltAPI.userCache.values.filter { user ->
user.relationship == "Friend" && user.online == true
}
}
fun getFriends(excludeOnline: Boolean = false): List<User> {
return RevoltAPI.userCache.values.filter { user ->
user.relationship == "Friend" && (excludeOnline && user.online == false)
}
}
}

View File

@ -199,6 +199,78 @@ fun FriendsScreen(useDrawer: Boolean, onDrawerClicked: () -> Unit) {
})
}
stickyHeader(key = "online") {
Text(
text = AnnotatedString.Builder().apply {
pushStyle(SpanStyle(fontWeight = FontWeight.Bold))
append(stringResource(id = R.string.status_online))
pop()
pushStyle(
SpanStyle(
fontWeight = FontWeight.Medium,
fontSize = LocalTextStyle.current.fontSize * 0.8,
color = LocalContentColor.current.copy(alpha = 0.6f)
)
)
append("${FriendRequests.getOnlineFriends().size}")
pop()
}.toAnnotatedString(),
style = MaterialTheme.typography.labelLarge,
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.background)
.padding(10.dp)
)
}
items(FriendRequests.getOnlineFriends().size) {
val item = FriendRequests.getOnlineFriends()[it]
UserItem(item, onClick = {
scope.launch {
item.id?.let { userId ->
ActionChannel.send(Action.OpenUserSheet(userId, null))
}
}
})
}
stickyHeader(key = "not_online") {
Text(
text = AnnotatedString.Builder().apply {
pushStyle(SpanStyle(fontWeight = FontWeight.Bold))
append(stringResource(id = R.string.friends_all))
pop()
pushStyle(
SpanStyle(
fontWeight = FontWeight.Medium,
fontSize = LocalTextStyle.current.fontSize * 0.8,
color = LocalContentColor.current.copy(alpha = 0.6f)
)
)
append("${FriendRequests.getFriends(true).size}")
pop()
}.toAnnotatedString(),
style = MaterialTheme.typography.labelLarge,
modifier = Modifier
.fillMaxWidth()
.background(MaterialTheme.colorScheme.background)
.padding(10.dp)
)
}
items(FriendRequests.getFriends(true).size) {
val item = FriendRequests.getFriends(true)[it]
UserItem(item, onClick = {
scope.launch {
item.id?.let { userId ->
ActionChannel.send(Action.OpenUserSheet(userId, null))
}
}
})
}
stickyHeader(key = "blocked") {
Text(
text = AnnotatedString.Builder().apply {

View File

@ -126,6 +126,7 @@
<string name="friends">Friends</string>
<string name="friends_incoming_requests">Incoming Requests</string>
<string name="friends_outgoing_requests">Outgoing Requests</string>
<string name="friends_all">All</string>
<string name="friends_blocked">Blocked</string>
<string name="friends_deny_all_incoming">Clear all incoming requests</string>