From 66b3433e305cc12e9cc9523e0dc66347d55886b6 Mon Sep 17 00:00:00 2001 From: Mr_Diamond123 Date: Mon, 27 Jul 2020 14:19:06 -0400 Subject: [PATCH 1/4] Start to work on private mode --- .../me/ccrama/redditslide/SettingValues.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/app/src/main/java/me/ccrama/redditslide/SettingValues.java b/app/src/main/java/me/ccrama/redditslide/SettingValues.java index 46b52a2bd7..ace20ce1c1 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,17 @@ 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 privateMode; + } + } public static void resetSelftextEnabled(String subreddit) { prefs.edit().remove("cardtextenabled" + subreddit.toLowerCase(Locale.ENGLISH)).apply(); From 2e82283b5f8a670f943af7d4179020edc9ed7ebd Mon Sep 17 00:00:00 2001 From: Mr_Diamond123 Date: Mon, 27 Jul 2020 14:49:14 -0400 Subject: [PATCH 2/4] Add missing else/return --- app/src/main/java/me/ccrama/redditslide/SettingValues.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/me/ccrama/redditslide/SettingValues.java b/app/src/main/java/me/ccrama/redditslide/SettingValues.java index ace20ce1c1..c9c04a28f5 100644 --- a/app/src/main/java/me/ccrama/redditslide/SettingValues.java +++ b/app/src/main/java/me/ccrama/redditslide/SettingValues.java @@ -474,7 +474,9 @@ public static boolean getIsNSFWEnabled() { public static boolean shouldPrivateModeBeEnabled(boolean nsfw) { if (nsfw) { if (privateMode || privateModeNSFW) { - return true; + return true; + } else { + return false; } } else { From 2dcd139f91b1278d0b5e22c6acb6b693d7fb339f Mon Sep 17 00:00:00 2001 From: MrDiamond123 Date: Mon, 27 Jul 2020 15:30:40 -0400 Subject: [PATCH 3/4] Might have added 2/3 of the feature, possibly --- .../me/ccrama/redditslide/Activities/SubredditView.java | 7 +++++++ 1 file changed, 7 insertions(+) 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..edd51643eb 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; @@ -177,6 +178,10 @@ public void onCreate(Bundle savedInstanceState) { setContentView(R.layout.activity_singlesubreddit); setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit); + 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); setResult(3); @@ -466,6 +471,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(); From 889b30d9aefd7202c51bacf533dff7a37bd81caf Mon Sep 17 00:00:00 2001 From: MrDiamond123 Date: Wed, 29 Jul 2020 19:54:55 -0400 Subject: [PATCH 4/4] Most of Private Mode Working - Needs settings and keyboard stuff --- .../ccrama/redditslide/Activities/SubredditView.java | 12 ++++++++---- .../redditslide/Fragments/SubmissionsView.java | 12 ++++++++++++ .../redditslide/Fragments/SubredditListView.java | 1 - app/src/main/res/values/strings.xml | 3 +++ 4 files changed, 23 insertions(+), 5 deletions(-) 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 edd51643eb..df019ef84f 100644 --- a/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java +++ b/app/src/main/java/me/ccrama/redditslide/Activities/SubredditView.java @@ -177,10 +177,11 @@ public void onCreate(Bundle savedInstanceState) { applyColorTheme(subreddit); setContentView(R.layout.activity_singlesubreddit); setupSubredditAppBar(R.id.toolbar, subreddit, true, subreddit); - - if (SettingValues.shouldPrivateModeBeEnabled(sub.isNsfw())) { - getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE); - } + //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); @@ -2112,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/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