Implement copy
This commit is contained in:
1 parent
feb13cbd79
commit
886e025ac8
2 files changed
+20
-1
No files matched your search
@@ -1,5 +1,6 @@
|
||||
package com.hippo.ehviewer.ui.reader
|
||||
|
||||
import android.content.ClipData
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
@@ -13,9 +14,11 @@ import com.hippo.ehviewer.client.data.GalleryInfo
|
||||
import com.hippo.ehviewer.gallery.PageLoader2
|
||||
import com.hippo.ehviewer.util.AppConfig
|
||||
import com.hippo.ehviewer.util.FileUtils
|
||||
import com.hippo.ehviewer.util.isAtLeastT
|
||||
import com.hippo.unifile.asUniFile
|
||||
import eu.kanade.tachiyomi.ui.reader.model.ReaderPage
|
||||
import java.io.File
|
||||
import splitties.systemservices.clipboardManager
|
||||
|
||||
context(PageLoader2)
|
||||
private fun Context.provideImage(index: Int): Uri? {
|
||||
@@ -48,3 +51,19 @@ suspend fun shareImage(page: ReaderPage, info: GalleryInfo? = null) {
|
||||
showSnackbar(noActivity)
|
||||
}
|
||||
}
|
||||
|
||||
context(SnackbarHostState, Context, PageLoader2)
|
||||
suspend fun copy(page: ReaderPage) {
|
||||
val error = getString(R.string.error_cant_save_image)
|
||||
val copied = getString(R.string.copied_to_clipboard)
|
||||
val uri = provideImage(page.index)
|
||||
if (uri == null) {
|
||||
showSnackbar(error)
|
||||
return
|
||||
}
|
||||
val clipData = ClipData.newUri(contentResolver, "ehviewer", uri)
|
||||
clipboardManager.setPrimaryClip(clipData)
|
||||
if (!isAtLeastT) {
|
||||
showSnackbar(copied)
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ fun ReaderScreen(info: BaseGalleryInfo, page: Int = -1) {
|
||||
retry = { pageLoader.retryPage(page.index) },
|
||||
retryOrigin = { pageLoader.retryPage(page.index, true) },
|
||||
share = { scope.launchIO { with(snackbarHostState, pageLoader, context) { shareImage(page, info) } } },
|
||||
copy = {},
|
||||
copy = { scope.launchIO { with(snackbarHostState, pageLoader, context) { copy(page) } } },
|
||||
save = {},
|
||||
saveTo = {},
|
||||
dismiss = { scope.launch { state.hide().also { dispose() } } },
|
||||
|
||||
Reference in new issue
Block a user