aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2021-07-22 11:40:04 +0000
committerAlex Ning <chineseperson5@gmail.com>2021-07-22 11:40:04 +0000
commit346cb491f32e13d6a3f46d91148a6e7fa2e1c201 (patch)
treedf194944330f68ebecedb48e170fc8807a042da4
parentd2900b66c4a12dadf42cd54d6d3a113a6189e23a (diff)
downloadinfinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar.gz
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar.bz2
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar.lz
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar.xz
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.tar.zst
infinity-for-reddit-346cb491f32e13d6a3f46d91148a6e7fa2e1c201.zip
Directly edit post in FullMarkdownActivity for EditPostActivity.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java67
1 files changed, 37 insertions, 30 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
index e17e8753..13ee9fa3 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java
@@ -70,6 +70,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
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";
@@ -219,37 +220,9 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
Intent intent = new Intent(this, FullMarkdownActivity.class);
intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
- startActivity(intent);
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
} else if (item.getItemId() == R.id.action_send_edit_post_activity) {
- if (!isSubmitting) {
- isSubmitting = true;
-
- Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
-
- Map<String, String> params = new HashMap<>();
- params.put(APIUtils.THING_ID_KEY, mFullName);
- params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
-
- mOauthRetrofit.create(RedditAPI.class)
- .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
- .enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
- isSubmitting = false;
- Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
- Intent returnIntent = new Intent();
- setResult(RESULT_OK, returnIntent);
- finish();
- }
-
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- isSubmitting = false;
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
- }
- });
-
- }
+ editPost();
return true;
} else if (item.getItemId() == android.R.id.home) {
onBackPressed();
@@ -258,6 +231,38 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
return false;
}
+ private void editPost() {
+ if (!isSubmitting) {
+ isSubmitting = true;
+
+ Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_SHORT).show();
+
+ Map<String, String> params = new HashMap<>();
+ params.put(APIUtils.THING_ID_KEY, mFullName);
+ params.put(APIUtils.TEXT_KEY, contentEditText.getText().toString());
+
+ mOauthRetrofit.create(RedditAPI.class)
+ .editPostOrComment(APIUtils.getOAuthHeader(mAccessToken), params)
+ .enqueue(new Callback<String>() {
+ @Override
+ public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ isSubmitting = false;
+ Toast.makeText(EditPostActivity.this, R.string.edit_success, Toast.LENGTH_SHORT).show();
+ Intent returnIntent = new Intent();
+ setResult(RESULT_OK, returnIntent);
+ finish();
+ }
+
+ @Override
+ public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ isSubmitting = false;
+ Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ }
+ });
+
+ }
+ }
+
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -272,6 +277,8 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
mAccessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ editPost();
}
}
}