enhancement: drawer handles and search (#556)

This commit is contained in:
Diego Beraldin 2024-02-27 18:42:53 +01:00 committed by GitHub
parent 8734ff853c
commit 8a4666b364
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 8 deletions

View File

@ -51,6 +51,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.notifications.di.getNotific
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.onClick
import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallback
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.ListingType
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableHandle
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.readableName
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toIcon
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.toReadableName
@ -262,6 +263,7 @@ object ModalDrawerContent : Tab {
) { community ->
DrawerCommunityItem(
title = community.readableName(uiState.preferNicknames),
subtitle = community.readableHandle,
url = community.icon,
favorite = community.favorite,
autoLoadImages = uiState.autoLoadImages,

View File

@ -157,7 +157,14 @@ class ModalDrawerViewModel(
favoriteCommunityRepository.getAll(accountId).map { it.communityId }
val searchText = uiState.value.searchText
val communities = communityRepository.getSubscribed(auth)
.filter { e -> if (searchText.isEmpty()) true else e.name.contains(searchText) }
.filter { e ->
if (searchText.isEmpty()) {
true
} else {
e.name.contains(other = searchText, ignoreCase = true)
|| e.title.contains(other = searchText, ignoreCase = true)
}
}
.map { community ->
community.copy(favorite = community.id in favoriteCommunityIds)
}
@ -169,12 +176,18 @@ class ModalDrawerViewModel(
}
val multiCommunitites = accountId?.let {
multiCommunityRepository.getAll(it)
.filter { e -> if (searchText.isEmpty()) true else e.name.contains(searchText) }
.filter { e ->
if (searchText.isEmpty()) {
true
} else {
e.name.contains(other = searchText, ignoreCase = true)
}
}
.sortedBy { e -> e.name }
}.orEmpty()
updateState {
it.copy(
isFiltering = searchText.isNotEmpty(),
isFiltering = searchText.isNotEmpty(),
refreshing = false,
communities = communities,
multiCommunities = multiCommunitites,

View File

@ -1,6 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.unit.drawer.components
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.icons.Icons
@ -21,6 +21,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.utils.compose.rememberCallb
@Composable
internal fun DrawerCommunityItem(
title: String,
subtitle: String? = null,
modifier: Modifier = Modifier,
url: String? = null,
favorite: Boolean = false,
@ -49,15 +50,22 @@ internal fun DrawerCommunityItem(
},
label = {
val fullColor = MaterialTheme.colorScheme.onBackground
Row {
val ancillaryColor = MaterialTheme.colorScheme.onBackground.copy(alpha = 0.75f)
Column {
Text(
text = buildString {
append(title)
},
text = title,
color = fullColor,
style = MaterialTheme.typography.titleSmall,
maxLines = 1,
)
subtitle.takeIf { it != title }?.also { subtitle ->
Text(
text = subtitle,
color = ancillaryColor,
style = MaterialTheme.typography.bodySmall,
maxLines = 1,
)
}
}
},
badge = if (favorite) {