1
0
Fork 0
mirror of https://github.com/syncthing/syncthing-android.git synced 2024-11-30 00:01:19 +00:00

Webview improvements (respect back button, open external links in browser)

ref https://github.com/syncthing/syncthing/issues/4264
This commit is contained in:
Felix Ableitner 2017-07-21 01:43:28 +09:00
parent c13828b734
commit a9b80fbdc4

View file

@ -2,12 +2,13 @@ package com.nutomic.syncthingandroid.activities;
import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Intent;
import android.net.Uri;
import android.net.http.SslCertificate;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.webkit.HttpAuthHandler;
@ -90,6 +91,17 @@ public class WebGuiActivity extends SyncthingActivity
handler.proceed(mConfig.getUserName(), mConfig.getApiKey());
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Uri uri = Uri.parse(url);
if(uri.getHost().equals("127.0.0.1")) {
return false;
} else {
startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
}
}
@Override
public void onPageFinished(WebView view, String url) {
mWebView.setVisibility(View.VISIBLE);
@ -130,6 +142,15 @@ public class WebGuiActivity extends SyncthingActivity
mWebView.loadUrl(getService().getWebGuiUrl().toString());
}
@Override
public void onBackPressed() {
if (mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
/**
* Reads the SyncthingService.HTTPS_CERT_FILE Ca Cert key and loads it in memory
*/