Fix cross posting

Closes #222
This commit is contained in:
Balazs Toldi 2023-11-10 07:49:52 +01:00
parent 55f4689984
commit e5ffaf3d97
No known key found for this signature in database
GPG Key ID: 6C7D440036F99D58
4 changed files with 29 additions and 55 deletions

View File

@ -112,8 +112,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
View divider1;
@BindView(R.id.flair_custom_text_view_submit_crosspost_activity)
CustomTextView flairTextView;
@BindView(R.id.spoiler_custom_text_view_submit_crosspost_activity)
CustomTextView spoilerTextView;
@BindView(R.id.nsfw_custom_text_view_submit_crosspost_activity)
CustomTextView nsfwTextView;
@BindView(R.id.divider_2_submit_crosspost_activity)
@ -259,11 +257,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
flairTextView.setBorderColor(flairBackgroundColor);
flairTextView.setTextColor(flairTextColor);
}
if (isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
}
if (isNSFW) {
nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
nsfwTextView.setBorderColor(nsfwBackgroundColor);
@ -287,13 +280,14 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
titleEditText.setText(post.getTitle());
}
if (post.getPostType() == Post.TEXT_TYPE) {
if (post.getPostType() == Post.TEXT_TYPE || post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getSelfTextPlain());
} else if (post.getPostType() == Post.LINK_TYPE || post.getPostType() == Post.NO_PREVIEW_LINK_TYPE) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getUrl());
contentTextView.setText(generateCrossPostText(post));
} else {
if (post.getSelfTextPlain() != null && !post.getSelfTextPlain().equals("")) {
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(generateCrossPostText(post));
}
Post.Preview preview = getPreview(post);
if (preview != null) {
frameLayout.setVisibility(View.VISIBLE);
@ -368,18 +362,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
});
spoilerTextView.setOnClickListener(view -> {
if (!isSpoiler) {
spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
spoilerTextView.setBorderColor(spoilerBackgroundColor);
spoilerTextView.setTextColor(spoilerTextColor);
isSpoiler = true;
} else {
spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
spoilerTextView.setTextColor(primaryTextColor);
isSpoiler = false;
}
});
nsfwTextView.setOnClickListener(view -> {
if (!isNSFW) {
@ -461,7 +443,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
flairTextView.setTextColor(primaryTextColor);
spoilerTextView.setTextColor(primaryTextColor);
nsfwTextView.setTextColor(primaryTextColor);
titleEditText.setTextColor(primaryTextColor);
titleEditText.setHintTextColor(secondaryTextColor);
@ -474,7 +455,6 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
rulesButton.setTypeface(typeface);
receivePostReplyNotificationsTextView.setTypeface(typeface);
flairTextView.setTypeface(typeface);
spoilerTextView.setTypeface(typeface);
nsfwTextView.setTypeface(typeface);
titleEditText.setTypeface(typeface);
}
@ -561,22 +541,19 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
mPostingSnackbar.show();
String subredditName;
if (subredditIsUser) {
subredditName = "u_" + subredditNameTextView.getText().toString();
} else {
subredditName = subredditNameTextView.getText().toString();
}
String subredditName = subredditNameTextView.getText().toString();
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, communityData.getId());
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
if (post.isCrosspost()) {
intent.putExtra(SubmitPostService.EXTRA_BODY, "t3_" + post.getCrosspostParentId());
} else {
intent.putExtra(SubmitPostService.EXTRA_BODY, post.getFullName());
intent.putExtra(SubmitPostService.EXTRA_BODY, generateCrossPostText(post));
if (post.getUrl() != null && !post.getUrl().equals("")) {
intent.putExtra(SubmitPostService.EXTRA_URL, post.getUrl());
}
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_CROSSPOST);
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
@ -699,4 +676,15 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
}
}
}
private static String generateCrossPostText(Post post) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("cross-posted from: ").append(post.getPermalink()).append("\n");
String[] lines = post.getSelfTextPlain().split("\n");
for (String line : lines) {
stringBuilder.append("> ").append(line).append("\n");
}
return stringBuilder.toString();
}
}

View File

@ -55,11 +55,11 @@ public class SubmitPost {
public static void submitCrosspost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,
int communityId, String title, String crosspostFullname,
Flair flair, boolean isSpoiler, boolean isNSFW,
String url, boolean isSpoiler, boolean isNSFW,
boolean receivePostReplyNotifications, String kind, PostEnricher postEnricher,
SubmitPostListener submitPostListener) {
submitPost(executor, handler, oauthRetrofit, accessToken, communityId, title, crosspostFullname,
isNSFW, receivePostReplyNotifications, kind, null, postEnricher, submitPostListener);
isNSFW, receivePostReplyNotifications, kind, url, postEnricher, submitPostListener);
}
private static void submitPost(Executor executor, Handler handler, Retrofit oauthRetrofit, String accessToken,

View File

@ -144,7 +144,7 @@ public class SubmitPostService extends Service {
receivePostReplyNotifications, kind);
} else if (postType == EXTRA_POST_TYPE_CROSSPOST) {
submitCrosspost(mExecutor, handler, mRetrofit.getRetrofit(), account, subredditName, title, body,
flair, isSpoiler, isNSFW, receivePostReplyNotifications);
url, isSpoiler, isNSFW, receivePostReplyNotifications);
} else if (postType == EXTRA_POST_TYPE_IMAGE) {
Uri mediaUri = Uri.parse(bundle.getString(EXTRA_MEDIA_URI));
submitImagePost(mRetrofit, account, mediaUri, subredditName, title, body, flair, isSpoiler, isNSFW,
@ -243,10 +243,10 @@ public class SubmitPostService extends Service {
private void submitCrosspost(Executor executor, Handler handler, Retrofit newAuthenticatorOauthRetrofit,
Account selectedAccount, int communityId,
String title, String content, Flair flair, boolean isSpoiler, boolean isNSFW,
String title, String content, String url, boolean isSpoiler, boolean isNSFW,
boolean receivePostReplyNotifications) {
SubmitPost.submitCrosspost(executor, handler, newAuthenticatorOauthRetrofit, selectedAccount.getAccessToken(), communityId, title,
content, flair, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST, postEnricher,
content, url, isSpoiler, isNSFW, receivePostReplyNotifications, APIUtils.KIND_CROSSPOST, postEnricher,
new SubmitPost.SubmitPostListener() {
@Override
public void submitSuccessful(Post post) {

View File

@ -124,20 +124,6 @@
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/spoiler_custom_text_view_submit_crosspost_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:padding="4dp"
android:text="@string/spoiler"
android:textColor="?attr/primaryTextColor"
android:textSize="?attr/font_default"
android:fontFamily="?attr/font_family"
app:lib_setRadius="6dp"
app:lib_setRoundedView="true"
app:lib_setShape="rectangle" />
<com.libRG.CustomTextView
android:id="@+id/nsfw_custom_text_view_submit_crosspost_activity"
android:layout_width="wrap_content"