Add a library filter button to clear current search
This commit is contained in:
@ -1,18 +1,24 @@
|
||||
package app.omnivore.omnivore.ui.library
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material.icons.filled.Clear
|
||||
import androidx.compose.material.icons.filled.Close
|
||||
import androidx.compose.material.icons.filled.Search
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemLabel
|
||||
import app.omnivore.omnivore.ui.components.LabelChipColors
|
||||
|
||||
@ -23,6 +29,7 @@ fun LibraryFilterBar(viewModel: LibraryViewModel) {
|
||||
val activeSavedItemFilter: SavedItemFilter by viewModel.appliedFilterLiveData.observeAsState(SavedItemFilter.INBOX)
|
||||
val activeLabels: List<SavedItemLabel> by viewModel.activeLabelsLiveData.observeAsState(listOf())
|
||||
|
||||
val searchText: String by viewModel.searchTextLiveData.observeAsState("")
|
||||
var isSavedItemSortFilterMenuExpanded by remember { mutableStateOf(false) }
|
||||
val activeSavedItemSortFilter: SavedItemSortFilter by viewModel.appliedSortFilterLiveData.observeAsState(SavedItemSortFilter.NEWEST)
|
||||
val listState = rememberLazyListState()
|
||||
@ -37,6 +44,39 @@ fun LibraryFilterBar(viewModel: LibraryViewModel) {
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
item {
|
||||
if (searchText.isNotEmpty()) {
|
||||
AssistChip(
|
||||
onClick = {
|
||||
viewModel.updateSearchText("")
|
||||
},
|
||||
label = { Text(searchText) },
|
||||
border = null,
|
||||
colors = SuggestionChipDefaults.elevatedSuggestionChipColors(
|
||||
containerColor = colorResource(R.color.gray_898989),
|
||||
labelColor = Color.White,
|
||||
iconContentColor = Color.White
|
||||
),
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
painter = painterResource(id = R.drawable.funnel_simple),
|
||||
contentDescription = "Clear current search",
|
||||
modifier = Modifier.size(17.dp),
|
||||
tint = Color.White
|
||||
)
|
||||
},
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
Icons.Default.Clear,
|
||||
contentDescription = "close icon to remove label",
|
||||
modifier = Modifier.size(15.dp),
|
||||
tint = Color.White
|
||||
)
|
||||
|
||||
},
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 4.dp)
|
||||
)
|
||||
}
|
||||
AssistChip(
|
||||
onClick = { isSavedItemFilterMenuExpanded = true },
|
||||
label = { Text(activeSavedItemFilter.displayText) },
|
||||
|
||||
@ -110,47 +110,6 @@ class LibraryViewModel @Inject constructor(
|
||||
viewModelScope.launch {
|
||||
itemsLiveData.postValue(listOf())
|
||||
librarySearchCursor = null
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val result = dataService.librarySearch(cursor = librarySearchCursor, query = searchQueryString())
|
||||
result.cursor?.let {
|
||||
librarySearchCursor = it
|
||||
}
|
||||
CoroutineScope(Dispatchers.Main).launch {
|
||||
isRefreshing = false
|
||||
}
|
||||
|
||||
result.savedItems.map {
|
||||
val isSavedInDB = dataService.isSavedItemContentStoredInDB(it.slug)
|
||||
|
||||
if (!isSavedInDB) {
|
||||
delay(2000)
|
||||
contentRequestChannel.send(it.slug)
|
||||
}
|
||||
}
|
||||
|
||||
val newItems = result.savedItems.map {
|
||||
SavedItemCardDataWithLabels(
|
||||
cardData = SavedItemCardData(
|
||||
savedItemId = it.savedItemId,
|
||||
savedAt = it.savedAt,
|
||||
readingProgress = it.readingProgress,
|
||||
slug = it.slug,
|
||||
publisherURLString = it.publisherURLString,
|
||||
title = it.title,
|
||||
author = it.author,
|
||||
imageURLString = it.imageURLString,
|
||||
isArchived = it.isArchived,
|
||||
pageURLString = it.pageURLString,
|
||||
contentReader = it.contentReader,
|
||||
wordsCount = it.wordsCount
|
||||
),
|
||||
labels = listOf()
|
||||
)
|
||||
}
|
||||
|
||||
itemsLiveData.postValue(newItems)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="256"
|
||||
android:viewportHeight="256">
|
||||
<path
|
||||
android:pathData="M200,128a8,8 0,0 1,-8 8L64,136a8,8 0,0 1,0 -16L192,120A8,8 0,0 1,200 128ZM232,72L24,72a8,8 0,0 0,0 16L232,88a8,8 0,0 0,0 -16ZM152,168L104,168a8,8 0,0 0,0 16h48a8,8 0,0 0,0 -16Z"
|
||||
android:fillColor="#000000"/>
|
||||
</vector>
|
||||
Reference in New Issue
Block a user