|
@@ -7,36 +7,30 @@ import android.content.pm.PackageManager;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
import android.os.Build;
|
|
import android.os.Build;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
-import android.os.Handler;
|
|
|
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.NonNull;
|
|
|
import android.support.v4.app.ActivityCompat;
|
|
import android.support.v4.app.ActivityCompat;
|
|
|
-import android.support.v4.content.ContextCompat;
|
|
|
|
|
import android.support.v7.app.AlertDialog;
|
|
import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
-import android.util.Base64;
|
|
|
|
|
-import android.webkit.ValueCallback;
|
|
|
|
|
import android.webkit.WebChromeClient;
|
|
import android.webkit.WebChromeClient;
|
|
|
import android.webkit.WebView;
|
|
import android.webkit.WebView;
|
|
|
import android.webkit.WebViewClient;
|
|
import android.webkit.WebViewClient;
|
|
|
-import android.widget.Toast;
|
|
|
|
|
|
|
|
|
|
import com.knacki.mimou.BuildConfig;
|
|
import com.knacki.mimou.BuildConfig;
|
|
|
|
|
+import com.knacki.mimou.bridge.JavascriptFunction;
|
|
|
import com.knacki.mimou.preference.CredentialHolder;
|
|
import com.knacki.mimou.preference.CredentialHolder;
|
|
|
-import com.knacki.mimou.JsInterface;
|
|
|
|
|
|
|
+import com.knacki.mimou.bridge.JsInterface;
|
|
|
import com.knacki.mimou.R;
|
|
import com.knacki.mimou.R;
|
|
|
-import com.knacki.mimou.preference.UserSettings;
|
|
|
|
|
|
|
|
|
|
-import java.io.UnsupportedEncodingException;
|
|
|
|
|
-import java.security.Permissions;
|
|
|
|
|
-import java.util.concurrent.Callable;
|
|
|
|
|
-import java.util.logging.Level;
|
|
|
|
|
import java.util.logging.Logger;
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
public class MainActivity extends AppCompatActivity {
|
|
public class MainActivity extends AppCompatActivity {
|
|
|
public final static int SMS_PERMISSION_CALLBACK = 42;
|
|
public final static int SMS_PERMISSION_CALLBACK = 42;
|
|
|
protected WebView web;
|
|
protected WebView web;
|
|
|
protected JsInterface interfaceMimouDroid;
|
|
protected JsInterface interfaceMimouDroid;
|
|
|
|
|
+ public static boolean needReload = true;
|
|
|
private static Logger log = Logger.getLogger(MainActivity.class.getName());
|
|
private static Logger log = Logger.getLogger(MainActivity.class.getName());
|
|
|
|
|
+ private JsInterface.TypedCallback<Boolean> currentCallback = null;
|
|
|
|
|
+
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
@@ -70,7 +64,14 @@ public class MainActivity extends AppCompatActivity {
|
|
|
|
|
|
|
|
web.getSettings().setJavaScriptEnabled(true);
|
|
web.getSettings().setJavaScriptEnabled(true);
|
|
|
web.addJavascriptInterface(interfaceMimouDroid, "__native");
|
|
web.addJavascriptInterface(interfaceMimouDroid, "__native");
|
|
|
- web.loadUrl(CredentialHolder.isLocal(this) ? (getString(R.string.mimouUrl) + (getString(R.string.localUrl))) : getString(R.string.mimouUrl));
|
|
|
|
|
|
|
+ needReload = true;
|
|
|
|
|
+ reload();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public void reload() {
|
|
|
|
|
+ if (needReload)
|
|
|
|
|
+ web.loadUrl(CredentialHolder.isLocal(this) ? (getString(R.string.mimouUrl) + (getString(R.string.localUrl))) : getString(R.string.mimouUrl));
|
|
|
|
|
+ needReload = false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void showLogin() {
|
|
public void showLogin() {
|
|
@@ -80,29 +81,20 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
@Override
|
|
|
protected void onResume() {
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
super.onResume();
|
|
|
- if (!CredentialHolder.hasCredential(this)) {
|
|
|
|
|
|
|
+ if (!CredentialHolder.hasCredential(this))
|
|
|
showLogin();
|
|
showLogin();
|
|
|
- }
|
|
|
|
|
|
|
+ else
|
|
|
|
|
+ reload();
|
|
|
interfaceMimouDroid.setActivity(this);
|
|
interfaceMimouDroid.setActivity(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void injectJavascript(String js) {
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT || false) {
|
|
|
|
|
- web.evaluateJavascript(js, new ValueCallback<String>() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public void onReceiveValue(String s) {
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- } else {
|
|
|
|
|
- try {
|
|
|
|
|
- web.loadUrl("data:text/html;charset=utf-8;base64," + Base64.encodeToString(("<script>" +js +"</script>").getBytes("UTF-8"), Base64.DEFAULT));
|
|
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
|
|
- log.log(Level.SEVERE, e.getMessage(), e);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ private void runJavascript(String js) {
|
|
|
|
|
+ web.loadUrl("javascript:" +js);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private JsInterface.TypedCallback<Boolean> currentCallback = null;
|
|
|
|
|
|
|
+ public void runJavascript(JavascriptFunction fnc) {
|
|
|
|
|
+ runJavascript(fnc.toString());
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
@@ -139,11 +131,12 @@ public class MainActivity extends AppCompatActivity {
|
|
|
callback.onResult(false);
|
|
callback.onResult(false);
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
+ .setCancelable(false)
|
|
|
.show();
|
|
.show();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void requestSmsPermission(JsInterface.TypedCallback<Boolean> callback) {
|
|
public void requestSmsPermission(JsInterface.TypedCallback<Boolean> callback) {
|
|
|
- Boolean userPermission = UserSettings.readSms(this);
|
|
|
|
|
|
|
+ Boolean userPermission = CredentialHolder.hasSMSPermission(this);
|
|
|
if (userPermission == null) {
|
|
if (userPermission == null) {
|
|
|
promptSmsPermission(callback);
|
|
promptSmsPermission(callback);
|
|
|
} else if (userPermission == false) {
|
|
} else if (userPermission == false) {
|