mirror of
https://github.com/mihonapp/mihon.git
synced 2025-11-16 05:57:29 +01:00
Adds Option to Copy Panel to Clipboard (#1003)
* Add Copy to Clipboard * Removing Unused Import * Reusing onShare function * Commit Suggestion * Early Return on null Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com> --------- Co-authored-by: AntsyLich <59261191+AntsyLich@users.noreply.github.com>
This commit is contained in:
@@ -3,6 +3,8 @@ package eu.kanade.tachiyomi.ui.reader
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.app.assist.AssistContent
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.Color
|
||||
@@ -28,6 +30,7 @@ import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.ColorUtils
|
||||
import androidx.core.net.toUri
|
||||
import androidx.core.transition.doOnEnd
|
||||
@@ -223,6 +226,9 @@ class ReaderActivity : BaseActivity() {
|
||||
is ReaderViewModel.Event.ShareImage -> {
|
||||
onShareImageResult(event.uri, event.page)
|
||||
}
|
||||
is ReaderViewModel.Event.CopyImage -> {
|
||||
onCopyImageResult(event.uri)
|
||||
}
|
||||
is ReaderViewModel.Event.SetCoverResult -> {
|
||||
onSetAsCoverResult(event.result)
|
||||
}
|
||||
@@ -721,6 +727,12 @@ class ReaderActivity : BaseActivity() {
|
||||
startActivity(Intent.createChooser(intent, stringResource(MR.strings.action_share)))
|
||||
}
|
||||
|
||||
private fun onCopyImageResult(uri: Uri) {
|
||||
val clipboardManager = applicationContext.getSystemService<ClipboardManager>() ?: return
|
||||
val clipData = ClipData.newUri(applicationContext.contentResolver, "", uri)
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
}
|
||||
|
||||
/**
|
||||
* Called from the presenter when a page is saved or fails. It shows a message or logs the
|
||||
* event depending on the [result].
|
||||
|
||||
@@ -809,7 +809,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
* get a path to the file and it has to be decompressed somewhere first. Only the last shared
|
||||
* image will be kept so it won't be taking lots of internal disk space.
|
||||
*/
|
||||
fun shareImage() {
|
||||
fun shareImage(copyToClipboard: Boolean) {
|
||||
val page = (state.value.dialog as? Dialog.PageActions)?.page
|
||||
if (page?.status != Page.State.READY) return
|
||||
val manga = manga ?: return
|
||||
@@ -829,7 +829,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
location = Location.Cache,
|
||||
),
|
||||
)
|
||||
eventChannel.send(Event.ShareImage(uri, page))
|
||||
eventChannel.send(if (copyToClipboard) Event.CopyImage(uri) else Event.ShareImage(uri, page))
|
||||
}
|
||||
} catch (e: Throwable) {
|
||||
logcat(LogPriority.ERROR, e)
|
||||
@@ -949,5 +949,6 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||
|
||||
data class SavedImage(val result: SaveImageResult) : Event
|
||||
data class ShareImage(val uri: Uri, val page: ReaderPage) : Event
|
||||
data class CopyImage(val uri: Uri) : Event
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user