Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds Option to Copy Panel to Clipboard #1003

Merged
merged 5 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) }
Expand All @@ -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()
},
)
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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].
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
}