mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-08 19:18:47 +01:00
enhancement: drawer handles and search (#556)
This commit is contained in:
parent
8734ff853c
commit
8a4666b364
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user