aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-22 11:36:17 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-22 11:36:17 +0000
commitd2900b66c4a12dadf42cd54d6d3a113a6189e23a (patch)
tree91920579ad12aa080d78120cd12eec496b79becd /app
parent8b0aed58b21b4ba5f62b4785b145d1b95ff3965e (diff)
downloadinfinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar.gz
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar.bz2
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar.lz
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar.xz
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.tar.zst
infinity-for-reddit-d2900b66c4a12dadf42cd54d6d3a113a6189e23a.zip
Directly send comment in FullMarkdownActivity for CommentActivity.
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java95
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java1
2 files changed, 56 insertions, 40 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
index 6d9abd84..cbbcdd17 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
@@ -91,6 +91,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
public static final int WRITE_COMMENT_REQUEST_CODE = 1;
private static final int PICK_IMAGE_REQUEST_CODE = 100;
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
+ private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
private static final String UPLOADED_IMAGES_STATE = "UIS";
@BindView(R.id.coordinator_layout_comment_activity)
@@ -134,6 +135,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
private int markdownColor;
private Uri capturedImageUri;
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
+ private Menu mMenu;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -335,6 +337,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.comment_activity, menu);
+ mMenu = menu;
applyMenuItemTheme(menu);
return true;
}
@@ -349,59 +352,69 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, commentEditText.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
- startActivity(intent);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (itemId == R.id.action_send_comment_activity) {
- if (!isSubmitting) {
- isSubmitting = true;
- if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
- isSubmitting = false;
- Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ sendComment(item);
+ return true;
+ }
+
+ return false;
+ }
+ public void sendComment(@Nullable MenuItem item) {
+ if (!isSubmitting) {
+ isSubmitting = true;
+ if (commentEditText.getText() == null || commentEditText.getText().toString().equals("")) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.comment_content_required, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
+
+ if (item != null) {
item.setEnabled(false);
item.getIcon().setAlpha(130);
- Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
- sendingSnackbar.show();
-
- SendComment.sendComment(mExecutor, new Handler(), commentEditText.getText().toString(),
- parentFullname, parentDepth, mOauthRetrofit, mAccessToken,
- new SendComment.SendCommentListener() {
- @Override
- public void sendCommentSuccess(Comment comment) {
- isSubmitting = false;
+ }
+ Snackbar sendingSnackbar = Snackbar.make(coordinatorLayout, R.string.sending_comment, Snackbar.LENGTH_INDEFINITE);
+ sendingSnackbar.show();
+
+ SendComment.sendComment(mExecutor, new Handler(), commentEditText.getText().toString(),
+ parentFullname, parentDepth, mOauthRetrofit, mAccessToken,
+ new SendComment.SendCommentListener() {
+ @Override
+ public void sendCommentSuccess(Comment comment) {
+ isSubmitting = false;
+ if (item != null) {
item.setEnabled(true);
item.getIcon().setAlpha(255);
- Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
- Intent returnIntent = new Intent();
- returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
- returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
- if (isReplying) {
- returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
- }
- setResult(RESULT_OK, returnIntent);
- finish();
}
+ Toast.makeText(CommentActivity.this, R.string.send_comment_success, Toast.LENGTH_SHORT).show();
+ Intent returnIntent = new Intent();
+ returnIntent.putExtra(RETURN_EXTRA_COMMENT_DATA_KEY, comment);
+ returnIntent.putExtra(EXTRA_PARENT_FULLNAME_KEY, parentFullname);
+ if (isReplying) {
+ returnIntent.putExtra(EXTRA_PARENT_POSITION_KEY, parentPosition);
+ }
+ setResult(RESULT_OK, returnIntent);
+ finish();
+ }
- @Override
- public void sendCommentFailed(@Nullable String errorMessage) {
- isSubmitting = false;
- sendingSnackbar.dismiss();
+ @Override
+ public void sendCommentFailed(@Nullable String errorMessage) {
+ isSubmitting = false;
+ sendingSnackbar.dismiss();
+ if (item != null) {
item.setEnabled(true);
item.getIcon().setAlpha(255);
+ }
- if (errorMessage == null || !errorMessage.equals("")) {
- Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
- } else {
- Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
- }
+ if (errorMessage == null || !errorMessage.equals("")) {
+ Snackbar.make(coordinatorLayout, R.string.send_comment_failed, Snackbar.LENGTH_SHORT).show();
+ } else {
+ Snackbar.make(coordinatorLayout, errorMessage, Snackbar.LENGTH_SHORT).show();
}
- });
- }
- return true;
+ }
+ });
}
-
- return false;
}
private void promptAlertDialog(int titleResId, int messageResId) {
@@ -428,6 +441,8 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, commentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ sendComment(mMenu == null ? null : mMenu.findItem(R.id.action_send_comment_activity));
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
index 117adf81..8ed8fa5e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java
@@ -240,6 +240,7 @@ public class FullMarkdownActivity extends BaseActivity {
public boolean onCreateOptionsMenu(Menu menu) {
if (getIntent().getBooleanExtra(EXTRA_SUBMIT_POST, false)) {
getMenuInflater().inflate(R.menu.full_markdown_activity, menu);
+ applyMenuItemTheme(menu);
return true;
}