|
@@ -5,7 +5,6 @@ import android.content.DialogInterface;
|
|
|
import android.content.Intent;
|
|
import android.content.Intent;
|
|
|
import android.content.pm.PackageManager;
|
|
import android.content.pm.PackageManager;
|
|
|
import android.net.Uri;
|
|
import android.net.Uri;
|
|
|
-import android.os.Build;
|
|
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
import android.os.Handler;
|
|
import android.os.Handler;
|
|
|
import android.os.Looper;
|
|
import android.os.Looper;
|
|
@@ -15,24 +14,23 @@ import android.support.v7.app.AlertDialog;
|
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
|
import android.view.Menu;
|
|
import android.view.Menu;
|
|
|
import android.view.MenuItem;
|
|
import android.view.MenuItem;
|
|
|
-import android.webkit.WebChromeClient;
|
|
|
|
|
-import android.webkit.WebView;
|
|
|
|
|
-import android.webkit.WebViewClient;
|
|
|
|
|
|
|
|
|
|
-import com.knacki.mimou.BuildConfig;
|
|
|
|
|
|
|
+import com.knacki.mimou.R;
|
|
|
|
|
+import com.knacki.mimou.bridge.CookieManager;
|
|
|
import com.knacki.mimou.bridge.JavascriptFunction;
|
|
import com.knacki.mimou.bridge.JavascriptFunction;
|
|
|
-import com.knacki.mimou.preference.CredentialHolder;
|
|
|
|
|
import com.knacki.mimou.bridge.JsInterface;
|
|
import com.knacki.mimou.bridge.JsInterface;
|
|
|
-import com.knacki.mimou.R;
|
|
|
|
|
-import com.knacki.mimou.preference.PreferenceHolder;
|
|
|
|
|
|
|
+import com.knacki.mimou.bridge.MimouWebView;
|
|
|
|
|
+import com.knacki.mimou.preference.CredentialHolder;
|
|
|
import com.knacki.mimou.preference.UserSettings;
|
|
import com.knacki.mimou.preference.UserSettings;
|
|
|
|
|
|
|
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
|
+import java.util.Map;
|
|
|
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 MimouWebView web;
|
|
|
protected JsInterface interfaceMimouDroid;
|
|
protected JsInterface interfaceMimouDroid;
|
|
|
protected MainActivityMenu menu;
|
|
protected MainActivityMenu menu;
|
|
|
protected String currentChannel = null;
|
|
protected String currentChannel = null;
|
|
@@ -43,38 +41,19 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
@Override
|
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
protected void onCreate(Bundle savedInstanceState) {
|
|
|
super.onCreate(savedInstanceState);
|
|
super.onCreate(savedInstanceState);
|
|
|
|
|
+
|
|
|
setContentView(R.layout.activity_main);
|
|
setContentView(R.layout.activity_main);
|
|
|
interfaceMimouDroid = new JsInterface();
|
|
interfaceMimouDroid = new JsInterface();
|
|
|
- web = (WebView) findViewById(R.id.webview);
|
|
|
|
|
- web.setWebChromeClient(new WebChromeClient());
|
|
|
|
|
- web.setWebViewClient(new WebViewClient() {
|
|
|
|
|
- @Override
|
|
|
|
|
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
|
|
- Uri uri = Uri.parse(url);
|
|
|
|
|
-
|
|
|
|
|
- log.fine("Loading url " +url);
|
|
|
|
|
- if (uri.getHost().equals(getString(R.string.mimouHost))) {
|
|
|
|
|
- List<String> pathSegments = uri.getPathSegments();
|
|
|
|
|
- if (pathSegments.size() > 0) {
|
|
|
|
|
- if (pathSegments.get(0).equals("login") && !url.contains("?phoneAccess=")) {
|
|
|
|
|
- PreferenceHolder.reset(MainActivity.this);
|
|
|
|
|
- showLogin();
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- return super.shouldOverrideUrlLoading(view, url);
|
|
|
|
|
- }
|
|
|
|
|
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
|
|
|
|
|
- return true;
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
|
|
|
|
- web.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ web = ((MimouWebView) findViewById(R.id.webview));
|
|
|
|
|
+ web.onContextCreated(this);
|
|
|
|
|
+
|
|
|
|
|
+ // Cookies stuff
|
|
|
|
|
+ android.webkit.CookieSyncManager.createInstance(this);
|
|
|
|
|
+ android.webkit.CookieManager.getInstance().setAcceptCookie(true);
|
|
|
|
|
+ CookieManager cookieJar = new CookieManager(null, java.net.CookiePolicy.ACCEPT_ALL);
|
|
|
|
|
+ java.net.CookieHandler.setDefault(cookieJar);
|
|
|
|
|
|
|
|
- web.getSettings().setJavaScriptEnabled(true);
|
|
|
|
|
- web.addJavascriptInterface(interfaceMimouDroid, "__native");
|
|
|
|
|
needReload = true;
|
|
needReload = true;
|
|
|
|
|
|
|
|
Uri intentUri = getIntent().getData();
|
|
Uri intentUri = getIntent().getData();
|
|
@@ -95,12 +74,16 @@ public class MainActivity extends AppCompatActivity {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public JsInterface getJsInterface() {
|
|
|
|
|
+ return interfaceMimouDroid;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public void uiThread(Runnable e) {
|
|
public void uiThread(Runnable e) {
|
|
|
new Handler(Looper.getMainLooper()).post(e);
|
|
new Handler(Looper.getMainLooper()).post(e);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public void reload() {
|
|
public void reload() {
|
|
|
- if (needReload && web != null) {
|
|
|
|
|
|
|
+ if (needReload) {
|
|
|
if (CredentialHolder.hasCredential(this)) {
|
|
if (CredentialHolder.hasCredential(this)) {
|
|
|
final String url;
|
|
final String url;
|
|
|
if (CredentialHolder.isLocal(this))
|
|
if (CredentialHolder.isLocal(this))
|
|
@@ -109,6 +92,7 @@ public class MainActivity extends AppCompatActivity {
|
|
|
url = getString(R.string.mimouUrl) + getString(R.string.loginUrl) + "/android?phoneAccess=" + CredentialHolder.getToken(this);
|
|
url = getString(R.string.mimouUrl) + getString(R.string.loginUrl) + "/android?phoneAccess=" + CredentialHolder.getToken(this);
|
|
|
log.fine("Loading URL: " +url);
|
|
log.fine("Loading URL: " +url);
|
|
|
web.loadUrl(url);
|
|
web.loadUrl(url);
|
|
|
|
|
+
|
|
|
} else {
|
|
} else {
|
|
|
showLogin();
|
|
showLogin();
|
|
|
}
|
|
}
|
|
@@ -140,26 +124,32 @@ public class MainActivity extends AppCompatActivity {
|
|
|
@Override
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
protected void onDestroy() {
|
|
|
super.onDestroy();
|
|
super.onDestroy();
|
|
|
|
|
+ web.onContextDestroyed();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- if (web != null) {
|
|
|
|
|
- web.removeAllViews();
|
|
|
|
|
- web.clearHistory();
|
|
|
|
|
- web.clearCache(true);
|
|
|
|
|
- web.destroyDrawingCache();
|
|
|
|
|
- web.pauseTimers();
|
|
|
|
|
- web.destroy();
|
|
|
|
|
- web = null;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public Map<String, List<String>> getCookies() {
|
|
|
|
|
+ Map<String, List<String>> result = new HashMap<>();
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Unsafe (must be called from ui thread, web must be initialized)
|
|
|
|
|
+ */
|
|
|
|
|
+ private void loadJavascriptUnsafe(String js) {
|
|
|
|
|
+ log.severe(js);
|
|
|
|
|
+ web.loadUrl("javascript:" + js);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private void runJavascript(final String js) {
|
|
private void runJavascript(final String js) {
|
|
|
- uiThread(new Runnable() {
|
|
|
|
|
|
|
+ web.onceLoaded(new MimouWebView.DoneLoadingListener() {
|
|
|
@Override
|
|
@Override
|
|
|
- public void run() {
|
|
|
|
|
- if (web != null) {
|
|
|
|
|
- log.severe(js);
|
|
|
|
|
- web.loadUrl("javascript:" + js);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public void doneLoadind() {
|
|
|
|
|
+ uiThread(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ loadJavascriptUnsafe(js);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|