mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
gst
This commit is contained in:
parent
497461e7f1
commit
59c47c2f23
5 changed files with 82 additions and 27 deletions
|
|
@ -1,10 +1,7 @@
|
|||
package app.omnivore.omnivore
|
||||
|
||||
import app.omnivore.omnivore.ui.reader.WebFont
|
||||
|
||||
object Constants {
|
||||
const val apiURL = BuildConfig.OMNIVORE_API_URL
|
||||
const val webURL = BuildConfig.OMNIVORE_WEB_URL
|
||||
const val dataStoreName = "omnivore-datastore"
|
||||
}
|
||||
|
||||
|
|
@ -18,6 +15,7 @@ object DatastoreKeys {
|
|||
const val preferredWebMaxWidthPercentage = "preferredWebMaxWidthPercentage"
|
||||
const val preferredWebFontFamily = "preferredWebFontFamily"
|
||||
const val prefersWebHighContrastText = "prefersWebHighContrastText"
|
||||
const val lastUsedSavedItemFilter = "lastUsedSavedItemFilter"
|
||||
}
|
||||
|
||||
object AppleConstants {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,54 @@
|
|||
package app.omnivore.omnivore.ui.library
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.ArrowDropDown
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LibraryFilterBar(viewModel: LibraryViewModel) {
|
||||
var isSavedItemFilterMenuExpanded by remember { mutableStateOf(false) }
|
||||
Column {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.Start,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
AssistChip(
|
||||
onClick = { isSavedItemFilterMenuExpanded = true },
|
||||
label = { Text("Inbox") },
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
Icons.Default.ArrowDropDown,
|
||||
contentDescription = "drop down button to change primary library filter"
|
||||
)
|
||||
},
|
||||
modifier = Modifier.padding(end = 6.dp)
|
||||
)
|
||||
AssistChip(
|
||||
onClick = { /* Do something! */ },
|
||||
label = { Text("Newest") },
|
||||
trailingIcon = {
|
||||
Icon(
|
||||
Icons.Default.ArrowDropDown,
|
||||
contentDescription = "drop down button to change library sort order"
|
||||
)
|
||||
},
|
||||
modifier = Modifier.padding(end = 6.dp)
|
||||
)
|
||||
}
|
||||
|
||||
SavedItemFilterContextMenu(
|
||||
isExpanded = isSavedItemFilterMenuExpanded,
|
||||
onDismiss = { isSavedItemFilterMenuExpanded = false },
|
||||
actionHandler = { it -> Log.d("ss", "$it")}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -84,6 +84,9 @@ fun LibraryViewContent(libraryViewModel: LibraryViewModel, modifier: Modifier) {
|
|||
.fillMaxSize()
|
||||
.padding(horizontal = 6.dp)
|
||||
) {
|
||||
item {
|
||||
LibraryFilterBar(libraryViewModel)
|
||||
}
|
||||
items(if (searchText.isNotEmpty()) searchedCardsData else cardsData) { cardDataWithLabels ->
|
||||
SavedItemCard(
|
||||
cardData = cardDataWithLabels.cardData,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,9 @@ import androidx.lifecycle.viewModelScope
|
|||
import app.omnivore.omnivore.*
|
||||
import app.omnivore.omnivore.dataService.*
|
||||
import app.omnivore.omnivore.networking.*
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItem
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemCardDataWithLabels
|
||||
import app.omnivore.omnivore.ui.reader.WebFont
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.*
|
||||
import java.time.Instant
|
||||
|
|
@ -22,6 +24,21 @@ class LibraryViewModel @Inject constructor(
|
|||
private val dataService: DataService,
|
||||
private val datastoreRepo: DatastoreRepository
|
||||
): ViewModel() {
|
||||
|
||||
init {
|
||||
// Load the last saved library filter
|
||||
runBlocking {
|
||||
datastoreRepo.getString(DatastoreKeys.lastUsedSavedItemFilter)?.let { str ->
|
||||
try {
|
||||
val filter = SavedItemFilter.values().first { it.rawValue == str }
|
||||
appliedFilterLiveData.postValue(filter)
|
||||
} catch (e: Exception) {
|
||||
Log.d("error", "invalid filter value store in datastore repo: $e")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var cursor: String? = null
|
||||
|
||||
// These are used to make sure we handle search result
|
||||
|
|
@ -33,6 +50,7 @@ class LibraryViewModel @Inject constructor(
|
|||
val searchTextLiveData = MutableLiveData("")
|
||||
val searchItemsLiveData = MutableLiveData<List<SavedItemCardDataWithLabels>>(listOf())
|
||||
val itemsLiveData = dataService.db.savedItemDao().getLibraryLiveDataWithLabels()
|
||||
val appliedFilterLiveData = MutableLiveData<SavedItemFilter>(SavedItemFilter.INBOX)
|
||||
|
||||
var isRefreshing by mutableStateOf(false)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,51 +1,33 @@
|
|||
package app.omnivore.omnivore.ui.savedItemViews
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.Delete
|
||||
import androidx.compose.material.icons.outlined.List
|
||||
import androidx.compose.material3.DropdownMenu
|
||||
import androidx.compose.material3.DropdownMenuItem
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import app.omnivore.omnivore.ui.library.SavedItemAction
|
||||
import app.omnivore.omnivore.ui.library.SavedItemFilter
|
||||
|
||||
@Composable
|
||||
fun SavedItemContextMenu(
|
||||
isExpanded: Boolean,
|
||||
isArchived: Boolean,
|
||||
onDismiss: () -> Unit,
|
||||
actionHandler: (SavedItemAction) -> Unit
|
||||
actionHandler: (SavedItemFilter) -> Unit
|
||||
) {
|
||||
DropdownMenu(
|
||||
expanded = isExpanded,
|
||||
onDismissRequest = onDismiss
|
||||
) {
|
||||
DropdownMenuItem(
|
||||
text = { Text(if (isArchived) "Unarchive" else "Archive") },
|
||||
text = { Text("One") },
|
||||
onClick = {
|
||||
val action = if (isArchived) SavedItemAction.Unarchive else SavedItemAction.Archive
|
||||
actionHandler(action)
|
||||
actionHandler(SavedItemFilter.INBOX)
|
||||
onDismiss()
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.List, // TODO: use more appropriate icon
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text("Remove Item") },
|
||||
text = { Text("Two") },
|
||||
onClick = {
|
||||
actionHandler(SavedItemAction.Delete)
|
||||
actionHandler(SavedItemFilter.INBOX)
|
||||
onDismiss()
|
||||
},
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
Icons.Outlined.Delete,
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue