Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
df341db
Add multiRetrieve method call
ydag Jun 30, 2021
2d1a871
Refactor finishWithSuccess to cache list of images
ydag Jun 30, 2021
30a067f
Refactor retrieveLostImage method
ydag Jun 30, 2021
01ad85e
Add new MAP_KEY_PATH_LIST key
ydag Jun 30, 2021
5a9e99f
Refactor saveTypeWithMethodCallName
ydag Jun 30, 2021
364c79d
Update saveResult method
ydag Jun 30, 2021
757da4c
Update the getCacheMap method
ydag Jun 30, 2021
3418641
Add statement to return null
ydag Jun 30, 2021
74f3990
Merge branch 'master' into image_picker/android_update_cache
ydag Jul 1, 2021
93de29f
Update CHANGELOG and version number
ydag Jul 1, 2021
9264ad9
Revert "Refactor finishWithSuccess to cache list of images"
ydag Jul 1, 2021
e585603
Refactor finishWithSuccess method
ydag Jul 1, 2021
33fb183
Update dependency version
ydag Jul 1, 2021
226ef21
Merge branch 'master' into image_picker/android_update_cache
ydag Jul 16, 2021
ec4079e
Update version and CHANGELOG
ydag Jul 16, 2021
a675352
Add unit tests
ydag Jul 16, 2021
91fd73d
Update CHANGELOG
ydag Jul 16, 2021
56c29b0
Update dependency version
ydag Jul 17, 2021
156d845
Remove unused method call
ydag Jul 21, 2021
c38ad2b
Remove unit tests from deprecated LostData
ydag Aug 20, 2021
27f87ca
Remove redundant unit test
ydag Aug 20, 2021
c567525
Refactor to assign the last item to path to avoid breaking change
ydag Aug 20, 2021
0454d80
Refactor retrieveLostData multiple files unit test
ydag Aug 20, 2021
db5d48e
Update the dependency version
ydag Aug 20, 2021
ca9c5b2
Merge branch 'master' into image_picker/android_update_cache
ydag Aug 23, 2021
e8d71e9
Fix the length call
ydag Aug 26, 2021
a1555bb
Merge branch 'master' into image_picker/android_update_cache
ydag Aug 26, 2021
933931b
Update the CHANGELOG
ydag Aug 26, 2021
c08c461
Update CHANGELOG
ydag Aug 26, 2021
a43ffeb
Add null check
ydag Aug 27, 2021
ced68ec
Add unit test
ydag Aug 27, 2021
0325f33
Update the example app
ydag Aug 27, 2021
29d9e0e
Remove redundant comment
ydag Aug 27, 2021
4ad0263
Refactor handleMultiImageResult
ydag Aug 27, 2021
0764514
Variable rename
BeMacized Aug 30, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/image_picker/image_picker/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.8.2

* Update cache system to save list of images and retrieve them when it is needed. On Android,
`getLostData` will return `LostData` object that has new `List<PickedFile>` property to get multiple lost images.

## 0.8.1+3

