Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Private Mode - Adds #3240 #3241

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -36,6 +37,7 @@

import net.dean.jraw.models.Submission;

import java.util.Iterator;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -503,6 +505,16 @@ public static void datachanged(int adaptorPosition2) {
}

private void refresh() {
Iterator<Submission> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/me/ccrama/redditslide/SettingValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -797,12 +797,15 @@
<string name="settings_mod_toolbox_modmail">Send removal reasons as a subreddit</string>
<string name="settings_mod_toolbox_refreshing">Refreshing Toolbox data for all subreddits</string>

<!-- Settings for private mode -->

<!-- Quick setting toggles in the drawer -->
<string name="toggle_night_mode">Night mode</string>
<string name="toggle_immersive_mode">Immersive mode</string>
<string name="toggle_nsfw">Show NSFW content</string>
<string name="toggle_right_thumbnails">Right-aligned thumbnails</string>
<string name="toggle_reader_mode">Use reader mode</string>
<string name="toggle_private_mode">Use private mode</string>

<!-- View types -->
<string name="view_type_tabs">Subreddit tabs</string>
Expand Down