Switch share local to AUID

pull/653/merge
Varun Patil 2023-09-30 15:01:35 -07:00
parent 12d5f137da
commit 0796b58b87
3 changed files with 11 additions and 10 deletions

View File

@ -21,8 +21,8 @@ import java.net.URLDecoder
val TAG = NativeX::class.java.simpleName val TAG = NativeX::class.java.simpleName
private var themeStored = false private var themeStored = false
val image = ImageService(mCtx)
val query = TimelineQuery(mCtx) val query = TimelineQuery(mCtx)
val image = ImageService(mCtx, query)
val account = AccountService(mCtx) val account = AccountService(mCtx)
object API { object API {
@ -43,7 +43,7 @@ import java.net.URLDecoder
} }
init { init {
dlService = DownloadService(mCtx) dlService = DownloadService(mCtx, query)
} }
companion object { companion object {
@ -219,7 +219,7 @@ import java.net.URLDecoder
} else if (path.matches(API.IMAGE_PREVIEW)) { } else if (path.matches(API.IMAGE_PREVIEW)) {
makeResponse(image.getPreview(parts[3].toLong()), "image/jpeg") makeResponse(image.getPreview(parts[3].toLong()), "image/jpeg")
} else if (path.matches(API.IMAGE_FULL)) { } 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)) { } else if (path.matches(API.SHARE_URL)) {
makeResponse(dlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8"))) makeResponse(dlService!!.shareUrl(URLDecoder.decode(parts[4], "UTF-8")))
} else if (path.matches(API.SHARE_BLOB)) { } else if (path.matches(API.SHARE_BLOB)) {

View File

@ -1,19 +1,17 @@
package gallery.memories.service package gallery.memories.service
import android.app.DownloadManager import android.app.DownloadManager
import android.content.ContentUris
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Environment import android.os.Environment
import android.provider.MediaStore
import android.webkit.CookieManager import android.webkit.CookieManager
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.collection.ArrayMap import androidx.collection.ArrayMap
import java.util.concurrent.CountDownLatch 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<Long, () -> Unit> = ArrayMap() private val mDownloads: MutableMap<Long, () -> Unit> = ArrayMap()
fun runDownloadCallback(intent: Intent) { fun runDownloadCallback(intent: Intent) {
@ -84,8 +82,11 @@ class DownloadService(private val mActivity: AppCompatActivity) {
} }
@Throws(Exception::class) @Throws(Exception::class)
fun shareLocal(id: Long): Boolean { fun shareLocal(auid: Long): Boolean {
val uri = ContentUris.withAppendedId(MediaStore.Files.getContentUri("external"), id) 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) val intent = Intent(Intent.ACTION_SEND)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.type = mActivity.contentResolver.getType(uri) intent.type = mActivity.contentResolver.getType(uri)

View File

@ -8,7 +8,7 @@ import android.os.Build
import android.provider.MediaStore import android.provider.MediaStore
import java.io.ByteArrayOutputStream import java.io.ByteArrayOutputStream
class ImageService(private val mCtx: Context) { class ImageService(private val mCtx: Context, private val query: TimelineQuery) {
@Throws(Exception::class) @Throws(Exception::class)
fun getPreview(id: Long): ByteArray { fun getPreview(id: Long): ByteArray {
val bitmap = val bitmap =
@ -37,7 +37,7 @@ class ImageService(private val mCtx: Context) {
} }
@Throws(Exception::class) @Throws(Exception::class)
fun getFull(query: TimelineQuery, auid: Long): ByteArray { fun getFull(auid: Long): ByteArray {
val sysImgs = query.getSystemImagesByAUIDs(listOf(auid)) val sysImgs = query.getSystemImagesByAUIDs(listOf(auid))
if (sysImgs.isEmpty()) { if (sysImgs.isEmpty()) {
throw Exception("Image not found") throw Exception("Image not found")