mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-12-30 21:07:11 +01:00
Mark posts as read on scroll.
This commit is contained in:
parent
321f4da623
commit
a6f728a96b
@ -196,6 +196,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
private boolean mDisableImagePreview = false;
|
||||
private boolean mMarkPostsAsRead;
|
||||
private boolean mMarkPostsAsReadAfterVoting;
|
||||
private boolean mMarkPostsAsReadOnScroll;
|
||||
private boolean mHideReadPostsAutomatically;
|
||||
private Drawable mCommentIcon;
|
||||
private NetworkState networkState;
|
||||
@ -261,6 +262,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);
|
||||
mMarkPostsAsReadOnScroll = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false);
|
||||
mHideReadPostsAutomatically = postHistorySharedPreferences.getBoolean((accountName == null ? "" : accountName) + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false);
|
||||
|
||||
mPostLayout = postLayout;
|
||||
@ -1318,6 +1320,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
|
||||
super.onViewRecycled(holder);
|
||||
if (holder instanceof PostBaseViewHolder) {
|
||||
if (mMarkPostsAsReadOnScroll) {
|
||||
int position = holder.getAdapterPosition();
|
||||
if (position < super.getItemCount() && position >= 0) {
|
||||
Post post = getItem(position);
|
||||
((PostBaseViewHolder) holder).markPostRead(post, false);
|
||||
}
|
||||
}
|
||||
((PostBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE);
|
||||
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) holder.itemView.getLayoutParams();
|
||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
@ -1366,6 +1375,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
((PostBaseViewHolder) holder).scoreTextView.setTextColor(mPostIconAndInfoColor);
|
||||
((PostBaseViewHolder) holder).downvoteButton.setColorFilter(mPostIconAndInfoColor, android.graphics.PorterDuff.Mode.SRC_IN);
|
||||
} else if (holder instanceof PostCompactBaseViewHolder) {
|
||||
if (mMarkPostsAsReadOnScroll) {
|
||||
int position = holder.getAdapterPosition();
|
||||
if (position < super.getItemCount() && position >= 0) {
|
||||
Post post = getItem(position);
|
||||
((PostCompactBaseViewHolder) holder).markPostRead(post, false);
|
||||
}
|
||||
}
|
||||
((PostCompactBaseViewHolder) holder).itemView.setVisibility(View.VISIBLE);
|
||||
ViewGroup.LayoutParams params = holder.itemView.getLayoutParams();
|
||||
params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
|
||||
@ -1590,7 +1606,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
if (position >= 0 && canStartActivity) {
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
canStartActivity = false;
|
||||
|
||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||
@ -1706,7 +1722,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
|
||||
if (mMarkPostsAsReadAfterVoting) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
}
|
||||
|
||||
if (post.isArchived()) {
|
||||
@ -1796,7 +1812,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
|
||||
if (mMarkPostsAsReadAfterVoting) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
}
|
||||
|
||||
if (post.isArchived()) {
|
||||
@ -1949,13 +1965,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
});
|
||||
}
|
||||
|
||||
void markPostRead(Post post) {
|
||||
void markPostRead(Post post, boolean changePostItemColor) {
|
||||
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
|
||||
post.markAsRead();
|
||||
cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
|
||||
titleTextView.setTextColor(mReadPostTitleColor);
|
||||
if (this instanceof PostTextTypeViewHolder) {
|
||||
((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor);
|
||||
if (changePostItemColor) {
|
||||
cardView.setBackgroundTintList(ColorStateList.valueOf(mReadPostCardViewBackgroundColor));
|
||||
titleTextView.setTextColor(mReadPostTitleColor);
|
||||
if (this instanceof PostTextTypeViewHolder) {
|
||||
((PostTextTypeViewHolder) this).contentTextView.setTextColor(mReadPostContentColor);
|
||||
}
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
@ -2077,7 +2095,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (post.isGfycat()) {
|
||||
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT);
|
||||
@ -2322,7 +2340,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
((PostBaseViewHolder) this).markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (post.isGfycat()) {
|
||||
@ -2604,7 +2622,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null && canStartActivity) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
canStartActivity = false;
|
||||
|
||||
Intent intent = new Intent(mActivity, ViewPostDetailActivity.class);
|
||||
@ -2623,7 +2641,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
mCallback.delayTransition();
|
||||
} else {
|
||||
mCallback.delayTransition();
|
||||
ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) bottomConstraintLayout.getLayoutParams();
|
||||
ViewGroup.LayoutParams params = bottomConstraintLayout.getLayoutParams();
|
||||
params.height = 0;
|
||||
bottomConstraintLayout.setLayoutParams(params);
|
||||
}
|
||||
@ -2690,7 +2708,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
}
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
if (post.getPostType() == Post.VIDEO_TYPE) {
|
||||
Intent intent = new Intent(mActivity, ViewVideoActivity.class);
|
||||
if (post.isGfycat()) {
|
||||
@ -2756,7 +2774,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (mMarkPostsAsReadAfterVoting) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
}
|
||||
|
||||
if (post.isArchived()) {
|
||||
@ -2846,7 +2864,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
Post post = getItem(position);
|
||||
if (post != null) {
|
||||
if (mMarkPostsAsReadAfterVoting) {
|
||||
markPostRead(post);
|
||||
markPostRead(post, true);
|
||||
}
|
||||
|
||||
if (post.isArchived()) {
|
||||
@ -3000,11 +3018,13 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
|
||||
});
|
||||
}
|
||||
|
||||
void markPostRead(Post post) {
|
||||
void markPostRead(Post post, boolean changePostItemColor) {
|
||||
if (mAccessToken != null && !post.isRead() && mMarkPostsAsRead) {
|
||||
post.markAsRead();
|
||||
itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
|
||||
titleTextView.setTextColor(mReadPostTitleColor);
|
||||
if (changePostItemColor) {
|
||||
itemView.setBackgroundColor(mReadPostCardViewBackgroundColor);
|
||||
titleTextView.setTextColor(mReadPostTitleColor);
|
||||
}
|
||||
if (mActivity != null && mActivity instanceof MarkPostAsReadInterface) {
|
||||
((MarkPostAsReadInterface) mActivity).markPostAsRead(post);
|
||||
}
|
||||
|
@ -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.mark_posts_as_read_on_scroll_linear_layout_post_history_fragment)
|
||||
LinearLayout markPostsAsReadOnScrollLinearLayout;
|
||||
@BindView(R.id.mark_posts_as_read_on_scroll_switch_post_history_fragment)
|
||||
SwitchMaterial markPostsAsReadOnScrollSwitch;
|
||||
@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)
|
||||
@ -74,6 +78,8 @@ public class PostHistoryFragment extends Fragment {
|
||||
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_BASE, false));
|
||||
markPostsAsReadAfterVotingSwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, false));
|
||||
markPostsAsReadOnScrollSwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, false));
|
||||
hideReadPostsAutomaticallySwitch.setChecked(postHistorySharedPreferences.getBoolean(
|
||||
accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, false));
|
||||
|
||||
@ -89,6 +95,10 @@ public class PostHistoryFragment extends Fragment {
|
||||
markPostsAsReadAfterVotingSwitch.setOnCheckedChangeListener((compoundButton, b) ->
|
||||
postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_AFTER_VOTING_BASE, b).apply());
|
||||
|
||||
markPostsAsReadOnScrollLinearLayout.setOnClickListener(view -> markPostsAsReadOnScrollSwitch.performClick());
|
||||
|
||||
markPostsAsReadOnScrollSwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.MARK_POSTS_AS_READ_ON_SCROLL_BASE, b).apply());
|
||||
|
||||
hideReadPostsAutomaticallyLinearLayout.setOnClickListener(view -> hideReadPostsAutomaticallySwitch.performClick());
|
||||
|
||||
hideReadPostsAutomaticallySwitch.setOnCheckedChangeListener((compoundButton, b) -> postHistorySharedPreferences.edit().putBoolean(accountName + SharedPreferencesUtils.HIDE_READ_POSTS_AUTOMATICALLY_BASE, b).apply());
|
||||
|
@ -222,6 +222,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 MARK_POSTS_AS_READ_ON_SCROLL_BASE = "_mark_posts_as_read_on_scroll";
|
||||
public static final String HIDE_READ_POSTS_AUTOMATICALLY_BASE = "_hide_read_posts_automatically";
|
||||
|
||||
//Legacy Settings
|
||||
|
@ -92,6 +92,37 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/mark_posts_as_read_on_scroll_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_on_scroll_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_on_scroll_switch_post_history_fragment"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/hide_read_posts_automatically_linear_layout_post_history_fragment"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -517,8 +517,9 @@
|
||||
<string name="settings_language_title">Language</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="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_on_scroll_title">Mark Posts as Read on Scroll</string>
|
||||
<string name="settings_hide_read_posts_automatically_title">Hide Read Posts Automatically</string>
|
||||
|
||||
<string name="no_link_available">Cannot get the link</string>
|
||||
|
Loading…
Reference in New Issue
Block a user