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

Moved WebView related method calls to UiThread

This commit is contained in:
vanitasvitae 2016-10-25 17:37:22 +02:00
parent 84d02a38f9
commit 03166de709
Signed by: vanitasvitae
GPG key ID: DCCFB3302C9E4615
3 changed files with 54 additions and 15 deletions

View file

@ -440,11 +440,22 @@ public class MainActivity extends ThemedActivity
} else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
AppLog.v(this, "Reset pod data and show PodSelectionFragment");
appSettings.setPod(null);
runOnUiThread(new Runnable() {
@Override
public void run() {
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
}
});
showFragment(getFragment(PodSelectionFragment.TAG));
} else if (ACTION_CLEAR_CACHE.equals(action)) {
AppLog.v(this, "Clear WebView cache");
runOnUiThread(new Runnable() {
@Override
public void run() {
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
}
});
} else if (Intent.ACTION_SEND.equals(action) && type != null) {
switch (type) {
case "text/plain":

View file

@ -95,7 +95,13 @@ public class BrowserFragment extends ThemedFragment {
if (this.webView == null) {
this.webView = (ContextMenuWebView) view.findViewById(R.id.webView);
this.applyWebViewSettings();
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
BrowserFragment.this.applyWebViewSettings();
}
});
ProxyHandler.getInstance().addWebView(webView);
}
@ -249,16 +255,27 @@ public class BrowserFragment extends ThemedFragment {
public boolean onBackPressed() {
if (webView.canGoBack()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.goBack();
}
});
return true;
}
return false;
}
public void loadUrl(String url) {
public void loadUrl(final String url) {
if (getWebView() != null) {
AppLog.v(this, "loadUrl(): load " + url);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getWebView().loadUrlNew(url);
}
});
} else {
AppLog.v(this, "loadUrl(): WebView null: Set pending url to " + url);
pendingUrl = url;
@ -276,8 +293,14 @@ public class BrowserFragment extends ThemedFragment {
public void reloadUrl() {
AppLog.v(this, "reloadUrl()");
if (getWebView() != null) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getWebView().reload();
}
});
}
}
public ContextMenuWebView getWebView() {

View file

@ -75,8 +75,10 @@ public class DiasporaStreamFragment extends BrowserFragment {
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
this.urls = new DiasporaUrlHelper(appSettings);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setWebChromeClient(new DiasporaStreamWebChromeClient(webView, progressBar, fileUploadCallback, sharedTextCallback));
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
if (((MainActivity) getActivity()).getTextToBeShared() != null) {
@ -85,6 +87,9 @@ public class DiasporaStreamFragment extends BrowserFragment {
loadUrl(urls.getStreamUrl());
}
}
});
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_top, menu);