Skip to content

Crosspost support #1169

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

Merged
merged 5 commits into from
Apr 20, 2025
Merged
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
2 changes: 2 additions & 0 deletions src/main/assets/changelog-alpha.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/Alpha 359 (2025-04-20)
Added support for emotes in comment flairs (thanks to bharatknv)
Added "Mark as Read/Unread" fling action, and optional context menu item (thanks to JoshAusHessen and codeofdusk)
Show label on crossposts, and add "Go to Crosspost Origin" to post menu (thanks to folkemat)
Added preference to prevent posts being marked as read when clicked (thanks to Daniel Ho)

/Alpha 358 (2025-03-12)
Added video playback speed control (thanks to folkemat)
Expand Down
3 changes: 2 additions & 1 deletion src/main/assets/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
114/1.25
Added video playback speed control (thanks to folkemat)
Added support for emotes in comment flairs (thanks to bharatknv)
Added "Mark as Read/Unread" fling action, and optional context menu item (thanks to JoshAusHessen and codeofdusk)
Show label on crossposts, and add "Go to Crosspost Origin" to post menu (thanks to folkemat)
Added "Mark as Read/Unread" fling action, and optional post menu item (thanks to JoshAusHessen and codeofdusk)
Added preference to prevent posts being marked as read when clicked (thanks to Daniel Ho)

113/1.24.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ private enum FeatureFlag {
OPEN_COMMENT_EXTERNALLY_FEATURE("openCommentExternallyFeature"),
POST_TITLE_TAP_ACTION_FEATURE("postTitleTapActionFeature"),
DEFAULT_PREF_VIDEO_PLAYBACK_CONTROLS("defaultPrefVideoPlaybackControls"),
DEFAULT_PREF_CUSTOM_TABS("defaultPrefCustomTabs");
DEFAULT_PREF_CUSTOM_TABS("defaultPrefCustomTabs"),
CROSSPOST_ORIGIN_MENU_ITEM("crosspostOriginMenuItem");

@NonNull private final String id;

Expand Down Expand Up @@ -307,6 +308,27 @@ public static void handleUpgrade(@NonNull final Context context) {
true)
.apply();
}

