Share image with long click

This commit is contained in:
tom5079
2021-12-18 00:48:49 +09:00
parent 338b789e62
commit bdd2bc8645
5 changed files with 14 additions and 5 deletions

View File

@@ -20,7 +20,7 @@ android {
minSdk = 21
targetSdk = 31
versionCode = 600
versionName = "6.0.0-alpha2"
versionName = "6.0.0-alpha1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@@ -27,7 +27,7 @@
tools:ignore="UnusedAttribute">
<provider
android:authorities="${applicationId}.provider"
android:authorities="xyz.quaver.pupil.fileprovider"
android:name="androidx.core.content.FileProvider"
android:exported="false"
android:grantUriPermissions="true">

View File

@@ -18,6 +18,7 @@
package xyz.quaver.pupil.ui
import android.content.ClipData
import android.content.Intent
import android.net.Uri
import android.os.Bundle
@@ -47,6 +48,7 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.core.content.FileProvider
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
import coil.annotation.ExperimentalCoilApi
@@ -221,6 +223,13 @@ class ReaderActivity : ComponentActivity(), DIAware {
combinedClickable(
onLongClick = {
haptic.performHapticFeedback(HapticFeedbackType.LongPress)
val uri = FileProvider.getUriForFile(this@ReaderActivity, "xyz.quaver.pupil.fileprovider", (imageSource as FileXImageSource).file)
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND).apply {
type = "image/*"
putExtra(Intent.EXTRA_STREAM, uri)
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}, "Share image"))
}
) {
model.isFullscreen = true

View File

@@ -54,7 +54,7 @@ class NetworkCache(context: Context) : DIAware {
private val client: HttpClient by instance()
private val networkScope = CoroutineScope(Executors.newFixedThreadPool(4).asCoroutineDispatcher())
private val cacheDir = context.cacheDir
private val cacheDir = File(context.cacheDir, "networkcache")
private val channel = ConcurrentHashMap<String, Channel<Float>>()
private val requests = ConcurrentHashMap<String, Job>()
@@ -103,6 +103,7 @@ class NetworkCache(context: Context) : DIAware {
else
requests[url] = networkScope.launch {
kotlin.runCatching {
cacheDir.mkdirs()
file.createNewFile()
client.request<HttpStatement>(request).execute { httpResponse ->

View File

@@ -18,6 +18,5 @@
-->
<paths>
<external-path name="external" path="/"/>
<external-files-path name="files" path="/"/>
<cache-path name="cached_image" path="networkcache/" />
</paths>