mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
implement copy highlight action
This commit is contained in:
parent
88a27b52e3
commit
c022ef1874
8 changed files with 62 additions and 9 deletions
File diff suppressed because one or more lines are too long
|
|
@ -269,7 +269,7 @@ class PDFReaderActivity: AppCompatActivity(), DocumentListener, TextSelectionMan
|
|||
// TODO: anchor popover at exact position of tap (maybe add an empty view at tap loc and anchor to that?)
|
||||
val popupMenu = PopupMenu(this, fragment.view, Gravity.CENTER, androidx.appcompat.R.attr.actionOverflowMenuStyle, 0)
|
||||
|
||||
popupMenu.menuInflater.inflate(R.menu.highlight_selection_menu, popupMenu.menu)
|
||||
popupMenu.menuInflater.inflate(R.menu.pdf_highlight_selection_menu, popupMenu.menu)
|
||||
|
||||
popupMenu.setOnMenuItemClickListener { item ->
|
||||
when(item.itemId) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package app.omnivore.omnivore.ui.reader
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.util.Log
|
||||
|
|
@ -24,11 +26,13 @@ import androidx.compose.ui.input.nestedscroll.nestedScroll
|
|||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import androidx.core.content.ContextCompat.getSystemService
|
||||
import app.omnivore.omnivore.R
|
||||
import com.google.gson.Gson
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONObject
|
||||
import java.util.*
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
|
@ -187,6 +191,14 @@ fun WebReader(
|
|||
startActionMode(null, ActionMode.TYPE_FLOATING)
|
||||
}
|
||||
}
|
||||
"writeToClipboard" -> {
|
||||
val quote = Gson().fromJson(json, HighlightQuote::class.java).quote
|
||||
quote.let { unwrappedQuote ->
|
||||
val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText(unwrappedQuote, unwrappedQuote)
|
||||
clipboard.setPrimaryClip(clip)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
webReaderViewModel.handleIncomingWebMessage(actionID, json)
|
||||
}
|
||||
|
|
@ -241,7 +253,7 @@ class OmnivoreWebView(context: Context) : WebView(context) {
|
|||
// Called when the user selects a contextual menu item
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
return when (item.itemId) {
|
||||
R.id.annotate -> {
|
||||
R.id.annotateHighlight -> {
|
||||
val script = "var event = new Event('annotate');document.dispatchEvent(event);"
|
||||
evaluateJavascript(script) {
|
||||
mode.finish()
|
||||
|
|
@ -258,7 +270,16 @@ class OmnivoreWebView(context: Context) : WebView(context) {
|
|||
}
|
||||
true
|
||||
}
|
||||
R.id.delete -> {
|
||||
R.id.copyHighlight -> {
|
||||
val script = "var event = new Event('copyHighlight');document.dispatchEvent(event);"
|
||||
evaluateJavascript(script) {
|
||||
clearFocus()
|
||||
mode.finish()
|
||||
actionMode = null
|
||||
}
|
||||
true
|
||||
}
|
||||
R.id.removeHighlight -> {
|
||||
val script = "var event = new Event('remove');document.dispatchEvent(event);"
|
||||
evaluateJavascript(script) {
|
||||
clearFocus()
|
||||
|
|
@ -330,3 +351,5 @@ data class TapCoordinates(
|
|||
val tapX: Double,
|
||||
val tapY: Double
|
||||
)
|
||||
|
||||
data class HighlightQuote(val quote: String?)
|
||||
|
|
|
|||
|
|
@ -2,14 +2,20 @@
|
|||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:id="@+id/removeHighlight"
|
||||
android:title="@string/pdf_remove_highlight"
|
||||
app:showAsAction="always">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/copyPdfHighlight"
|
||||
android:title="@string/pdf_highlight_copy"
|
||||
android:id="@+id/annotateHighlight"
|
||||
android:title="@string/highlight_note"
|
||||
app:showAsAction="always">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/copyHighlight"
|
||||
android:title="@string/pdf_highlight_copy"
|
||||
app:showAsAction="ifRoom">
|
||||
</item>
|
||||
</menu>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:id="@+id/delete"
|
||||
android:title="@string/pdf_remove_highlight"
|
||||
app:showAsAction="always">
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:id="@+id/copyPdfHighlight"
|
||||
android:title="@string/pdf_highlight_copy"
|
||||
app:showAsAction="always">
|
||||
</item>
|
||||
</menu>
|
||||
|
|
@ -9,4 +9,5 @@
|
|||
<string name="pdf_remove_highlight">Remove</string>
|
||||
<string name="pdf_highlight_menu_action">Highlight</string>
|
||||
<string name="pdf_highlight_copy">Copy</string>
|
||||
<string name="highlight_note">Note</string>
|
||||
</resources>
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -470,7 +470,15 @@ export function HighlightsLayer(props: HighlightsLayerProps): JSX.Element {
|
|||
|
||||
const copy = async () => {
|
||||
if (focusedHighlight) {
|
||||
await navigator.clipboard.writeText(focusedHighlight.quote)
|
||||
if (window.AndroidWebKitMessenger) {
|
||||
window.AndroidWebKitMessenger.handleIdentifiableMessage(
|
||||
'writeToClipboard',
|
||||
JSON.stringify({ quote: focusedHighlight.quote })
|
||||
)
|
||||
} else {
|
||||
await navigator.clipboard.writeText(focusedHighlight.quote)
|
||||
}
|
||||
|
||||
setFocusedHighlight(undefined)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue