Adapt to new nx api

pull/653/merge
Varun Patil 2023-09-30 14:15:29 -07:00
parent 9f466511eb
commit f5daa0e557
2 changed files with 37 additions and 19 deletions

View File

@ -147,23 +147,35 @@ import java.net.URLDecoder
} }
@JavascriptInterface @JavascriptInterface
fun playVideoRemote(fileId: String?, urlsArray: String?) { fun playVideo(auid: String?, fileid: String?, urlsArray: String?) {
if (fileId == null || urlsArray == null) return if (auid == null || fileid == null || urlsArray == null) return
Thread {
// Get URI of remote videos
val urls = JSONArray(urlsArray) val urls = JSONArray(urlsArray)
val list = Array(urls.length()) { val list = Array(urls.length()) {
Uri.parse(urls.getString(it)) Uri.parse(urls.getString(it))
} }
// Get URI of local video
val videos = query.getSystemImagesByAUIDs(arrayListOf(auid.toLong()))
// Play with exoplayer
mCtx.runOnUiThread { mCtx.runOnUiThread {
mCtx.initializePlayer(list, fileId) if (!videos.isEmpty()) {
mCtx.initializePlayer(arrayOf(videos[0].uri), fileid)
} else {
mCtx.initializePlayer(list, fileid)
} }
} }
}.start()
}
@JavascriptInterface @JavascriptInterface
fun destroyVideo(fileId: String?) { fun destroyVideo(fileid: String?) {
if (fileId == null) return; if (fileid == null) return;
mCtx.runOnUiThread { mCtx.runOnUiThread {
mCtx.destroyPlayer(fileId) mCtx.destroyPlayer(fileid)
} }
} }

View File

@ -105,6 +105,13 @@ class TimelineQuery(private val mCtx: MainActivity) {
return observer return observer
} }
fun getSystemImagesByAUIDs(auids: List<Long>): List<SystemImage> {
val photos = mPhotoDao.getPhotosByAUIDs(auids)
val fileIds = photos.map { it.localId }
if (fileIds.isEmpty()) return listOf()
return SystemImage.getByIds(mCtx, fileIds)
}
@Throws(JSONException::class) @Throws(JSONException::class)
fun getByDayId(dayId: Long): JSONArray { fun getByDayId(dayId: Long): JSONArray {
// Get the photos for the day from DB // Get the photos for the day from DB
@ -183,19 +190,18 @@ class TimelineQuery(private val mCtx: MainActivity) {
try { try {
// Get list of file IDs // Get list of file IDs
val photos = mPhotoDao.getPhotosByAUIDs(auids) val sysImgs = getSystemImagesByAUIDs(auids)
// Let the UI know how many files we are deleting // 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 // Let the UI know if we are going to ask for confirmation
response.put("confirms", Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) response.put("confirms", Build.VERSION.SDK_INT >= Build.VERSION_CODES.R)
if (dry || photos.isEmpty()) return response // Exit if dry or nothing to do
if (dry || sysImgs.isEmpty()) return response
val fileIds = photos.map { it.localId }
// List of URIs // List of URIs
val uris = SystemImage.getByIds(mCtx, fileIds).map { it.uri } val uris = sysImgs.map { it.uri }
if (uris.isEmpty()) return Response.OK if (uris.isEmpty()) return Response.OK
// Delete file with media store // Delete file with media store
@ -226,7 +232,7 @@ class TimelineQuery(private val mCtx: MainActivity) {
} }
// Delete from database // Delete from database
mPhotoDao.deleteFileIds(fileIds) mPhotoDao.deleteFileIds(sysImgs.map { it.fileId})
} finally { } finally {
synchronized(this) { deleting = false } synchronized(this) { deleting = false }
} }