diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-19 18:04:48 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-19 18:04:48 +0000 |
commit | 951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33 (patch) | |
tree | 4e47b3beb044eda4924d045ea9c221a724d0b5f0 | |
parent | b07dc816fd3b21911c12dec66206b0cde240c29e (diff) | |
download | infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar.gz infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar.bz2 infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar.lz infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar.xz infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.tar.zst infinity-for-reddit-951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33.zip |
Showing content preview in PostPollActivity is available.
-rw-r--r-- | app/build.gradle | 4 | ||||
-rw-r--r-- | app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java | 172 | ||||
-rw-r--r-- | app/src/main/res/menu/post_poll_activity.xml | 8 | ||||
-rw-r--r-- | app/src/main/res/values/strings.xml | 15 |
4 files changed, 111 insertions, 88 deletions
diff --git a/app/build.gradle b/app/build.gradle index b00a3e76..e4017930 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -99,7 +99,7 @@ dependencies { implementation "com.squareup.retrofit2:retrofit:$retrofitVersion" implementation "com.squareup.retrofit2:converter-scalars:$retrofitVersion" implementation "com.squareup.retrofit2:adapter-guava:$retrofitVersion" - implementation 'com.squareup.okhttp3:okhttp:4.9.1' + implementation 'com.squareup.okhttp3:okhttp:4.12.0' // Dependency injection def daggerVersion = '2.40.5' @@ -144,7 +144,7 @@ dependencies { /**** User Interface (frontend) ****/ //Image loading - def glideVersion = "4.12.0" + def glideVersion = "4.16.0" implementation "com.github.bumptech.glide:glide:$glideVersion" annotationProcessor "com.github.bumptech.glide:compiler:$glideVersion" implementation 'jp.wasabeef:glide-transformations:4.3.0' 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> |