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:
parent
84d02a38f9
commit
03166de709
3 changed files with 54 additions and 15 deletions
|
@ -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);
|
||||
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));
|
||||
} else if (ACTION_CLEAR_CACHE.equals(action)) {
|
||||
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) {
|
||||
switch (type) {
|
||||
case "text/plain":
|
||||
|
|
|
@ -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()) {
|
||||
webView.goBack();
|
||||
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);
|
||||
getWebView().loadUrlNew(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,7 +293,13 @@ public class BrowserFragment extends ThemedFragment {
|
|||
public void reloadUrl() {
|
||||
AppLog.v(this, "reloadUrl()");
|
||||
if (getWebView() != null) {
|
||||
getWebView().reload();
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getWebView().reload();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,15 +75,20 @@ public class DiasporaStreamFragment extends BrowserFragment {
|
|||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue