From b7b53e09c6c094c53dcd5a59a65dc5c0c1c176c8 Mon Sep 17 00:00:00 2001 From: Tuomas Airaksinen Date: Thu, 20 May 2021 12:00:08 +0300 Subject: [PATCH] Start working on adjusting previously existing bookmark range --- .../src/components/BookmarkButtons.vue | 41 +++++++++++++++++-- .../components/documents/BibleDocument.vue | 2 +- .../components/modals/AmbiguousSelection.vue | 3 +- .../AmbiguousSelectionBookmarkButton.vue | 8 ++-- .../src/components/modals/BookmarkModal.vue | 7 +++- app/bibleview-js/src/composables/android.js | 5 +++ app/bibleview-js/src/composables/bookmarks.js | 8 ++-- .../activity/page/BibleJavascriptInterface.kt | 5 +++ .../android/view/activity/page/BibleView.kt | 31 +++++++++----- 9 files changed, 84 insertions(+), 26 deletions(-) diff --git a/app/bibleview-js/src/components/BookmarkButtons.vue b/app/bibleview-js/src/components/BookmarkButtons.vue index f686840617..8a6d81e5f8 100644 --- a/app/bibleview-js/src/components/BookmarkButtons.vue +++ b/app/bibleview-js/src/components/BookmarkButtons.vue @@ -30,6 +30,9 @@
+
+ +
@@ -85,7 +86,7 @@ export default { if(eventFunctions.length > 0) { if(eventFunctions.length === 1) { if(eventFunctions[0].options.bookmarkId) { - emit(Events.BOOKMARK_CLICKED, eventFunctions[0].options.bookmarkId); + emit(Events.BOOKMARK_CLICKED, eventFunctions[0].options.bookmarkId, eventFunctions[0].options.documentId); } else { eventFunctions[0].callback(); } diff --git a/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue b/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue index bcebfff91a..807fc38526 100644 --- a/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue +++ b/app/bibleview-js/src/components/modals/AmbiguousSelectionBookmarkButton.vue @@ -24,6 +24,7 @@
@@ -45,6 +46,7 @@ export default { name: "AmbiguousSelectionBookmarkButton", props: { bookmarkId: {required: true, type: Number}, + documentId: {required: true, type: String}, }, components: {LabelList, BookmarkButtons}, setup(props, {emit: $emit}) { @@ -71,17 +73,17 @@ export default { function editNotes() { $emit("selected"); - emit(Events.BOOKMARK_CLICKED, bookmark.value.id, {open: true}); + emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId, {open: true}); } function openBookmark() { $emit("selected"); - emit(Events.BOOKMARK_CLICKED, bookmark.value.id); + emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId); } function bookmarkInfo() { $emit("selected"); - emit(Events.BOOKMARK_CLICKED, bookmark.value.id, {openInfo: true}); + emit(Events.BOOKMARK_CLICKED, bookmark.value.id, props.documentId, {openInfo: true}); } return { diff --git a/app/bibleview-js/src/components/modals/BookmarkModal.vue b/app/bibleview-js/src/components/modals/BookmarkModal.vue index 87aa52309a..7251f5c4f2 100644 --- a/app/bibleview-js/src/components/modals/BookmarkModal.vue +++ b/app/bibleview-js/src/components/modals/BookmarkModal.vue @@ -66,6 +66,7 @@
@@ -108,6 +109,7 @@ export default { const areYouSure = ref(null); const infoShown = ref(false); const bookmarkId = ref(null); + const documentId = ref(null); const {bookmarkMap, bookmarkLabels} = inject("globalBookmarks"); @@ -124,8 +126,9 @@ export default { const bookmarkNotes = computed(() => bookmark.value.notes); let originalNotes = null; - setupEventBusListener(Events.BOOKMARK_CLICKED, (bookmarkId_, {openInfo = false, open = false} = {}) => { + setupEventBusListener(Events.BOOKMARK_CLICKED, (bookmarkId_, documentId_, {openInfo = false, open = false} = {}) => { bookmarkId.value = bookmarkId_; + documentId.value = documentId_; originalNotes = bookmarkNotes.value; //if(!showBookmark.value) infoShown.value = false; infoShown.value = openInfo; @@ -159,7 +162,7 @@ export default { return { showBookmark, closeBookmark, areYouSure, infoShown, bookmarkNotes, bookmark, labelColor, - changeNote, labels, originalBookLink, strings, adjustedColor, editDirectly, ...common + changeNote, labels, originalBookLink, strings, adjustedColor, editDirectly, documentId, ...common }; }, } diff --git a/app/bibleview-js/src/composables/android.js b/app/bibleview-js/src/composables/android.js index 6123627ac8..085fbd63ca 100644 --- a/app/bibleview-js/src/composables/android.js +++ b/app/bibleview-js/src/composables/android.js @@ -227,6 +227,10 @@ export function useAndroid({bookmarks}, config) { android.openStudyPad(labelId); } + function adjustRange() { + android.adjustRange(); + } + function updateOrderNumber(labelId, bookmarks, journals) { const orderNumberPairs = l => l.map(v=>[v.id, v.orderNumber]) android.updateOrderNumber(labelId, JSON.stringify( @@ -289,6 +293,7 @@ export function useAndroid({bookmarks}, config) { toggleBookmarkLabel, reportModalState, setBookmarkWholeVerse, + adjustRange, } if(config.developmentMode) return { diff --git a/app/bibleview-js/src/composables/bookmarks.js b/app/bibleview-js/src/composables/bookmarks.js index 31b7818149..17c3bb85b0 100644 --- a/app/bibleview-js/src/composables/bookmarks.js +++ b/app/bibleview-js/src/composables/bookmarks.js @@ -373,7 +373,7 @@ export function useBookmarks(documentId, function addBookmarkEventFunctions(event) { for (const b of bookmarks) { - addEventFunction(event, null, {bookmarkId: b.id}); + addEventFunction(event, null, {bookmarkId: b.id, documentId}); } } @@ -424,7 +424,7 @@ export function useBookmarks(documentId, const iconElement = getIconElement(speakIcon, color); iconElement.addEventListener("click", event => addEventFunction(event, - null, {bookmarkId: b.id})); + null, {bookmarkId: b.id, documentId})); firstElement.parentElement.insertBefore(iconElement, firstElement); undoHighlights.push(() => iconElement.remove()); } @@ -436,7 +436,7 @@ export function useBookmarks(documentId, const iconElement = getIconElement(b.notes ? editIcon : bookmarkIcon, color); iconElement.addEventListener("click", event => addEventFunction(event, - null, {bookmarkId: b.id})); + null, {bookmarkId: b.id, documentId})); lastElement.parentNode.insertBefore(iconElement, lastElement.nextSibling); undoHighlights.push(() => iconElement.remove()); } @@ -459,7 +459,7 @@ export function useBookmarks(documentId, const iconElement = getIconElement(bookmarkIcon, color); iconElement.addEventListener("click", event => { for(const b of bookmarkList) { - addEventFunction(event, null, {bookmarkId: b.id}); + addEventFunction(event, null, {bookmarkId: b.id, documentId}); } }); if(bookmarkList.length>1) { diff --git a/app/src/main/java/net/bible/android/view/activity/page/BibleJavascriptInterface.kt b/app/src/main/java/net/bible/android/view/activity/page/BibleJavascriptInterface.kt index c5ed764e35..b4343d91cc 100644 --- a/app/src/main/java/net/bible/android/view/activity/page/BibleJavascriptInterface.kt +++ b/app/src/main/java/net/bible/android/view/activity/page/BibleJavascriptInterface.kt @@ -217,5 +217,10 @@ class BibleJavascriptInterface( if(value) ABEventBus.getDefault().post(ToastEvent(R.string.whole_verse_turned_on)) } + @JavascriptInterface + fun adjustRange() { + bibleView.adjustRange() + } + private val TAG get() = "BibleView[${bibleView.windowRef.get()?.id}] JSInt" } diff --git a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt index 69909accc9..709294ab43 100644 --- a/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt +++ b/app/src/main/java/net/bible/android/view/activity/page/BibleView.kt @@ -356,30 +356,39 @@ class BibleView(val mainBibleActivity: MainBibleActivity, if(removeRanges) executeJavascriptOnUiThread("bibleView.emit('remove_ranges')") } + fun adjustRange() { + //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + // runOnUiThread { + // mainBibleActivity.startActionMode(ActionModeCallback2(null), ActionMode.TYPE_FLOATING) + // //startActionMode(null, ActionMode.TYPE_FLOATING) + // } + //} + } + @RequiresApi(Build.VERSION_CODES.M) - private inner class ActionModeCallback2(val callback: ActionMode.Callback): ActionMode.Callback2() { + private inner class ActionModeCallback2(val callback: ActionMode.Callback?): ActionMode.Callback2() { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - val wasUpdated2 = callback.onCreateActionMode(mode, menu) + val wasUpdated2 = callback?.onCreateActionMode(mode, menu)?: false val wasUpdated1 = false return wasUpdated1 || wasUpdated2 } override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { if(!actionModeEnabled) return true - val wasUpdated2 = callback.onPrepareActionMode(mode, menu) + val wasUpdated2 = callback?.onPrepareActionMode(mode, menu)?:false val wasUpdated1 = onPrepareActionMenu(mode, menu) return wasUpdated1 || wasUpdated2 } override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { val handled1 = onActionMenuItemClicked(mode, item) - val handled2 = callback.onActionItemClicked(mode, item) + val handled2 = callback?.onActionItemClicked(mode, item)?:false if(handled1) stopSelection(true) return handled1 || handled2 } override fun onDestroyActionMode(mode: ActionMode) { - return callback.onDestroyActionMode(mode) + callback?.onDestroyActionMode(mode) } override fun onGetContentRect(mode: ActionMode, view: View, outRect: Rect) { @@ -391,7 +400,7 @@ class BibleView(val mainBibleActivity: MainBibleActivity, } } - override fun startActionMode(callback: ActionMode.Callback, type: Int): ActionMode { + override fun startActionMode(callback: ActionMode.Callback?, type: Int): ActionMode { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { super.startActionMode(ActionModeCallback2(callback), type) } else { @@ -404,25 +413,25 @@ class BibleView(val mainBibleActivity: MainBibleActivity, } // This can be removed after Lollipop support is dropped. - private inner class ActionModeCallback(val callback: ActionMode.Callback): ActionMode.Callback { + private inner class ActionModeCallback(val callback: ActionMode.Callback?): ActionMode.Callback { override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { - callback.onCreateActionMode(mode, menu) + callback?.onCreateActionMode(mode, menu) return true } override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean { if(!actionModeEnabled) return true - val wasUpdated1 = callback.onPrepareActionMode(mode, menu) + val wasUpdated1 = callback?.onPrepareActionMode(mode, menu)?: false val wasUpdated2 = onPrepareActionMenu(mode, menu) return wasUpdated1 || wasUpdated2 } override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - return onActionMenuItemClicked(mode, item) || callback.onActionItemClicked(mode, item) + return onActionMenuItemClicked(mode, item) || callback?.onActionItemClicked(mode, item)?: false } override fun onDestroyActionMode(mode: ActionMode?) { - return callback.onDestroyActionMode(mode) + callback?.onDestroyActionMode(mode) } }