clean up
This commit is contained in:
@ -8,21 +8,21 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
suspend fun DataService.updateWebReadingProgress(jsonString: String) {
|
||||
val readingProgressParams = Gson().fromJson(jsonString, ReadingProgressParams::class.java)
|
||||
val savedItemId = readingProgressParams.id ?: return
|
||||
val readingProgressParams = Gson().fromJson(jsonString, ReadingProgressParams::class.java)
|
||||
val savedItemId = readingProgressParams.id ?: return
|
||||
|
||||
withContext(Dispatchers.IO) {
|
||||
val savedItem = db.savedItemDao().findById(savedItemId) ?: return@withContext
|
||||
savedItem.readingProgress = readingProgressParams.readingProgressPercent ?: 0.0
|
||||
savedItem.readingProgressAnchor = readingProgressParams.readingProgressAnchorIndex ?: 0
|
||||
savedItem.serverSyncStatus = ServerSyncStatus.NEEDS_UPDATE.rawValue
|
||||
db.savedItemDao().update(savedItem)
|
||||
withContext(Dispatchers.IO) {
|
||||
val savedItem = db.savedItemDao().findById(savedItemId) ?: return@withContext
|
||||
savedItem.readingProgress = readingProgressParams.readingProgressPercent ?: 0.0
|
||||
savedItem.readingProgressAnchor = readingProgressParams.readingProgressAnchorIndex ?: 0
|
||||
savedItem.serverSyncStatus = ServerSyncStatus.NEEDS_UPDATE.rawValue
|
||||
db.savedItemDao().update(savedItem)
|
||||
|
||||
val isUpdatedOnServer = networker.updateReadingProgress(readingProgressParams)
|
||||
val isUpdatedOnServer = networker.updateReadingProgress(readingProgressParams)
|
||||
|
||||
if (isUpdatedOnServer) {
|
||||
savedItem.serverSyncStatus = ServerSyncStatus.IS_SYNCED.rawValue
|
||||
db.savedItemDao().update(savedItem)
|
||||
if (isUpdatedOnServer) {
|
||||
savedItem.serverSyncStatus = ServerSyncStatus.IS_SYNCED.rawValue
|
||||
db.savedItemDao().update(savedItem)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,144 +0,0 @@
|
||||
package app.omnivore.omnivore.feature.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Add
|
||||
import androidx.compose.material.icons.filled.ArrowBack
|
||||
import androidx.compose.material.icons.filled.Check
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.FilterChipDefaults
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.material3.TopAppBarDefaults
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateMapOf
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.dp
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.core.database.entities.SavedItemLabel
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
fun LabelsSelectionSheetContent2(
|
||||
isLibraryMode: Boolean,
|
||||
labels: List<SavedItemLabel>,
|
||||
initialSelectedLabels: List<SavedItemLabel>,
|
||||
labelsViewModel: LabelsViewModel,
|
||||
onCancel: () -> Unit,
|
||||
onSave: (List<SavedItemLabel>) -> Unit,
|
||||
onCreateLabel: (String, String) -> Unit
|
||||
) {
|
||||
// Use mutableStateMapOf for more idiomatic management of collection state
|
||||
val selectedLabels = remember {
|
||||
mutableStateMapOf<SavedItemLabel, Boolean>().apply {
|
||||
initialSelectedLabels.forEach {
|
||||
put(
|
||||
it,
|
||||
true
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
var newLabelName by remember { mutableStateOf("") }
|
||||
|
||||
Scaffold(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
topBar = {
|
||||
TopAppBar(
|
||||
title = {
|
||||
Text(
|
||||
text = if (isLibraryMode) stringResource(R.string.label_selection_sheet_title) else
|
||||
stringResource(R.string.label_selection_sheet_title_alt)
|
||||
)
|
||||
},
|
||||
navigationIcon = {
|
||||
IconButton(onClick = onCancel) {
|
||||
Icon(Icons.AutoMirrored.Rounded.ArrowBack, contentDescription = "Back")
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
IconButton(onClick = { onSave(selectedLabels.filter { it.value }.keys.toList()) }) {
|
||||
Text(
|
||||
text = if (isLibraryMode)
|
||||
stringResource(R.string.label_selection_sheet_action_search) else
|
||||
stringResource(R.string.label_selection_sheet_action_save)
|
||||
)
|
||||
}
|
||||
},
|
||||
colors = TopAppBarDefaults.topAppBarColors(
|
||||
containerColor = MaterialTheme.colorScheme.background
|
||||
)
|
||||
)
|
||||
}
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(top = paddingValues.calculateTopPadding())
|
||||
.verticalScroll(rememberScrollState()),
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = newLabelName,
|
||||
onValueChange = { newLabelName = it },
|
||||
label = { Text("New Label Name") },
|
||||
singleLine = true,
|
||||
trailingIcon = {
|
||||
IconButton(onClick = {
|
||||
val labelHexValue = "#FFFFFF"
|
||||
onCreateLabel(newLabelName, labelHexValue)
|
||||
newLabelName = ""
|
||||
}) {
|
||||
Icon(Icons.Filled.Add, contentDescription = "Create Label")
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(8.dp)
|
||||
)
|
||||
Row {
|
||||
labels.forEach { label ->
|
||||
FilterChip(
|
||||
selected = selectedLabels[label] ?: false,
|
||||
onClick = {
|
||||
selectedLabels[label] = !(selectedLabels[label] ?: false)
|
||||
},
|
||||
label = { Text(label.name) },
|
||||
leadingIcon = if (selectedLabels[label] == true) {
|
||||
{
|
||||
Icon(
|
||||
imageVector = Icons.Filled.Check,
|
||||
contentDescription = "Selected",
|
||||
modifier = Modifier.size(FilterChipDefaults.IconSize)
|
||||
)
|
||||
}
|
||||
} else null,
|
||||
modifier = Modifier.padding(8.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,6 @@ import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Scaffold
|
||||
import androidx.compose.material.TextFieldDefaults
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.AddCircle
|
||||
import androidx.compose.material3.CenterAlignedTopAppBar
|
||||
@ -277,10 +276,10 @@ fun LabelsSelectionSheetContent(
|
||||
focusedBorderColor = Color(0xFF2A2A2A),
|
||||
focusedBackgroundColor = Color(0xFF2A2A2A)
|
||||
),
|
||||
colors = TextFieldDefaults.textFieldColors(
|
||||
/* colors = androidx.compose.material3.TextFieldDefaults.colors(
|
||||
textColor = MaterialTheme.colorScheme.onBackground,
|
||||
backgroundColor = MaterialTheme.colorScheme.surface
|
||||
),
|
||||
),*/
|
||||
contentPadding = PaddingValues(10.dp),
|
||||
modifier = Modifier
|
||||
.defaultMinSize(minHeight = 45.dp)
|
||||
|
||||
@ -131,7 +131,7 @@ fun LibraryNavigationBar(
|
||||
contentDescription = null
|
||||
)
|
||||
}
|
||||
IconButton(onClick = { isMenuExpanded = true } ) {
|
||||
/* IconButton(onClick = { isMenuExpanded = true } ) {
|
||||
Icon(
|
||||
imageVector = Icons.Default.MoreVert,
|
||||
contentDescription = null
|
||||
@ -144,7 +144,7 @@ fun LibraryNavigationBar(
|
||||
onDismiss = { isMenuExpanded = false },
|
||||
)
|
||||
}
|
||||
}
|
||||
}*/
|
||||
} ?: run {
|
||||
IconButton(onClick = onSearchClicked) {
|
||||
Icon(
|
||||
|
||||
@ -48,8 +48,8 @@ class LibraryViewModel @Inject constructor(
|
||||
private val datastoreRepo: DatastoreRepository,
|
||||
private val resourceProvider: ResourceProvider
|
||||
) : ViewModel(), SavedItemViewModel {
|
||||
private val contentRequestChannel = Channel<String>(capacity = Channel.UNLIMITED)
|
||||
|
||||
private val contentRequestChannel = Channel<String>(capacity = Channel.UNLIMITED)
|
||||
private var cursor: String? = null
|
||||
private var librarySearchCursor: String? = null
|
||||
|
||||
|
||||
@ -52,7 +52,7 @@ import androidx.core.view.WindowInsetsCompat
|
||||
import app.omnivore.omnivore.MainActivity
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.core.database.entities.SavedItemLabel
|
||||
import app.omnivore.omnivore.feature.components.LabelsSelectionSheetContent2
|
||||
import app.omnivore.omnivore.feature.components.LabelsSelectionSheetContent
|
||||
import app.omnivore.omnivore.feature.components.LabelsViewModel
|
||||
import app.omnivore.omnivore.feature.editinfo.EditInfoSheetContent
|
||||
import app.omnivore.omnivore.feature.editinfo.EditInfoViewModel
|
||||
@ -299,7 +299,7 @@ fun WebReaderLoadingContainer(
|
||||
|
||||
BottomSheetState.LABELS -> {
|
||||
BottomSheetUI {
|
||||
LabelsSelectionSheetContent2(
|
||||
LabelsSelectionSheetContent(
|
||||
labels = labels,
|
||||
labelsViewModel = labelsViewModel,
|
||||
initialSelectedLabels = webReaderParams?.labels ?: listOf(),
|
||||
|
||||
@ -1,10 +1,24 @@
|
||||
package app.omnivore.omnivore.feature.savedItemViews
|
||||
|
||||
import androidx.compose.foundation.*
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.combinedClickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ExperimentalLayoutApi
|
||||
import androidx.compose.foundation.layout.FlowRow
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.defaultMinSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
@ -17,12 +31,13 @@ import androidx.compose.ui.text.intl.Locale
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.text.toLowerCase
|
||||
import androidx.compose.ui.text.toUpperCase
|
||||
import androidx.compose.ui.unit.*
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import app.omnivore.omnivore.R
|
||||
import app.omnivore.omnivore.core.database.entities.SavedItemLabel
|
||||
import app.omnivore.omnivore.core.database.entities.SavedItemWithLabelsAndHighlights
|
||||
import app.omnivore.omnivore.feature.components.LabelChip
|
||||
import app.omnivore.omnivore.feature.components.LabelChipColors
|
||||
import app.omnivore.omnivore.feature.components.LabelFilterChip
|
||||
import app.omnivore.omnivore.feature.library.SavedItemAction
|
||||
import app.omnivore.omnivore.feature.library.SavedItemViewModel
|
||||
import coil.compose.rememberAsyncImagePainter
|
||||
@ -30,137 +45,119 @@ import coil.compose.rememberAsyncImagePainter
|
||||
@OptIn(ExperimentalFoundationApi::class, ExperimentalLayoutApi::class)
|
||||
@Composable
|
||||
fun SavedItemCard(
|
||||
selected: Boolean,
|
||||
savedItemViewModel: SavedItemViewModel,
|
||||
savedItem: SavedItemWithLabelsAndHighlights,
|
||||
onClickHandler: () -> Unit,
|
||||
actionHandler: (SavedItemAction) -> Unit) {
|
||||
// Log.d("selected", "is selected: ${selected}")
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.combinedClickable(
|
||||
onClick = onClickHandler,
|
||||
onLongClick = {
|
||||
savedItemViewModel.actionsMenuItemLiveData.postValue(savedItem)
|
||||
}
|
||||
)
|
||||
.background(if (selected) MaterialTheme.colorScheme.surfaceVariant else MaterialTheme.colorScheme.background)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
.background(Color.Transparent)
|
||||
|
||||
selected: Boolean,
|
||||
savedItemViewModel: SavedItemViewModel,
|
||||
savedItem: SavedItemWithLabelsAndHighlights,
|
||||
onClickHandler: () -> Unit,
|
||||
actionHandler: (SavedItemAction) -> Unit
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.combinedClickable(onClick = onClickHandler, onLongClick = {
|
||||
savedItemViewModel.actionsMenuItemLiveData.postValue(savedItem)
|
||||
})
|
||||
.background(if (selected) MaterialTheme.colorScheme.surfaceVariant else MaterialTheme.colorScheme.background)
|
||||
.fillMaxWidth()
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(5.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f, fill = false)
|
||||
.padding(end = 20.dp)
|
||||
.defaultMinSize(minHeight = 55.dp)
|
||||
) {
|
||||
ReadInfo(item = savedItem)
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.Top,
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
.background(Color.Transparent)
|
||||
|
||||
Text(
|
||||
text = savedItem.savedItem.title,
|
||||
style = TextStyle(
|
||||
fontSize = 18.sp,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
),
|
||||
maxLines = 2,
|
||||
lineHeight = 20.sp
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(5.dp),
|
||||
modifier = Modifier
|
||||
.weight(1f, fill = false)
|
||||
.padding(end = 20.dp)
|
||||
.defaultMinSize(minHeight = 55.dp)
|
||||
) {
|
||||
ReadInfo(item = savedItem)
|
||||
|
||||
if (savedItem.savedItem.author != null && savedItem.savedItem.author != "") {
|
||||
Text(
|
||||
text = byline(savedItem),
|
||||
style = TextStyle(
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = Color(red = 137, green = 137, blue = 137)
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = savedItem.savedItem.title, style = TextStyle(
|
||||
fontSize = 18.sp,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
fontWeight = FontWeight.SemiBold
|
||||
), maxLines = 2, lineHeight = 20.sp
|
||||
)
|
||||
|
||||
if (savedItem.savedItem.author != null && savedItem.savedItem.author != "") {
|
||||
Text(
|
||||
text = byline(savedItem), style = TextStyle(
|
||||
fontSize = 15.sp,
|
||||
fontWeight = FontWeight.Normal,
|
||||
color = Color(red = 137, green = 137, blue = 137)
|
||||
), maxLines = 1, overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Image(
|
||||
painter = rememberAsyncImagePainter(savedItem.savedItem.imageURLString),
|
||||
contentDescription = "Image associated with saved item",
|
||||
modifier = Modifier
|
||||
.size(55.dp, 73.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.defaultMinSize(minWidth = 55.dp, minHeight = 73.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Image(
|
||||
painter = rememberAsyncImagePainter(savedItem.savedItem.imageURLString),
|
||||
contentDescription = "Image associated with saved item",
|
||||
modifier = Modifier
|
||||
.size(55.dp, 73.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.defaultMinSize(minWidth = 55.dp, minHeight = 73.dp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
)
|
||||
FlowRow(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
) {
|
||||
savedItem.labels.filter { !isFlairLabel(it) }
|
||||
.sortedWith(compareBy { it.name.toLowerCase(Locale.current) }).forEach { label ->
|
||||
val chipColors = LabelChipColors.fromHex(label.color)
|
||||
|
||||
LabelChip(
|
||||
modifier = Modifier.clickable { }, name = label.name, colors = chipColors
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Divider(color = MaterialTheme.colorScheme.outlineVariant, thickness = 1.dp)
|
||||
}
|
||||
|
||||
FlowRow(modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)) {
|
||||
savedItem.labels.filter { !isFlairLabel(it) }.sortedWith(compareBy { it.name.toLowerCase(Locale.current) }).forEach { label ->
|
||||
val chipColors = LabelChipColors.fromHex(label.color)
|
||||
|
||||
LabelFilterChip(
|
||||
onClick = { },
|
||||
label = label.name,
|
||||
//colors = chipColors,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Divider(color = MaterialTheme.colorScheme.outlineVariant, thickness = 1.dp)
|
||||
}
|
||||
}
|
||||
|
||||
fun byline(item: SavedItemWithLabelsAndHighlights): String {
|
||||
item.savedItem.author?.let {
|
||||
return item.savedItem.author
|
||||
}
|
||||
item.savedItem.author?.let {
|
||||
return item.savedItem.author
|
||||
}
|
||||
|
||||
val publisherDisplayName = item.savedItem.publisherDisplayName()
|
||||
publisherDisplayName?.let {
|
||||
return publisherDisplayName
|
||||
}
|
||||
val publisherDisplayName = item.savedItem.publisherDisplayName()
|
||||
publisherDisplayName?.let {
|
||||
return publisherDisplayName
|
||||
}
|
||||
|
||||
return ""
|
||||
return ""
|
||||
}
|
||||
|
||||
//
|
||||
//var readingSpeed: Int64 {
|
||||
// var result = UserDefaults.standard.integer(forKey: UserDefaultKey.userWordsPerMinute.rawValue)
|
||||
// if result <= 0 {
|
||||
// result = 235
|
||||
// }
|
||||
// return Int64(result)
|
||||
//}
|
||||
|
||||
fun estimatedReadingTime(item: SavedItemWithLabelsAndHighlights): String {
|
||||
item.savedItem.wordsCount?.let {
|
||||
if (it > 0) {
|
||||
val readLen = kotlin.math.max(1, it / 235)
|
||||
return "$readLen MIN READ • "
|
||||
item.savedItem.wordsCount?.let {
|
||||
if (it > 0) {
|
||||
val readLen = kotlin.math.max(1, it / 235)
|
||||
return "$readLen MIN READ • "
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return ""
|
||||
}
|
||||
|
||||
fun readingProgress(item: SavedItemWithLabelsAndHighlights): String {
|
||||
// If there is no wordsCount don't show progress because it will make no sense
|
||||
item.savedItem.wordsCount?.let {
|
||||
if (it > 0) {
|
||||
val intVal = item.savedItem.readingProgress.toInt()
|
||||
return "$intVal%"
|
||||
// If there is no wordsCount don't show progress because it will make no sense
|
||||
item.savedItem.wordsCount?.let {
|
||||
if (it > 0) {
|
||||
val intVal = item.savedItem.readingProgress.toInt()
|
||||
return "$intVal%"
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
return ""
|
||||
}
|
||||
|
||||
//var highlightsText: String {
|
||||
@ -195,115 +192,97 @@ fun readingProgress(item: SavedItemWithLabelsAndHighlights): String {
|
||||
|
||||
|
||||
enum class FlairIcon(
|
||||
val rawValue: String,
|
||||
val sortOrder: Int
|
||||
val rawValue: String, val sortOrder: Int
|
||||
) {
|
||||
FEED("feed", 0),
|
||||
RSS("rss", 0),
|
||||
FAVORITE("favorite", 1),
|
||||
NEWSLETTER("newsletter", 2),
|
||||
RECOMMENDED("recommended", 3),
|
||||
PINNED("pinned", 4)
|
||||
FEED("feed", 0), RSS("rss", 0), FAVORITE("favorite", 1), NEWSLETTER(
|
||||
"newsletter", 2
|
||||
),
|
||||
RECOMMENDED("recommended", 3), PINNED("pinned", 4)
|
||||
}
|
||||
|
||||
val FLAIR_ICON_NAMES = listOf("feed", "rss", "favorite", "newsletter", "recommended", "pinned")
|
||||
|
||||
fun isFlairLabel(label: SavedItemLabel): Boolean {
|
||||
return FLAIR_ICON_NAMES.contains(label.name.toLowerCase(Locale.current))
|
||||
return FLAIR_ICON_NAMES.contains(label.name.toLowerCase(Locale.current))
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun flairIcons(item: SavedItemWithLabelsAndHighlights) {
|
||||
val labels = item.labels.filter { isFlairLabel(it) }.map {
|
||||
FlairIcon.valueOf(it.name.toUpperCase(Locale.current))
|
||||
}
|
||||
labels.forEach {
|
||||
when (it) {
|
||||
FlairIcon.RSS,
|
||||
FlairIcon.FEED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_feed),
|
||||
contentDescription = "Feed flair Icon",
|
||||
modifier = Modifier
|
||||
.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.FAVORITE -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flaire_favorite),
|
||||
contentDescription = "Favorite flair Icon",
|
||||
modifier = Modifier
|
||||
.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.NEWSLETTER -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_newsletter),
|
||||
contentDescription = "Newsletter flair Icon",
|
||||
modifier = Modifier
|
||||
.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.RECOMMENDED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_recommended),
|
||||
contentDescription = "Recommended flair Icon",
|
||||
modifier = Modifier
|
||||
.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.PINNED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_pinned),
|
||||
contentDescription = "Pinned flair Icon",
|
||||
modifier = Modifier
|
||||
.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
val labels = item.labels.filter { isFlairLabel(it) }.map {
|
||||
FlairIcon.valueOf(it.name.toUpperCase(Locale.current))
|
||||
}
|
||||
labels.forEach {
|
||||
when (it) {
|
||||
FlairIcon.RSS, FlairIcon.FEED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_feed),
|
||||
contentDescription = "Feed flair Icon",
|
||||
modifier = Modifier.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.FAVORITE -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flaire_favorite),
|
||||
contentDescription = "Favorite flair Icon",
|
||||
modifier = Modifier.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.NEWSLETTER -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_newsletter),
|
||||
contentDescription = "Newsletter flair Icon",
|
||||
modifier = Modifier.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.RECOMMENDED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_recommended),
|
||||
contentDescription = "Recommended flair Icon",
|
||||
modifier = Modifier.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
FlairIcon.PINNED -> {
|
||||
Image(
|
||||
painter = painterResource(id = R.drawable.flair_pinned),
|
||||
contentDescription = "Pinned flair Icon",
|
||||
modifier = Modifier.padding(end = 5.0.dp)
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ReadInfo(item: SavedItemWithLabelsAndHighlights) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.defaultMinSize(minHeight = 15.dp)
|
||||
) {
|
||||
// Show flair here
|
||||
flairIcons(item)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.defaultMinSize(minHeight = 15.dp)
|
||||
) {
|
||||
// Show flair here
|
||||
flairIcons(item)
|
||||
|
||||
Text(
|
||||
text = estimatedReadingTime(item),
|
||||
style = TextStyle(
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = Color(red = 137, green = 137, blue = 137)
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = estimatedReadingTime(item), style = TextStyle(
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = Color(red = 137, green = 137, blue = 137)
|
||||
), maxLines = 1, overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
Text(
|
||||
text = readingProgress(item),
|
||||
style = TextStyle(
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (item.savedItem.readingProgress > 1) colorResource(R.color.green_55B938) else colorResource(R.color.gray_898989)
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
// Text("\(highlightsText)")
|
||||
//
|
||||
// Text("\(notesText)")
|
||||
|
||||
}
|
||||
Text(
|
||||
text = readingProgress(item), style = TextStyle(
|
||||
fontSize = 11.sp,
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = if (item.savedItem.readingProgress > 1) colorResource(R.color.green_55B938) else colorResource(
|
||||
R.color.gray_898989
|
||||
)
|
||||
), maxLines = 1, overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,7 +1,13 @@
|
||||
package app.omnivore.omnivore.feature.settings
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
@ -21,47 +27,47 @@ import app.omnivore.omnivore.R
|
||||
|
||||
@Composable
|
||||
fun ManageAccountDialog(onDismiss: () -> Unit, settingsViewModel: SettingsViewModel) {
|
||||
Dialog(onDismissRequest = { onDismiss() }) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = Color.White,
|
||||
modifier = Modifier
|
||||
.height(300.dp)
|
||||
) {
|
||||
ManageAccountView(settingsViewModel = settingsViewModel)
|
||||
Dialog(onDismissRequest = { onDismiss() }) {
|
||||
Surface(
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
color = Color.White,
|
||||
modifier = Modifier
|
||||
.height(300.dp)
|
||||
) {
|
||||
ManageAccountView(settingsViewModel = settingsViewModel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun ManageAccountView(settingsViewModel: SettingsViewModel) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = 6.dp, start = 6.dp, end = 6.dp, bottom = 6.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 12.dp, bottom = 12.dp),
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(stringResource(R.string.manage_account_title))
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clickable(onClick = { settingsViewModel.resetDataCache() })
|
||||
) {
|
||||
Text(stringResource(R.string.manage_account_action_reset_data_cache))
|
||||
Spacer(modifier = Modifier.weight(1.0F))
|
||||
Icon(imageVector = Icons.Filled.Refresh, contentDescription = null)
|
||||
}
|
||||
.padding(top = 6.dp, start = 6.dp, end = 6.dp, bottom = 6.dp)
|
||||
) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(top = 12.dp, bottom = 12.dp),
|
||||
horizontalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(stringResource(R.string.manage_account_title))
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
modifier = Modifier
|
||||
.clickable(onClick = { settingsViewModel.resetDataCache() })
|
||||
) {
|
||||
Text(stringResource(R.string.manage_account_action_reset_data_cache))
|
||||
Spacer(modifier = Modifier.weight(1.0F))
|
||||
Icon(imageVector = Icons.Filled.Refresh, contentDescription = null)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user