Commit a7100ae0 authored by Ben Bieker's avatar Ben Bieker

Fix config options for Android release builds

Using reflection was not a good idea because when the Android App is
compiled for release mode, some code optimizations are executed. The
fields of the configuration classes were then renamed and the mapping
via reflections did not work again. Now everything has an explicit
mapping form the untyped HashMap to the class fields and vice versa.
parent 9c7ac0da
...@@ -2,7 +2,11 @@ package com.pichillilorenzo.flutter_inappwebview.ChromeCustomTabs; ...@@ -2,7 +2,11 @@ package com.pichillilorenzo.flutter_inappwebview.ChromeCustomTabs;
import com.pichillilorenzo.flutter_inappwebview.Options; import com.pichillilorenzo.flutter_inappwebview.Options;
public class ChromeCustomTabsOptions extends Options { import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class ChromeCustomTabsOptions implements Options {
final static String LOG_TAG = "ChromeCustomTabsOptions"; final static String LOG_TAG = "ChromeCustomTabsOptions";
...@@ -12,4 +16,47 @@ public class ChromeCustomTabsOptions extends Options { ...@@ -12,4 +16,47 @@ public class ChromeCustomTabsOptions extends Options {
public boolean enableUrlBarHiding = false; public boolean enableUrlBarHiding = false;
public boolean instantAppsEnabled = false; public boolean instantAppsEnabled = false;
ChromeCustomTabsOptions parse(HashMap<String, Object> options) {
Iterator it = options.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> pair = (Map.Entry<String, Object>) it.next();
String key = pair.getKey();
Object value = pair.getValue();
if (value == null) {
continue;
}
switch (key) {
case "addShareButton":
addShareButton = (boolean) value;
break;
case "showTitle":
showTitle = (boolean) value;
break;
case "toolbarBackgroundColor":
toolbarBackgroundColor = (String) value;
break;
case "enableUrlBarHiding":
enableUrlBarHiding = (boolean) value;
break;
case "instantAppsEnabled":
instantAppsEnabled = (boolean) value;
break;
}
}
return this;
}
@Override
public HashMap<String, Object> getHashMap() {
HashMap<String, Object> options = new HashMap<>();
options.put("addShareButton", addShareButton);
options.put("showTitle", showTitle);
options.put("toolbarBackgroundColor", toolbarBackgroundColor);
options.put("enableUrlBarHiding", enableUrlBarHiding);
options.put("instantAppsEnabled", instantAppsEnabled);
return options;
}
} }
package com.pichillilorenzo.flutter_inappwebview; package com.pichillilorenzo.flutter_inappwebview;
public class InAppBrowserOptions extends Options { import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class InAppBrowserOptions implements Options {
public static final String LOG_TAG = "InAppBrowserOptions"; public static final String LOG_TAG = "InAppBrowserOptions";
...@@ -13,4 +17,60 @@ public class InAppBrowserOptions extends Options { ...@@ -13,4 +17,60 @@ public class InAppBrowserOptions extends Options {
public boolean hideTitleBar = false; public boolean hideTitleBar = false;
public boolean closeOnCannotGoBack = true; public boolean closeOnCannotGoBack = true;
public boolean progressBar = true; public boolean progressBar = true;
public InAppBrowserOptions parse(HashMap<String, Object> options) {
Iterator it = options.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> pair = (Map.Entry<String, Object>) it.next();
String key = pair.getKey();
Object value = pair.getValue();
if (value == null) {
continue;
}
switch (key) {
case "hidden":
hidden = (boolean) value;
break;
case "toolbarTop":
toolbarTop = (boolean) value;
break;
case "toolbarTopBackgroundColor":
toolbarTopBackgroundColor = (String) value;
break;
case "toolbarTopFixedTitle":
toolbarTopFixedTitle = (String) value;
break;
case "hideUrlBar":
hideUrlBar = (boolean) value;
break;
case "hideTitleBar":
hideTitleBar = (boolean) value;
break;
case "closeOnCannotGoBack":
closeOnCannotGoBack = (boolean) value;
break;
case "progressBar":
progressBar = (boolean) value;
break;
}
}
return this;
}
@Override
public HashMap<String, Object> getHashMap() {
final HashMap<String, Object> options = new HashMap<>();
options.put("hidden", hidden);
options.put("toolbarTop", toolbarTop);
options.put("toolbarTopBackgroundColor", toolbarTopBackgroundColor);
options.put("toolbarTopFixedTitle", toolbarTopFixedTitle);
options.put("hideUrlBar", hideUrlBar);
options.put("hideTitleBar", hideTitleBar);
options.put("closeOnCannotGoBack", closeOnCannotGoBack);
options.put("progressBar", progressBar);
return options;
}
} }
package com.pichillilorenzo.flutter_inappwebview; package com.pichillilorenzo.flutter_inappwebview;
import android.util.Log;
import java.lang.reflect.Field;
import java.util.Iterator;
import java.util.Map;
import java.util.HashMap; import java.util.HashMap;
public class Options { public interface Options {
HashMap<String, Object> getHashMap();
static String LOG_TAG = "Options";
public Options parse(HashMap<String, Object> options) {
Iterator it = options.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> pair = (Map.Entry<String, Object>) it.next();
Object value = this.onParse(pair);
try {
this.getClass().getDeclaredField(pair.getKey()).set(this, value);
} catch (NoSuchFieldException e) {
Log.d(LOG_TAG, e.getMessage());
} catch (IllegalAccessException e) {
Log.d(LOG_TAG, e.getMessage());
}
}
return this;
}
public Object onParse(Map.Entry<String, Object> pair) {
return pair.getValue();
}
public HashMap<String, Object> getHashMap() {
HashMap<String, Object> options = new HashMap<>();
for (Field field : this.getClass().getDeclaredFields()) {
options.put(field.getName(), onGetHashMap(field));
}
return options;
}
public Object onGetHashMap(Field field) {
try {
return field.get(this);
} catch (IllegalAccessException e) {
Log.d(LOG_TAG, e.getMessage());
}
return null;
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment