android: a playlist's cover from a photo on the phone

The storage plugin gains pick_image — the document picker limited to
images, the picked content copied into the app's cache so the Rust side
gets a plain path. playlist_cover_set(id, path) is the desktop pick's
install step split out and shared (squared, the master cover, the row's
revision moved). A playlist's sheet offers Choose cover photo and Remove
custom cover; the mock walk exercises both.
This commit is contained in:
KeelrLeek committed 2026-09-13 21:20:11 -05:00
1 parent d95c3f48d1
commit b50577fc81
15 files changed
+188 -12

No files matched your search

@@ -91,4 +91,37 @@ class StoragePlugin(private val activity: Activity) : Plugin(activity) {
}
invoke.resolve()
}
/** A photo from the phone: the document picker limited to images, the
* picked content copied into the app's cache so the Rust side gets a
* plain path (a content URI is not one). */
@Command
fun pickImage(invoke: Invoke) {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT)
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.type = "image/*"
startActivityForResult(invoke, intent, "imagePicked")
}
@ActivityCallback
fun imagePicked(invoke: Invoke, result: ActivityResult) {
when (result.resultCode) {
Activity.RESULT_OK -> {
val uri = result.data?.data
if (uri == null) { invoke.reject("no image came back"); return }
try {
val target = java.io.File(activity.cacheDir, "picked-cover-" + System.currentTimeMillis() + ".img")
val input = activity.contentResolver.openInputStream(uri)
if (input == null) { invoke.reject("the image could not be read"); return }
input.use { i -> target.outputStream().use { o -> i.copyTo(o) } }
val out = JSObject()
out.put("path", target.absolutePath)
invoke.resolve(out)
} catch (e: Exception) {
invoke.reject("the image could not be read: " + e.message)
}
}
Activity.RESULT_CANCELED -> invoke.reject("cancelled")
else -> invoke.reject("the picker failed")
}
}
}