1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-22 12:22: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)) { } else if (ACTION_CHANGE_ACCOUNT.equals(action)) {
AppLog.v(this, "Reset pod data and show PodSelectionFragment"); AppLog.v(this, "Reset pod data and show PodSelectionFragment");
appSettings.setPod(null); appSettings.setPod(null);
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView()); runOnUiThread(new Runnable() {
@Override
public void run() {
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView());
}
});
showFragment(getFragment(PodSelectionFragment.TAG)); showFragment(getFragment(PodSelectionFragment.TAG));
} else if (ACTION_CLEAR_CACHE.equals(action)) { } else if (ACTION_CLEAR_CACHE.equals(action)) {
AppLog.v(this, "Clear WebView cache"); AppLog.v(this, "Clear WebView cache");
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true); runOnUiThread(new Runnable() {
@Override
public void run() {
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true);
}
});
} else if (Intent.ACTION_SEND.equals(action) && type != null) { } else if (Intent.ACTION_SEND.equals(action) && type != null) {
switch (type) { switch (type) {
case "text/plain": case "text/plain":

View file

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

View file

@ -75,15 +75,20 @@ public class DiasporaStreamFragment extends BrowserFragment {
public void onViewCreated(View view, Bundle savedInstanceState) { public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState); super.onViewCreated(view, savedInstanceState);
this.urls = new DiasporaUrlHelper(appSettings); this.urls = new DiasporaUrlHelper(appSettings);
webView.setWebChromeClient(new DiasporaStreamWebChromeClient(webView, progressBar, fileUploadCallback, sharedTextCallback)); 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) {
loadUrl(urls.getNewPostUrl());
} else if (webView.getUrl() == null) {
loadUrl(urls.getStreamUrl());
}
}
});
webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
if (((MainActivity) getActivity()).getTextToBeShared() != null) {
loadUrl(urls.getNewPostUrl());
} else if (webView.getUrl() == null) {
loadUrl(urls.getStreamUrl());
}
} }
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {