Directly submit post in FullMarkdownActivity.

This commit is contained in:
Alex Ning 2021-07-22 19:26:36 +08:00
parent 7803b376b2
commit 8b0aed58b2
6 changed files with 78 additions and 38 deletions

View File

@ -348,6 +348,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
} else if (itemId == R.id.action_preview_comment_activity) { } else if (itemId == R.id.action_preview_comment_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class); Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, commentEditText.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, commentEditText.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
startActivity(intent); startActivity(intent);
} else if (itemId == R.id.action_send_comment_activity) { } else if (itemId == R.id.action_send_comment_activity) {
if (!isSubmitting) { if (!isSubmitting) {

View File

@ -206,6 +206,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
if (item.getItemId() == R.id.action_preview_edit_comment_activity) { if (item.getItemId() == R.id.action_preview_edit_comment_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class); Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
startActivity(intent); startActivity(intent);
} else if (item.getItemId() == R.id.action_send_edit_comment_activity) { } else if (item.getItemId() == R.id.action_send_edit_comment_activity) {
if (!isSubmitting) { if (!isSubmitting) {

View File

@ -218,6 +218,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
if (item.getItemId() == R.id.action_preview_edit_post_activity) { if (item.getItemId() == R.id.action_preview_edit_post_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class); Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
startActivity(intent); startActivity(intent);
} else if (item.getItemId() == R.id.action_send_edit_post_activity) { } else if (item.getItemId() == R.id.action_send_edit_post_activity) {
if (!isSubmitting) { if (!isSubmitting) {

View File

@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.activities; package ml.docilealligator.infinityforreddit.activities;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Color; import android.graphics.Color;
@ -11,6 +12,7 @@ import android.text.Spanned;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.ClickableSpan; import android.text.style.ClickableSpan;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.Window; import android.view.Window;
@ -58,6 +60,7 @@ public class FullMarkdownActivity extends BaseActivity {
public static final String EXTRA_COMMENT_MARKDOWN = "ECM"; public static final String EXTRA_COMMENT_MARKDOWN = "ECM";
public static final String EXTRA_IS_NSFW = "EIN"; public static final String EXTRA_IS_NSFW = "EIN";
public static final String EXTRA_SUBMIT_POST = "ESP";
@BindView(R.id.coordinator_layout_comment_full_markdown_activity) @BindView(R.id.coordinator_layout_comment_full_markdown_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -233,11 +236,26 @@ public class FullMarkdownActivity extends BaseActivity {
markwonAdapter.notifyDataSetChanged(); markwonAdapter.notifyDataSetChanged();
} }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
if (getIntent().getBooleanExtra(EXTRA_SUBMIT_POST, false)) {
getMenuInflater().inflate(R.menu.full_markdown_activity, menu);
return true;
}
return false;
}
@Override @Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == android.R.id.home) { if (item.getItemId() == android.R.id.home) {
finish(); finish();
return true; return true;
} else if (item.getItemId() == R.id.action_send_full_markdown_activity) {
Intent returnIntent = new Intent();
setResult(Activity.RESULT_OK, returnIntent);
finish();
return true;
} }
return false; return false;

View File

@ -91,6 +91,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0; private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
private static final int PICK_IMAGE_REQUEST_CODE = 100; private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200; private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
@BindView(R.id.coordinator_layout_post_text_activity) @BindView(R.id.coordinator_layout_post_text_activity)
CoordinatorLayout coordinatorLayout; CoordinatorLayout coordinatorLayout;
@ -474,51 +475,57 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else if (itemId == R.id.action_preview_post_text_activity) { } else if (itemId == R.id.action_preview_post_text_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class); Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
startActivity(intent); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (itemId == R.id.action_send_post_text_activity) { } else if (itemId == R.id.action_send_post_text_activity) {
if (!subredditSelected) { submitPost(item);
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return true;
}
if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
return true;
}
isPosting = true;
item.setEnabled(false);
item.getIcon().setAlpha(130);
mPostingSnackbar.show();
String subredditName;
if (subredditIsUser) {
subredditName = "u_" + subredditNameTextView.getText().toString();
} else {
subredditName = subredditNameTextView.getText().toString();
}
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
ContextCompat.startForegroundService(this, intent);
return true; return true;
} }
return false; return false;
} }
private void submitPost(MenuItem item) {
if (!subredditSelected) {
Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return;
}
if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
return;
}
isPosting = true;
if (item != null) {
item.setEnabled(false);
item.getIcon().setAlpha(130);
}
mPostingSnackbar.show();
String subredditName;
if (subredditIsUser) {
subredditName = "u_" + subredditNameTextView.getText().toString();
} else {
subredditName = subredditNameTextView.getText().toString();
}
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCESS_TOKEN, mAccessToken);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
intent.putExtra(SubmitPostService.EXTRA_KIND, APIUtils.KIND_SELF);
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
ContextCompat.startForegroundService(this, intent);
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {
if (isPosting) { if (isPosting) {
@ -577,6 +584,8 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) { } else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit, Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages); mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
submitPost(mMenu.findItem(R.id.action_send_post_text_activity));
} }
} }

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_send_full_markdown_activity"
android:orderInCategory="1"
android:title="@string/action_send"
android:icon="@drawable/ic_send_toolbar_24dp"
app:showAsAction="ifRoom" />
</menu>