mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
update note on pdf annotation when confirm is tapped on note modal
This commit is contained in:
parent
5df82d0d14
commit
5b2c58d955
3 changed files with 45 additions and 10 deletions
|
|
@ -377,8 +377,10 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan
|
|||
return when (item.itemId) {
|
||||
R.id.annotate -> {
|
||||
Log.d("pdf", "annotate button tapped")
|
||||
viewModel.annotationUnderNoteEdit = clickedHighlight
|
||||
showAnnotationView("") // TODO: grab initial text
|
||||
clickedHighlight?.let {
|
||||
viewModel.annotationUnderNoteEdit = it
|
||||
showAnnotationView(viewModel.pluckExistingNote(it) ?: "")
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.delete -> {
|
||||
|
|
@ -432,6 +434,7 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan
|
|||
actionMode = null
|
||||
clickedHighlight = null
|
||||
clickedHighlightPosition = null
|
||||
viewModel.annotationUnderNoteEdit = null
|
||||
}
|
||||
|
||||
override fun startActionMode(callback: ActionMode.Callback?, type: Int): ActionMode? {
|
||||
|
|
@ -448,8 +451,11 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan
|
|||
|
||||
confirmButton.setOnClickListener {
|
||||
val newNoteText = textField.text
|
||||
// TODO: persist new note
|
||||
Log.d("pdf", "new annotation text: $newNoteText")
|
||||
|
||||
clickedHighlight?.let { highlight ->
|
||||
viewModel.updateHighlightNote(highlight, newNoteText.toString())
|
||||
}
|
||||
|
||||
resetHighlightTap()
|
||||
annotationDialog.dismiss()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,7 +115,7 @@ class PDFReaderViewModel @Inject constructor(
|
|||
|
||||
if (overlapIds.isNotEmpty()) {
|
||||
val input = MergeHighlightInput(
|
||||
annotation = Optional.presentIfNotNull(newAnnotation.contents),
|
||||
annotation = Optional.Absent, // TODO: make sure we preserve note locally
|
||||
articleId = itemID,
|
||||
id = highlightID,
|
||||
overlapHighlightIdList = overlapIds,
|
||||
|
|
@ -143,6 +143,19 @@ class PDFReaderViewModel @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
fun updateHighlightNote(annotation: Annotation, note: String) {
|
||||
// Save the updated note locally
|
||||
val omnivoreHighlight = annotation.customData?.get("omnivoreHighlight") as? JSONObject
|
||||
omnivoreHighlight?.put("editedNote", note)
|
||||
omnivoreHighlight?.let {
|
||||
Log.d("pdf", "setting custom data: $omnivoreHighlight")
|
||||
annotation.customData = JSONObject().put("omnivoreHighlight", it)
|
||||
}
|
||||
|
||||
// TODO: Sync update with data service
|
||||
|
||||
}
|
||||
|
||||
fun deleteHighlight(annotation: Annotation) {
|
||||
val highlightID = pluckHighlightID(annotation) ?: return
|
||||
viewModelScope.launch {
|
||||
|
|
@ -168,6 +181,22 @@ class PDFReaderViewModel @Inject constructor(
|
|||
return omnivoreHighlight?.get("id") as? String
|
||||
}
|
||||
|
||||
fun pluckExistingNote(annotation: Annotation): String? {
|
||||
val omnivoreHighlight = annotation.customData?.opt("omnivoreHighlight") as? JSONObject ?: return null
|
||||
|
||||
val editedNote = omnivoreHighlight.opt("editedNote") as? String
|
||||
if (editedNote != null) { return editedNote }
|
||||
|
||||
val shortID = omnivoreHighlight.get("shortId") as? String ?: return null
|
||||
|
||||
pdfReaderParamsLiveData.value?.articleContent?.highlights?.let {
|
||||
val matchingHighlight = it.firstOrNull { highlight -> highlight.shortId == shortID }
|
||||
return matchingHighlight?.annotation
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun hasOverlaps(leftAnnotation: Annotation, rightAnnotation: Annotation): Boolean {
|
||||
for (leftRect in (leftAnnotation as? HighlightAnnotation)?.rects ?: listOf()) {
|
||||
for (rightRect in (rightAnnotation as? HighlightAnnotation)?.rects ?: listOf()) {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@
|
|||
app:showAsAction="always">
|
||||
</item>
|
||||
|
||||
<!-- <item-->
|
||||
<!-- android:id="@+id/annotate"-->
|
||||
<!-- android:title="@string/pdf_highlight_menu_note"-->
|
||||
<!-- app:showAsAction="always">-->
|
||||
<!-- </item>-->
|
||||
<item
|
||||
android:id="@+id/annotate"
|
||||
android:title="@string/pdf_highlight_menu_note"
|
||||
app:showAsAction="always">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
|
|
|
|||
Loading…
Reference in a new issue