1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 04:12:08 +01:00

Handle links from browseable intent filter #38

This commit is contained in:
Gregor Santner 2016-07-30 16:48:43 +02:00
parent 389bb1b4e5
commit 05aa6231c7

View file

@ -182,11 +182,11 @@ public class MainActivity extends AppCompatActivity
podUserProfile.setCallbackHandler(uiHandler); podUserProfile.setCallbackHandler(uiHandler);
podUserProfile.setListener(this); podUserProfile.setListener(this);
if(appSettings.isProxyEnabled()) { if (appSettings.isProxyEnabled()) {
if(!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) { if (!setProxy(appSettings.getProxyHost(), appSettings.getProxyPort())) {
Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed,Toast.LENGTH_SHORT).show(); Toast.makeText(MainActivity.this, R.string.toast_set_proxy_failed, Toast.LENGTH_SHORT).show();
} }
} else if(appSettings.wasProxyEnabled()) { } else if (appSettings.wasProxyEnabled()) {
resetProxy(); resetProxy();
} }
@ -278,8 +278,9 @@ public class MainActivity extends AppCompatActivity
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge"); webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
//Set proxy //Set proxy
if(appSettings.isProxyEnabled()) { if (appSettings.isProxyEnabled()) {
if(!setProxy()) Toast.makeText(this, R.string.toast_set_proxy_failed, Toast.LENGTH_LONG).show(); if (!setProxy())
Toast.makeText(this, R.string.toast_set_proxy_failed, Toast.LENGTH_LONG).show();
} }
/* /*
@ -431,16 +432,30 @@ public class MainActivity extends AppCompatActivity
} }
private void handleIntent(Intent intent) { private void handleIntent(Intent intent) {
if (intent == null) {
return;
}
String action = intent.getAction(); String action = intent.getAction();
if(ACTION_OPEN_URL.equals(action)) { String loadUrl = null;
String url = intent.getStringExtra(URL_MESSAGE);
webView.loadUrl(url);
} else if(ACTION_CHANGE_ACCOUNT.equals(action)) { if (ACTION_OPEN_URL.equals(action)) {
loadUrl = intent.getStringExtra(URL_MESSAGE);
} else if (Intent.ACTION_VIEW.equals(action) && intent.getDataString() != null) {
loadUrl = intent.getDataString();
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
app.resetPodData(webView); app.resetPodData(webView);
Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true); Helpers.animateToActivity(MainActivity.this, PodSelectionActivity.class, true);
} else if(ACTION_CLEAR_CACHE.equals(action)) { } else if (ACTION_CLEAR_CACHE.equals(action)) {
webView.clearCache(true); webView.clearCache(true);
} }
if (loadUrl != null) {
webView.stopLoading();
navDrawer.closeDrawers();
webView.loadUrl(loadUrl);
}
} }
@Override @Override
@ -495,7 +510,7 @@ public class MainActivity extends AppCompatActivity
if (webView.canGoBack()) { if (webView.canGoBack()) {
webView.goBack(); webView.goBack();
} else { } else {
if(!snackbarExitApp.isShown()) if (!snackbarExitApp.isShown())
snackbarExitApp.show(); snackbarExitApp.show();
} }
} }
@ -799,7 +814,7 @@ public class MainActivity extends AppCompatActivity
if (item != null) { if (item != null) {
if (notificationCount > 0) { if (notificationCount > 0) {
item.setIcon(R.drawable.ic_bell_ring_white_24dp); item.setIcon(R.drawable.ic_bell_ring_white_24dp);
if(!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications")) if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
snackbarNewNotification.show(); snackbarNewNotification.show();
} else { } else {
item.setIcon(R.drawable.ic_bell_outline_white_24dp); item.setIcon(R.drawable.ic_bell_outline_white_24dp);
@ -833,7 +848,7 @@ public class MainActivity extends AppCompatActivity
if (item != null) { if (item != null) {
if (conversationCount > 0) { if (conversationCount > 0) {
item.setIcon(R.drawable.ic_message_text_white_24dp); item.setIcon(R.drawable.ic_message_text_white_24dp);
if(!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications")) if (!snackbarNewNotification.isShown() && !webView.getUrl().equals("https://" + podDomain + "/notifications"))
snackbarNewNotification.show(); snackbarNewNotification.show();
} else { } else {
item.setIcon(R.drawable.ic_message_text_outline_white_24dp); item.setIcon(R.drawable.ic_message_text_outline_white_24dp);
@ -977,7 +992,7 @@ public class MainActivity extends AppCompatActivity
} }
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main__layout); DrawerLayout drawer = (DrawerLayout) findViewById(R.id.main__layout);
if(drawer != null) drawer.closeDrawer(GravityCompat.START); if (drawer != null) drawer.closeDrawer(GravityCompat.START);
return true; return true;
} }
@ -1001,13 +1016,14 @@ public class MainActivity extends AppCompatActivity
/** /**
* Set proxy according to arguments. host must not be "" or null, port must be positive. * Set proxy according to arguments. host must not be "" or null, port must be positive.
* Return true on success and update appSettings' proxy related values. * Return true on success and update appSettings' proxy related values.
*
* @param host proxy host (eg. localhost or 127.0.0.1) * @param host proxy host (eg. localhost or 127.0.0.1)
* @param port proxy port (eg. 8118) * @param port proxy port (eg. 8118)
* @return success * @return success
* @throws IllegalArgumentException if arguments do not fit specifications above * @throws IllegalArgumentException if arguments do not fit specifications above
*/ */
private boolean setProxy(final String host, final int port) { private boolean setProxy(final String host, final int port) {
if(host != null && !host.equals("") && port >=0) { if (host != null && !host.equals("") && port >= 0) {
//Temporary change thread policy //Temporary change thread policy
StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy(); StrictMode.ThreadPolicy old = StrictMode.getThreadPolicy();
StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy tmp = new StrictMode.ThreadPolicy.Builder().permitAll().build();
@ -1046,7 +1062,7 @@ public class MainActivity extends AppCompatActivity
StrictMode.setThreadPolicy(tmp); StrictMode.setThreadPolicy(tmp);
NetCipher.clearProxy(); NetCipher.clearProxy();
try{ try {
WebkitProxy.resetProxy(MainActivity.class.getName(), this); WebkitProxy.resetProxy(MainActivity.class.getName(), this);
} catch (Exception e) {/*Nothing*/} } catch (Exception e) {/*Nothing*/}