mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 20:57:25 +01:00
New feature: Hide read posts automatically.
This commit is contained in:
parent
c293e9f22f
commit
68bdee3952
@ -2,7 +2,6 @@ package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
@ -34,7 +33,6 @@ public class PostFilter implements Parcelable {
|
||||
|
||||
public static boolean isPostAllowed(Post post, PostFilter postFilter) {
|
||||
if (postFilter == null || post == null) {
|
||||
Log.i("asdasfd", "s " + post.getTitle());
|
||||
return true;
|
||||
}
|
||||
if (post.isNSFW() && !postFilter.allowNSFW) {
|
||||
|
@ -196,6 +196,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
private boolean mDisableImagePreview = false;
|
||||
private boolean mMarkPostsAsRead;
|
||||
private boolean mMarkPostsAsReadAfterVoting;
|
||||
private boolean mHideReadPostsAutomatically;
|
||||
private Drawable mCommentIcon;
|
||||
private NetworkState networkState;
|
||||
private ExoCreator mExoCreator;
|
||||
@ -260,6 +261,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
|
||||
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);
|
||||
mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false);
|
||||
|
||||
mPostLayout = postLayout;
|
||||
|
||||
@ -401,7 +403,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (post.isRead()) {
|
||||
if (position < mHideReadPostsIndex) {
|
||||
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) {
|
||||
post.hidePostInRecyclerView();
|
||||
holder.itemView.setVisibility(View.GONE);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
||||
@ -723,7 +725,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (post.isRead()) {
|
||||
if (position < mHideReadPostsIndex) {
|
||||
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) {
|
||||
post.hidePostInRecyclerView();
|
||||
holder.itemView.setVisibility(View.GONE);
|
||||
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
||||
|
@ -39,6 +39,10 @@ public class PostHistoryFragment extends Fragment {
|
||||
LinearLayout markPostsAsReadAfterVotingLinearLayout;
|
||||
@BindView(R.id.mark_posts_as_read_after_voting_switch_post_history_fragment)
|
||||
SwitchMaterial markPostsAsReadAfterVotingSwitch;
|
||||
@BindView(R.id.hide_read_posts_automatically_linear_layout_post_history_fragment)
|
||||
LinearLayout hideReadPostsAutomaticallyLinearLayout;
|
||||
@BindView(R.id.hide_read_posts_automatically_switch_post_history_fragment)
|
||||
SwitchMaterial hideReadPostsAutomaticallySwitch;
|
||||
@Inject
|
||||
@Named("post_history")
|
||||
SharedPreferences postHistorySharedPreferences;
|
||||
@ -67,25 +71,27 @@ public class PostHistoryFragment extends Fragment {
|
||||
}
|
||||
|
||||
markPostsAsReadSwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
(accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false));
|
||||
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false));
|
||||
markPostsAsReadAfterVotingSwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
(accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false));
|
||||
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false));
|
||||
hideReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_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());
|
||||
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply());
|
||||
|
||||
markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> {
|
||||
markPostsAsReadAfterVotingSwitch.performClick();
|
||||
});
|
||||
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());
|
||||
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply());
|
||||
|
||||
hideReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> hideReadPostsAutomaticallySwitch.performClick());
|
||||
|
||||
hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply());
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
@ -221,6 +221,7 @@ public class SharedPreferencesUtils {
|
||||
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";
|
||||
public static final String HIDE_READ_POSTS_AUTOMATICALLY_BASE = "_hide_read_posts_automatically";
|
||||
|
||||
//Legacy Settings
|
||||
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
|
||||
|
@ -25,6 +25,11 @@
|
||||
android:fontFamily="?attr/font_family"
|
||||
app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="@color/dividerColor" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/mark_posts_as_read_linear_layout_post_history_fragment"
|
||||
android:layout_width="match_parent"
|
||||
@ -88,6 +93,37 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/hide_read_posts_automatically_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_hide_read_posts_automatically_title"
|
||||
android:textColor="?attr/primaryTextColor"
|
||||
android:textSize="?attr/font_16"
|
||||
android:fontFamily="?attr/font_family" />
|
||||
|
||||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/hide_read_posts_automatically_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>
|
@ -517,6 +517,7 @@
|
||||
<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="settings_hide_read_posts_automatically_title">Hide Read Posts Automatically</string>
|
||||
|
||||
<string name="no_link_available">Cannot get the link</string>
|
||||
|
||||
|
@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
</PreferenceScreen>
|
Loading…
Reference in New Issue
Block a user