diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index 4b1f54ae..0ac03b69 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -21,8 +21,8 @@ import java.net.URLDecoder val TAG = NativeX::class.java.simpleName private var themeStored = false - val image = ImageService(mCtx) val query = TimelineQuery(mCtx) + val image = ImageService(mCtx, query) val account = AccountService(mCtx) object API { @@ -43,7 +43,7 @@ import java.net.URLDecoder } init { - dlService = DownloadService(mCtx) + dlService = DownloadService(mCtx, query) } companion object { @@ -219,7 +219,7 @@ import java.net.URLDecoder } else if (path.matches(API.IMAGE_PREVIEW)) { makeResponse(image.getPreview(parts[3].toLong()), "image/jpeg") } else if (path.matches(API.IMAGE_FULL)) { - makeResponse(image.getFull(query, parts[3].toLong()), "image/jpeg") + makeResponse(image.getFull(parts[3].toLong()), "image/jpeg") } else if (path.matches(API.SHARE_URL)) { makeResponse(dlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8"))) } else if (path.matches(API.SHARE_BLOB)) { diff --git a/app/src/main/java/gallery/memories/service/DownloadService.kt b/app/src/main/java/gallery/memories/service/DownloadService.kt index 54cfbb09..201683be 100644 --- a/app/src/main/java/gallery/memories/service/DownloadService.kt +++ b/app/src/main/java/gallery/memories/service/DownloadService.kt @@ -1,19 +1,17 @@ package gallery.memories.service import android.app.DownloadManager -import android.content.ContentUris import android.content.Context import android.content.Intent import android.net.Uri import android.os.Environment -import android.provider.MediaStore import android.webkit.CookieManager import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.collection.ArrayMap import java.util.concurrent.CountDownLatch -class DownloadService(private val mActivity: AppCompatActivity) { +class DownloadService(private val mActivity: AppCompatActivity, private val query: TimelineQuery) { private val mDownloads: MutableMap Unit> = ArrayMap() fun runDownloadCallback(intent: Intent) { @@ -84,8 +82,11 @@ class DownloadService(private val mActivity: AppCompatActivity) { } @Throws(Exception::class) - fun shareLocal(id: Long): Boolean { - val uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id) + fun shareLocal(auid: Long): Boolean { + val sysImgs = query.getSystemImagesByAUIDs(listOf(auid)) + if (sysImgs.isEmpty()) throw Exception("Image not found locally") + val uri = sysImgs[0].uri + val intent = Intent(Intent.ACTION_SEND) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.type = mActivity.contentResolver.getType(uri) diff --git a/app/src/main/java/gallery/memories/service/ImageService.kt b/app/src/main/java/gallery/memories/service/ImageService.kt index e3cd8b96..d0bf2012 100644 --- a/app/src/main/java/gallery/memories/service/ImageService.kt +++ b/app/src/main/java/gallery/memories/service/ImageService.kt @@ -8,7 +8,7 @@ import android.os.Build import android.provider.MediaStore import java.io.ByteArrayOutputStream -class ImageService(private val mCtx: Context) { +class ImageService(private val mCtx: Context, private val query: TimelineQuery) { @Throws(Exception::class) fun getPreview(id: Long): ByteArray { val bitmap = @@ -37,7 +37,7 @@ class ImageService(private val mCtx: Context) { } @Throws(Exception::class) - fun getFull(query: TimelineQuery, auid: Long): ByteArray { + fun getFull(auid: Long): ByteArray { val sysImgs = query.getSystemImagesByAUIDs(listOf(auid)) if (sysImgs.isEmpty()) { throw Exception("Image not found")