Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1633 fix allow compression Android #1634

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 8.3.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changelog entry will need to be updated to the next hotfix version. (you will need to move it to the top of this file and change the version)

### Android
- Fixes allowCompression not working on Android. [1633](https://github.com/miguelpruivo/flutter_file_picker/issues/1633)

## 8.3.1
### iOS
- Fix [1367](https://github.com/miguelpruivo/flutter_file_picker/issues/1367)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class FilePickerDelegate implements PluginRegistry.ActivityResultListener
private boolean isMultipleSelection = false;
private boolean loadDataToMemory = false;
private String type;
private boolean allowCompression=true;
navaronbracke marked this conversation as resolved.
Show resolved Hide resolved
private int compressionQuality=20;
private String[] allowedExtensions;
private EventChannel.EventSink eventSink;
Expand Down Expand Up @@ -121,7 +122,7 @@ public void run() {
while (currentItem < count) {
Uri currentUri = data.getClipData().getItemAt(currentItem).getUri();

if (Objects.equals(type, "image/*") && compressionQuality > 0) {
if (Objects.equals(type, "image/*") && allowCompression && compressionQuality > 0) {
currentUri = FileUtils.compressImage(currentUri, compressionQuality, activity.getApplicationContext());
}
final FileInfo file = FileUtils.openFileStream(FilePickerDelegate.this.activity, currentUri, loadDataToMemory);
Expand All @@ -136,7 +137,7 @@ public void run() {
} else if (data.getData() != null) {
Uri uri = data.getData();

if (Objects.equals(type, "image/*") && compressionQuality > 0) {
if (Objects.equals(type, "image/*") && allowCompression && compressionQuality > 0) {
uri = FileUtils.compressImage(uri, compressionQuality, activity.getApplicationContext());
}

Expand Down Expand Up @@ -274,7 +275,7 @@ private void startFileExplorer() {
}

@SuppressWarnings("deprecation")
public void startFileExplorer(final String type, final boolean isMultipleSelection, final boolean withData, final String[] allowedExtensions, final int compressionQuality, final MethodChannel.Result result) {
public void startFileExplorer(final String type, final boolean isMultipleSelection, final boolean withData, final String[] allowedExtensions, final boolean allowCompression, final int compressionQuality, final MethodChannel.Result result) {

if (!this.setPendingMethodCallAndResult(result)) {
finishWithAlreadyActiveError(result);
Expand All @@ -284,7 +285,8 @@ public void startFileExplorer(final String type, final boolean isMultipleSelecti
this.isMultipleSelection = isMultipleSelection;
this.loadDataToMemory = withData;
this.allowedExtensions = allowedExtensions;
this.compressionQuality=compressionQuality;
this.compressionQuality = compressionQuality;
this.allowCompression = allowCompression;

this.startFileExplorer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public void onActivityStopped(final Activity activity) {
private static boolean isMultipleSelection = false;
private static boolean withData = false;
private static int compressionQuality;
private static boolean allowCompression;

@SuppressWarnings("unchecked")
@Override
Expand Down Expand Up @@ -150,14 +151,15 @@ public void onMethodCall(final MethodCall call, final MethodChannel.Result rawRe
} else if (fileType != "dir") {
isMultipleSelection = (boolean) arguments.get("allowMultipleSelection");
withData = (boolean) arguments.get("withData");
allowCompression = (boolean) arguments.get("allowCompression");
compressionQuality=(int) arguments.get("compressionQuality");
allowedExtensions = FileUtils.getMimeTypes((ArrayList<String>) arguments.get("allowedExtensions"));
}

if (call.method != null && call.method.equals("custom") && (allowedExtensions == null || allowedExtensions.length == 0)) {
result.error(TAG, "Unsupported filter. Make sure that you are only using the extension without the dot, (ie., jpg instead of .jpg). This could also have happened because you are using an unsupported file extension. If the problem persists, you may want to consider using FileType.any instead.", null);
} else {
this.delegate.startFileExplorer(fileType, isMultipleSelection, withData, allowedExtensions, compressionQuality,result);
this.delegate.startFileExplorer(fileType, isMultipleSelection, withData, allowedExtensions, allowCompression, compressionQuality,result);
navaronbracke marked this conversation as resolved.
Show resolved Hide resolved
}

}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A package that allows you to use a native file explorer to pick sin
homepage: https://github.com/miguelpruivo/plugins_flutter_file_picker
repository: https://github.com/miguelpruivo/flutter_file_picker
issue_tracker: https://github.com/miguelpruivo/flutter_file_picker/issues
version: 8.3.1
version: 8.3.2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This version will need to be updated to the next hotfix version.


dependencies:
flutter:
Expand Down