mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Adds Option to Copy Panel to Clipboard (#1003)
Some checks failed
CI / Build app (push) Has been cancelled
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:
parent
913ff22132
commit
0af90999c8
3 changed files with 27 additions and 4 deletions
|
@ -4,6 +4,7 @@ import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material.icons.Icons
|
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.Photo
|
||||||
import androidx.compose.material.icons.outlined.Save
|
import androidx.compose.material.icons.outlined.Save
|
||||||
import androidx.compose.material.icons.outlined.Share
|
import androidx.compose.material.icons.outlined.Share
|
||||||
|
@ -28,7 +29,7 @@ import tachiyomi.presentation.core.i18n.stringResource
|
||||||
fun ReaderPageActionsDialog(
|
fun ReaderPageActionsDialog(
|
||||||
onDismissRequest: () -> Unit,
|
onDismissRequest: () -> Unit,
|
||||||
onSetAsCover: () -> Unit,
|
onSetAsCover: () -> Unit,
|
||||||
onShare: () -> Unit,
|
onShare: (Boolean) -> Unit,
|
||||||
onSave: () -> Unit,
|
onSave: () -> Unit,
|
||||||
) {
|
) {
|
||||||
var showSetCoverDialog by remember { mutableStateOf(false) }
|
var showSetCoverDialog by remember { mutableStateOf(false) }
|
||||||
|
@ -44,12 +45,21 @@ fun ReaderPageActionsDialog(
|
||||||
icon = Icons.Outlined.Photo,
|
icon = Icons.Outlined.Photo,
|
||||||
onClick = { showSetCoverDialog = true },
|
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(
|
ActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
title = stringResource(MR.strings.action_share),
|
title = stringResource(MR.strings.action_share),
|
||||||
icon = Icons.Outlined.Share,
|
icon = Icons.Outlined.Share,
|
||||||
onClick = {
|
onClick = {
|
||||||
onShare()
|
onShare(false)
|
||||||
onDismissRequest()
|
onDismissRequest()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
|
@ -3,6 +3,8 @@ package eu.kanade.tachiyomi.ui.reader
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.app.assist.AssistContent
|
import android.app.assist.AssistContent
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
|
@ -28,6 +30,7 @@ import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
|
import androidx.core.content.getSystemService
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.net.toUri
|
import androidx.core.net.toUri
|
||||||
import androidx.core.transition.doOnEnd
|
import androidx.core.transition.doOnEnd
|
||||||
|
@ -223,6 +226,9 @@ class ReaderActivity : BaseActivity() {
|
||||||
is ReaderViewModel.Event.ShareImage -> {
|
is ReaderViewModel.Event.ShareImage -> {
|
||||||
onShareImageResult(event.uri, event.page)
|
onShareImageResult(event.uri, event.page)
|
||||||
}
|
}
|
||||||
|
is ReaderViewModel.Event.CopyImage -> {
|
||||||
|
onCopyImageResult(event.uri)
|
||||||
|
}
|
||||||
is ReaderViewModel.Event.SetCoverResult -> {
|
is ReaderViewModel.Event.SetCoverResult -> {
|
||||||
onSetAsCoverResult(event.result)
|
onSetAsCoverResult(event.result)
|
||||||
}
|
}
|
||||||
|
@ -721,6 +727,12 @@ class ReaderActivity : BaseActivity() {
|
||||||
startActivity(Intent.createChooser(intent, stringResource(MR.strings.action_share)))
|
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
|
* Called from the presenter when a page is saved or fails. It shows a message or logs the
|
||||||
* event depending on the [result].
|
* 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
|
* 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.
|
* 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
|
val page = (state.value.dialog as? Dialog.PageActions)?.page
|
||||||
if (page?.status != Page.State.READY) return
|
if (page?.status != Page.State.READY) return
|
||||||
val manga = manga ?: return
|
val manga = manga ?: return
|
||||||
|
@ -829,7 +829,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
location = Location.Cache,
|
location = Location.Cache,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
eventChannel.send(Event.ShareImage(uri, page))
|
eventChannel.send(if (copyToClipboard) Event.CopyImage(uri) else Event.ShareImage(uri, page))
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logcat(LogPriority.ERROR, e)
|
logcat(LogPriority.ERROR, e)
|
||||||
|
@ -949,5 +949,6 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
|
|
||||||
data class SavedImage(val result: SaveImageResult) : Event
|
data class SavedImage(val result: SaveImageResult) : Event
|
||||||
data class ShareImage(val uri: Uri, val page: ReaderPage) : Event
|
data class ShareImage(val uri: Uri, val page: ReaderPage) : Event
|
||||||
|
data class CopyImage(val uri: Uri) : Event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue