From f5daa0e5578d24fc5dced59c477c8a0da4829a0e Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 30 Sep 2023 14:15:29 -0700 Subject: [PATCH] Adapt to new nx api --- app/src/main/java/gallery/memories/NativeX.kt | 36 ++++++++++++------- .../gallery/memories/service/TimelineQuery.kt | 20 +++++++---- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/app/src/main/java/gallery/memories/NativeX.kt b/app/src/main/java/gallery/memories/NativeX.kt index d51ac8c4..b7397bae 100644 --- a/app/src/main/java/gallery/memories/NativeX.kt +++ b/app/src/main/java/gallery/memories/NativeX.kt @@ -147,23 +147,35 @@ import java.net.URLDecoder } @JavascriptInterface - fun playVideoRemote(fileId: String?, urlsArray: String?) { - if (fileId == null || urlsArray == null) return - val urls = JSONArray(urlsArray) - val list = Array(urls.length()) { - Uri.parse(urls.getString(it)) - } + fun playVideo(auid: String?, fileid: String?, urlsArray: String?) { + if (auid == null || fileid == null || urlsArray == null) return - mCtx.runOnUiThread { - mCtx.initializePlayer(list, fileId) - } + Thread { + // Get URI of remote videos + val urls = JSONArray(urlsArray) + val list = Array(urls.length()) { + Uri.parse(urls.getString(it)) + } + + // Get URI of local video + val videos = query.getSystemImagesByAUIDs(arrayListOf(auid.toLong())) + + // Play with exoplayer + mCtx.runOnUiThread { + if (!videos.isEmpty()) { + mCtx.initializePlayer(arrayOf(videos[0].uri), fileid) + } else { + mCtx.initializePlayer(list, fileid) + } + } + }.start() } @JavascriptInterface - fun destroyVideo(fileId: String?) { - if (fileId == null) return; + fun destroyVideo(fileid: String?) { + if (fileid == null) return; mCtx.runOnUiThread { - mCtx.destroyPlayer(fileId) + mCtx.destroyPlayer(fileid) } } diff --git a/app/src/main/java/gallery/memories/service/TimelineQuery.kt b/app/src/main/java/gallery/memories/service/TimelineQuery.kt index 2d050523..7bdea231 100644 --- a/app/src/main/java/gallery/memories/service/TimelineQuery.kt +++ b/app/src/main/java/gallery/memories/service/TimelineQuery.kt @@ -105,6 +105,13 @@ class TimelineQuery(private val mCtx: MainActivity) { return observer } + fun getSystemImagesByAUIDs(auids: List): List { + val photos = mPhotoDao.getPhotosByAUIDs(auids) + val fileIds = photos.map { it.localId } + if (fileIds.isEmpty()) return listOf() + return SystemImage.getByIds(mCtx, fileIds) + } + @Throws(JSONException::class) fun getByDayId(dayId: Long): JSONArray { // Get the photos for the day from DB @@ -183,19 +190,18 @@ class TimelineQuery(private val mCtx: MainActivity) { try { // Get list of file IDs - val photos = mPhotoDao.getPhotosByAUIDs(auids) + val sysImgs = getSystemImagesByAUIDs(auids) // Let the UI know how many files we are deleting - response.put("count", photos.size) + response.put("count", sysImgs.size) // Let the UI know if we are going to ask for confirmation response.put("confirms", Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) - if (dry || photos.isEmpty()) return response - - val fileIds = photos.map { it.localId } + // Exit if dry or nothing to do + if (dry || sysImgs.isEmpty()) return response // List of URIs - val uris = SystemImage.getByIds(mCtx, fileIds).map { it.uri } + val uris = sysImgs.map { it.uri } if (uris.isEmpty()) return Response.OK // Delete file with media store @@ -226,7 +232,7 @@ class TimelineQuery(private val mCtx: MainActivity) { } // Delete from database - mPhotoDao.deleteFileIds(fileIds) + mPhotoDao.deleteFileIds(sysImgs.map { it.fileId}) } finally { synchronized(this) { deleting = false } }