if(getAndSetFeatureFlag(prefs, FeatureFlag.CROSSPOST_ORIGIN_MENU_ITEM)
== FeatureFlagStatus.UPGRADE_NEEDED) {

Log.i(TAG, "Upgrading, add crosspost origin button to post action menu.");

final Set<String> existingPostActionMenuItems = getStringSet(
R.string.pref_menus_post_context_items_key,
R.array.pref_menus_post_context_items_default,
context,
prefs);

existingPostActionMenuItems.add("crosspost_origin");

prefs.edit()
.putStringSet(
context.getString(
R.string.pref_menus_post_context_items_key),
existingPostActionMenuItems)
.apply();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ public enum AppearancePostSubtitleItem {
SCORE,
AGE,
GOLD,
CROSSPOST,
SUBREDDIT,
DOMAIN,
STICKY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import android.content.Context;
import android.content.res.TypedArray;

import org.quantumbadger.redreader.R;

import java.util.EnumSet;
Expand All @@ -37,6 +38,8 @@ public class RRThemeAttributes {
public final int rrCommentBodyCol;
public final int rrMainTextCol;
public final int colorAccent;
public final int rrCrosspostBackCol;
public final int rrCrosspostTextCol;

private final EnumSet<PrefsUtility.AppearanceCommentHeaderItem> mCommentHeaderItems;

Expand All @@ -57,7 +60,9 @@ public RRThemeAttributes(final Context context) {
R.attr.rrCommentHeaderCol,
R.attr.rrCommentBodyCol,
R.attr.rrMainTextCol,
com.google.android.material.R.attr.colorAccent
com.google.android.material.R.attr.colorAccent,
R.attr.rrCrosspostBackCol,
R.attr.rrCrosspostTextCol
});

rrCommentHeaderBoldCol = appearance.getColor(0, 255);
Expand All @@ -72,6 +77,8 @@ public RRThemeAttributes(final Context context) {
rrCommentBodyCol = appearance.getColor(9, 255);
rrMainTextCol = appearance.getColor(10, 255);
colorAccent = appearance.getColor(11, 255);
rrCrosspostBackCol = appearance.getColor(12, 255);
rrCrosspostTextCol = appearance.getColor(13, 255);

appearance.recycle();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ import org.quantumbadger.redreader.reddit.prepared.RedditChangeDataManager
import org.quantumbadger.redreader.reddit.prepared.RedditPreparedPost
import org.quantumbadger.redreader.reddit.things.InvalidSubredditNameException
import org.quantumbadger.redreader.reddit.things.SubredditCanonicalId
import org.quantumbadger.redreader.reddit.url.PostCommentListingURL
import org.quantumbadger.redreader.reddit.url.SubredditPostListURL
import org.quantumbadger.redreader.reddit.url.UserProfileURL
import org.quantumbadger.redreader.views.AccessibilityActionManager
import org.quantumbadger.redreader.views.RedditPostView.PostSelectionListener
import org.quantumbadger.redreader.views.bezelmenu.SideToolbarOverlay
import org.quantumbadger.redreader.views.bezelmenu.VerticalToolbar


object RedditPostActions {

enum class Action(@StringRes val descriptionResId: Int) {
Expand Down Expand Up @@ -105,7 +107,9 @@ object RedditPostActions {
PIN(R.string.action_pin_subreddit),
UNPIN(R.string.action_unpin_subreddit),
SUBSCRIBE(R.string.action_subscribe_subreddit),
UNSUBSCRIBE(R.string.action_unsubscribe_subreddit)
UNSUBSCRIBE(R.string.action_unsubscribe_subreddit),
CROSSPOST_ORIGIN(R.string.action_crosspost_origin)

}

data class ActionDescriptionPair(
Expand Down Expand Up @@ -383,6 +387,11 @@ object RedditPostActions {
.setNegativeButton(R.string.dialog_cancel, null)
.show()

Action.CROSSPOST_ORIGIN -> {
val crosspostOriginPost = PostCommentListingURL.forPostId(post.src.isCrosspost)
LinkHandler.onLinkClicked(activity, crosspostOriginPost.toUriString())
}

Action.EXTERNAL -> {
try {
val url: UriString? = if (activity is WebViewActivity) activity.currentUrl else post.src.url
Expand Down Expand Up @@ -707,6 +716,18 @@ object RedditPostActions {
)
)
}
if (post.src.isCrosspost != null) {
if (itemPref.contains(Action.CROSSPOST_ORIGIN)) {
menu.add(
RPVMenuItem(
String.format(
activity.getText(R.string.action_crosspost_origin).toString(),
),
Action.CROSSPOST_ORIGIN
)
)
}
}
if (!RedditAccountManager.getInstance(activity).defaultAccount.isAnonymous) {
if (itemPref.contains(Action.SAVE)) {
if (!post.isSaved) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data class RedditPost(
val num_comments: Int,
val score: Int,
val gilded: Int = 0,
val crosspost_parent: String? = null,
val upvote_ratio: Double? = null,
val archived: Boolean = false,
val over_18: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class RedditParsedPost(
parseSelfText: Boolean
) : RedditThingWithIdAndType {

val title: String = src.title?.decoded?.replace('\n', ' ')?.trim() ?: "[null]"
val title: String = src.title?.decoded?.replace('\n', ' ')?.trim() ?: "[null]"

val url: UriString?
val selfText: BodyElement?
Expand Down Expand Up @@ -96,6 +96,8 @@ class RedditParsedPost(

val goldAmount = src.gilded

val isCrosspost = src.crosspost_parent

val isNsfw = src.over_18

val createdTimeUTC = src.created_utc.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ public SpannableStringBuilder buildSubtitle(
R.attr.rrFlairBackCol,
R.attr.rrFlairTextCol,
R.attr.rrGoldTextCol,
R.attr.rrGoldBackCol
R.attr.rrGoldBackCol,
R.attr.rrCrosspostTextCol,
R.attr.rrCrosspostBackCol
});

final int boldCol;
Expand All @@ -194,6 +196,8 @@ public SpannableStringBuilder buildSubtitle(
final int rrFlairTextCol = appearance.getColor(4, 255);
final int rrGoldTextCol = appearance.getColor(5, 255);
final int rrGoldBackCol = appearance.getColor(6, 255);
final int rrCrosspostTextCol = appearance.getColor(7, 255);
final int rrCrosspostBackCol = appearance.getColor(8, 255);

appearance.recycle();

Expand Down Expand Up @@ -239,6 +243,22 @@ public SpannableStringBuilder buildSubtitle(
}
}

if(mPostSubtitleItems.contains(PrefsUtility.AppearancePostSubtitleItem.CROSSPOST)) {
if(src.isCrosspost() != null) {
postListDescSb.append(
" "
+ context.getString(R.string.crosspost)
+ " ",
BetterSSB.BOLD
| BetterSSB.FOREGROUND_COLOR
| BetterSSB.BACKGROUND_COLOR,
rrCrosspostTextCol,
rrCrosspostBackCol,
1f);
postListDescSb.append(" ", 0);
}
}

if(mPostSubtitleItems.contains(PrefsUtility.AppearancePostSubtitleItem.NSFW)) {
if(src.isNsfw()) {
postListDescSb.append(
Expand Down Expand Up @@ -666,6 +686,15 @@ private String buildAccessibilityEmbellishments(
}
}

if(mPostSubtitleItems.contains(PrefsUtility.AppearancePostSubtitleItem.CROSSPOST)) {
if(src.isCrosspost() != null) {
a11yEmbellish
.append(context.getString(
R.string.accessibility_subtitle_crosspost))
.append(separator);
}
}

return a11yEmbellish.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,15 +281,18 @@ public String humanReadablePath() {
return builder.toString();
}

@NonNull
public UriString browserUrl() {
return new UriString(Constants.Reddit.SCHEME_HTTPS + "://" + humanReadableUrl());
}

@Override
@NonNull
public String toString() {
return generateJsonUri().toString();
}

@NonNull
public UriString toUriString() {
return new UriString(toString());
}
Expand Down
6 changes: 6 additions & 0 deletions src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@
<item>@string/action_upvote</item>
<item>@string/action_downvote</item>
<item>@string/action_comments</item>
<item>@string/action_crosspost_origin</item>
<item>@string/action_save</item>
<item>@string/action_hide</item>
<item>@string/action_delete</item>
Expand Down Expand Up @@ -469,6 +470,7 @@
<item>upvote</item>
<item>downvote</item>
<item>comments</item>
<item>crosspost_origin</item>
<item>save</item>
<item>hide</item>
<item>delete</item>
Expand Down Expand Up @@ -877,6 +879,7 @@
<item>@string/pref_appearance_post_subtitle_items_sticky</item>
<item>@string/pref_appearance_post_subtitle_items_spoiler</item>
<item>@string/pref_appearance_post_subtitle_items_nsfw</item>
<item>@string/pref_appearance_post_subtitle_items_crosspost</item>
</string-array>

<!-- Constants. Do not change. -->
Expand All @@ -893,6 +896,7 @@
<item>sticky</item>
<item>spoiler</item>
<item>nsfw</item>
<item>crosspost</item>
</string-array>

<!-- Constants. Do not change. -->
Expand All @@ -907,6 +911,7 @@
<item>sticky</item>
<item>spoiler</item>
<item>nsfw</item>
<item>crosspost</item>
</string-array>

<!-- 2020-02-05 -->
Expand Down Expand Up @@ -1131,6 +1136,7 @@
<item>user_profile</item>
<item>properties</item>
<item>edit</item>
<item>crosspost_origin</item>
</string-array>

<!-- 2020-10-31 -->
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
<attr name="rrGoldBackCol" format="color" />
<attr name="rrGoldTextCol" format="color" />
<attr name="rrPostInlinePreviewDivider" format="color" />
<attr name="rrCrosspostBackCol" format="color" />
<attr name="rrCrosspostTextCol" format="color" />

<attr name="rrCommentBodyCol" format="color" />
<attr name="rrCommentHeaderCol" format="color" />
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 @@ -1914,4 +1914,8 @@
<string name="pref_behaviour_mark_posts_as_read_key" translatable="false">pref_behaviour_mark_posts_as_read</string>
<string name="pref_behaviour_mark_posts_as_read_title">Mark posts as read</string>

<string name="crosspost">Crosspost</string>
<string name="pref_appearance_post_subtitle_items_crosspost">Crosspost tag</string>
<string name="accessibility_subtitle_crosspost">Crosspost.</string>
<string name="action_crosspost_origin">Go to Crosspost Origin</string>
</resources>
8 changes: 8 additions & 0 deletions src/main/res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@
<item name="rrFlairTextCol">#AAAAAA</item>
<item name="rrGoldBackCol">#B0923C</item>
<item name="rrGoldTextCol">#000000</item>
<item name="rrCrosspostBackCol">#0288D1</item>
<item name="rrCrosspostTextCol">#FFFFFF</item>

<item name="rrPostToolbarCol">#181818</item>

Expand Down Expand Up @@ -195,6 +197,8 @@
<item name="rrFlairTextCol">#AAAAAA</item>
<item name="rrGoldBackCol">#B0923C</item>
<item name="rrGoldTextCol">#000000</item>
<item name="rrCrosspostBackCol">#0288D1</item>
<item name="rrCrosspostTextCol">#FFFFFF</item>

<!-- Comment -->

Expand Down Expand Up @@ -263,6 +267,8 @@
<item name="rrFlairTextCol">#AAAAAA</item>
<item name="rrGoldBackCol">#B0923C</item>
<item name="rrGoldTextCol">#000000</item>
<item name="rrCrosspostBackCol">#0288D1</item>
<item name="rrCrosspostTextCol">#FFFFFF</item>

<item name="rrPostToolbarCol">#000000</item>

Expand Down Expand Up @@ -387,6 +393,8 @@
<item name="rrFlairTextCol">#444444</item>
<item name="rrGoldBackCol">#FFDF52</item>
<item name="rrGoldTextCol">#000000</item>
<item name="rrCrosspostBackCol">#0288D1</item>
<item name="rrCrosspostTextCol">#FFFFFF</item>

<item name="rrPostToolbarCol">#F2FBFB</item>

Expand Down
Loading