Remove delete on upload for android.
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import i18n from "@/translations/i18n";
|
||||
import axios from "axios";
|
||||
import * as FileSystem from "expo-file-system/legacy";
|
||||
import * as ImagePicker from "expo-image-picker";
|
||||
@@ -11,6 +12,7 @@ import { client } from '../../graphql/client';
|
||||
import { INSERT_NEW_DOCUMENT } from "../../graphql/documents.queries";
|
||||
import { axiosAuthInterceptorId } from "../../util/CleanAxios";
|
||||
import { fetchImageFromUri, replaceAccents } from '../../util/uploadUtils';
|
||||
import { toggleDeleteAfterUpload } from "../app/app.actions";
|
||||
import { selectDeleteAfterUpload } from "../app/app.selectors";
|
||||
import { store } from "../store";
|
||||
import { selectBodyshop, selectCurrentUser } from "../user/user.selectors";
|
||||
@@ -411,60 +413,69 @@ function* mediaUploadCompletedAction({ payload: photos }) {
|
||||
const filesToDelete = Object.keys(progress).filter((key) => progress[key].status === 'completed').map((key) => progress[key]);
|
||||
|
||||
if (Platform.OS === "android") {
|
||||
yield MediaLibrary.getPermissionsAsync(false);
|
||||
const asset = filesToDelete[0];
|
||||
let assetIdToDelete = asset.assetId;
|
||||
Alert.alert(
|
||||
i18n.t("mediabrowser.labels.android_deletephotos"),
|
||||
i18n.t("mediabrowser.labels.android_deletephotos_message"),)
|
||||
|
||||
// 2. ANDROID FIX: Find the original asset ID
|
||||
if (!assetIdToDelete && Platform.OS === 'android') {
|
||||
// Fetch the last 50 images from the gallery
|
||||
const recentAssets = yield call(MediaLibrary.getAssetsAsync, {
|
||||
first: 50,
|
||||
sortBy: [MediaLibrary.SortBy.creationTime],
|
||||
mediaType: MediaLibrary.MediaType.photo,
|
||||
});
|
||||
//Set delete on upload to false
|
||||
yield put(toggleDeleteAfterUpload()) //Toggle is fine - if we got here, it's true.
|
||||
|
||||
// Try to match based on width, height, and proximity of creation time
|
||||
// Note: The cache file timestamp might differ slightly from the original
|
||||
const foundAsset = recentAssets.assets.find(libraryItem => {
|
||||
console.log("Comparing library item:", moment(asset.exif.DateTime, "YYYY:MM:DD HH:mm:ss").valueOf(), libraryItem.creationTime);
|
||||
return (
|
||||
libraryItem.width === asset.exif.ImageWidth &&
|
||||
libraryItem.height === asset.exif.ImageLength &&
|
||||
Math.abs(moment(asset.exif.DateTimeOriginal, "YYYY:MM:DD HH:mm:ss").valueOf() - libraryItem.creationTime) < 1000
|
||||
);
|
||||
});
|
||||
// //With new Android restrictions, we can't do this because we don't get the asset ID back from the picker.
|
||||
// //The workarounds below don't work currently. Leaving code for reference.
|
||||
// yield MediaLibrary.getPermissionsAsync(false);
|
||||
// const asset = filesToDelete[0];
|
||||
// let assetIdToDelete = asset.assetId;
|
||||
|
||||
if (foundAsset) {
|
||||
assetIdToDelete = foundAsset.id;
|
||||
}
|
||||
}
|
||||
// // 2. ANDROID FIX: Find the original asset ID
|
||||
// if (!assetIdToDelete && Platform.OS === 'android') {
|
||||
// // Fetch the last 50 images from the gallery
|
||||
// const recentAssets = yield call(MediaLibrary.getAssetsAsync, {
|
||||
// first: 50,
|
||||
// sortBy: [MediaLibrary.SortBy.creationTime],
|
||||
// mediaType: MediaLibrary.MediaType.photo,
|
||||
// });
|
||||
|
||||
// 3. Upload and Delete
|
||||
if (assetIdToDelete) {
|
||||
// await uploadFunction(asset.uri);
|
||||
yield call(MediaLibrary.deleteAssetsAsync, assetIdToDelete);
|
||||
}
|
||||
// // Try to match based on width, height, and proximity of creation time
|
||||
// // Note: The cache file timestamp might differ slightly from the original
|
||||
// const foundAsset = recentAssets.assets.find(libraryItem => {
|
||||
// console.log("Comparing library item:", moment(asset.exif.DateTime, "YYYY:MM:DD HH:mm:ss").valueOf(), libraryItem.creationTime);
|
||||
// return (
|
||||
// libraryItem.width === asset.exif.ImageWidth &&
|
||||
// libraryItem.height === asset.exif.ImageLength &&
|
||||
// Math.abs(moment(asset.exif.DateTimeOriginal, "YYYY:MM:DD HH:mm:ss").valueOf() - libraryItem.creationTime) < 1000
|
||||
// );
|
||||
// });
|
||||
|
||||
// if (foundAsset) {
|
||||
// assetIdToDelete = foundAsset.id;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 3. Upload and Delete
|
||||
// if (assetIdToDelete) {
|
||||
// // await uploadFunction(asset.uri);
|
||||
// yield call(MediaLibrary.deleteAssetsAsync, assetIdToDelete);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
//Create a new asset with the first file to delete.
|
||||
// console.log('Trying new delete.');
|
||||
// //Create a new asset with the first file to delete.
|
||||
// // console.log('Trying new delete.');
|
||||
|
||||
const album = yield call(MediaLibrary.createAlbumAsync,
|
||||
"ImEX Mobile Deleted",
|
||||
filesToDelete.pop().assetId,
|
||||
false
|
||||
);
|
||||
//Move the rest.
|
||||
if (filesToDelete.length > 0) {
|
||||
const moveResult = yield call(MediaLibrary.addAssetsToAlbumAsync,
|
||||
filesToDelete.map(f => f.assetId),
|
||||
album,
|
||||
false
|
||||
);
|
||||
}
|
||||
yield call(MediaLibrary.deleteAlbumsAsync, album);
|
||||
// const album = yield call(MediaLibrary.createAlbumAsync,
|
||||
// "ImEX Mobile Deleted",
|
||||
// filesToDelete.pop().assetId,
|
||||
// false
|
||||
// );
|
||||
// //Move the rest.
|
||||
// if (filesToDelete.length > 0) {
|
||||
// const moveResult = yield call(MediaLibrary.addAssetsToAlbumAsync,
|
||||
// filesToDelete.map(f => f.assetId),
|
||||
// album,
|
||||
// false
|
||||
// );
|
||||
// }
|
||||
// yield call(MediaLibrary.deleteAlbumsAsync, album);
|
||||
} else {
|
||||
yield call(MediaLibrary.deleteAssetsAsync, filesToDelete.map(f => f.assetId));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user