aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-12-23 09:03:41 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-12-23 09:03:41 +0000
commit6a8f27f9476db4328b1a00595c9e09c5a83ffb22 (patch)
tree309f01899d26c463e70d0b2f12df5ccc1190a198 /app/src/main
parentc88ceb737be67e0240f5eff51a5570a038bd27c7 (diff)
downloadinfinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar.gz
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar.bz2
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar.lz
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar.xz
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.tar.zst
infinity-for-reddit-6a8f27f9476db4328b1a00595c9e09c5a83ffb22.zip
Add a new option category: Post Filter. Marking posts as read is disabled by default. Marking posts as read after voting is now available.
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java3
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java50
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java98
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java4
-rw-r--r--app/src/main/res/drawable-night/ic_history_24dp.xml9
-rw-r--r--app/src/main/res/layout/fragment_post_history.xml93
-rw-r--r--app/src/main/res/values/strings.xml5
-rw-r--r--app/src/main/res/xml/main_preferences.xml5
-rw-r--r--app/src/main/res/xml/miscellaneous_preferences.xml2
-rw-r--r--app/src/main/res/xml/post_history.xml4
14 files changed, 288 insertions, 20 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
index dc7be5e3..2f881530 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppComponent.java
@@ -73,6 +73,7 @@ import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.MiscellaneousPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NotificationPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment;
+import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
import ml.docilealligator.infinityforreddit.settings.SecurityPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.ThemePreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.TranslationFragment;
@@ -230,4 +231,6 @@ public interface AppComponent {
void inject(SubredditFilterPopularAndAllActivity subredditFilterPopularAndAllActivity);
void inject(CustomizePostFilterActivity customizePostFilterActivity);
+
+ void inject(PostHistoryFragment postHistoryFragment);
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
index 8e483803..38d971a5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java
@@ -223,6 +223,12 @@ class AppModule {
}
@Provides
+ @Named("post_history")
+ SharedPreferences providePostHistorySharedPreferences() {
+ return mApplication.getSharedPreferences(SharedPreferencesUtils.POST_HISTORY_SHARED_PREFERENCES_FILE, Context.MODE_PRIVATE);
+ }
+
+ @Provides
@Singleton
CustomThemeWrapper provideCustomThemeWrapper(@Named("light_theme") SharedPreferences lightThemeSharedPreferences,
@Named("dark_theme") SharedPreferences darkThemeSharedPreferences,
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java
index f9c8c39e..699946a5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/SettingsActivity.java
@@ -35,6 +35,7 @@ import ml.docilealligator.infinityforreddit.settings.GesturesAndButtonsPreferenc
import ml.docilealligator.infinityforreddit.settings.InterfacePreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.MainPreferenceFragment;
import ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment;
+import ml.docilealligator.infinityforreddit.settings.PostHistoryFragment;
public class SettingsActivity extends BaseActivity implements
PreferenceFragmentCompat.OnPreferenceStartFragmentCallback {
@@ -168,6 +169,8 @@ public class SettingsActivity extends BaseActivity implements
args.putString(NsfwAndBlurringFragment.EXTRA_ACCOUNT_NAME, mAccountName);
} else if (fragment instanceof CustomizeBottomAppBarFragment) {
args.putString(CustomizeBottomAppBarFragment.EXTRA_ACCOUNT_NAME, mAccountName);
+ } else if (fragment instanceof PostHistoryFragment) {
+ args.putString(PostHistoryFragment.EXTRA_ACCOUNT_NAME, mAccountName);
}
fragment.setArguments(args);
fragment.setTargetFragment(caller, 0);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index 819874b7..defbb0a5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -194,6 +194,8 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mCompactLayoutToolbarHiddenByDefault;
private boolean mDataSavingMode = false;
private boolean mDisableImagePreview = false;
+ private boolean mMarkPostsAsRead;
+ private boolean mMarkPostsAsReadAfterVoting;
private Drawable mCommentIcon;
private NetworkState networkState;
private ExoCreator mExoCreator;
@@ -205,6 +207,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
CustomThemeWrapper customThemeWrapper, Locale locale, int imageViewWidth,
String accessToken, String accountName, int postType, int postLayout, boolean displaySubredditName,
SharedPreferences sharedPreferences, SharedPreferences nsfwAndSpoilerSharedPreferences,
+ SharedPreferences postHistorySharedPreferences,
ExoCreator exoCreator, Callback callback) {
super(DIFF_CALLBACK);
if (activity != null) {
@@ -255,6 +258,9 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
mDisableImagePreview = sharedPreferences.getBoolean(SharedPreferencesUtils.DISABLE_IMAGE_PREVIEW, false);
+ mMarkPostsAsRead = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false);
+ mMarkPostsAsReadAfterVoting = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false);
+
mPostLayout = postLayout;
mColorPrimaryLightTheme = customThemeWrapper.getColorPrimaryLightTheme();
@@ -1697,6 +1703,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return;
}
+ if (mMarkPostsAsReadAfterVoting) {
+ markPostRead(post);
+ }
+
if (post.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
return;
@@ -1783,6 +1793,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
return;
}
+ if (mMarkPostsAsReadAfterVoting) {
+ markPostRead(post);
+ }
+
if (post.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
return;
@@ -2747,6 +2761,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null) {
+ if (mMarkPostsAsReadAfterVoting) {
+ markPostRead(post);
+ }
+
if (post.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
return;
@@ -2833,6 +2851,10 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
Post post = getItem(position);
if (post != null) {
+ if (mMarkPostsAsReadAfterVoting) {
+ markPostRead(post);
+ }
+
if (post.isArchived()) {
Toast.makeText(mActivity, R.string.archived_post_vote_unavailable, Toast.LENGTH_SHORT).show();
return;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
index 96b04e23..832de6c0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/PostFragment.java
@@ -58,6 +58,7 @@ import javax.inject.Named;
import butterknife.BindView;
import butterknife.ButterKnife;
+import butterknife.Unbinder;
import im.ene.toro.exoplayer.ExoCreator;
import im.ene.toro.media.PlaybackInfo;
import im.ene.toro.media.VolumeInfo;
@@ -178,6 +179,9 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
@Named("nsfw_and_spoiler")
SharedPreferences mNsfwAndSpoilerSharedPreferences;
@Inject
+ @Named("post_history")
+ SharedPreferences mPostHistorySharedPreferences;
+ @Inject
CustomThemeWrapper customThemeWrapper;
@Inject
ExoCreator exoCreator;
@@ -222,6 +226,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
private ItemTouchHelper touchHelper;
private ArrayList<SubredditFilter> subredditFilterList;
private ArrayList<ReadPost> readPosts;
+ private Unbinder unbinder;
public PostFragment() {
// Required empty public constructor
@@ -275,7 +280,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
((Infinity) activity.getApplication()).getAppComponent().inject(this);
- ButterKnife.bind(this, rootView);
+ unbinder = ButterKnife.bind(this, rootView);
EventBus.getDefault().register(this);
@@ -469,7 +474,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true,
- mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
+ exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -513,13 +519,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
String sortTime = null;
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_SUBREDDIT_POST_BASE + subredditName, SortType.Type.HOT.name());
- if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_SUBREDDIT_POST_BASE + subredditName, SortType.Time.ALL.name());
}
boolean displaySubredditName = subredditName != null && (subredditName.equals("popular") || subredditName.equals("all"));
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_SUBREDDIT_POST_BASE + subredditName, defaultPostLayout);
- if(sortTime != null) {
+ if (sortTime != null) {
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(SortType.Type.valueOf(sort));
@@ -528,7 +534,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, displaySubredditName,
- mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
+ exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -564,21 +571,21 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
TransitionManager.beginDelayedTransition(mPostRecyclerView, new AutoTransition());
}
});
- } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) {
+ } else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
multiRedditPath = getArguments().getString(EXTRA_NAME);
String sort;
String sortTime = null;
sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Type.HOT.name());
- if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_MULTI_REDDIT_POST_BASE + multiRedditPath,
SortType.Time.ALL.name());
}
postLayout = mPostLayoutSharedPreferences.getInt(SharedPreferencesUtils.POST_LAYOUT_MULTI_REDDIT_POST_BASE + multiRedditPath,
defaultPostLayout);
- if(sortTime != null) {
+ if (sortTime != null) {
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
sortType = new SortType(SortType.Type.valueOf(sort));
@@ -587,7 +594,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true,
- mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
+ exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -633,7 +641,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, SortType.Type.NEW.name());
- if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
@@ -644,7 +652,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true,
- mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
+ exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -684,7 +693,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
});
} else {
String sort = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TYPE_BEST_POST, SortType.Type.BEST.name());
- if(sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
+ if (sort.equals(SortType.Type.CONTROVERSIAL.name()) || sort.equals(SortType.Type.TOP.name())) {
String sortTime = mSortTypeSharedPreferences.getString(SharedPreferencesUtils.SORT_TIME_BEST_POST, SortType.Time.ALL.name());
sortType = new SortType(SortType.Type.valueOf(sort), SortType.Time.valueOf(sortTime));
} else {
@@ -695,7 +704,8 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
mAdapter = new PostRecyclerViewAdapter(activity, mOauthRetrofit, mRetrofit, mGfycatRetrofit,
mRedgifsRetrofit, mRedditDataRoomDatabase, customThemeWrapper, locale,
windowWidth, accessToken, accountName, postType, postLayout, true,
- mSharedPreferences, mNsfwAndSpoilerSharedPreferences, exoCreator, new PostRecyclerViewAdapter.Callback() {
+ mSharedPreferences, mNsfwAndSpoilerSharedPreferences, mPostHistorySharedPreferences,
+ exoCreator, new PostRecyclerViewAdapter.Callback() {
@Override
public void retryLoadingMore() {
mPostViewModel.retryLoadingMore();
@@ -740,7 +750,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
if (accountName != null && !accountName.equals("")) {
- if (readPosts == null) {
+ if (mPostHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false) && readPosts == null) {
if (getArguments().getBoolean(EXTRA_DISABLE_READ_POSTS, false)) {
initializeAndBindPostViewModel(accessToken);
} else {
@@ -1011,13 +1021,13 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
break;
case PostDataSource.TYPE_USER:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_USER_POST_BASE + username, sortType.getType().name()).apply();
- if(sortType.getTime() != null) {
+ if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_USER_POST_BASE + username, sortType.getTime().name()).apply();
}
break;
case PostDataSource.TYPE_SEARCH:
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TYPE_SEARCH_POST, sortType.getType().name()).apply();
- if(sortType.getTime() != null) {
+ if (sortType.getTime() != null) {
mSortTypeSharedPreferences.edit().putString(SharedPreferencesUtils.SORT_TIME_SEARCH_POST, sortType.getTime().name()).apply();
}
break;
@@ -1279,7 +1289,7 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, subredditName);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
startActivity(intent);
- } else if(postType == PostDataSource.TYPE_MULTI_REDDIT) {
+ } else if (postType == PostDataSource.TYPE_MULTI_REDDIT) {
Intent intent = new Intent(activity, FilteredPostsActivity.class);
intent.putExtra(FilteredPostsActivity.EXTRA_NAME, multiRedditPath);
intent.putExtra(FilteredPostsActivity.EXTRA_POST_TYPE, postType);
@@ -1617,6 +1627,12 @@ public class PostFragment extends Fragment implements FragmentCommunicator {
}
@Override
+ public void onDestroyView() {
+ super.onDestroyView();
+ unbinder.unbind();
+ }
+
+ @Override
public void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java
index b5d34c6f..60ddffe2 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/readpost/InsertReadPost.java
@@ -27,7 +27,9 @@ public class InsertReadPost {
if (readPostDao.getReadPostsCount() > 500) {
readPostDao.deleteOldestReadPosts(username);
}
- readPostDao.insert(new ReadPost(username, postId));
+ if (username != null && !username.equals("")) {
+ readPostDao.insert(new ReadPost(username, postId));
+ }
return null;
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java
new file mode 100644
index 00000000..eebfe17f
--- /dev/null
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/settings/PostHistoryFragment.java
@@ -0,0 +1,98 @@
+package ml.docilealligator.infinityforreddit.settings;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.appcompat.app.AppCompatActivity;
+import androidx.fragment.app.Fragment;
+
+import com.google.android.material.switchmaterial.SwitchMaterial;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import ml.docilealligator.infinityforreddit.Infinity;
+import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
+
+public class PostHistoryFragment extends Fragment {
+
+ public static final String EXTRA_ACCOUNT_NAME = "EAN";
+
+ @BindView(R.id.info_text_view_post_history_fragment)
+ TextView infoTextView;
+ @BindView(R.id.mark_posts_as_read_linear_layout_post_history_fragment)
+ LinearLayout markPostsAsReadLinearLayout;
+ @BindView(R.id.mark_posts_as_read_switch_post_history_fragment)
+ SwitchMaterial markPostsAsReadSwitch;
+ @BindView(R.id.mark_posts_as_read_after_voting_linear_layout_post_history_fragment)
+ LinearLayout markPostsAsReadAfterVotingLinearLayout;
+ @BindView(R.id.mark_posts_as_read_after_voting_switch_post_history_fragment)
+ SwitchMaterial markPostsAsReadAfterVotingSwitch;
+ @Inject
+ @Named("post_history")
+ SharedPreferences postHistorySharedPreferences;
+ private Activity activity;
+
+ public PostHistoryFragment() {
+ // Required empty public constructor
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+ // Inflate the layout for this fragment
+ View rootView = inflater.inflate(R.layout.fragment_post_history, container, false);
+
+ ((Infinity) activity.getApplication()).getAppComponent().inject(this);
+
+ ButterKnife.bind(this, rootView);
+
+ String accountName = getArguments().getString(EXTRA_ACCOUNT_NAME);
+ if (accountName == null) {
+ infoTextView.setText(R.string.only_for_logged_in_user);
+ markPostsAsReadLinearLayout.setVisibility(View.GONE);
+ markPostsAsReadAfterVotingLinearLayout.setVisibility(View.GONE);
+ return rootView;
+ }
+
+ markPostsAsReadSwitch.setChecked(postHistorySharedPreferences.getBoolean(
+ (accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false));
+ markPostsAsReadAfterVotingSwitch.setChecked(postHistorySharedPreferences.getBoolean(
+ (accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false));
+
+ markPostsAsReadLinearLayout.setOnClickListener(view -> {
+ markPostsAsReadSwitch.performClick();
+ });
+
+ markPostsAsReadSwitch.setOnCheckedChangeListener((compoundButton, b) ->
+ postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName)
+ + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply());
+
+ markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> {
+ markPostsAsReadAfterVotingSwitch.performClick();
+ });
+
+ markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) ->
+ postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName)
+ + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply());
+
+ return rootView;
+ }
+
+ @Override
+ public void onAttach(@NonNull Context context) {
+ super.onAttach(context);
+ this.activity = (AppCompatActivity) context;
+ }
+} \ No newline at end of file
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
index 5751af30..72d85aa6 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/SharedPreferencesUtils.java
@@ -218,6 +218,10 @@ public class SharedPreferencesUtils {
public static final String BLUR_NSFW_BASE = "_blur_nsfw";
public static final String BLUR_SPOILER_BASE = "_blur_spoiler";
+ public static final String POST_HISTORY_SHARED_PREFERENCES_FILE = "ml.docilealligator.infinityforreddit.post_history";
+ public static final String MARK_POSTS_AS_READ_BASE = "_mark_posts_as_read";
+ public static final String MARK_POSTS_AS_READ_AFTER_VOTING_BASE = "_mark_posts_as_read_after_voting";
+
//Legacy Settings
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
public static final String MAIN_PAGE_TAB_2_TITLE_LEGACY = "main_page_tab_2_title";
diff --git a/app/src/main/res/drawable-night/ic_history_24dp.xml b/app/src/main/res/drawable-night/ic_history_24dp.xml
new file mode 100644
index 00000000..af91e161
--- /dev/null
+++ b/app/src/main/res/drawable-night/ic_history_24dp.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:pathData="M13,3c-4.97,0 -9,4.03 -9,9L1,12l3.89,3.89 0.07,0.14L9,12L6,12c0,-3.87 3.13,-7 7,-7s7,3.13 7,7 -3.13,7 -7,7c-1.93,0 -3.68,-0.79 -4.94,-2.06l-1.42,1.42C8.27,19.99 10.51,21 13,21c4.97,0 9,-4.03 9,-9s-4.03,-9 -9,-9zM12,8v5l4.28,2.54 0.72,-1.21 -3.5,-2.08L13.5,8L12,8z"
+ android:fillColor="#FFFFFF"/>
+</vector>
diff --git a/app/src/main/res/layout/fragment_post_history.xml b/app/src/main/res/layout/fragment_post_history.xml
new file mode 100644
index 00000000..7eb07801
--- /dev/null
+++ b/app/src/main/res/layout/fragment_post_history.xml
@@ -0,0 +1,93 @@
+<?xml version="1.0" encoding="utf-8"?>
+<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ android:orientation="vertical"
+ tools:context=".settings.NsfwAndBlurringFragment">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/info_text_view_post_history_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:padding="16dp"
+ android:drawablePadding="32dp"
+ android:text="@string/restart_app_see_changes"
+ android:textColor="@color/settingsSubtitleColor"
+ android:gravity="center_vertical"
+ android:textSize="?attr/font_default"
+ android:fontFamily="?attr/font_family"
+ app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
+
+ <LinearLayout
+ android:id="@+id/mark_posts_as_read_linear_layout_post_history_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp"
+ android:paddingStart="72dp"
+ android:paddingEnd="16dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginEnd="16dp"
+ android:layout_gravity="center_vertical"
+ android:drawablePadding="32dp"
+ android:text="@string/settings_mark_posts_as_read_title"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_16"
+ android:fontFamily="?attr/font_family" />
+
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/mark_posts_as_read_switch_post_history_fragment"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/mark_posts_as_read_after_voting_linear_layout_post_history_fragment"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingTop="4dp"
+ android:paddingBottom="4dp"
+ android:paddingStart="72dp"
+ android:paddingEnd="16dp"
+ android:clickable="true"
+ android:focusable="true"
+ android:background="?attr/selectableItemBackground">
+
+ <TextView
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_marginEnd="16dp"
+ android:layout_gravity="center_vertical"
+ android:text="@string/settings_mark_posts_as_read_after_voting_title"
+ android:textColor="?attr/primaryTextColor"
+ android:textSize="?attr/font_16"
+ android:fontFamily="?attr/font_family" />
+
+ <com.google.android.material.switchmaterial.SwitchMaterial
+ android:id="@+id/mark_posts_as_read_after_voting_switch_post_history_fragment"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical" />
+
+ </LinearLayout>
+
+ </LinearLayout>
+
+</androidx.core.widget.NestedScrollView> \ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 0843d94e..ea62ed9c 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -513,7 +513,10 @@
<string name="settings_swipe_action_swipe_right_title">Swipe Right</string>
<string name="settings_swipe_action_info_summary">Not applicable to post feed with more than 1 column or post detail.</string>
<string name="settings_language_title">Language</string>
- <string name="settings_enable_search_history">Enable Search History</string>
+ <string name="settings_enable_search_history_title">Enable Search History</string>
+ <string name="settings_post_history_title">Post History</string>
+ <string name="settings_mark_posts_as_read_title">Mark Posts As Read</string>
+ <string name="settings_mark_posts_as_read_after_voting_title">Mark Posts As Read After Voting</string>
<string name="no_link_available">Cannot get the link</string>
diff --git a/app/src/main/res/xml/main_preferences.xml b/app/src/main/res/xml/main_preferences.xml
index 666bc186..334ebd1a 100644
--- a/app/src/main/res/xml/main_preferences.xml
+++ b/app/src/main/res/xml/main_preferences.xml
@@ -58,6 +58,11 @@
app:fragment="ml.docilealligator.infinityforreddit.settings.NsfwAndBlurringFragment"/>
<Preference
+ app:icon="@drawable/ic_history_24dp"
+ android:title="@string/settings_post_history_title"
+ app:fragment="ml.docilealligator.infinityforreddit.settings.PostHistoryFragment" />
+
+ <Preference
app:icon="@drawable/ic_filter_24dp"
app:title="@string/settings_filter_title"
app:fragment="ml.docilealligator.infinityforreddit.settings.FilterPreferenceFragment"/>
diff --git a/app/src/main/res/xml/miscellaneous_preferences.xml b/app/src/main/res/xml/miscellaneous_preferences.xml
index 81a811fc..6fb763f6 100644
--- a/app/src/main/res/xml/miscellaneous_preferences.xml
+++ b/app/src/main/res/xml/miscellaneous_preferences.xml
@@ -28,7 +28,7 @@
<SwitchPreference
app:defaultValue="true"
app:key="enable_search_history"
- app:title="@string/settings_enable_search_history"
+ app:title="@string/settings_enable_search_history_title"
app:summary="@string/only_for_logged_in_user" />
<ListPreference
diff --git a/app/src/main/res/xml/post_history.xml b/app/src/main/res/xml/post_history.xml
new file mode 100644
index 00000000..624ed13a
--- /dev/null
+++ b/app/src/main/res/xml/post_history.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+
+</PreferenceScreen> \ No newline at end of file