Adds Option to Copy Panel to Clipboard (mihonapp/mihon#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> (cherry picked from commit 0af90999c8eed4b6c56a94418e5558833f273aa9)
This commit is contained in:
parent
b11a32f2c1
commit
4c19c80013
4 changed files with 71 additions and 13 deletions
|
|
@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Column
|
||||||
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
|
||||||
|
|
@ -29,11 +30,11 @@ import tachiyomi.presentation.core.i18n.stringResource
|
||||||
@Composable
|
@Composable
|
||||||
fun ReaderPageActionsDialog(
|
fun ReaderPageActionsDialog(
|
||||||
onDismissRequest: () -> Unit,
|
onDismissRequest: () -> Unit,
|
||||||
|
onSetAsCover: (/* SY --> */useExtraPage: Boolean/* SY <-- */) -> Unit,
|
||||||
|
onShare: (copyToClipboard: Boolean, /* SY --> */useExtraPage: Boolean/* SY <-- */) -> Unit,
|
||||||
|
onSave: (/* SY --> */useExtraPage: Boolean/* SY <-- */) -> Unit,
|
||||||
// SY -->
|
// SY -->
|
||||||
onSetAsCover: (useExtraPage: Boolean) -> Unit,
|
onShareCombined: (copyToClipboard: Boolean) -> Unit,
|
||||||
onShare: (useExtraPage: Boolean) -> Unit,
|
|
||||||
onSave: (useExtraPage: Boolean) -> Unit,
|
|
||||||
onShareCombined: () -> Unit,
|
|
||||||
onSaveCombined: () -> Unit,
|
onSaveCombined: () -> Unit,
|
||||||
hasExtraPage: Boolean,
|
hasExtraPage: Boolean,
|
||||||
// SY <--
|
// SY <--
|
||||||
|
|
@ -62,6 +63,25 @@ fun ReaderPageActionsDialog(
|
||||||
icon = Icons.Outlined.Photo,
|
icon = Icons.Outlined.Photo,
|
||||||
onClick = { showSetCoverDialog = true },
|
onClick = { showSetCoverDialog = true },
|
||||||
)
|
)
|
||||||
|
ActionButton(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
title = stringResource(
|
||||||
|
// SY -->
|
||||||
|
if (hasExtraPage) {
|
||||||
|
SYMR.strings.action_copy_to_clipboard_first_page
|
||||||
|
} else {
|
||||||
|
MR.strings.action_copy_to_clipboard
|
||||||
|
},
|
||||||
|
// SY <--
|
||||||
|
),
|
||||||
|
icon = Icons.Outlined.ContentCopy,
|
||||||
|
onClick = {
|
||||||
|
// SY -->
|
||||||
|
onShare(true, false)
|
||||||
|
// SY <--
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
)
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
title = stringResource(
|
title = stringResource(
|
||||||
|
|
@ -76,12 +96,11 @@ fun ReaderPageActionsDialog(
|
||||||
icon = Icons.Outlined.Share,
|
icon = Icons.Outlined.Share,
|
||||||
onClick = {
|
onClick = {
|
||||||
// SY -->
|
// SY -->
|
||||||
onShare(false)
|
onShare(false, false)
|
||||||
// SY <--
|
// SY <--
|
||||||
onDismissRequest()
|
onDismissRequest()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
title = stringResource(
|
title = stringResource(
|
||||||
|
|
@ -114,12 +133,21 @@ fun ReaderPageActionsDialog(
|
||||||
showSetCoverDialog = true
|
showSetCoverDialog = true
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
ActionButton(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
title = stringResource(SYMR.strings.action_copy_to_clipboard_second_page),
|
||||||
|
icon = Icons.Outlined.ContentCopy,
|
||||||
|
onClick = {
|
||||||
|
onShare(true, true)
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
)
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
title = stringResource(SYMR.strings.action_share_second_page),
|
title = stringResource(SYMR.strings.action_share_second_page),
|
||||||
icon = Icons.Outlined.Share,
|
icon = Icons.Outlined.Share,
|
||||||
onClick = {
|
onClick = {
|
||||||
onShare(true)
|
onShare(false, true)
|
||||||
onDismissRequest()
|
onDismissRequest()
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
@ -136,12 +164,21 @@ fun ReaderPageActionsDialog(
|
||||||
Row(
|
Row(
|
||||||
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
|
horizontalArrangement = Arrangement.spacedBy(MaterialTheme.padding.small),
|
||||||
) {
|
) {
|
||||||
|
ActionButton(
|
||||||
|
modifier = Modifier.weight(1f),
|
||||||
|
title = stringResource(SYMR.strings.action_copy_to_clipboard_combined_page),
|
||||||
|
icon = Icons.Outlined.ContentCopy,
|
||||||
|
onClick = {
|
||||||
|
onShareCombined(true)
|
||||||
|
onDismissRequest()
|
||||||
|
},
|
||||||
|
)
|
||||||
ActionButton(
|
ActionButton(
|
||||||
modifier = Modifier.weight(1f),
|
modifier = Modifier.weight(1f),
|
||||||
title = stringResource(SYMR.strings.action_share_combined_page),
|
title = stringResource(SYMR.strings.action_share_combined_page),
|
||||||
icon = Icons.Outlined.Share,
|
icon = Icons.Outlined.Share,
|
||||||
onClick = {
|
onClick = {
|
||||||
onShareCombined()
|
onShareCombined(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.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
|
|
@ -38,6 +40,7 @@ import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.graphics.toArgb
|
import androidx.compose.ui.graphics.toArgb
|
||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
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
|
||||||
|
|
@ -285,6 +288,9 @@ class ReaderActivity : BaseActivity() {
|
||||||
is ReaderViewModel.Event.ShareImage -> {
|
is ReaderViewModel.Event.ShareImage -> {
|
||||||
onShareImageResult(event.uri, event.page /* SY --> */, event.secondPage /* SY <-- */)
|
onShareImageResult(event.uri, event.page /* SY --> */, event.secondPage /* SY <-- */)
|
||||||
}
|
}
|
||||||
|
is ReaderViewModel.Event.CopyImage -> {
|
||||||
|
onCopyImageResult(event.uri)
|
||||||
|
}
|
||||||
is ReaderViewModel.Event.SetCoverResult -> {
|
is ReaderViewModel.Event.SetCoverResult -> {
|
||||||
onSetAsCoverResult(event.result)
|
onSetAsCoverResult(event.result)
|
||||||
}
|
}
|
||||||
|
|
@ -1186,6 +1192,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].
|
||||||
|
|
|
||||||
|
|
@ -701,7 +701,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
// SY -->
|
// SY -->
|
||||||
if (readerChapter.chapter.chapter_number > 0 && readerPreferences.markReadDupe().get()) {
|
if (readerChapter.chapter.chapter_number > 0 && readerPreferences.markReadDupe().get()) {
|
||||||
getChaptersByMangaId.await(manga!!.id).sortedByDescending { it.sourceOrder }
|
getChaptersByMangaId.await(manga!!.id).sortedByDescending { it.sourceOrder }
|
||||||
.filter {
|
.filter {
|
||||||
it.id != readerChapter.chapter.id &&
|
it.id != readerChapter.chapter.id &&
|
||||||
!it.read &&
|
!it.read &&
|
||||||
it.chapterNumber.toFloat() == readerChapter.chapter.chapter_number
|
it.chapterNumber.toFloat() == readerChapter.chapter.chapter_number
|
||||||
|
|
@ -1156,7 +1156,12 @@ 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(useExtraPage: Boolean) {
|
fun shareImage(
|
||||||
|
copyToClipboard: Boolean,
|
||||||
|
// SY -->
|
||||||
|
useExtraPage: Boolean,
|
||||||
|
// SY <--
|
||||||
|
) {
|
||||||
// SY -->
|
// SY -->
|
||||||
val page = if (useExtraPage) {
|
val page = if (useExtraPage) {
|
||||||
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
(state.value.dialog as? Dialog.PageActions)?.extraPage
|
||||||
|
|
@ -1182,7 +1187,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)
|
||||||
|
|
@ -1190,7 +1195,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
}
|
}
|
||||||
|
|
||||||
// SY -->
|
// SY -->
|
||||||
fun shareImages() {
|
fun shareImages(copyToClipboard: Boolean) {
|
||||||
val (firstPage, secondPage) = (state.value.dialog as? Dialog.PageActions ?: return)
|
val (firstPage, secondPage) = (state.value.dialog as? Dialog.PageActions ?: return)
|
||||||
val viewer = state.value.viewer as? PagerViewer ?: return
|
val viewer = state.value.viewer as? PagerViewer ?: return
|
||||||
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
val isLTR = (viewer !is R2LPagerViewer) xor (viewer.config.invertDoublePages)
|
||||||
|
|
@ -1214,7 +1219,7 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
location = Location.Cache,
|
location = Location.Cache,
|
||||||
manga = manga,
|
manga = manga,
|
||||||
)
|
)
|
||||||
eventChannel.send(Event.ShareImage(uri, firstPage, secondPage))
|
eventChannel.send(if (copyToClipboard) Event.CopyImage(uri) else Event.ShareImage(uri, firstPage, secondPage))
|
||||||
}
|
}
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
logcat(LogPriority.ERROR, e)
|
logcat(LogPriority.ERROR, e)
|
||||||
|
|
@ -1382,5 +1387,6 @@ class ReaderViewModel @JvmOverloads constructor(
|
||||||
val page: ReaderPage/* SY --> */,
|
val page: ReaderPage/* SY --> */,
|
||||||
val secondPage: ReaderPage? = null, /* SY <-- */
|
val secondPage: ReaderPage? = null, /* SY <-- */
|
||||||
) : Event
|
) : Event
|
||||||
|
data class CopyImage(val uri: Uri) : Event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -346,8 +346,11 @@
|
||||||
<string name="action_save_second_page">Save second page</string>
|
<string name="action_save_second_page">Save second page</string>
|
||||||
<string name="action_share_first_page">Share first page</string>
|
<string name="action_share_first_page">Share first page</string>
|
||||||
<string name="action_share_second_page">Share second page</string>
|
<string name="action_share_second_page">Share second page</string>
|
||||||
|
<string name="action_copy_to_clipboard_first_page">Copy first page to clipboard</string>
|
||||||
|
<string name="action_copy_to_clipboard_second_page">Copy second page to clipboard</string>
|
||||||
<string name="action_save_combined_page">Save combined page</string>
|
<string name="action_save_combined_page">Save combined page</string>
|
||||||
<string name="action_share_combined_page">Share combined page</string>
|
<string name="action_share_combined_page">Share combined page</string>
|
||||||
|
<string name="action_copy_to_clipboard_combined_page">Copy combined page to clipboard</string>
|
||||||
|
|
||||||
<!-- Reader Sharing -->
|
<!-- Reader Sharing -->
|
||||||
<string name="share_pages_info">%1$s: %2$s, pages %3$s</string>
|
<string name="share_pages_info">%1$s: %2$s, pages %3$s</string>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue