mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Update highlights on edit from the notebook view
This commit is contained in:
parent
49903bf938
commit
ddf7c51816
3 changed files with 38 additions and 14 deletions
|
|
@ -1,13 +1,19 @@
|
|||
package app.omnivore.omnivore.ui.notebook
|
||||
|
||||
import androidx.lifecycle.*
|
||||
import androidx.room.Query
|
||||
import app.omnivore.omnivore.DatastoreRepository
|
||||
import app.omnivore.omnivore.dataService.DataService
|
||||
import app.omnivore.omnivore.dataService.createNoteHighlight
|
||||
import app.omnivore.omnivore.dataService.updateWebHighlight
|
||||
import app.omnivore.omnivore.graphql.generated.type.UpdateHighlightInput
|
||||
import app.omnivore.omnivore.models.ServerSyncStatus
|
||||
import app.omnivore.omnivore.networking.Networker
|
||||
import app.omnivore.omnivore.networking.updateHighlight
|
||||
import app.omnivore.omnivore.persistence.entities.Highlight
|
||||
import app.omnivore.omnivore.persistence.entities.SavedItemWithLabelsAndHighlights
|
||||
import app.omnivore.omnivore.ui.library.SavedItemViewModel
|
||||
import com.apollographql.apollo3.api.Optional
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
|
|
@ -34,10 +40,25 @@ class NotebookViewModel @Inject constructor(
|
|||
noteHighlight?.let {
|
||||
dataService.db.highlightDao()
|
||||
.updateNote(highlightId = noteHighlight.highlightId, note = note)
|
||||
|
||||
networker.updateHighlight(input = UpdateHighlightInput(
|
||||
highlightId = noteHighlight.highlightId,
|
||||
annotation = Optional.presentIfNotNull(note),
|
||||
))
|
||||
} ?: run {
|
||||
dataService.createNoteHighlight(savedItemId, note)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun updateHighlightNote(highlightId: String, note: String?) {
|
||||
withContext(Dispatchers.IO) {
|
||||
dataService.db.highlightDao().updateNote(highlightId, note ?: "")
|
||||
networker.updateHighlight(input = UpdateHighlightInput(
|
||||
highlightId = highlightId,
|
||||
annotation = Optional.presentIfNotNull(note),
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,22 +4,19 @@ import android.annotation.SuppressLint
|
|||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.Color
|
||||
import android.graphics.Rect
|
||||
import android.util.Log
|
||||
import android.view.*
|
||||
import android.view.View.OnScrollChangeListener
|
||||
import android.view.ViewTreeObserver.OnScrollChangedListener
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.material3.*
|
||||
import androidx.compose.runtime.*
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import app.omnivore.omnivore.R
|
||||
import com.google.gson.Gson
|
||||
|
|
@ -35,9 +32,6 @@ fun WebReader(
|
|||
webReaderViewModel: WebReaderViewModel,
|
||||
currentTheme: Themes?
|
||||
) {
|
||||
val currentThemeKey = webReaderViewModel.currentThemeKey.observeAsState()
|
||||
val currentTheme = Themes.values().find { it.themeKey == currentThemeKey.value }
|
||||
|
||||
val javascriptActionLoopUUID: UUID by webReaderViewModel
|
||||
.javascriptActionLoopUUIDLiveData
|
||||
.observeAsState(UUID.randomUUID())
|
||||
|
|
@ -61,7 +55,9 @@ fun WebReader(
|
|||
|
||||
alpha = 1.0f
|
||||
viewModel?.showNavBar()
|
||||
setBackgroundColor(0xff0000);
|
||||
currentTheme?.let { theme ->
|
||||
setBackgroundColor(theme.backgroundColor.toInt());
|
||||
}
|
||||
|
||||
webViewClient = object : WebViewClient() {
|
||||
override fun shouldOverrideUrlLoading(
|
||||
|
|
|
|||
|
|
@ -214,13 +214,20 @@ fun WebReaderLoadingContainer(slug: String? = null, requestID: String? = null,
|
|||
EditNoteModal(
|
||||
initialValue = notebookViewModel.highlightUnderEdit?.annotation,
|
||||
onDismiss = { save, note ->
|
||||
if (save && note != null) {
|
||||
coroutineScope.launch {
|
||||
notebookViewModel.addArticleNote(
|
||||
savedItemId = params.item.savedItemId,
|
||||
note = note
|
||||
)
|
||||
coroutineScope.launch {
|
||||
if (save) {
|
||||
notebookViewModel.highlightUnderEdit?.let { highlight ->
|
||||
notebookViewModel.updateHighlightNote(highlight.highlightId, note)
|
||||
} ?: run {
|
||||
if (note != null) {
|
||||
notebookViewModel.addArticleNote(
|
||||
savedItemId = params.item.savedItemId,
|
||||
note = note
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
notebookViewModel.highlightUnderEdit = null
|
||||
}
|
||||
webReaderViewModel.setBottomSheet(BottomSheetState.NOTEBOOK)
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue