Skip to content

Commit 23be4db

Browse files
authored
feat: sort tags alphabetically (WPB-21606) (#4510)
1 parent bbccabf commit 23be4db

File tree

5 files changed

+60
-27
lines changed

5 files changed

+60
-27
lines changed

core/ui-common/src/main/kotlin/com/wire/android/ui/common/chip/WireFilterChip.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ fun WireFilterChip(
6262
enabled = isEnabled,
6363
selected = isSelected,
6464
colors = wireChipColors(),
65-
border = null,
6665
trailingIcon = {
6766
Icon(
6867
modifier = Modifier

features/cells/src/main/java/com/wire/android/feature/cells/ui/AllFilesScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fun AllFilesScreen(
103103
)
104104

105105
FilterBottomSheet(
106-
selectableTags = viewModel.tags.collectAsState().value,
106+
selectableTags = viewModel.sortedTags.collectAsState().value,
107107
selectedTags = viewModel.selectedTags.collectAsState().value,
108108
onApply = {
109109
filterBottomSheetState.hide()

features/cells/src/main/java/com/wire/android/feature/cells/ui/CellViewModel.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import kotlinx.coroutines.delay
5454
import kotlinx.coroutines.flow.MutableSharedFlow
5555
import kotlinx.coroutines.flow.MutableStateFlow
5656
import kotlinx.coroutines.flow.SharedFlow
57+
import kotlinx.coroutines.flow.SharingStarted
5758
import kotlinx.coroutines.flow.StateFlow
5859
import kotlinx.coroutines.flow.asSharedFlow
5960
import kotlinx.coroutines.flow.asStateFlow
@@ -65,7 +66,9 @@ import kotlinx.coroutines.flow.first
6566
import kotlinx.coroutines.flow.flatMapLatest
6667
import kotlinx.coroutines.flow.flow
6768
import kotlinx.coroutines.flow.flowOf
69+
import kotlinx.coroutines.flow.map
6870
import kotlinx.coroutines.flow.onStart
71+
import kotlinx.coroutines.flow.stateIn
6972
import kotlinx.coroutines.flow.update
7073
import kotlinx.coroutines.launch
7174
import okio.Path
@@ -118,7 +121,13 @@ class CellViewModel @Inject constructor(
118121
val selectedTags: StateFlow<Set<String>> = _selectedTags.asStateFlow()
119122

120123
private val _tags = MutableStateFlow<Set<String>>(emptySet())
121-
val tags: StateFlow<Set<String>> = _tags.asStateFlow()
124+
val sortedTags: StateFlow<List<String>> = _tags.asStateFlow()
125+
.map { it.sortedBy { tag -> tag.lowercase() } }
126+
.stateIn(
127+
scope = viewModelScope,
128+
started = SharingStarted.WhileSubscribed(STOP_TIMEOUT_MILLIS),
129+
initialValue = emptyList()
130+
)
122131

123132
// Used to navigate to the root of the recycle bin after restoring a parent folder.
124133
private val _navigateToRecycleBinRoot = MutableStateFlow(false)
@@ -500,7 +509,7 @@ class CellViewModel @Inject constructor(
500509
}
501510

502511
suspend fun loadTags() {
503-
getAllTagsUseCase().onSuccess { updated -> _tags.update { updated.sorted().toSet() } }
512+
getAllTagsUseCase().onSuccess { updated -> _tags.update { updated } }
504513
// apply delay to avoid too frequent requests
505514
delay(30.seconds)
506515
}
@@ -515,6 +524,7 @@ class CellViewModel @Inject constructor(
515524
append = LoadState.NotLoading(true)
516525
)
517526
)
527+
const val STOP_TIMEOUT_MILLIS = 1_000L
518528
}
519529
}
520530

features/cells/src/main/java/com/wire/android/feature/cells/ui/filter/FilterBottomSheet.kt

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import com.wire.android.ui.theme.wireTypography
6262

6363
@Composable
6464
fun FilterBottomSheet(
65-
selectableTags: Set<String>,
65+
selectableTags: List<String>,
6666
selectedTags: Set<String>,
6767
onApply: (Set<String>) -> Unit,
6868
onClearAll: () -> Unit,
@@ -95,7 +95,7 @@ fun FilterBottomSheet(
9595

9696
@Composable
9797
private fun SheetContent(
98-
selectableTags: Set<String>,
98+
selectableTags: List<String>,
9999
selectedTags: Set<String>,
100100
onApply: (Set<String>) -> Unit = {},
101101
onClearAll: () -> Unit = {},
@@ -155,28 +155,37 @@ private fun SheetContent(
155155
style = MaterialTheme.wireTypography.label01,
156156
color = colorsScheme().secondaryText,
157157
)
158-
LazyRow(
159-
modifier = Modifier.padding(
160-
top = dimensions().spacing16x,
161-
bottom = dimensions().spacing16x
158+
if (selectableTags.isEmpty()) {
159+
Text(
160+
modifier = Modifier.padding(top = dimensions().spacing16x, bottom = dimensions().spacing16x),
161+
text = stringResource(R.string.no_tags_created_yet_label),
162+
style = MaterialTheme.wireTypography.body01,
163+
color = colorsScheme().onBackground,
162164
)
163-
) {
164-
selectableTags.forEach { tag ->
165-
val isSelected = selectedChips.contains(tag)
166-
167-
item {
168-
WireFilterChip(
169-
label = tag,
170-
isSelected = isSelected,
171-
modifier = Modifier.padding(end = dimensions().spacing16x),
172-
onSelectChip = { label ->
173-
selectedChips = if (isSelected) {
174-
selectedChips - label
175-
} else {
176-
selectedChips + label
165+
} else {
166+
LazyRow(
167+
modifier = Modifier.padding(
168+
top = dimensions().spacing16x,
169+
bottom = dimensions().spacing16x
170+
)
171+
) {
172+
selectableTags.forEach { tag ->
173+
val isSelected = selectedChips.contains(tag)
174+
175+
item {
176+
WireFilterChip(
177+
label = tag,
178+
isSelected = isSelected,
179+
modifier = Modifier.padding(end = dimensions().spacing16x),
180+
onSelectChip = { label ->
181+
selectedChips = if (isSelected) {
182+
selectedChips - label
183+
} else {
184+
selectedChips + label
185+
}
177186
}
178-
}
179-
)
187+
)
188+
}
180189
}
181190
}
182191
}
@@ -218,7 +227,21 @@ private fun SheetContent(
218227
fun PreviewFilterBottomSheet() {
219228
WireTheme {
220229
FilterBottomSheet(
221-
setOf("Android", "iOS", "Web", "QA"),
230+
listOf("Android", "iOS", "Web", "QA"),
231+
emptySet(),
232+
onApply = {},
233+
onClearAll = {},
234+
onDismiss = {},
235+
)
236+
}
237+
}
238+
239+
@MultipleThemePreviews
240+
@Composable
241+
fun PreviewEmptyFilterBottomSheet() {
242+
WireTheme {
243+
FilterBottomSheet(
244+
listOf(),
222245
emptySet(),
223246
onApply = {},
224247
onClearAll = {},

features/cells/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
<string name="filter_label">Filter</string>
114114
<string name="tags_label">Tags</string>
115115
<string name="select_tags_label">select tags</string>
116+
<string name="no_tags_created_yet_label">No tags were created yet.</string>
116117
<string name="clear_all_label">Clear All</string>
117118
<string name="apply_label">Apply</string>
118119
<string name="add_or_remove_tags_title">Add or remove tags</string>

0 commit comments

Comments
 (0)