mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
send saved highlight to server
This commit is contained in:
parent
a0d4e06d34
commit
aac794949c
8 changed files with 100 additions and 13 deletions
|
|
@ -0,0 +1,13 @@
|
|||
mutation CreateHighlight($input: CreateHighlightInput!) {
|
||||
createHighlight(input: $input) {
|
||||
... on CreateHighlightSuccess {
|
||||
highlight {
|
||||
...HighlightFields
|
||||
}
|
||||
}
|
||||
|
||||
... on CreateHighlightError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
mutation DeleteHighlight($highlightId: ID!) {
|
||||
deleteHighlight(highlightId: $highlightId) {
|
||||
... on DeleteHighlightSuccess {
|
||||
highlight {
|
||||
id
|
||||
}
|
||||
}
|
||||
... on DeleteHighlightError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
mutation SaveArticleReadingProgress($input: SaveArticleReadingProgressInput!) {
|
||||
saveArticleReadingProgress(input: $input) {
|
||||
... on SaveArticleReadingProgressSuccess {
|
||||
updatedArticle {
|
||||
id
|
||||
readingProgressPercent
|
||||
readingProgressAnchorIndex
|
||||
}
|
||||
}
|
||||
... on SaveArticleReadingProgressError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
mutation UpdateHighlight($input: UpdateHighlightInput!) {
|
||||
updateHighlight(input: $input) {
|
||||
... on UpdateHighlightSuccess {
|
||||
highlight {
|
||||
id
|
||||
}
|
||||
}
|
||||
|
||||
... on UpdateHighlightError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package app.omnivore.omnivore.networking
|
||||
|
||||
import app.omnivore.omnivore.graphql.generated.CreateHighlightMutation
|
||||
import app.omnivore.omnivore.graphql.generated.type.CreateHighlightInput
|
||||
import com.apollographql.apollo3.api.Optional
|
||||
import com.google.gson.Gson
|
||||
|
||||
data class CreateHighlightParams(
|
||||
val shortId: String?,
|
||||
val highlightID: String?,
|
||||
val quote: String?,
|
||||
val patch: String?,
|
||||
val articleId: String?,
|
||||
val `annotation`: String?
|
||||
) {
|
||||
fun asCreateHighlightInput() = CreateHighlightInput(
|
||||
annotation = Optional.presentIfNotNull(`annotation`),
|
||||
articleId = articleId ?: "",
|
||||
id = highlightID ?: "",
|
||||
patch = patch ?: "",
|
||||
quote = quote ?: "",
|
||||
shortId = shortId ?: ""
|
||||
)
|
||||
}
|
||||
|
||||
suspend fun Networker.createHighlight(jsonString: String) {
|
||||
val input = Gson().fromJson(jsonString, CreateHighlightParams::class.java).asCreateHighlightInput()
|
||||
|
||||
authenticatedApolloClient().mutation(
|
||||
CreateHighlightMutation(input)
|
||||
).execute()
|
||||
}
|
||||
|
|
@ -22,7 +22,7 @@ suspend fun Networker.search(
|
|||
)
|
||||
).execute()
|
||||
|
||||
val cursor = result.data?.search?.onSearchSuccess?.pageInfo?.endCursor
|
||||
val newCursor = result.data?.search?.onSearchSuccess?.pageInfo?.endCursor
|
||||
val itemList = result.data?.search?.onSearchSuccess?.edges ?: listOf()
|
||||
|
||||
val items = itemList.map {
|
||||
|
|
@ -49,5 +49,5 @@ suspend fun Networker.search(
|
|||
)
|
||||
}
|
||||
|
||||
return SearchQueryResponse(cursor, items)
|
||||
return SearchQueryResponse(newCursor, items)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ fun WebReaderLoadingContainer(slug: String, webReaderViewModel: WebReaderViewMod
|
|||
if (webReaderParams != null) {
|
||||
WebReader(webReaderParams!!, webReaderViewModel)
|
||||
} else {
|
||||
// TODO: add a proper loading view
|
||||
// TODO: add a proper loading viewhandleIncomingWebMessage
|
||||
Text("Loading...")
|
||||
}
|
||||
}
|
||||
|
|
@ -143,9 +143,9 @@ class OmnivoreWebView(context: Context) : WebView(context) {
|
|||
}
|
||||
}
|
||||
|
||||
class AndroidWebKitMessenger(val messageHandler: (String, JSONObject) -> Unit) {
|
||||
class AndroidWebKitMessenger(val messageHandler: (String, String) -> Unit) {
|
||||
@JavascriptInterface
|
||||
fun handleIdentifiableMessage(actionID: String, jsonString: String) {
|
||||
messageHandler(actionID, JSONObject(jsonString))
|
||||
messageHandler(actionID, jsonString)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import androidx.lifecycle.viewModelScope
|
|||
import app.omnivore.omnivore.DatastoreRepository
|
||||
import app.omnivore.omnivore.models.LinkedItem
|
||||
import app.omnivore.omnivore.networking.Networker
|
||||
import app.omnivore.omnivore.networking.createHighlight
|
||||
import app.omnivore.omnivore.networking.linkedItem
|
||||
import com.google.gson.Gson
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
|
|
@ -45,32 +46,34 @@ class WebReaderViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun handleIncomingWebMessage(actionID: String, json: JSONObject) {
|
||||
fun handleIncomingWebMessage(actionID: String, jsonString: String) {
|
||||
when (actionID) {
|
||||
"createHighlight" -> {
|
||||
Log.d("Loggo", "receive create highlight action: $json")
|
||||
viewModelScope.launch {
|
||||
networker.createHighlight(jsonString)
|
||||
}
|
||||
}
|
||||
"deleteHighlight" -> {
|
||||
// { highlightId }
|
||||
Log.d("Loggo", "receive delete highlight action: $json")
|
||||
Log.d("Loggo", "receive delete highlight action: $jsonString")
|
||||
}
|
||||
"updateHighlight" -> {
|
||||
Log.d("Loggo", "receive update highlight action: $json")
|
||||
Log.d("Loggo", "receive update highlight action: $jsonString")
|
||||
}
|
||||
"articleReadingProgress" -> {
|
||||
Log.d("Loggo", "received article reading progress action: $json")
|
||||
Log.d("Loggo", "received article reading progress action: $jsonString")
|
||||
}
|
||||
"annotate" -> {
|
||||
Log.d("Loggo", "received annotate action: $json")
|
||||
Log.d("Loggo", "received annotate action: $jsonString")
|
||||
}
|
||||
"existingHighlightTap" -> {
|
||||
Log.d("Loggo", "receive existing highlight tap action: $json")
|
||||
Log.d("Loggo", "receive existing highlight tap action: $jsonString")
|
||||
}
|
||||
"shareHighlight" -> {
|
||||
// unimplemented
|
||||
}
|
||||
else -> {
|
||||
Log.d("Loggo", "receive unrecognized action of $actionID with json: $json")
|
||||
Log.d("Loggo", "receive unrecognized action of $actionID with json: $jsonString")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue