Skip to content

Mark posts as read on scroll #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public static boolean isRefreshRequired(final Context context, final String key)
|| key.equals(context.getString(R.string.pref_behaviour_fling_post_right_key))
|| key.equals(context.getString(R.string.pref_behaviour_nsfw_key))
|| key.equals(context.getString(R.string.pref_behaviour_postcount_key))
|| key.equals(context.getString(R.string.pref_behaviour_mark_read_on_scroll_key))
|| key.equals(context.getString(R.string.pref_behaviour_comment_min_key))
|| key.equals(context.getString(R.string.pref_behaviour_pinned_subredditsort_key))
|| key.equals(context.getString(
Expand Down Expand Up @@ -1772,6 +1773,12 @@ public static boolean pref_behaviour_keep_screen_awake() {
false);
}

public static boolean pref_mark_read_on_scroll() {
return getBoolean(
R.string.pref_behaviour_mark_read_on_scroll_key,
false);
}

@Nullable
public static String pref_reddit_client_id_override() {
final String value = getString(R.string.pref_reddit_client_id_override_key, null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,43 @@ private void onLoadMoreItemsCheck() {

General.checkThisIsUIThread();

if(PrefsUtility.pref_mark_read_on_scroll()) {

final LinearLayoutManager layoutManager
= (LinearLayoutManager)mRecyclerView.getLayoutManager();

if(layoutManager != null) {

final int firstVisibleItemPosition
= layoutManager.findFirstVisibleItemPosition();

final int firstCompletelyVisibleItemPosition
= layoutManager.findFirstCompletelyVisibleItemPosition();

if(firstVisibleItemPosition >= 1
&& firstCompletelyVisibleItemPosition != 0) {

final RedditPostView view = (RedditPostView) layoutManager.getChildAt(0);

final int position =
(view != null) ? layoutManager.getPosition(view) : RecyclerView.NO_POSITION;

final RedditPreparedPost post
= (position == firstVisibleItemPosition) ? view.getPost() : null;

// Mark the first visible post read if it is unread
if((post != null) && !post.isRead()) {
new Thread() {
@Override
public void run() {
post.markAsRead(getActivity());
}
}.start();
}
}
}
}

if(mReadyToDownloadMore && mAfter != null && !mAfter.equals(mLastAfter)) {

final LinearLayoutManager layoutManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,4 +667,8 @@ private void showPrefPrompt() {
.apply();
});
}

@Nullable public RedditPreparedPost getPost() {
return mPost;
}
}
4 changes: 4 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1907,4 +1907,8 @@
<string name="video_speed_setting">Change video speed</string>
<string name="video_speed_instruction">Choose playback speed</string>
<string name="video_speed_term">Speed</string>

<!-- 2025-03-22 -->
<string name="pref_behaviour_mark_read_on_scroll_key" translatable="false">pref_behaviour_mark_read_on_scroll</string>
<string name="pref_behaviour_mark_read_on_scroll_title">Mark posts as read on scroll</string>
</resources>
4 changes: 4 additions & 0 deletions src/main/res/xml/prefs_behaviour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@
android:entryValues="@array/pref_behaviour_postcount_items_return"
android:defaultValue="ALL"/>

<CheckBoxPreference android:title="@string/pref_behaviour_mark_read_on_scroll_title"
android:key="@string/pref_behaviour_mark_read_on_scroll_key"
android:defaultValue="false" />

</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_behaviour_comments_header">
Expand Down