Create labels inline

This commit is contained in:
Jackson Harper
2023-05-15 12:05:58 +08:00
parent 9fba4aa1af
commit b9c4a6a476
3 changed files with 29 additions and 2 deletions

View File

@ -135,6 +135,10 @@ object LabelSwatchHelper {
return listOf(shuffledSwatches.last()) + webSwatchHexes + shuffledSwatches.dropLast(1)
}
fun random(): String {
return webSwatchHexes.random()
}
private val webSwatchHexes = listOf(
"#FF5D99",
"#7CFF7B",

View File

@ -52,6 +52,10 @@ import app.omnivore.omnivore.ui.library.LibraryViewModel
import com.dokar.chiptextfield.*
import com.google.accompanist.flowlayout.FlowRow
import kotlinx.coroutines.delay
import java.time.LocalDate
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter
import java.util.*
//@Composable
@ -257,9 +261,10 @@ fun LabelsSelectionSheetContent(
?: SavedItemLabel(
savedItemLabelId = "",
name = name.text,
color = "#FFFFFF",
createdAt = "",
labelDescription = "",
color = "#FFFFFF", // LabelSwatchHelper.random(),
createdAt = LocalDate.now().atStartOfDay().atOffset(ZoneOffset.UTC).format(
DateTimeFormatter.ISO_DATE_TIME),
serverSyncStatus = ServerSyncStatus.NEEDS_CREATION.rawValue
)
}

View File

@ -9,9 +9,11 @@ import app.omnivore.omnivore.*
import app.omnivore.omnivore.dataService.*
import app.omnivore.omnivore.graphql.generated.type.CreateLabelInput
import app.omnivore.omnivore.graphql.generated.type.SetLabelsInput
import app.omnivore.omnivore.models.ServerSyncStatus
import app.omnivore.omnivore.networking.*
import app.omnivore.omnivore.persistence.entities.*
import com.apollographql.apollo3.api.Optional
import com.apollographql.apollo3.api.Optional.Companion.presentIfNotNull
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
@ -283,6 +285,22 @@ class LibraryViewModel @Inject constructor(
fun updateSavedItemLabels(savedItemID: String, labels: List<SavedItemLabel>) {
viewModelScope.launch {
withContext(Dispatchers.IO) {
val synced = labels.filter { it.serverSyncStatus == ServerSyncStatus.IS_SYNCED.rawValue }
val unsynced = labels.filter { it.serverSyncStatus != ServerSyncStatus.IS_SYNCED.rawValue }
var labelIds = mutableListOf<String>()
labelIds.addAll(synced.map { it.savedItemLabelId })
unsynced.forEach { label ->
val result = networker.createNewLabel(CreateLabelInput(
name = label.name,
color = presentIfNotNull(label.color),
description = presentIfNotNull(label.labelDescription),
))
result?.let {
labelIds.add(it.id)
}
}
val input = SetLabelsInput(labelIds = labels.map { it.savedItemLabelId }, pageId = savedItemID)
val networkResult = networker.updateLabelsForSavedItem(input)