aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java172
-rw-r--r--app/src/main/res/menu/post_poll_activity.xml8
-rw-r--r--app/src/main/res/values/strings.xml15
3 files changed, 109 insertions, 86 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
index 31684679..872d288f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
@@ -46,7 +46,6 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
-import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Flair;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -132,7 +131,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
private boolean isSpoiler = false;
private boolean isNSFW = false;
private Resources resources;
- private Menu mMemu;
+ private Menu mMenu;
private RequestManager mGlide;
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
private Snackbar mPostingSnackbar;
@@ -520,10 +519,10 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.post_poll_activity, menu);
applyMenuItemTheme(menu);
- mMemu = menu;
+ mMenu = menu;
if (isPosting) {
- mMemu.findItem(R.id.action_send_post_poll_activity).setEnabled(false);
- mMemu.findItem(R.id.action_send_post_poll_activity).getIcon().setAlpha(130);
+ mMenu.findItem(R.id.action_send_post_poll_activity).setEnabled(false);
+ mMenu.findItem(R.id.action_send_post_poll_activity).getIcon().setAlpha(130);
}
return true;
}
@@ -550,95 +549,106 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
}
finish();
return true;
- } else if (itemId == R.id.action_send_post_poll_activity) {
- if (!subredditSelected) {
- Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
- return true;
+ } else if (itemId == R.id.action_preview_post_poll_activity) {
+ Intent intent = new Intent(this, FullMarkdownActivity.class);
+ intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.postContentEditTextPostPollActivity.getText().toString());
+ intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
+ if (!uploadedImages.isEmpty()) {
+ intent.putParcelableArrayListExtra("test", uploadedImages);
}
+ startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE);
+ } else if (itemId == R.id.action_send_post_poll_activity) {
+ submitPost(item);
+ return true;
+ }
- if (binding.postTitleEditTextPostPollActivity.getText() == null) {
- Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.title_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ return false;
+ }
- String subredditName;
- if (subredditIsUser) {
- subredditName = "u_" + binding.subredditNameTextViewPostPollActivity.getText().toString();
- } else {
- subredditName = binding.subredditNameTextViewPostPollActivity.getText().toString();
- }
+ private void submitPost(MenuItem item) {
+ if (!subredditSelected) {
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
- ArrayList<String> optionList = new ArrayList<>();
- if (!binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
- if (!binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
- if (!binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
- if (!binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
- if (!binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
- if (!binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
- optionList.add(binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString());
- }
-
- if (optionList.size() < 2) {
- Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.two_options_required, Snackbar.LENGTH_SHORT).show();
- return true;
- }
+ if (binding.postTitleEditTextPostPollActivity.getText() == null) {
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
+
+ String subredditName;
+ if (subredditIsUser) {
+ subredditName = "u_" + binding.subredditNameTextViewPostPollActivity.getText().toString();
+ } else {
+ subredditName = binding.subredditNameTextViewPostPollActivity.getText().toString();
+ }
+
+ ArrayList<String> optionList = new ArrayList<>();
+ if (!binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
+ if (!binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
+ if (!binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
+ if (!binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
+ if (!binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
+ if (!binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString().isEmpty()) {
+ optionList.add(binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString());
+ }
- isPosting = true;
+ if (optionList.size() < 2) {
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.two_options_required, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
- item.setEnabled(false);
- item.getIcon().setAlpha(130);
+ isPosting = true;
- mPostingSnackbar.show();
+ item.setEnabled(false);
+ item.getIcon().setAlpha(130);
- Intent intent = new Intent(this, SubmitPostService.class);
- intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
- intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_POLL);
+ mPostingSnackbar.show();
- PollPayload payload;
- if (!binding.postContentEditTextPostPollActivity.getText().toString().isEmpty()) {
- if (uploadedImages.isEmpty()) {
- payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
- optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
- null, binding.postContentEditTextPostPollActivity.getText().toString(),
- binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
- subredditIsUser ? "profile" : "subreddit");
- } else {
- try {
- payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
- optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
- new RichTextJSONConverter().constructRichTextJSON(this, binding.postContentEditTextPostPollActivity.getText().toString(), uploadedImages),
- null, binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
- subredditIsUser ? "profile" : "subreddit");
- } catch (JSONException e) {
- Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.convert_to_richtext_json_failed, Snackbar.LENGTH_SHORT).show();
- return true;
- }
- }
- } else {
+ Intent intent = new Intent(this, SubmitPostService.class);
+ intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
+ intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
+ intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TYPE_POLL);
+
+ PollPayload payload;
+ if (!binding.postContentEditTextPostPollActivity.getText().toString().isEmpty()) {
+ if (uploadedImages.isEmpty()) {
payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
+ null, binding.postContentEditTextPostPollActivity.getText().toString(),
binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
subredditIsUser ? "profile" : "subreddit");
+ } else {
+ try {
+ payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
+ optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
+ new RichTextJSONConverter().constructRichTextJSON(this, binding.postContentEditTextPostPollActivity.getText().toString(), uploadedImages),
+ null, binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
+ subredditIsUser ? "profile" : "subreddit");
+ } catch (JSONException e) {
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.convert_to_richtext_json_failed, Snackbar.LENGTH_SHORT).show();
+ return;
+ }
}
- intent.putExtra(SubmitPostService.EXTRA_POLL_PAYLOAD, new Gson().toJson(payload));
-
- ContextCompat.startForegroundService(this, intent);
-
- return true;
+ } else {
+ payload = new PollPayload(subredditName, binding.postTitleEditTextPostPollActivity.getText().toString(),
+ optionList.toArray(new String[0]), (int) binding.votingLengthSliderPostPollActivity.getValue(), isNSFW, isSpoiler, flair,
+ binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.isChecked(),
+ subredditIsUser ? "profile" : "subreddit");
}
+ intent.putExtra(SubmitPostService.EXTRA_POLL_PAYLOAD, new Gson().toJson(payload));
- return false;
+ ContextCompat.startForegroundService(this, intent);
}
@Override
@@ -706,6 +716,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
accessToken, binding.postContentEditTextPostPollActivity, binding.coordinatorLayoutPostPollActivity, capturedImageUri, uploadedImages);
+ } else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
+ submitPost(mMenu.findItem(R.id.action_send_post_poll_activity));
}
}
}
@@ -789,8 +801,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
startActivity(intent);
finish();
} else {
- mMemu.findItem(R.id.action_send_post_poll_activity).setEnabled(true);
- mMemu.findItem(R.id.action_send_post_poll_activity).getIcon().setAlpha(255);
+ mMenu.findItem(R.id.action_send_post_poll_activity).setEnabled(true);
+ mMenu.findItem(R.id.action_send_post_poll_activity).getIcon().setAlpha(255);
if (submitPollPostEvent.errorMessage == null || submitPollPostEvent.errorMessage.isEmpty()) {
Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
diff --git a/app/src/main/res/menu/post_poll_activity.xml b/app/src/main/res/menu/post_poll_activity.xml
index e497c4e5..a0c5e65f 100644
--- a/app/src/main/res/menu/post_poll_activity.xml
+++ b/app/src/main/res/menu/post_poll_activity.xml
@@ -2,8 +2,14 @@
<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_post_poll_activity"
+ android:id="@+id/action_preview_post_poll_activity"
android:orderInCategory="1"
+ android:title="@string/action_preview"
+ android:icon="@drawable/ic_preview_24dp"
+ app:showAsAction="ifRoom" />
+ <item
+ android:id="@+id/action_send_post_poll_activity"
+ android:orderInCategory="2"
android:title="@string/action_send"
android:icon="@drawable/ic_send_toolbar_24dp"
app:showAsAction="ifRoom" />
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 5dce1f90..3a27f838 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1215,13 +1215,18 @@
<string name="reply">Reply</string>
<string name="uploaded_images">Uploaded Images</string>
- <string name="uploaded_images_explanation">This is an experimental feature, and here are some things you need to know:
- \n1. Uploaded images will not be shown in the text editor, and instead, a piece of text will be inserted as a block,
+ <string name="uploaded_images_explanation">This is an experimental feature, and here are some things you need to know:\n
+ 1. Uploaded images will not be shown in the text editor, and instead, a piece of text will be inserted as a block,
with a format similar to ![](XXXXX). XXXXX is the image id, and it should not be modified. To add a caption for
your image, simply type between the brackets. Example: ![This is a caption](XXXXX). Note that the caption will be treated
- as plain text.\n2. To write a superscript, please use ^(), and put the texts inside the parentheses, instead of only
- using a single ^.\n3. This feature converts your markdown to rich text format and some formatting may be lost in the
- process.\n4. You cannot edit a submitted post with embedded images in it.</string>
+ as plain text.\n
+ 2. To write a superscript, please use ^(), and put the texts inside the parentheses, instead of only
+ using a single ^. For simplicity, click the superscript option in the formatting tools to insert a superscript.\n
+ 3. This feature converts your markdown to rich text format and some formatting may be lost in the process.\n
+ 4. Uploaded images may not be shown on the preview screen.
+ 5. You cannot edit a submitted post with embedded images in it.\n
+ 6. Please do not change your account using the account chooser on the editing screen. You should switch
+ your account in the navigation drawer on the main screen.</string>
<string name="select_image">Select an Image</string>
<string name="capture">Capture</string>
<string name="uploading_image">Uploading</string>