[Android] Save photos to "Bluesky" folder (#8018)
This commit is contained in:
@@ -73,7 +73,7 @@ function ShareDialogInner({
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await saveImageToMediaLibrary({uri: imageUrl})
|
await saveImageToMediaLibrary({uri: imageUrl})
|
||||||
Toast.show(_(msg`Image saved to your camera roll!`))
|
Toast.show(_(msg`Image saved`))
|
||||||
control.close()
|
control.close()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
Toast.show(_(msg`An error occurred while saving the QR code!`), 'xmark')
|
Toast.show(_(msg`An error occurred while saving the QR code!`), 'xmark')
|
||||||
|
|||||||
+30
-2
@@ -126,6 +126,8 @@ export async function shareImageModal({uri}: {uri: string}) {
|
|||||||
safeDeleteAsync(imagePath)
|
safeDeleteAsync(imagePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ALBUM_NAME = 'Bluesky'
|
||||||
|
|
||||||
export async function saveImageToMediaLibrary({uri}: {uri: string}) {
|
export async function saveImageToMediaLibrary({uri}: {uri: string}) {
|
||||||
// download the file to cache
|
// download the file to cache
|
||||||
// NOTE
|
// NOTE
|
||||||
@@ -139,8 +141,34 @@ export async function saveImageToMediaLibrary({uri}: {uri: string}) {
|
|||||||
imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true)
|
imagePath = normalizePath(await moveToPermanentPath(imagePath, '.png'), true)
|
||||||
|
|
||||||
// save
|
// save
|
||||||
await MediaLibrary.createAssetAsync(imagePath)
|
try {
|
||||||
safeDeleteAsync(imagePath)
|
if (isAndroid) {
|
||||||
|
// android triggers an annoying permission prompt if you try and move an image
|
||||||
|
// between albums. therefore, we need to either create the album with the image
|
||||||
|
// as the starting image, or put it directly into the album
|
||||||
|
const album = await MediaLibrary.getAlbumAsync(ALBUM_NAME)
|
||||||
|
if (album) {
|
||||||
|
// if album exists, put the image straight in there
|
||||||
|
await MediaLibrary.createAssetAsync(imagePath, album)
|
||||||
|
} else {
|
||||||
|
// otherwise, create album with asset (albums must always have at least one asset)
|
||||||
|
await MediaLibrary.createAlbumAsync(
|
||||||
|
ALBUM_NAME,
|
||||||
|
undefined,
|
||||||
|
undefined,
|
||||||
|
imagePath,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
await MediaLibrary.createAssetAsync(imagePath)
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
logger.error(err instanceof Error ? err : String(err), {
|
||||||
|
message: 'Failed to save image to media library',
|
||||||
|
})
|
||||||
|
} finally {
|
||||||
|
safeDeleteAsync(imagePath)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getImageDim(path: string): Promise<Dimensions> {
|
export function getImageDim(path: string): Promise<Dimensions> {
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export function Lightbox() {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await saveImageToMediaLibrary({uri})
|
await saveImageToMediaLibrary({uri})
|
||||||
Toast.show(_(msg`Saved to your camera roll`))
|
Toast.show(_(msg`Image saved`))
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
Toast.show(_(msg`Failed to save image: ${String(e)}`), 'xmark')
|
Toast.show(_(msg`Failed to save image: ${String(e)}`), 'xmark')
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user