1
0
Fork 0
mirror of https://github.com/gsantner/dandelion synced 2024-11-25 13:52: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);
runOnUiThread(new Runnable() {
@Override
public void run() {
app.resetPodData(((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView()); 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");
runOnUiThread(new Runnable() {
@Override
public void run() {
((DiasporaStreamFragment) getFragment(DiasporaStreamFragment.TAG)).getWebView().clearCache(true); ((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()) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.goBack(); 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);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getWebView().loadUrlNew(url); 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,8 +293,14 @@ 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) {
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
getWebView().reload(); getWebView().reload();
} }
});
}
} }
public ContextMenuWebView getWebView() { public ContextMenuWebView getWebView() {

View file

@ -75,8 +75,10 @@ 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);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
webView.setWebChromeClient(new DiasporaStreamWebChromeClient(webView, progressBar, fileUploadCallback, sharedTextCallback)); webView.setWebChromeClient(new DiasporaStreamWebChromeClient(webView, progressBar, fileUploadCallback, sharedTextCallback));
webView.getSettings().setJavaScriptEnabled(true); webView.getSettings().setJavaScriptEnabled(true);
webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge"); webView.addJavascriptInterface(new JavaScriptInterface(), "AndroidBridge");
if (((MainActivity) getActivity()).getTextToBeShared() != null) { if (((MainActivity) getActivity()).getTextToBeShared() != null) {
@ -85,6 +87,9 @@ public class DiasporaStreamFragment extends BrowserFragment {
loadUrl(urls.getStreamUrl()); loadUrl(urls.getStreamUrl());
} }
} }
});
}
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.stream__menu_top, menu); inflater.inflate(R.menu.stream__menu_top, menu);