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 5 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 packages/android_intent/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.3.7+4

* Android Code Inspection and Clean up.

## 0.3.7+3

* Update the `platform` package dependency to resolve the conflict with the latest flutter.
Expand Down
5 changes: 5 additions & 0 deletions packages/android_intent/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
group 'io.flutter.plugins.androidintent'
version '1.0-SNAPSHOT'
def args = ["-Xlint:deprecation","-Xlint:unchecked","-Werror"]

buildscript {
repositories {
Expand All @@ -19,6 +20,10 @@ rootProject.allprojects {
}
}

project.getTasks().withType(JavaCompile){
options.compilerArgs.addAll(args)
}

apply plugin: 'com.android.library'

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/** Forwards incoming {@link MethodCall}s to {@link IntentSender#send}. */
Expand Down Expand Up @@ -75,19 +76,24 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
String action = convertAction((String) call.argument("action"));
Integer flags = call.argument("flags");
String category = call.argument("category");
Uri data = call.argument("data") != null ? Uri.parse((String) call.argument("data")) : null;
Bundle arguments = convertArguments((Map<String, ?>) call.argument("arguments"));
String stringData = call.argument("data");
Uri data = call.argument("data") != null ? Uri.parse(stringData) : null;
Map<String, ?> stringMap = call.argument("arguments");
Bundle arguments = convertArguments(stringMap);
String packageName = call.argument("package");
String component = call.argument("componentName");
ComponentName componentName =
(!TextUtils.isEmpty(packageName)
&& !TextUtils.isEmpty((String) call.argument("componentName")))
? new ComponentName(packageName, (String) call.argument("componentName"))
: null;
(packageName != null
&& component != null
&& !TextUtils.isEmpty(packageName)
&& !TextUtils.isEmpty(component))
? new ComponentName(packageName, component)
: null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I would find this easier to read as a regular declaration followed by an if statement. This seems like a lot of logic for a ternary.

String type = call.argument("type");

Intent intent =
sender.buildIntent(
action, flags, category, data, arguments, packageName, componentName, type);
sender.buildIntent(
action, flags, category, data, arguments, packageName, componentName, type);

if ("launch".equalsIgnoreCase(call.method)) {
sender.send(intent);
Expand Down Expand Up @@ -146,42 +152,67 @@ private static Bundle convertArguments(Map<String, ?> arguments) {
bundle.putLongArray(key, (long[]) value);
} else if (value instanceof double[]) {
bundle.putDoubleArray(key, (double[]) value);
} else if (isTypedArrayList(value, Integer.class)) {
bundle.putIntegerArrayList(key, (ArrayList<Integer>) value);
} else if (isTypedArrayList(value, String.class)) {
bundle.putStringArrayList(key, (ArrayList<String>) value);
} else if (isStringKeyedMap(value)) {
bundle.putBundle(key, convertArguments((Map<String, ?>) value));
} else if (integers(value) != null) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: I think I prefer the old name of these - I'm a bit surprised to see a function named integers or strings or map.

I also wonder if we can just somehow avoid traversing the array twice and creating the object twice.

bundle.putIntegerArrayList(key, integers(value));
} else if (strings(value) != null) {
bundle.putStringArrayList(key, strings(value));
} else if (map(value) != null) {
bundle.putBundle(key, convertArguments((map(value))));
} else {
throw new UnsupportedOperationException("Unsupported type " + value);
}
}
return bundle;
}

private static boolean isTypedArrayList(Object value, Class<?> type) {
private static ArrayList<Integer> integers(Object value) {
ArrayList<Integer> integerArrayList = new ArrayList<>();
if (!(value instanceof ArrayList)) {
return false;
return null;
}
ArrayList<?> intList = (ArrayList<?>) value;
for (Object o : intList) {
if (!(o instanceof Integer)) {
return null;
} else {
integerArrayList.add((Integer) o);
}
}
return integerArrayList;
}

private static ArrayList<String> strings(Object value) {
ArrayList<String> stringArrayList = new ArrayList<>();
if (!(value instanceof ArrayList)) {
return null;
}
ArrayList list = (ArrayList) value;
for (Object o : list) {
if (!(o == null || type.isInstance(o))) {
return false;
ArrayList<?> stringList = (ArrayList<?>) value;
for (Object o : stringList) {
if (!(o instanceof String)) {
return null;
} else {
stringArrayList.add((String) o);
}
}
return true;
return stringArrayList;
}

private static boolean isStringKeyedMap(Object value) {
private static Map<String, ?> map(Object value) {
Map<String, Object> stringMap = new HashMap<>();
if (!(value instanceof Map)) {
return false;
return null;
}
Map map = (Map) value;
for (Object key : map.keySet()) {
if (!(key == null || key instanceof String)) {
return false;
Map<?, ?> mapValue = (Map<?, ?>) value;
for (Object key : mapValue.keySet()) {
if (!(key instanceof String)) {
return null;
} else {
Object o = mapValue.get(key);
if (o != null) {
stringMap.put((String) key, o);
}
}
}
return true;
return stringMap;
}
}
2 changes: 1 addition & 1 deletion packages/android_intent/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ homepage: https://github.com/flutter/plugins/tree/master/packages/android_intent
# 0.3.y+z is compatible with 1.0.0, if you land a breaking change bump
# the version to 2.0.0.
# See more details: https://github.com/flutter/flutter/wiki/Package-migration-to-1.0.0
version: 0.3.7+3
version: 0.3.7+4

flutter:
plugin:
Expand Down