diff --git a/News-Android-App/src/main/assets/web.css b/News-Android-App/src/main/assets/web.css index aa127598..9645f204 100644 --- a/News-Android-App/src/main/assets/web.css +++ b/News-Android-App/src/main/assets/web.css @@ -53,16 +53,13 @@ body#darkTheme a:visited { } */ -body, blockquote, img, iframe, video, div, table, tbody, tr, td, pre, code, blockquote, p, em, b { +body, blockquote, img, iframe, video, div, table, tbody, tr, td, pre, code, blockquote, p, em, b, span { width: auto !important; height: auto !important; max-width: 100% !important; } span { - width: auto !important; - height: auto !important; - max-width: 100% !important; display: block; } 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 e10233ce..9a91d330 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 @@ -26,7 +26,9 @@ import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.os.PersistableBundle; import android.text.Html; import android.util.Log; import android.util.SparseArray; @@ -34,8 +36,11 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; import android.view.ViewGroup; +import android.webkit.WebView; +import android.widget.ImageButton; import android.widget.ProgressBar; +import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; import androidx.browser.customtabs.CustomTabsIntent; import androidx.core.content.ContextCompat; @@ -58,6 +63,7 @@ import butterknife.ButterKnife; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm.SORT_DIRECTION; import de.luhmer.owncloudnewsreader.database.model.RssItem; +import de.luhmer.owncloudnewsreader.helper.ThemeUtils; import de.luhmer.owncloudnewsreader.model.PodcastItem; import de.luhmer.owncloudnewsreader.model.TTSItem; import de.luhmer.owncloudnewsreader.widget.WidgetProvider; @@ -65,6 +71,7 @@ import de.luhmer.owncloudnewsreader.widget.WidgetProvider; public class NewsDetailActivity extends PodcastFragmentActivity { private static final String TAG = NewsDetailActivity.class.getCanonicalName(); + public static final String INCOGNITO_MODE_ENABLED = "INCOGNITO_MODE_ENABLED"; /** * The {@link PagerAdapter} that will provide * fragments for each of the sections. We use a @@ -76,6 +83,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { private SectionsPagerAdapter mSectionsPagerAdapter; protected @BindView(R.id.toolbar) Toolbar toolbar; protected @BindView(R.id.progressIndicator) ProgressBar progressIndicator; + protected @BindView(R.id.btn_disable_incognito) ImageButton mBtnDisableIncognito; /** * The {@link ViewPager} that will host the section contents. @@ -101,7 +109,14 @@ public class NewsDetailActivity extends PodcastFragmentActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_news_detail); - ButterKnife.bind(this); + /* + // For Debugging the WebView using Chrome Remote Debugging + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { + WebView.setWebContentsDebuggingEnabled(true); + } + */ + + ButterKnife.bind(this); if (toolbar != null) { setSupportActionBar(toolbar); @@ -170,7 +185,21 @@ public class NewsDetailActivity extends PodcastFragmentActivity { } mViewPager.addOnPageChangeListener(onPageChangeListener); - } + + mBtnDisableIncognito.setOnClickListener(v -> { + // toggle incognito mode + setIncognitoEnabled(!isIncognitoEnabled()); + + for(int i = currentPosition-1; i <= currentPosition+1; i++) { + Log.d(TAG, "change incognito for idx: " + i); + WeakReference ndf = mSectionsPagerAdapter.items.get(i); + if(ndf != null) { + ndf.get().syncIncognitoState(); + ndf.get().startLoadRssItemToWebViewTask(); + } + } + }); + } @Override protected void onDestroy() { @@ -337,7 +366,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { menuItem_Read = menu.findItem(R.id.action_read); menuItem_PlayPodcast = menu.findItem(R.id.action_playPodcast); - Set selections = mPrefs.getStringSet("sp_news_detail_actionbar_icons", new HashSet()); + Set selections = mPrefs.getStringSet("sp_news_detail_actionbar_icons", new HashSet<>()); String[] selected = selections.toArray(new String[] {}); for(String selection : selected) { switch(selection) { @@ -358,6 +387,8 @@ public class NewsDetailActivity extends PodcastFragmentActivity { updateActionBarIcons(); + initIncognitoMode(); + return true; } @@ -510,6 +541,21 @@ public class NewsDetailActivity extends PodcastFragmentActivity { super.finish(); } + public boolean isIncognitoEnabled() { + return mPrefs.getBoolean(INCOGNITO_MODE_ENABLED, false); + } + + public void setIncognitoEnabled(boolean enabled) { + mPrefs.edit().putBoolean(INCOGNITO_MODE_ENABLED, enabled).commit(); + initIncognitoMode(); + } + + public void initIncognitoMode() { + int color = getResources().getColor(isIncognitoEnabled() ? R.color.material_grey_900 : R.color.colorPrimary); + ThemeUtils.colorizeToolbar(toolbar, color); + ThemeUtils.changeStatusBarColor(this, color); + } + /** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. 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 d2f17eb9..5105b4b9 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 @@ -42,6 +42,7 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.Button; +import android.widget.ImageButton; import android.widget.ProgressBar; import android.widget.TextView; @@ -85,8 +86,6 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li protected @BindView(R.id.progressBarLoading) ProgressBar mProgressBarLoading; protected @BindView(R.id.progressbar_webview) ProgressBar mProgressbarWebView; protected @BindView(R.id.tv_offline_version) TextView mTvOfflineVersion; - protected @BindView(R.id.btn_disable_incognito) Button mBtnDisableIncognito; - protected @Inject SharedPreferences mPrefs; @@ -183,19 +182,24 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li } else { mWebView.restoreState(savedInstanceState); mProgressBarLoading.setVisibility(View.GONE); + // Make sure to sync the incognitio on retained views + syncIncognitoState(); } + + setUpGestureDetector(); - mBtnDisableIncognito.setOnClickListener(v -> { - mWebView.getSettings().setBlockNetworkLoads(false); - mWebView.getSettings().setBlockNetworkImage(false); - mWebView.reload(); - }); - return rootView; } + void syncIncognitoState() { + NewsDetailActivity ndActivity = ((NewsDetailActivity)getActivity()); + boolean isIncognito = ndActivity.isIncognitoEnabled(); + mWebView.getSettings().setBlockNetworkLoads(isIncognito); + mWebView.getSettings().setBlockNetworkImage(isIncognito); + } + @Override public void onSaveInstanceState(Bundle outState) { mWebView.saveState(outState); @@ -233,7 +237,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li }); } - private void startLoadRssItemToWebViewTask() { + void startLoadRssItemToWebViewTask() { Log.d(TAG, "startLoadRssItemToWebViewTask() called"); mWebView.setVisibility(View.GONE); mProgressBarLoading.setVisibility(View.VISIBLE); @@ -304,11 +308,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li webSettings.setAppCacheEnabled(true); webSettings.setMediaPlaybackRequiresUserGesture(true); - //if(true) { - //webSettings.setLoadsImagesAutomatically(false); - webSettings.setBlockNetworkImage(true); - webSettings.setBlockNetworkLoads(true); - //} + syncIncognitoState(); registerForContextMenu(mWebView); @@ -411,7 +411,7 @@ public class NewsDetailFragment extends Fragment implements RssItemToHtmlTask.Li String imgaltval; String imgsrcval; - imgsrcval = imageUrl.substring(imageUrl.lastIndexOf('/') + 1, imageUrl.length()); + imgsrcval = imageUrl.substring(imageUrl.lastIndexOf('/') + 1); Elements imgtag = htmlDoc.getElementsByAttributeValueContaining("src", imageUrl); try { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/RssItemToHtmlTask.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/RssItemToHtmlTask.java index 954cc54c..bed2085e 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/RssItemToHtmlTask.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/async_tasks/RssItemToHtmlTask.java @@ -24,6 +24,7 @@ import de.luhmer.owncloudnewsreader.database.model.RssItem; import de.luhmer.owncloudnewsreader.helper.ImageHandler; import de.luhmer.owncloudnewsreader.helper.ThemeChooser; +import static de.luhmer.owncloudnewsreader.NewsDetailActivity.INCOGNITO_MODE_ENABLED; import static de.luhmer.owncloudnewsreader.helper.ThemeChooser.THEME; @@ -84,6 +85,8 @@ public class RssItemToHtmlTask extends AsyncTask { * @return given RSS item as full HTML page */ public static String getHtmlPage(RssItem rssItem, boolean showHeader, SharedPreferences mPrefs, boolean isRightToLeft) { + boolean incognitoMode = mPrefs.getBoolean(INCOGNITO_MODE_ENABLED, false); + String favIconUrl = null; Feed feed = rssItem.getFeed(); @@ -122,7 +125,14 @@ public class RssItemToHtmlTask extends AsyncTask { } String description = rssItem.getBody(); - description = getDescriptionWithCachedImages(description).trim(); + if(!incognitoMode) { + // If incognito mode is disabled, try getting images from cache + description = getDescriptionWithCachedImages(description).trim(); + } else { + // When incognito is on, we need to provide some error handling + //description = description.replaceAll(". + * + */ + package de.luhmer.owncloudnewsreader.helper; +import android.app.Activity; +import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; +import android.os.Build; import android.util.Log; +import android.view.View; +import android.view.Window; +import android.view.WindowManager; import android.widget.SearchView; import android.widget.TextView; import java.lang.reflect.Field; import androidx.annotation.ColorInt; +import androidx.appcompat.widget.ActionMenuView; +import androidx.appcompat.widget.Toolbar; import androidx.core.content.ContextCompat; import de.luhmer.owncloudnewsreader.R; @@ -67,4 +96,42 @@ public class ThemeUtils { } } + + /** + * Use this method to colorize the toolbar to the desired target color + * @param toolbarView toolbar view being colored + * @param toolbarBackgroundColor the target background color + */ + public static void colorizeToolbar(Toolbar toolbarView, @ColorInt int toolbarBackgroundColor) { + + toolbarView.setBackgroundColor(toolbarBackgroundColor); + + for(int i = 0; i < toolbarView.getChildCount(); i++) { + final View v = toolbarView.getChildAt(i); + + v.setBackgroundColor(toolbarBackgroundColor); + + if(v instanceof ActionMenuView) { + for(int j = 0; j < ((ActionMenuView)v).getChildCount(); j++) { + v.setBackgroundColor(toolbarBackgroundColor); + } + } + } + } + + /** + * Use this method to colorize the status bar to the desired target color + * @param activity + * @param statusBarColor + */ + public static void changeStatusBarColor(Activity activity, @ColorInt int statusBarColor) { + Window window = activity.getWindow(); + // clear FLAG_TRANSLUCENT_STATUS flag: + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); + // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + window.setStatusBarColor(statusBarColor); + } + } } diff --git a/News-Android-App/src/main/res/layout/activity_news_detail.xml b/News-Android-App/src/main/res/layout/activity_news_detail.xml index be0c5eaa..1d5eb534 100644 --- a/News-Android-App/src/main/res/layout/activity_news_detail.xml +++ b/News-Android-App/src/main/res/layout/activity_news_detail.xml @@ -1,8 +1,8 @@ - + android:layout_width="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + + + + + + diff --git a/News-Android-App/src/main/res/layout/fragment_news_detail.xml b/News-Android-App/src/main/res/layout/fragment_news_detail.xml index 9aa5407e..5d609ab8 100644 --- a/News-Android-App/src/main/res/layout/fragment_news_detail.xml +++ b/News-Android-App/src/main/res/layout/fragment_news_detail.xml @@ -1,10 +1,10 @@ - -