* Fix image picker causing a crash when the cache directory is deleted.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import io.flutter.plugin.common.MethodCall;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class ImagePickerCache {

static final String MAP_KEY_PATH = "path";
static final String MAP_KEY_PATH_LIST = "pathList";
static final String MAP_KEY_MAX_WIDTH = "maxWidth";
static final String MAP_KEY_MAX_HEIGHT = "maxHeight";
static final String MAP_KEY_IMAGE_QUALITY = "imageQuality";
Expand Down Expand Up @@ -50,7 +54,8 @@ class ImagePickerCache {
}

void saveTypeWithMethodCallName(String methodCallName) {
if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_IMAGE)) {
if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_IMAGE)
| methodCallName.equals(ImagePickerPlugin.METHOD_CALL_MULTI_IMAGE)) {
setType("image");
} else if (methodCallName.equals(ImagePickerPlugin.METHOD_CALL_VIDEO)) {
setType("video");
Expand Down Expand Up @@ -99,11 +104,13 @@ String retrievePendingCameraMediaUriPath() {
}

void saveResult(
@Nullable String path, @Nullable String errorCode, @Nullable String errorMessage) {
@Nullable ArrayList<String> path, @Nullable String errorCode, @Nullable String errorMessage) {

Set<String> imageSet = new HashSet<>();
imageSet.addAll(path);
SharedPreferences.Editor editor = prefs.edit();
if (path != null) {
editor.putString(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, path);
editor.putStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, imageSet);
}
if (errorCode != null) {
editor.putString(SHARED_PREFERENCE_ERROR_CODE_KEY, errorCode);
Expand All @@ -121,11 +128,14 @@ void clear() {
Map<String, Object> getCacheMap() {

Map<String, Object> resultMap = new HashMap<>();
ArrayList<String> pathList = new ArrayList<>();
boolean hasData = false;

if (prefs.contains(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY)) {
final String imagePathValue = prefs.getString(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, "");
resultMap.put(MAP_KEY_PATH, imagePathValue);
final Set<String> imagePathList =
prefs.getStringSet(FLUTTER_IMAGE_PICKER_IMAGE_PATH_KEY, null);
pathList.addAll(imagePathList);
resultMap.put(MAP_KEY_PATH_LIST, pathList);
hasData = true;
}

Expand Down Expand Up @@ -159,7 +169,6 @@ Map<String, Object> getCacheMap() {
resultMap.put(MAP_KEY_IMAGE_QUALITY, 100);
}
}

return resultMap;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -229,17 +229,21 @@ void saveStateBeforeResult() {

void retrieveLostImage(MethodChannel.Result result) {
Map<String, Object> resultMap = cache.getCacheMap();
String path = (String) resultMap.get(cache.MAP_KEY_PATH);
if (path != null) {
Double maxWidth = (Double) resultMap.get(cache.MAP_KEY_MAX_WIDTH);
Double maxHeight = (Double) resultMap.get(cache.MAP_KEY_MAX_HEIGHT);
int imageQuality =
resultMap.get(cache.MAP_KEY_IMAGE_QUALITY) == null
? 100
: (int) resultMap.get(cache.MAP_KEY_IMAGE_QUALITY);

String newPath = imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight, imageQuality);
resultMap.put(cache.MAP_KEY_PATH, newPath);
ArrayList<String> pathList = (ArrayList<String>) resultMap.get(cache.MAP_KEY_PATH_LIST);
ArrayList<String> newPathList = new ArrayList<>();
if (pathList != null) {
for (String path : pathList) {
Double maxWidth = (Double) resultMap.get(cache.MAP_KEY_MAX_WIDTH);
Double maxHeight = (Double) resultMap.get(cache.MAP_KEY_MAX_HEIGHT);
int imageQuality =
resultMap.get(cache.MAP_KEY_IMAGE_QUALITY) == null
? 100
: (int) resultMap.get(cache.MAP_KEY_IMAGE_QUALITY);

newPathList.add(imageResizer.resizeImageIfNeeded(path, maxWidth, maxHeight, imageQuality));
}
resultMap.put(cache.MAP_KEY_PATH_LIST, newPathList);
resultMap.put(cache.MAP_KEY_PATH, newPathList.get(0));
Comment thread
ydag marked this conversation as resolved.
Outdated
}
if (resultMap.isEmpty()) {
result.success(null);
Expand Down Expand Up @@ -489,7 +493,7 @@ private void handleChooseImageResult(int resultCode, Intent data) {
}

// User cancelled choosing a picture.
finishWithSuccess(null);
finishWithSuccess(null, false);
}

private void handleChooseMultiImageResult(int resultCode, Intent intent) {
Expand All @@ -507,7 +511,7 @@ private void handleChooseMultiImageResult(int resultCode, Intent intent) {
}

// User cancelled choosing a picture.
finishWithSuccess(null);
finishWithSuccess(null, false);
}

private void handleChooseVideoResult(int resultCode, Intent data) {
Expand All @@ -518,7 +522,7 @@ private void handleChooseVideoResult(int resultCode, Intent data) {
}

// User cancelled choosing a picture.
finishWithSuccess(null);
finishWithSuccess(null, false);
}

private void handleCaptureImageResult(int resultCode) {
Expand All @@ -537,7 +541,7 @@ public void onPathReady(String path) {
}

// User cancelled taking a picture.
finishWithSuccess(null);
finishWithSuccess(null, false);
}

private void handleCaptureVideoResult(int resultCode) {
Expand All @@ -556,7 +560,7 @@ public void onPathReady(String path) {
}

// User cancelled taking a picture.
finishWithSuccess(null);
finishWithSuccess(null, false);
}

private void handleMultiImageResult(
Expand All @@ -573,21 +577,23 @@ private void handleMultiImageResult(
}
paths.set(i, finalImagePath);
}
finishWithListSuccess(paths);
finishWithSuccess(paths, true);
}
}

private void handleImageResult(String path, boolean shouldDeleteOriginalIfScaled) {
ArrayList<String> imageList = new ArrayList<String>();
if (methodCall != null) {
String finalImagePath = getResizedImagePath(path);
//delete original file if scaled
if (finalImagePath != null && !finalImagePath.equals(path) && shouldDeleteOriginalIfScaled) {
new File(path).delete();
}
finishWithSuccess(finalImagePath);
imageList.add(finalImagePath);
} else {
finishWithSuccess(path);
imageList.add(path);
}
finishWithSuccess(imageList, false);
}

private String getResizedImagePath(String path) {
Expand All @@ -599,7 +605,9 @@ private String getResizedImagePath(String path) {
}

private void handleVideoResult(String path) {
finishWithSuccess(path);
ArrayList<String> imageList = new ArrayList<String>();
imageList.add(path);
finishWithSuccess(imageList, false);
}

private boolean setPendingMethodCallAndResult(
Expand All @@ -617,23 +625,17 @@ private boolean setPendingMethodCallAndResult(
return true;
}

private void finishWithSuccess(String imagePath) {
private void finishWithSuccess(ArrayList<String> imagePath, boolean isMultiImage) {
Comment thread
ydag marked this conversation as resolved.
Outdated
if (pendingResult == null) {
cache.saveResult(imagePath, null, null);
return;
}
pendingResult.success(imagePath);
clearMethodCallAndResult();
}

private void finishWithListSuccess(ArrayList<String> imagePaths) {
if (pendingResult == null) {
for (String imagePath : imagePaths) {
cache.saveResult(imagePath, null, null);
}
return;
if (isMultiImage || imagePath == null) {
pendingResult.success(imagePath);
} else {
pendingResult.success(imagePath.get(0));
}
pendingResult.success(imagePaths);
clearMethodCallAndResult();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void onActivityStopped(Activity activity) {
static final String METHOD_CALL_MULTI_IMAGE = "pickMultiImage";
static final String METHOD_CALL_VIDEO = "pickVideo";
private static final String METHOD_CALL_RETRIEVE = "retrieve";
private static final String METHOD_CALL_MULTI_RETRIEVE = "multiRetrieve";
private static final int CAMERA_DEVICE_FRONT = 1;
private static final int CAMERA_DEVICE_REAR = 0;
private static final String CHANNEL = "plugins.flutter.io/image_picker";
Expand Down Expand Up @@ -320,6 +321,7 @@ public void onMethodCall(MethodCall call, MethodChannel.Result rawResult) {
}
break;
case METHOD_CALL_RETRIEVE:
case METHOD_CALL_MULTI_RETRIEVE:
delegate.retrieveLostImage(result);
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion packages/image_picker/image_picker/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flutter plugin for selecting images from the Android and iOS image
library, and taking new pictures with the camera.
repository: https://github.com/flutter/plugins/tree/master/packages/image_picker/image_picker
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+image_picker%22
version: 0.8.1+3
version: 0.8.2
Comment thread
ydag marked this conversation as resolved.
Outdated

environment:
sdk: ">=2.12.0 <3.0.0"
Expand Down