diff options
author | David Luhmer <david-dev@live.de> | 2021-12-30 17:56:27 +0300 |
---|---|---|
committer | David Luhmer <david-dev@live.de> | 2021-12-30 17:56:27 +0300 |
commit | 8d7a3c1eff1640eadf74e6451bc3f678ecbbe456 (patch) | |
tree | 687720e862b62a0ddab186e76efebc84a3bfe540 /News-Android-App/src/main/java | |
parent | 0f3c882e37586c6fcd773a1ef0b8db79e4a171e7 (diff) |
fix missing images if webview has been restored
Diffstat (limited to 'News-Android-App/src/main/java')
-rw-r--r-- | News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java | 2 | ||||
-rw-r--r-- | News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java | 60 |
2 files changed, 38 insertions, 24 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index 089ceb7b..fb18d86d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -227,7 +227,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { WeakReference<NewsDetailFragment> ndf = mSectionsPagerAdapter.items.get(i); if (ndf != null) { ndf.get().syncIncognitoState(); - ndf.get().startLoadRssItemToWebViewTask(); + ndf.get().startLoadRssItemToWebViewTask(this); } } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java index d3b09a2e..005c3b0c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailFragment.java @@ -27,6 +27,7 @@ import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.os.Looper; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; @@ -34,6 +35,8 @@ import android.view.View; import android.view.ViewGroup; import android.webkit.WebBackForwardList; import android.webkit.WebHistoryItem; +import android.webkit.WebResourceError; +import android.webkit.WebResourceRequest; import android.webkit.WebResourceResponse; import android.webkit.WebSettings; import android.webkit.WebView; @@ -125,8 +128,8 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li binding.webview.pauseTimers(); } - public void resumeCurrentPage() { + applyWebSettings(); binding.webview.onResume(); binding.webview.resumeTimers(); } @@ -148,7 +151,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li public void navigateBack() { if (isLastPageRssItem()) { binding.webview.clearHistory(); - startLoadRssItemToWebViewTask(); + startLoadRssItemToWebViewTask((NewsDetailActivity) getActivity()); } else if (!isCurrentPageRssItem()){ binding.webview.goBack(); } @@ -160,23 +163,34 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li section_number = (Integer) requireArguments().get(ARG_SECTION_NUMBER); - // Do not reload webview if retained - if(savedInstanceState == null) { - startLoadRssItemToWebViewTask(); - } else { + NewsDetailActivity ndActivity = ((NewsDetailActivity)getActivity()); + assert ndActivity != null; + + // Do not reload webView if retained + if (savedInstanceState != null) { + // Log.d(TAG, "onCreateView restore webview"); binding.webview.restoreState(savedInstanceState); + setWebViewBackgroundColor(ndActivity); binding.progressBarLoading.setVisibility(View.GONE); binding.progressbarWebview.setVisibility(View.GONE); // Make sure to sync the incognitio on retained views syncIncognitoState(); this.addBottomPaddingForFastActions(binding.webview); + } else { + // Log.d(TAG, "onCreateView new webview"); + startLoadRssItemToWebViewTask(ndActivity); } - // setUpGestureDetector(); return binding.getRoot(); } + private void setWebViewBackgroundColor(NewsDetailActivity ndActivity) { + int backgroundColor = ContextCompat.getColor(ndActivity, R.color.news_detail_background_color); + binding.webview.setBackgroundColor(backgroundColor); + ndActivity.setBackgroundColorOfViewPager(backgroundColor); + } + protected void syncIncognitoState() { NewsDetailActivity ndActivity = ((NewsDetailActivity) requireActivity()); boolean isIncognito = ndActivity.isIncognitoEnabled(); @@ -226,21 +240,15 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li } */ - - protected void startLoadRssItemToWebViewTask() { - Log.d(TAG, "startLoadRssItemToWebViewTask() called"); + protected void startLoadRssItemToWebViewTask(NewsDetailActivity ndActivity) { binding.webview.setVisibility(View.GONE); binding.progressBarLoading.setVisibility(View.VISIBLE); - NewsDetailActivity ndActivity = ((NewsDetailActivity)getActivity()); - assert ndActivity != null; - - int backgroundColor = ContextCompat.getColor(ndActivity, R.color.news_detail_background_color); - binding.webview.setBackgroundColor(backgroundColor); - ndActivity.setBackgroundColorOfViewPager(backgroundColor); + setWebViewBackgroundColor(ndActivity); init_webView(); RssItem rssItem = ndActivity.rssItems.get(section_number); + Log.d(TAG, "startLoadRssItemToWebViewTask: " + rssItem.getTitle()); RssItemToHtmlTask task = new RssItemToHtmlTask(ndActivity, rssItem, this, mPrefs); AsyncTaskHelper.StartAsyncTask(task); } @@ -249,6 +257,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li public void onRssItemParsed(String htmlPage) { binding.webview.setVisibility(View.VISIBLE); binding.progressBarLoading.setVisibility(View.GONE); + Log.d(TAG, "progressBarLoading gone"); setSoftwareRenderModeForWebView(htmlPage, binding.webview); @@ -278,12 +287,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li } } - @SuppressLint("SetJavaScriptEnabled") - private void init_webView() { - int backgroundColor = ColorHelper.getColorFromAttribute(getContext(), - R.attr.news_detail_background_color); - binding.webview.setBackgroundColor(backgroundColor); - + private void applyWebSettings() { WebSettings webSettings = binding.webview.getSettings(); //webSettings.setPluginState(WebSettings.PluginState.ON); webSettings.setJavaScriptEnabled(true); @@ -297,6 +301,17 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li webSettings.setMediaPlaybackRequiresUserGesture(true); syncIncognitoState(); + } + + @SuppressLint("SetJavaScriptEnabled") + private void init_webView() { + int backgroundColor = ColorHelper.getColorFromAttribute(getContext(), + R.attr.news_detail_background_color); + binding.webview.setBackgroundColor(backgroundColor); + + applyWebSettings(); + + syncIncognitoState(); binding.webview.setWebChromeClient(new ProgressBarWebChromeClient(binding.progressbarWebview)); @@ -370,7 +385,6 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li * * @param url address to load */ - public void loadURL(String url) { int selectedBrowser = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_DISPLAY_BROWSER, "0")); |