diff options
Diffstat (limited to 'app/src/main/java')
8 files changed, 172 insertions, 18 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"; |