mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-14 06:22:50 +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.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@ -34,7 +33,6 @@ public class PostFilter implements Parcelable {
|
|||||||
|
|
||||||
public static boolean isPostAllowed(Post post, PostFilter postFilter) {
|
public static boolean isPostAllowed(Post post, PostFilter postFilter) {
|
||||||
if (postFilter == null || post == null) {
|
if (postFilter == null || post == null) {
|
||||||
Log.i("asdasfd", "s " + post.getTitle());
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (post.isNSFW() && !postFilter.allowNSFW) {
|
if (post.isNSFW() && !postFilter.allowNSFW) {
|
||||||
|
@ -196,6 +196,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
private boolean mDisableImagePreview = false;
|
private boolean mDisableImagePreview = false;
|
||||||
private boolean mMarkPostsAsRead;
|
private boolean mMarkPostsAsRead;
|
||||||
private boolean mMarkPostsAsReadAfterVoting;
|
private boolean mMarkPostsAsReadAfterVoting;
|
||||||
|
private boolean mHideReadPostsAutomatically;
|
||||||
private Drawable mCommentIcon;
|
private Drawable mCommentIcon;
|
||||||
private NetworkState networkState;
|
private NetworkState networkState;
|
||||||
private ExoCreator mExoCreator;
|
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);
|
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);
|
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;
|
mPostLayout = postLayout;
|
||||||
|
|
||||||
@ -401,7 +403,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
Post post = getItem(position);
|
Post post = getItem(position);
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
if (post.isRead()) {
|
if (post.isRead()) {
|
||||||
if (position < mHideReadPostsIndex) {
|
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) {
|
||||||
post.hidePostInRecyclerView();
|
post.hidePostInRecyclerView();
|
||||||
holder.itemView.setVisibility(View.GONE);
|
holder.itemView.setVisibility(View.GONE);
|
||||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
||||||
@ -723,7 +725,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
|||||||
Post post = getItem(position);
|
Post post = getItem(position);
|
||||||
if (post != null) {
|
if (post != null) {
|
||||||
if (post.isRead()) {
|
if (post.isRead()) {
|
||||||
if (position < mHideReadPostsIndex) {
|
if (mHideReadPostsAutomatically || position < mHideReadPostsIndex) {
|
||||||
post.hidePostInRecyclerView();
|
post.hidePostInRecyclerView();
|
||||||
holder.itemView.setVisibility(View.GONE);
|
holder.itemView.setVisibility(View.GONE);
|
||||||
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
||||||
|
@ -39,6 +39,10 @@ public class PostHistoryFragment extends Fragment {
|
|||||||
LinearLayout markPostsAsReadAfterVotingLinearLayout;
|
LinearLayout markPostsAsReadAfterVotingLinearLayout;
|
||||||
@BindView(R.id.mark_posts_as_read_after_voting_switch_post_history_fragment)
|
@BindView(R.id.mark_posts_as_read_after_voting_switch_post_history_fragment)
|
||||||
SwitchMaterial markPostsAsReadAfterVotingSwitch;
|
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
|
@Inject
|
||||||
@Named("post_history")
|
@Named("post_history")
|
||||||
SharedPreferences postHistorySharedPreferences;
|
SharedPreferences postHistorySharedPreferences;
|
||||||
@ -67,25 +71,27 @@ public class PostHistoryFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
markPostsAsReadSwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
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(
|
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 -> {
|
markPostsAsReadLinearLayout.setOnClickListener(view -> {
|
||||||
markPostsAsReadSwitch.performClick();
|
markPostsAsReadSwitch.performClick();
|
||||||
});
|
});
|
||||||
|
|
||||||
markPostsAsReadSwitch.setOnCheckedChangeListener((compoundButton, b) ->
|
markPostsAsReadSwitch.setOnCheckedChangeListener((compoundButton, b) ->
|
||||||
postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName)
|
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply());
|
||||||
+ SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, b).apply());
|
|
||||||
|
|
||||||
markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> {
|
markPostsAsReadAfterVotingLinearLayout.setOnClickListener(view -> markPostsAsReadAfterVotingSwitch.performClick());
|
||||||
markPostsAsReadAfterVotingSwitch.performClick();
|
|
||||||
});
|
|
||||||
|
|
||||||
markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) ->
|
markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) ->
|
||||||
postHistorySharedPreferences.edit().putBoolean((accountName == null ? "" : accountName)
|
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply());
|
||||||
+ 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;
|
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 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_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 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
|
//Legacy Settings
|
||||||
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
|
public static final String MAIN_PAGE_TAB_1_TITLE_LEGACY = "main_page_tab_1_title";
|
||||||
|
@ -25,6 +25,11 @@
|
|||||||
android:fontFamily="?attr/font_family"
|
android:fontFamily="?attr/font_family"
|
||||||
app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
|
app:drawableStartCompat="@drawable/ic_info_preference_24dp" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:background="@color/dividerColor" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/mark_posts_as_read_linear_layout_post_history_fragment"
|
android:id="@+id/mark_posts_as_read_linear_layout_post_history_fragment"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@ -88,6 +93,37 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</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>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
</androidx.core.widget.NestedScrollView>
|
@ -517,6 +517,7 @@
|
|||||||
<string name="settings_post_history_title">Post 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_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_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>
|
<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