Adds Option to Copy Panel to Clipboard (#1003)
Some checks failed
CI / Build app (push) Has been cancelled

* 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:
Roshan Varughese 2024-07-27 08:59:59 +12:00 committed by GitHub
parent 913ff22132
commit 0af90999c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 4 deletions

View file

@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ContentCopy
import androidx.compose.material.icons.outlined.Photo
import androidx.compose.material.icons.outlined.Save
import androidx.compose.material.icons.outlined.Share
@ -28,7 +29,7 @@ import tachiyomi.presentation.core.i18n.stringResource
fun ReaderPageActionsDialog(
onDismissRequest: () -> Unit,
onSetAsCover: () -> Unit,
onShare: () -> Unit,
onShare: (Boolean) -> Unit,
onSave: () -> Unit,
) {
var showSetCoverDialog by remember { mutableStateOf(false) }
@ -44,12 +45,21 @@ fun ReaderPageActionsDialog(
icon = Icons.Outlined.Photo,
onClick = { showSetCoverDialog = true },
)
ActionButton(
modifier = Modifier.weight(1f),
title = stringResource(MR.strings.action_copy_to_clipboard),
icon = Icons.Outlined.ContentCopy,
onClick = {
onShare(true)
onDismissRequest()
},
)
ActionButton(
modifier = Modifier.weight(1f),
title = stringResource(MR.strings.action_share),
icon = Icons.Outlined.Share,
onClick = {
onShare()
onShare(false)
onDismissRequest()
},
)

View file

@ -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].

View file

@ -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
}
}