diff --git a/packages/share_plus/share_plus/CHANGELOG.md b/packages/share_plus/share_plus/CHANGELOG.md index 84fe98b280..d06e4e890f 100644 --- a/packages/share_plus/share_plus/CHANGELOG.md +++ b/packages/share_plus/share_plus/CHANGELOG.md @@ -1,3 +1,9 @@ +## 3.0.2 + +- Apply code improvements +- Update gradle for plugin +- Update flutter dependencies + ## 3.0.1 - Update Android dependencies for plugin and example, bump compileSDK to 31 diff --git a/packages/share_plus/share_plus/android/build.gradle b/packages/share_plus/share_plus/android/build.gradle index 541bc6c431..1ffb74eb60 100644 --- a/packages/share_plus/share_plus/android/build.gradle +++ b/packages/share_plus/share_plus/android/build.gradle @@ -8,7 +8,7 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:3.5.0' + classpath 'com.android.tools.build:gradle:7.0.2' } } @@ -22,7 +22,7 @@ rootProject.allprojects { apply plugin: 'com.android.library' android { - compileSdkVersion 28 + compileSdkVersion 31 defaultConfig { minSdkVersion 16 @@ -33,7 +33,7 @@ android { } dependencies { - implementation 'androidx.core:core:1.3.1' - implementation 'androidx.annotation:annotation:1.1.0' + implementation 'androidx.core:core:1.6.0' + implementation 'androidx.annotation:annotation:1.2.0' } } diff --git a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/MethodCallHandler.java b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/MethodCallHandler.java index e6ecb979dc..d06a87f832 100644 --- a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/MethodCallHandler.java +++ b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/MethodCallHandler.java @@ -4,6 +4,7 @@ package dev.fluttercommunity.plus.share; +import androidx.annotation.NonNull; import io.flutter.plugin.common.MethodCall; import io.flutter.plugin.common.MethodChannel; import java.io.*; @@ -13,7 +14,7 @@ /** Handles the method calls for the plugin. */ class MethodCallHandler implements MethodChannel.MethodCallHandler { - private Share share; + private final Share share; MethodCallHandler(Share share) { this.share = share; @@ -21,7 +22,7 @@ class MethodCallHandler implements MethodChannel.MethodCallHandler { @Override @SuppressWarnings("unchecked") - public void onMethodCall(MethodCall call, MethodChannel.Result result) { + public void onMethodCall(MethodCall call, @NonNull MethodChannel.Result result) { switch (call.method) { case "share": expectMapArguments(call); diff --git a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/Share.java b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/Share.java index 510f2f3d43..44990f14b5 100644 --- a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/Share.java +++ b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/Share.java @@ -24,10 +24,10 @@ /** Handles share intent. */ class Share { - private Context context; + private final Context context; private Activity activity; - private String providerAuthority; + private final String providerAuthority; /** * Constructs a Share object. The {@code context} and {@code activity} are used to start the share @@ -183,8 +183,9 @@ private boolean fileIsInShareCache(File file) { @SuppressWarnings("ResultOfMethodCallIgnored") private void clearShareCacheFolder() { File folder = getShareCacheFolder(); - if (folder.exists()) { - for (File file : folder.listFiles()) { + final File[] files = folder.listFiles(); + if (folder.exists() && files != null) { + for (File file : files) { file.delete(); } folder.delete(); @@ -220,21 +221,15 @@ private Context getContext() { } private static void copy(File src, File dst) throws IOException { - InputStream in = new FileInputStream(src); - try { - OutputStream out = new FileOutputStream(dst); - try { + try (InputStream in = new FileInputStream(src)) { + try (OutputStream out = new FileOutputStream(dst)) { // Transfer bytes from in to out byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } - } finally { - out.close(); } - } finally { - in.close(); } } } diff --git a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/SharePlusPlugin.java b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/SharePlusPlugin.java index d14b76dd7e..d10509ae47 100644 --- a/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/SharePlusPlugin.java +++ b/packages/share_plus/share_plus/android/src/main/java/dev/fluttercommunity/plus/share/SharePlusPlugin.java @@ -4,29 +4,29 @@ package dev.fluttercommunity.plus.share; -import android.app.Activity; -import android.content.Context; +import androidx.annotation.NonNull; import io.flutter.embedding.engine.plugins.FlutterPlugin; import io.flutter.embedding.engine.plugins.activity.ActivityAware; import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding; -import io.flutter.plugin.common.BinaryMessenger; import io.flutter.plugin.common.MethodChannel; /** Plugin method host for presenting a share sheet via Intent */ public class SharePlusPlugin implements FlutterPlugin, ActivityAware { private static final String CHANNEL = "dev.fluttercommunity.plus/share"; - private MethodCallHandler handler; private Share share; private MethodChannel methodChannel; @Override public void onAttachedToEngine(FlutterPluginBinding binding) { - setUpChannel(binding.getApplicationContext(), null, binding.getBinaryMessenger()); + methodChannel = new MethodChannel(binding.getBinaryMessenger(), CHANNEL); + share = new Share(binding.getApplicationContext(), null); + MethodCallHandler handler = new MethodCallHandler(share); + methodChannel.setMethodCallHandler(handler); } @Override - public void onDetachedFromEngine(FlutterPluginBinding binding) { + public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) { methodChannel.setMethodCallHandler(null); methodChannel = null; share = null; @@ -43,7 +43,7 @@ public void onDetachedFromActivity() { } @Override - public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding) { + public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBinding binding) { onAttachedToActivity(binding); } @@ -51,11 +51,4 @@ public void onReattachedToActivityForConfigChanges(ActivityPluginBinding binding public void onDetachedFromActivityForConfigChanges() { onDetachedFromActivity(); } - - private void setUpChannel(Context context, Activity activity, BinaryMessenger messenger) { - methodChannel = new MethodChannel(messenger, CHANNEL); - share = new Share(context, activity); - handler = new MethodCallHandler(share); - methodChannel.setMethodCallHandler(handler); - } } diff --git a/packages/share_plus/share_plus/example/pubspec.yaml b/packages/share_plus/share_plus/example/pubspec.yaml index e73c9e6665..790ead895f 100644 --- a/packages/share_plus/share_plus/example/pubspec.yaml +++ b/packages/share_plus/share_plus/example/pubspec.yaml @@ -6,7 +6,7 @@ dependencies: sdk: flutter share_plus: path: ../ - image_picker: ^0.8.4 + image_picker: ^0.8.4+2 dev_dependencies: flutter_driver: diff --git a/packages/share_plus/share_plus/pubspec.yaml b/packages/share_plus/share_plus/pubspec.yaml index f590ce2cde..849ad5af58 100644 --- a/packages/share_plus/share_plus/pubspec.yaml +++ b/packages/share_plus/share_plus/pubspec.yaml @@ -1,6 +1,6 @@ name: share_plus description: Flutter plugin for sharing content via the platform share UI, using the ACTION_SEND intent on Android and UIActivityViewController on iOS. -version: 3.0.1 +version: 3.0.2 homepage: https://plus.fluttercommunity.dev/ repository: https://github.com/fluttercommunity/plus_plugins/tree/main/packages/ @@ -22,7 +22,7 @@ flutter: default_package: share_plus_windows dependencies: - meta: ^1.3.0 + meta: ^1.7.0 mime: ^1.0.0 flutter: sdk: flutter