Skip to content

Ability to mark individual messages as read in the inbox #1238

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 1 commit 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 @@ -117,6 +117,8 @@ public static boolean isRefreshRequired(final Context context, final String key)
|| key.equals(context.getString(R.string.pref_behaviour_pinned_subredditsort_key))
|| key.equals(context.getString(
R.string.pref_behaviour_blocked_subredditsort_key))
|| key.equals(context.getString(
R.string.pref_behaviour_inbox_tapping_is_reading_key))
|| key.equals(context.getString(
R.string.pref_appearance_hide_headertoolbar_commentlist_key))
|| key.equals(context.getString(
Expand Down Expand Up @@ -887,6 +889,12 @@ public static boolean pref_behaviour_post_title_opens_comments() {
false);
}

public static boolean pref_behaviour_inbox_tapping_is_reading() {
return getBoolean(
R.string.pref_behaviour_inbox_tapping_is_reading_key,
false);
}

// pref_behaviour_imageview_mode

public enum ImageViewMode {
Expand Down
35 changes: 35 additions & 0 deletions src/main/java/org/quantumbadger/redreader/reddit/RedditAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,41 @@ public void onDataStreamComplete(
}));
}

public static void markMessageAsRead(
final CacheManager cm,
final APIResponseHandler.ActionResponseHandler responseHandler,
final RedditAccount user,
final String messageId,
final Context context) {

final LinkedList<PostField> postFields = new LinkedList<>();

postFields.add(new PostField("id", messageId));

cm.makeRequest(createPostRequestUnprocessedResponse(
Constants.Reddit.getUri("/api/read_message"),
user,
postFields,
context,
new CacheRequestCallbacks() {
@Override
public void onFailure(@NonNull final RRError error) {
responseHandler.notifyFailure(error);
}

@Override
public void onDataStreamComplete(
@NonNull final GenericFactory<SeekableInputStream, IOException> stream,
final TimestampUTC timestamp,
@NonNull final UUID session,
final boolean fromCache,
@Nullable final String mimetype) {

responseHandler.notifySuccess();
}
}));
}

public static void editComment(
final CacheManager cm,
final APIResponseHandler.ActionResponseHandler responseHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,22 @@
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import org.quantumbadger.redreader.account.RedditAccountManager;
import org.quantumbadger.redreader.activities.BaseActivity;
import org.quantumbadger.redreader.activities.BugReportActivity;
import org.quantumbadger.redreader.cache.CacheManager;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.common.Optional;
import org.quantumbadger.redreader.common.PrefsUtility;
import org.quantumbadger.redreader.common.RRError;
import org.quantumbadger.redreader.common.RRThemeAttributes;
import org.quantumbadger.redreader.reddit.APIResponseHandler;
import org.quantumbadger.redreader.reddit.RedditAPI;
import org.quantumbadger.redreader.reddit.prepared.RedditChangeDataManager;
import org.quantumbadger.redreader.reddit.prepared.RedditPreparedMessage;
import org.quantumbadger.redreader.reddit.prepared.RedditRenderableComment;
import org.quantumbadger.redreader.reddit.prepared.RedditRenderableInboxItem;

public class RedditInboxItemView extends LinearLayout {
Expand Down Expand Up @@ -140,6 +150,43 @@ public void reset(
public void handleInboxClick(final BaseActivity activity) {
if(currentItem != null) {
currentItem.handleInboxClick(activity);

//Mark clicked msg as read
if (PrefsUtility.pref_behaviour_inbox_tapping_is_reading()) {
final String messageID;
//Two different types of inbox messages
if (currentItem instanceof RedditRenderableComment){
final RedditRenderableComment comment = ((RedditRenderableComment) currentItem);
messageID = String.valueOf(comment.getIdAndType());
} else if (currentItem instanceof RedditPreparedMessage){
final RedditPreparedMessage message = ((RedditPreparedMessage) currentItem);
messageID = String.valueOf(message.idAndType);
} else {
return;
}
RedditAPI.markMessageAsRead(
CacheManager.getInstance(activity),
new APIResponseHandler.ActionResponseHandler(activity) {
@Override
protected void onSuccess() {
// Do nothing (result expected)
}

@Override
protected void onFailure(@NonNull final RRError error) {
General.showResultDialog(activity, error);
}

@Override
protected void onCallbackException(final Throwable t) {
BugReportActivity.handleGlobalError(activity, t);
}
},
RedditAccountManager.getInstance(activity).getDefaultAccount(),
messageID,
activity
);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1902,4 +1902,9 @@
<string name="album_grid_pref_horizontal_padding">Horizontal padding</string>

<string name="album_pref_compact_title">Compact title</string>

<!-- 2024-09-06 -->
<string name="pref_behaviour_inbox_header">Inbox</string>
<string name="pref_behaviour_inbox_tapping_is_reading_key" translatable="false">pref_behaviour_inbox_tapping_is_reading</string>
<string name="pref_behaviour_inbox_tapping_is_reading_title">Tapping a message marks it as read</string>
</resources>
8 changes: 8 additions & 0 deletions src/main/res/xml/prefs_behaviour.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,14 @@

</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_behaviour_inbox_header">

<CheckBoxPreference android:title="@string/pref_behaviour_inbox_tapping_is_reading_title"
android:key="@string/pref_behaviour_inbox_tapping_is_reading_key"
android:defaultValue="false"/>

</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_behaviour_sharing_header">

<ListPreference android:title="@string/pref_behaviour_sharing_domain_title"
Expand Down