Skip to content
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

'mark as read' fling option #3 #1049

Open
wants to merge 5 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 @@ -930,6 +930,7 @@ public enum PostFlingAction {
COPY,
USER_PROFILE,
PROPERTIES,
MARK_READ,
DISABLED
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ object RedditPostActions {
HIDE(R.string.action_hide),
UNSAVE(R.string.action_unsave),
UNHIDE(R.string.action_unhide),
MARK_READ(R.string.action_mark_read),
MARK_UNREAD(R.string.action_mark_unread),
EDIT(R.string.action_edit),
DELETE(R.string.action_delete),
REPORT(R.string.action_report),
Expand Down Expand Up @@ -134,6 +136,18 @@ object RedditPostActions {
)
}

PostFlingAction.MARK_READ -> if (post.isRead()) {
ActionDescriptionPair(
Action.MARK_UNREAD,
R.string.action_mark_unread
)
} else {
ActionDescriptionPair(
Action.MARK_READ,
R.string.action_mark_read
)
}

PostFlingAction.COMMENTS -> ActionDescriptionPair(
Action.COMMENTS,
R.string.action_comments_short
Expand Down Expand Up @@ -250,6 +264,9 @@ object RedditPostActions {

if (isOpen) {
// TODO: add an action here to jump focus from the body of the post to its comments.
}
addAccessibilityActionFromDescriptionPair(from(post, PostFlingAction.MARK_READ))
if (isOpen) {
addAccessibilityActionFromDescriptionPair(from(post, PostFlingAction.GOTO_SUBREDDIT))
if (isAuthenticated) {
if (!post.isArchived && !(post.isLocked && !post.canModerate))
Expand Down Expand Up @@ -304,6 +321,8 @@ object RedditPostActions {
Action.UNSAVE -> action(post, activity, RedditAPI.ACTION_UNSAVE)
Action.HIDE -> action(post, activity, RedditAPI.ACTION_HIDE)
Action.UNHIDE -> action(post, activity, RedditAPI.ACTION_UNHIDE)
Action.MARK_READ -> post.markAsRead(activity, true)
Action.MARK_UNREAD -> post.markAsRead(activity, false)
Action.EDIT -> {
val editIntent = Intent(activity, CommentEditActivity::class.java)
editIntent.putExtra("commentIdAndType", post.src.idAndType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,13 @@ Entry markUnvoted(final long timestamp) {
mIsHidden);
}

Entry markRead(final long timestamp) {
Entry markRead(final long timestamp, final Boolean read) {

return new Entry(
timestamp,
mIsUpvoted,
mIsDownvoted,
true,
read,
mIsSaved,
mIsHidden);
}
Expand Down Expand Up @@ -558,11 +558,14 @@ public void markHidden(
}
}

public void markRead(final long timestamp, final RedditThingWithIdAndType thing) {
public void markRead(
final long timestamp,
final RedditThingWithIdAndType thing,
final Boolean read) {

synchronized(mLock) {
final Entry existingEntry = get(thing);
final Entry updatedEntry = existingEntry.markRead(timestamp);
final Entry updatedEntry = existingEntry.markRead(timestamp, read);
set(thing, existingEntry, updatedEntry);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -796,10 +796,16 @@ public interface ThumbnailLoadedCallback {
}

public void markAsRead(final Context context) {
markAsRead(context, true);
}

public void markAsRead(
final Context context,
final Boolean read) {
final RedditAccount user =
RedditAccountManager.getInstance(context).getDefaultAccount();
RedditChangeDataManager.getInstance(user)
.markRead(RRTime.utcCurrentTimeMillis(), src);
.markRead(RRTime.utcCurrentTimeMillis(), src, read);
}

public boolean isUpvoted() {
Expand Down
3 changes: 3 additions & 0 deletions src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
<item>@string/action_user_profile</item>
<item>@string/action_properties</item>
<item>@string/action_edit</item>
<item>@string/action_mark_read</item>
</string-array>

<!-- Constants. Do not change. -->
Expand Down Expand Up @@ -486,6 +487,7 @@
<item>user_profile</item>
<item>properties</item>
<item>edit</item>
<item>mark_read</item>
</string-array>

<string-array name="pref_menus_subreddit_context_items">
Expand Down Expand Up @@ -1125,6 +1127,7 @@
<item>user_profile</item>
<item>properties</item>
<item>edit</item>
<item>mark_read</item>
</string-array>

<!-- 2020-10-31 -->
Expand Down
4 changes: 4 additions & 0 deletions src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1733,4 +1733,8 @@
<!-- 2023-01-15 -->
<string name="userprofile_avatar">Avatar</string>

<!-- 2023-01-22 -->
<string name="action_mark_read">Mark as read</string>
<string name="action_mark_unread">Mark as unread</string>

</resources>