diff --git a/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java b/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java index 750e8ee16d..df019ef84f 100644 --- a/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java +++ b/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java @@ -22,6 +22,7 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.view.animation.LinearInterpolator; import android.widget.CompoundButton; import android.widget.HorizontalScrollView; @@ -176,6 +177,11 @@ public void onCreate(Bundle savedInstanceState) { applyColorTheme(subreddit); setContentView(R.layout.activity_singlesubreddit); setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit); + //if (sub != null) { + // if (SettingValues.shouldPrivateModeBeEnabled(sub.isNsfw())) { + // getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + // } + //} header = findViewById(R.id.header); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); @@ -466,6 +472,8 @@ public void onClick(DialogInterface dialog, @Override public void onDestroy() { super.onDestroy(); + //Have no idea if I need this + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE); if (sub != null) { if (sub.isNsfw() && (!SettingValues.storeHistory || !SettingValues.storeNSFWHistory)) { SharedPreferences.Editor e = Reddit.cachedData.edit(); @@ -2105,6 +2113,9 @@ public void onPostExecute(Subreddit subreddit) { doSubSidebarNoLoad(sub.getDisplayName()); doSubSidebar(sub.getDisplayName()); doSubOnlyStuff(sub); + if (SettingValues.shouldPrivateModeBeEnabled(sub.isNsfw())) { + getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + } } catch (NullPointerException e) { //activity has been killed if (!isFinishing()) finish(); } diff --git a/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java b/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java index 2e5f3a901b..72f2730356 100644 --- a/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java +++ b/app/src/main/java/me/ccrama/redditslide/Fragments/SubmissionsView.java @@ -15,6 +15,7 @@ import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.widget.RelativeLayout; import android.widget.TextView; @@ -36,6 +37,7 @@ import net.dean.jraw.models.Submission; +import java.util.Iterator; import java.util.List; import java.util.Locale; @@ -503,6 +505,16 @@ public static void datachanged(int adaptorPosition2) { } private void refresh() { + Iterator i = posts.getPosts().iterator(); + boolean nsfw = false; + while (i.hasNext() && !nsfw) { + nsfw = i.next().isNsfw(); + } + + if (SettingValues.shouldPrivateModeBeEnabled(nsfw)) { + getActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); + } + posts.forced = true; forced = true; posts.loadMore(mSwipeRefreshLayout.getContext(), this, true, id); diff --git a/app/src/main/java/me/ccrama/redditslide/Fragments/SubredditListView.java b/app/src/main/java/me/ccrama/redditslide/Fragments/SubredditListView.java index 3f80734e71..5fb0f7cfed 100644 --- a/app/src/main/java/me/ccrama/redditslide/Fragments/SubredditListView.java +++ b/app/src/main/java/me/ccrama/redditslide/Fragments/SubredditListView.java @@ -40,7 +40,6 @@ public class SubredditListView extends Fragment { public String where; private SwipeRefreshLayout mSwipeRefreshLayout; - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { diff --git a/app/src/main/java/me/ccrama/redditslide/SettingValues.java b/app/src/main/java/me/ccrama/redditslide/SettingValues.java index 46b52a2bd7..c9c04a28f5 100644 --- a/app/src/main/java/me/ccrama/redditslide/SettingValues.java +++ b/app/src/main/java/me/ccrama/redditslide/SettingValues.java @@ -95,6 +95,8 @@ public class SettingValues { public static final String PREF_SHOW_NSFW_CONTENT = "showNSFWContent"; public static final String PREF_HIDE_NSFW_PREVIEW = "hideNSFWPreviews"; public static final String PREF_HIDE_NSFW_COLLECTION = "hideNSFWPreviewsCollection"; + public static final String PREF_PRIVATE_MODE = "privateMode"; + public static final String PREF_PRIVATE_MODE_NSFW = "privateModeNSFW"; public static final String PREF_IGNORE_SUB_SETTINGS = "ignoreSub"; public static final String PREF_HIGHLIGHT_TIME = "highlightTime"; public static final String PREF_MUTE = "muted"; @@ -194,6 +196,8 @@ public class SettingValues { public static boolean abbreviateScores; public static boolean shareLongLink; public static boolean isMuted; + public static boolean privateMode; + public static boolean privateModeNSFW; public static int subredditSearchMethod; public static int backButtonBehavior; public static int nightStart; @@ -289,6 +293,9 @@ public static void setAllValues(SharedPreferences settings) { showNSFWContent = prefs.getBoolean(PREF_SHOW_NSFW_CONTENT, false); hideNSFWCollection = prefs.getBoolean(PREF_HIDE_NSFW_COLLECTION, true); ignoreSubSetting = prefs.getBoolean(PREF_IGNORE_SUB_SETTINGS, false); + + privateMode = prefs.getBoolean(PREF_PRIVATE_MODE, false); + privateModeNSFW = prefs.getBoolean(PREF_PRIVATE_MODE_NSFW, true); single = prefs.getBoolean(PREF_SINGLE, false); readerNight = prefs.getBoolean(PREF_READER_NIGHT, false); @@ -463,6 +470,19 @@ public static void setSelftextEnabled(String sub, boolean checked) { public static boolean getIsNSFWEnabled() { return prefs.getBoolean(PREF_HIDE_NSFW_PREVIEW + Authentication.name, true); } + + public static boolean shouldPrivateModeBeEnabled(boolean nsfw) { + if (nsfw) { + if (privateMode || privateModeNSFW) { + return true; + } else { + return false; + } + } + else { + return privateMode; + } + } public static void resetSelftextEnabled(String subreddit) { prefs.edit().remove("cardtextenabled" + subreddit.toLowerCase(Locale.ENGLISH)).apply(); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e2b13711ba..7f44e2fb07 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -797,12 +797,15 @@ Send removal reasons as a subreddit Refreshing Toolbox data for all subreddits + + Night mode Immersive mode Show NSFW content Right-aligned thumbnails Use reader mode + Use private mode Subreddit tabs