aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java/ml/docilealligator/infinityforreddit
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java25
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java543
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java13
7 files changed, 363 insertions, 261 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java
index 0e33d3ed..1383ddf9 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PollPayload.java
@@ -14,6 +14,8 @@ public class PollPayload {
public String flairId;
@SerializedName("flair_text")
public String flairText;
+ @SerializedName("raw_rtjson")
+ public String richTextJSON;
@SerializedName("post_to_twitter")
public boolean postToTwitter = false;
@SerializedName("sendreplies")
@@ -26,12 +28,14 @@ public class PollPayload {
public String subredditName;
@SerializedName("submit_type")
public String submitType;
+ public String text;
public String title;
@SerializedName("validate_on_submit")
public boolean validateOnSubmit = true;
public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw,
- boolean isSpoiler, Flair flair, boolean sendReplies, String submitType) {
+ boolean isSpoiler, Flair flair, boolean sendReplies,
+ String submitType) {
this.subredditName = subredditName;
this.title = title;
this.options = options;
@@ -45,4 +49,23 @@ public class PollPayload {
this.sendReplies = sendReplies;
this.submitType = submitType;
}
+
+ public PollPayload(String subredditName, String title, String[] options, int duration, boolean isNsfw,
+ boolean isSpoiler, Flair flair, String richTextJSON, String text, boolean sendReplies,
+ String submitType) {
+ this.subredditName = subredditName;
+ this.title = title;
+ this.options = options;
+ this.duration = duration;
+ this.isNsfw = isNsfw;
+ this.isSpoiler = isSpoiler;
+ if (flair != null) {
+ flairId = flair.getId();
+ flairText = flair.getText();
+ }
+ this.richTextJSON = richTextJSON;
+ this.text = text;
+ this.sendReplies = sendReplies;
+ this.submitType = submitType;
+ }
}
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 78460e00..58f03537 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java
@@ -573,9 +573,16 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA
public void insertImageUrl(UploadedImage uploadedImage) {
int start = Math.max(binding.commentCommentEditText.getSelectionStart(), 0);
int end = Math.max(binding.commentCommentEditText.getSelectionEnd(), 0);
- binding.commentCommentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
- "![](" + uploadedImage.imageUrlOrKey + ")",
- 0, "![]()".length() + uploadedImage.imageUrlOrKey.length());
+ int realStart = Math.min(start, end);
+ if (realStart > 0 && binding.commentCommentEditText.getText().toString().charAt(realStart - 1) != '\n') {
+ binding.commentCommentEditText.getText().replace(realStart, Math.max(start, end),
+ "\n![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "\n![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ } else {
+ binding.commentCommentEditText.getText().replace(realStart, Math.max(start, end),
+ "![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
index a8caa0f0..c9dfc79e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java
@@ -386,8 +386,15 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab
public void insertImageUrl(UploadedImage uploadedImage) {
int start = Math.max(contentEditText.getSelectionStart(), 0);
int end = Math.max(contentEditText.getSelectionEnd(), 0);
- contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
- "![](" + uploadedImage.imageUrlOrKey + ")",
- 0, "![]()".length() + uploadedImage.imageUrlOrKey.length());
+ int realStart = Math.min(start, end);
+ if (realStart > 0 && contentEditText.getText().toString().charAt(realStart - 1) != '\n') {
+ contentEditText.getText().replace(realStart, Math.max(start, end),
+ "\n![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "\n![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ } else {
+ contentEditText.getText().replace(realStart, Math.max(start, end),
+ "![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ }
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
index 73d7f0be..6bebaf35 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/MainActivity.java
@@ -136,7 +136,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
ActivityToolbarInterface, FABMoreOptionsBottomSheetFragment.FABOptionSelectionCallback,
RandomBottomSheetFragment.RandomOptionSelectionCallback, MarkPostAsReadInterface, RecyclerViewContentScrollingInterface {
- static final String EXTRA_MESSSAGE_FULLNAME = "ENF";
+ static final String EXTRA_MESSAGE_FULLNAME = "ENF";
static final String EXTRA_NEW_ACCOUNT_NAME = "ENAN";
private static final String FETCH_USER_INFO_STATE = "FUIS";
@@ -327,7 +327,7 @@ public class MainActivity extends BaseActivity implements SortTypeSelectionCallb
mNewAccountName = savedInstanceState.getString(NEW_ACCOUNT_NAME_STATE);
inboxCount = savedInstanceState.getInt(INBOX_COUNT_STATE);
} else {
- mMessageFullname = getIntent().getStringExtra(EXTRA_MESSSAGE_FULLNAME);
+ mMessageFullname = getIntent().getStringExtra(EXTRA_MESSAGE_FULLNAME);
mNewAccountName = getIntent().getStringExtra(EXTRA_NEW_ACCOUNT_NAME);
}
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 b03723d9..ec95327b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java
@@ -1,5 +1,6 @@
package ml.docilealligator.infinityforreddit.activities;
+import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.ColorStateList;
@@ -9,38 +10,35 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Handler;
+import android.provider.MediaStore;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
-import android.widget.LinearLayout;
import android.widget.TextView;
+import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
-import androidx.appcompat.widget.Toolbar;
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
+import androidx.core.content.FileProvider;
+import androidx.recyclerview.widget.LinearLayoutManager;
import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.request.RequestOptions;
-import com.google.android.material.appbar.AppBarLayout;
-import com.google.android.material.button.MaterialButton;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
-import com.google.android.material.divider.MaterialDivider;
-import com.google.android.material.materialswitch.MaterialSwitch;
-import com.google.android.material.slider.Slider;
import com.google.android.material.snackbar.Snackbar;
-import com.google.android.material.textfield.TextInputEditText;
-import com.google.android.material.textfield.TextInputLayout;
import com.google.gson.Gson;
-import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
+import org.json.JSONException;
+import java.io.File;
+import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.concurrent.Executor;
@@ -48,7 +46,6 @@ import java.util.concurrent.Executor;
import javax.inject.Inject;
import javax.inject.Named;
-import butterknife.BindView;
import butterknife.ButterKnife;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.Flair;
@@ -56,20 +53,26 @@ import ml.docilealligator.infinityforreddit.Infinity;
import ml.docilealligator.infinityforreddit.PollPayload;
import ml.docilealligator.infinityforreddit.R;
import ml.docilealligator.infinityforreddit.RedditDataRoomDatabase;
+import ml.docilealligator.infinityforreddit.UploadImageEnabledActivity;
+import ml.docilealligator.infinityforreddit.UploadedImage;
import ml.docilealligator.infinityforreddit.account.Account;
+import ml.docilealligator.infinityforreddit.adapters.MarkdownBottomBarRecyclerViewAdapter;
import ml.docilealligator.infinityforreddit.asynctasks.LoadSubredditIcon;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.AccountChooserBottomSheetFragment;
import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomSheetFragment;
+import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
+import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
+import ml.docilealligator.infinityforreddit.databinding.ActivityPostPollBinding;
import ml.docilealligator.infinityforreddit.events.SubmitPollPostEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
+import ml.docilealligator.infinityforreddit.markdown.RichTextJSONConverter;
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
import ml.docilealligator.infinityforreddit.utils.Utils;
-import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class PostPollActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
- AccountChooserBottomSheetFragment.AccountChooserListener {
+ UploadImageEnabledActivity, AccountChooserBottomSheetFragment.AccountChooserListener {
static final String EXTRA_SUBREDDIT_NAME = "ESN";
@@ -83,75 +86,13 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
private static final String FLAIR_STATE = "FS";
private static final String IS_SPOILER_STATE = "ISS";
private static final String IS_NSFW_STATE = "INS";
+ private static final String UPLOADED_IMAGES_STATE = "UIS";
private static final int SUBREDDIT_SELECTION_REQUEST_CODE = 0;
+ 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;
- @BindView(R.id.coordinator_layout_post_poll_activity)
- CoordinatorLayout coordinatorLayout;
- @BindView(R.id.appbar_layout_post_poll_activity)
- AppBarLayout appBarLayout;
- @BindView(R.id.toolbar_post_poll_activity)
- Toolbar toolbar;
- @BindView(R.id.account_linear_layout_post_poll_activity)
- LinearLayout accountLinearLayout;
- @BindView(R.id.account_icon_gif_image_view_post_poll_activity)
- GifImageView accountIconImageView;
- @BindView(R.id.account_name_text_view_post_poll_activity)
- TextView accountNameTextView;
- @BindView(R.id.subreddit_icon_gif_image_view_post_poll_activity)
- GifImageView iconGifImageView;
- @BindView(R.id.subreddit_name_text_view_post_poll_activity)
- TextView subredditNameTextView;
- @BindView(R.id.rules_button_post_poll_activity)
- MaterialButton rulesButton;
- @BindView(R.id.divider_1_post_poll_activity)
- MaterialDivider divider1;
- @BindView(R.id.flair_custom_text_view_post_poll_activity)
- CustomTextView flairTextView;
- @BindView(R.id.spoiler_custom_text_view_post_poll_activity)
- CustomTextView spoilerTextView;
- @BindView(R.id.nsfw_custom_text_view_post_poll_activity)
- CustomTextView nsfwTextView;
- @BindView(R.id.receive_post_reply_notifications_linear_layout_post_poll_activity)
- LinearLayout receivePostReplyNotificationsLinearLayout;
- @BindView(R.id.receive_post_reply_notifications_text_view_post_poll_activity)
- TextView receivePostReplyNotificationsTextView;
- @BindView(R.id.receive_post_reply_notifications_switch_material_post_poll_activity)
- MaterialSwitch receivePostReplyNotificationsSwitchMaterial;
- @BindView(R.id.divider_2_post_poll_activity)
- MaterialDivider divider2;
- @BindView(R.id.post_title_edit_text_post_poll_activity)
- EditText titleEditText;
- @BindView(R.id.divider_3_post_poll_activity)
- MaterialDivider divider3;
- @BindView(R.id.voting_length_text_view_post_poll_activity)
- TextView votingLengthTextView;
- @BindView(R.id.voting_length_seek_bar_post_poll_activity)
- Slider votingLengthSlider;
- @BindView(R.id.option_1_text_input_layout_post_poll_activity)
- TextInputLayout option1TextInputLayout;
- @BindView(R.id.option_1_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option1TextInputEditText;
- @BindView(R.id.option_2_text_input_layout_post_poll_activity)
- TextInputLayout option2TextInputLayout;
- @BindView(R.id.option_2_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option2TextInputEditText;
- @BindView(R.id.option_3_text_input_layout_post_poll_activity)
- TextInputLayout option3TextInputLayout;
- @BindView(R.id.option_3_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option3TextInputEditText;
- @BindView(R.id.option_4_text_input_layout_post_poll_activity)
- TextInputLayout option4TextInputLayout;
- @BindView(R.id.option_4_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option4TextInputEditText;
- @BindView(R.id.option_5_text_input_layout_post_poll_activity)
- TextInputLayout option5TextInputLayout;
- @BindView(R.id.option_5_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option5TextInputEditText;
- @BindView(R.id.option_6_text_input_layout_post_poll_activity)
- TextInputLayout option6TextInputLayout;
- @BindView(R.id.option_6_text_input_layout_edit_text_post_poll_activity)
- TextInputEditText option6TextInputEditText;
@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@@ -159,6 +100,9 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
@Named("oauth")
Retrofit mOauthRetrofit;
@Inject
+ @Named("upload_media")
+ Retrofit mUploadMediaRetrofit;
+ @Inject
RedditDataRoomDatabase mRedditDataRoomDatabase;
@Inject
@Named("default")
@@ -192,6 +136,9 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
private RequestManager mGlide;
private FlairBottomSheetFragment flairSelectionBottomSheetFragment;
private Snackbar mPostingSnackbar;
+ private Uri capturedImageUri;
+ private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
+ private ActivityPostPollBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -200,7 +147,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
setImmersiveModeNotApplicable();
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_post_poll);
+ binding = ActivityPostPollBinding.inflate(getLayoutInflater());
+ setContentView(binding.getRoot());
ButterKnife.bind(this);
@@ -209,15 +157,15 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
applyCustomTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
- addOnOffsetChangedListener(appBarLayout);
+ addOnOffsetChangedListener(binding.appbarLayoutPostPollActivity);
}
- setSupportActionBar(toolbar);
+ setSupportActionBar(binding.toolbarPostPollActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
- mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
+ mPostingSnackbar = Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.posting, Snackbar.LENGTH_INDEFINITE);
resources = getResources();
@@ -234,23 +182,24 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
flair = savedInstanceState.getParcelable(FLAIR_STATE);
isSpoiler = savedInstanceState.getBoolean(IS_SPOILER_STATE);
isNSFW = savedInstanceState.getBoolean(IS_NSFW_STATE);
+ uploadedImages = savedInstanceState.getParcelableArrayList(UPLOADED_IMAGES_STATE);
if (selectedAccount != null) {
mGlide.load(selectedAccount.getProfileImageUrl())
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(accountIconImageView);
+ .into(binding.accountIconGifImageViewPostPollActivity);
- accountNameTextView.setText(selectedAccount.getAccountName());
+ binding.accountNameTextViewPostPollActivity.setText(selectedAccount.getAccountName());
} else {
loadCurrentAccount();
}
if (subredditName != null) {
- subredditNameTextView.setTextColor(primaryTextColor);
- subredditNameTextView.setText(subredditName);
- flairTextView.setVisibility(View.VISIBLE);
+ binding.subredditNameTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostPollActivity.setText(subredditName);
+ binding.flairCustomTextViewPostPollActivity.setVisibility(View.VISIBLE);
if (!loadSubredditIconSuccessful) {
loadSubredditIcon();
}
@@ -262,20 +211,20 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
}
if (flair != null) {
- flairTextView.setText(flair.getText());
- flairTextView.setBackgroundColor(flairBackgroundColor);
- flairTextView.setBorderColor(flairBackgroundColor);
- flairTextView.setTextColor(flairTextColor);
+ binding.flairCustomTextViewPostPollActivity.setText(flair.getText());
+ binding.flairCustomTextViewPostPollActivity.setBackgroundColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostPollActivity.setBorderColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostPollActivity.setTextColor(flairTextColor);
}
if (isSpoiler) {
- spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
- spoilerTextView.setBorderColor(spoilerBackgroundColor);
- spoilerTextView.setTextColor(spoilerTextColor);
+ binding.spoilerCustomTextViewPostPollActivity.setBackgroundColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostPollActivity.setBorderColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostPollActivity.setTextColor(spoilerTextColor);
}
if (isNSFW) {
- nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
- nsfwTextView.setBorderColor(nsfwBackgroundColor);
- nsfwTextView.setTextColor(nsfwTextColor);
+ binding.nsfwCustomTextViewPostPollActivity.setBackgroundColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostPollActivity.setBorderColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostPollActivity.setTextColor(nsfwTextColor);
}
} else {
isPosting = false;
@@ -286,33 +235,33 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
loadSubredditIconSuccessful = false;
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
subredditSelected = true;
- subredditNameTextView.setTextColor(primaryTextColor);
- subredditNameTextView.setText(subredditName);
- flairTextView.setVisibility(View.VISIBLE);
+ binding.subredditNameTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostPollActivity.setText(subredditName);
+ binding.flairCustomTextViewPostPollActivity.setVisibility(View.VISIBLE);
loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(iconGifImageView);
+ .into(binding.subredditIconGifImageViewPostPollActivity);
}
}
- accountLinearLayout.setOnClickListener(view -> {
+ binding.accountLinearLayoutPostPollActivity.setOnClickListener(view -> {
AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment();
fragment.show(getSupportFragmentManager(), fragment.getTag());
});
- iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick());
+ binding.subredditIconGifImageViewPostPollActivity.setOnClickListener(view -> binding.subredditNameTextViewPostPollActivity.performClick());
- subredditNameTextView.setOnClickListener(view -> {
+ binding.subredditNameTextViewPostPollActivity.setOnClickListener(view -> {
Intent intent = new Intent(this, SubredditSelectionActivity.class);
intent.putExtra(SubredditSelectionActivity.EXTRA_SPECIFIED_ACCOUNT, selectedAccount);
startActivityForResult(intent, SUBREDDIT_SELECTION_REQUEST_CODE);
});
- rulesButton.setOnClickListener(view -> {
+ binding.rulesButtonPostPollActivity.setOnClickListener(view -> {
if (subredditName == null) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(this, RulesActivity.class);
if (subredditIsUser) {
@@ -324,7 +273,7 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
}
});
- flairTextView.setOnClickListener(view -> {
+ binding.flairCustomTextViewPostPollActivity.setOnClickListener(view -> {
if (flair == null) {
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
Bundle bundle = new Bundle();
@@ -332,45 +281,70 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
flairSelectionBottomSheetFragment.setArguments(bundle);
flairSelectionBottomSheetFragment.show(getSupportFragmentManager(), flairSelectionBottomSheetFragment.getTag());
} else {
- flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- flairTextView.setTextColor(primaryTextColor);
- flairTextView.setText(getString(R.string.flair));
+ binding.flairCustomTextViewPostPollActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.flairCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.flairCustomTextViewPostPollActivity.setText(getString(R.string.flair));
flair = null;
}
});
- spoilerTextView.setOnClickListener(view -> {
+ binding.spoilerCustomTextViewPostPollActivity.setOnClickListener(view -> {
if (!isSpoiler) {
- spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
- spoilerTextView.setBorderColor(spoilerBackgroundColor);
- spoilerTextView.setTextColor(spoilerTextColor);
+ binding.spoilerCustomTextViewPostPollActivity.setBackgroundColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostPollActivity.setBorderColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostPollActivity.setTextColor(spoilerTextColor);
isSpoiler = true;
} else {
- spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- spoilerTextView.setTextColor(primaryTextColor);
+ binding.spoilerCustomTextViewPostPollActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.spoilerCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
isSpoiler = false;
}
});
- nsfwTextView.setOnClickListener(view -> {
+ binding.nsfwCustomTextViewPostPollActivity.setOnClickListener(view -> {
if (!isNSFW) {
- nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
- nsfwTextView.setBorderColor(nsfwBackgroundColor);
- nsfwTextView.setTextColor(nsfwTextColor);
+ binding.nsfwCustomTextViewPostPollActivity.setBackgroundColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostPollActivity.setBorderColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostPollActivity.setTextColor(nsfwTextColor);
isNSFW = true;
} else {
- nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- nsfwTextView.setTextColor(primaryTextColor);
+ binding.nsfwCustomTextViewPostPollActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.nsfwCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
isNSFW = false;
}
});
- receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
- receivePostReplyNotificationsSwitchMaterial.performClick();
+ binding.receivePostReplyNotificationsLinearLayoutPostPollActivity.setOnClickListener(view -> {
+ binding.receivePostReplyNotificationsSwitchMaterialPostPollActivity.performClick();
});
- votingLengthTextView.setText(getString(R.string.voting_length, (int) votingLengthSlider.getValue()));
- votingLengthSlider.addOnChangeListener((slider, value, fromUser) -> votingLengthTextView.setText(getString(R.string.voting_length, (int) value)));
+ binding.votingLengthTextViewPostPollActivity.setText(getString(R.string.voting_length, (int) binding.votingLengthSliderPostPollActivity.getValue()));
+ binding.votingLengthSliderPostPollActivity.addOnChangeListener((slider, value, fromUser) -> binding.votingLengthTextViewPostPollActivity.setText(getString(R.string.voting_length, (int) value)));
+
+ MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
+ mCustomThemeWrapper, true,
+ new MarkdownBottomBarRecyclerViewAdapter.ItemClickListener() {
+ @Override
+ public void onClick(int item) {
+ MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(
+ PostPollActivity.this, binding.postContentEditTextPostPollActivity, item);
+ }
+
+ @Override
+ public void onUploadImage() {
+ Utils.hideKeyboard(PostPollActivity.this);
+ UploadedImagesBottomSheetFragment fragment = new UploadedImagesBottomSheetFragment();
+ Bundle arguments = new Bundle();
+ arguments.putParcelableArrayList(UploadedImagesBottomSheetFragment.EXTRA_UPLOADED_IMAGES,
+ uploadedImages);
+ fragment.setArguments(arguments);
+ fragment.show(getSupportFragmentManager(), fragment.getTag());
+ }
+ });
+
+ binding.markdownBottomBarRecyclerViewPostPollActivity.setLayoutManager(new LinearLayoutManagerBugFixed(this,
+ LinearLayoutManager.HORIZONTAL, false));
+ binding.markdownBottomBarRecyclerViewPostPollActivity.setAdapter(adapter);
}
private void loadCurrentAccount() {
@@ -384,9 +358,9 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(accountIconImageView);
+ .into(binding.accountIconGifImageViewPostPollActivity);
- accountNameTextView.setText(account.getAccountName());
+ binding.accountNameTextViewPostPollActivity.setText(account.getAccountName());
}
});
});
@@ -409,85 +383,87 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
@Override
protected void applyCustomTheme() {
- coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
- applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
+ binding.coordinatorLayoutPostPollActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutPostPollActivity, null, binding.toolbarPostPollActivity);
primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
- accountNameTextView.setTextColor(primaryTextColor);
+ binding.accountNameTextViewPostPollActivity.setTextColor(primaryTextColor);
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
- subredditNameTextView.setTextColor(secondaryTextColor);
- rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
- receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostPollActivity.setTextColor(secondaryTextColor);
+ binding.rulesButtonPostPollActivity.setTextColor(mCustomThemeWrapper.getButtonTextColor());
+ binding.rulesButtonPostPollActivity.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ binding.receivePostReplyNotificationsTextViewPostPollActivity.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
- divider1.setDividerColor(dividerColor);
- divider2.setDividerColor(dividerColor);
- divider3.setDividerColor(dividerColor);
+ binding.divider1PostPollActivity.setDividerColor(dividerColor);
+ binding.divider2PostPollActivity.setDividerColor(dividerColor);
+ binding.divider3PostPollActivity.setDividerColor(dividerColor);
flairBackgroundColor = mCustomThemeWrapper.getFlairBackgroundColor();
flairTextColor = mCustomThemeWrapper.getFlairTextColor();
spoilerBackgroundColor = mCustomThemeWrapper.getSpoilerBackgroundColor();
spoilerTextColor = mCustomThemeWrapper.getSpoilerTextColor();
nsfwBackgroundColor = mCustomThemeWrapper.getNsfwBackgroundColor();
nsfwTextColor = mCustomThemeWrapper.getNsfwTextColor();
- flairTextView.setTextColor(primaryTextColor);
- spoilerTextView.setTextColor(primaryTextColor);
- nsfwTextView.setTextColor(primaryTextColor);
- titleEditText.setTextColor(primaryTextColor);
- titleEditText.setHintTextColor(secondaryTextColor);
- option1TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option1TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option1TextInputEditText.setTextColor(primaryTextColor);
-
- option2TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option2TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option2TextInputEditText.setTextColor(primaryTextColor);
-
- option3TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option3TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option3TextInputEditText.setTextColor(primaryTextColor);
-
- option4TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option4TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option4TextInputEditText.setTextColor(primaryTextColor);
-
- option5TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option5TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option5TextInputEditText.setTextColor(primaryTextColor);
-
- option6TextInputLayout.setBoxStrokeColor(primaryTextColor);
- option6TextInputLayout.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
- option6TextInputEditText.setTextColor(primaryTextColor);
+ binding.flairCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.spoilerCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.nsfwCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.postTitleEditTextPostPollActivity.setTextColor(primaryTextColor);
+ binding.postTitleEditTextPostPollActivity.setHintTextColor(secondaryTextColor);
+ binding.postContentEditTextPostPollActivity.setTextColor(primaryTextColor);
+ binding.postContentEditTextPostPollActivity.setHintTextColor(secondaryTextColor);
+ binding.option1TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option1TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option1TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
+
+ binding.option2TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option2TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option2TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
+
+ binding.option3TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option3TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option3TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
+
+ binding.option4TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option4TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option4TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
+
+ binding.option5TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option5TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option5TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
+
+ binding.option6TextInputLayoutPostPollActivity.setBoxStrokeColor(primaryTextColor);
+ binding.option6TextInputLayoutPostPollActivity.setDefaultHintTextColor(ColorStateList.valueOf(primaryTextColor));
+ binding.option6TextInputLayoutEditTextPostPollActivity.setTextColor(primaryTextColor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
Drawable cursorDrawable = Utils.getTintedDrawable(this, R.drawable.edit_text_cursor, primaryTextColor);
- option1TextInputEditText.setTextCursorDrawable(cursorDrawable);
- option2TextInputEditText.setTextCursorDrawable(cursorDrawable);
- option3TextInputEditText.setTextCursorDrawable(cursorDrawable);
- option4TextInputEditText.setTextCursorDrawable(cursorDrawable);
- option5TextInputEditText.setTextCursorDrawable(cursorDrawable);
- option6TextInputEditText.setTextCursorDrawable(cursorDrawable);
+ binding.option1TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
+ binding.option2TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
+ binding.option3TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
+ binding.option4TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
+ binding.option5TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
+ binding.option6TextInputLayoutEditTextPostPollActivity.setTextCursorDrawable(cursorDrawable);
} else {
- setCursorDrawableColor(option1TextInputEditText, primaryTextColor);
- setCursorDrawableColor(option2TextInputEditText, primaryTextColor);
- setCursorDrawableColor(option3TextInputEditText, primaryTextColor);
- setCursorDrawableColor(option4TextInputEditText, primaryTextColor);
- setCursorDrawableColor(option5TextInputEditText, primaryTextColor);
- setCursorDrawableColor(option6TextInputEditText, primaryTextColor);
+ setCursorDrawableColor(binding.option1TextInputLayoutEditTextPostPollActivity, primaryTextColor);
+ setCursorDrawableColor(binding.option2TextInputLayoutEditTextPostPollActivity, primaryTextColor);
+ setCursorDrawableColor(binding.option3TextInputLayoutEditTextPostPollActivity, primaryTextColor);
+ setCursorDrawableColor(binding.option4TextInputLayoutEditTextPostPollActivity, primaryTextColor);
+ setCursorDrawableColor(binding.option5TextInputLayoutEditTextPostPollActivity, primaryTextColor);
+ setCursorDrawableColor(binding.option6TextInputLayoutEditTextPostPollActivity, primaryTextColor);
}
if (typeface != null) {
- subredditNameTextView.setTypeface(typeface);
- rulesButton.setTypeface(typeface);
- receivePostReplyNotificationsTextView.setTypeface(typeface);
- flairTextView.setTypeface(typeface);
- spoilerTextView.setTypeface(typeface);
- nsfwTextView.setTypeface(typeface);
- titleEditText.setTypeface(typeface);
- option1TextInputEditText.setTypeface(typeface);
- option2TextInputEditText.setTypeface(typeface);
- option3TextInputEditText.setTypeface(typeface);
- option4TextInputEditText.setTypeface(typeface);
- option5TextInputEditText.setTypeface(typeface);
- option6TextInputEditText.setTypeface(typeface);
+ binding.subredditNameTextViewPostPollActivity.setTypeface(typeface);
+ binding.rulesButtonPostPollActivity.setTypeface(typeface);
+ binding.receivePostReplyNotificationsTextViewPostPollActivity.setTypeface(typeface);
+ binding.flairCustomTextViewPostPollActivity.setTypeface(typeface);
+ binding.spoilerCustomTextViewPostPollActivity.setTypeface(typeface);
+ binding.nsfwCustomTextViewPostPollActivity.setTypeface(typeface);
+ binding.postTitleEditTextPostPollActivity.setTypeface(typeface);
+ binding.option1TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
+ binding.option2TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
+ binding.option3TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
+ binding.option4TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
+ binding.option5TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
+ binding.option6TextInputLayoutEditTextPostPollActivity.setTypeface(typeface);
}
}
@@ -517,11 +493,11 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(iconGifImageView);
+ .into(binding.subredditIconGifImageViewPostPollActivity);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(iconGifImageView);
+ .into(binding.subredditIconGifImageViewPostPollActivity);
}
}
@@ -564,13 +540,13 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
return true;
} else {
- if (!titleEditText.getText().toString().equals("")
- || !option1TextInputEditText.getText().toString().equals("")
- || !option2TextInputEditText.getText().toString().equals("")
- || !option3TextInputEditText.getText().toString().equals("")
- || !option4TextInputEditText.getText().toString().equals("")
- || !option5TextInputEditText.getText().toString().equals("")
- || !option6TextInputEditText.getText().toString().equals("")) {
+ if (!binding.postTitleEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
promptAlertDialog(R.string.discard, R.string.discard_detail);
return true;
}
@@ -579,44 +555,44 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
return true;
} else if (itemId == R.id.action_send_post_poll_activity) {
if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return true;
}
- if (titleEditText.getText() == null) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ if (binding.postTitleEditTextPostPollActivity.getText() == null) {
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.title_required, Snackbar.LENGTH_SHORT).show();
return true;
}
String subredditName;
if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
+ subredditName = "u_" + binding.subredditNameTextViewPostPollActivity.getText().toString();
} else {
- subredditName = subredditNameTextView.getText().toString();
+ subredditName = binding.subredditNameTextViewPostPollActivity.getText().toString();
}
ArrayList<String> optionList = new ArrayList<>();
- if (!option1TextInputEditText.getText().toString().equals("")) {
- optionList.add(option1TextInputEditText.getText().toString());
+ if (!binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString());
}
- if (!option2TextInputEditText.getText().toString().equals("")) {
- optionList.add(option2TextInputEditText.getText().toString());
+ if (!binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString());
}
- if (!option3TextInputEditText.getText().toString().equals("")) {
- optionList.add(option3TextInputEditText.getText().toString());
+ if (!binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString());
}
- if (!option4TextInputEditText.getText().toString().equals("")) {
- optionList.add(option4TextInputEditText.getText().toString());
+ if (!binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString());
}
- if (!option5TextInputEditText.getText().toString().equals("")) {
- optionList.add(option5TextInputEditText.getText().toString());
+ if (!binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString());
}
- if (!option6TextInputEditText.getText().toString().equals("")) {
- optionList.add(option6TextInputEditText.getText().toString());
+ if (!binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
+ optionList.add(binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString());
}
if (optionList.size() < 2) {
- Snackbar.make(coordinatorLayout, R.string.two_options_required, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.two_options_required, Snackbar.LENGTH_SHORT).show();
return true;
}
@@ -631,9 +607,33 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
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 = new PollPayload(subredditName, titleEditText.getText().toString(),
- optionList.toArray(new String[0]), (int) votingLengthSlider.getValue(), isNSFW, isSpoiler, flair, receivePostReplyNotificationsSwitchMaterial.isChecked(),
- subredditIsUser ? "profile" : "subreddit");
+
+ 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 {
+ 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));
ContextCompat.startForegroundService(this, intent);
@@ -649,13 +649,13 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
if (isPosting) {
promptAlertDialog(R.string.exit_when_submit, R.string.exit_when_submit_post_detail);
} else {
- if (!titleEditText.getText().toString().equals("")
- || !option1TextInputEditText.getText().toString().equals("")
- || !option2TextInputEditText.getText().toString().equals("")
- || !option3TextInputEditText.getText().toString().equals("")
- || !option4TextInputEditText.getText().toString().equals("")
- || !option5TextInputEditText.getText().toString().equals("")
- || !option6TextInputEditText.getText().toString().equals("")) {
+ if (!binding.postTitleEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option1TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option2TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option3TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option4TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option5TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")
+ || !binding.option6TextInputLayoutEditTextPostPollActivity.getText().toString().equals("")) {
promptAlertDialog(R.string.discard, R.string.discard_detail);
} else {
finish();
@@ -676,27 +676,38 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
outState.putParcelable(FLAIR_STATE, flair);
outState.putBoolean(IS_SPOILER_STATE, isSpoiler);
outState.putBoolean(IS_NSFW_STATE, isNSFW);
+ outState.putParcelableArrayList(UPLOADED_IMAGES_STATE, uploadedImages);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
- if (resultCode == RESULT_OK) {
+ if (resultCode == RESULT_OK) {
+ if (requestCode == SUBREDDIT_SELECTION_REQUEST_CODE) {
subredditName = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_NAME);
iconUrl = data.getExtras().getString(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_ICON_URL);
subredditSelected = true;
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
- subredditNameTextView.setTextColor(primaryTextColor);
- subredditNameTextView.setText(subredditName);
+ binding.subredditNameTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostPollActivity.setText(subredditName);
displaySubredditIcon();
- flairTextView.setVisibility(View.VISIBLE);
- flairTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- flairTextView.setTextColor(primaryTextColor);
- flairTextView.setText(getString(R.string.flair));
+ binding.flairCustomTextViewPostPollActivity.setVisibility(View.VISIBLE);
+ binding.flairCustomTextViewPostPollActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.flairCustomTextViewPostPollActivity.setTextColor(primaryTextColor);
+ binding.flairCustomTextViewPostPollActivity.setText(getString(R.string.flair));
flair = null;
+ } else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
+ if (data == null) {
+ Toast.makeText(PostPollActivity.this, R.string.error_getting_image, Toast.LENGTH_LONG).show();
+ return;
+ }
+ Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
+ accessToken, binding.postContentEditTextPostPollActivity, binding.coordinatorLayoutPostPollActivity, data.getData(), uploadedImages);
+ } else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
+ Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
+ accessToken, binding.postContentEditTextPostPollActivity, binding.coordinatorLayoutPostPollActivity, capturedImageUri, uploadedImages);
}
}
}
@@ -704,10 +715,50 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
@Override
public void flairSelected(Flair flair) {
this.flair = flair;
- flairTextView.setText(flair.getText());
- flairTextView.setBackgroundColor(flairBackgroundColor);
- flairTextView.setBorderColor(flairBackgroundColor);
- flairTextView.setTextColor(flairTextColor);
+ binding.flairCustomTextViewPostPollActivity.setText(flair.getText());
+ binding.flairCustomTextViewPostPollActivity.setBackgroundColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostPollActivity.setBorderColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostPollActivity.setTextColor(flairTextColor);
+ }
+
+ @Override
+ public void uploadImage() {
+ Intent intent = new Intent();
+ intent.setType("image/*");
+ intent.setAction(Intent.ACTION_GET_CONTENT);
+ startActivityForResult(Intent.createChooser(intent,
+ getResources().getString(R.string.select_from_gallery)), PICK_IMAGE_REQUEST_CODE);
+ }
+
+ @Override
+ public void captureImage() {
+ Intent pictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
+ try {
+ capturedImageUri = FileProvider.getUriForFile(this, "ml.docilealligator.infinityforreddit.provider",
+ File.createTempFile("captured_image", ".jpg", getExternalFilesDir(Environment.DIRECTORY_PICTURES)));
+ pictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, capturedImageUri);
+ startActivityForResult(pictureIntent, CAPTURE_IMAGE_REQUEST_CODE);
+ } catch (IOException ex) {
+ Toast.makeText(this, R.string.error_creating_temp_file, Toast.LENGTH_SHORT).show();
+ } catch (ActivityNotFoundException e) {
+ Toast.makeText(this, R.string.no_camera_available, Toast.LENGTH_SHORT).show();
+ }
+ }
+
+ @Override
+ public void insertImageUrl(UploadedImage uploadedImage) {
+ int start = Math.max(binding.postContentEditTextPostPollActivity.getSelectionStart(), 0);
+ int end = Math.max(binding.postContentEditTextPostPollActivity.getSelectionEnd(), 0);
+ int realStart = Math.min(start, end);
+ if (realStart > 0 && binding.postContentEditTextPostPollActivity.getText().toString().charAt(realStart - 1) != '\n') {
+ binding.postContentEditTextPostPollActivity.getText().replace(realStart, Math.max(start, end),
+ "\n![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "\n![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ } else {
+ binding.postContentEditTextPostPollActivity.getText().replace(realStart, Math.max(start, end),
+ "![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ }
}
@Override
@@ -719,9 +770,9 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
.error(mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0))))
- .into(accountIconImageView);
+ .into(binding.accountIconGifImageViewPostPollActivity);
- accountNameTextView.setText(selectedAccount.getAccountName());
+ binding.accountNameTextViewPostPollActivity.setText(selectedAccount.getAccountName());
}
}
@@ -743,9 +794,9 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr
mMemu.findItem(R.id.action_send_post_poll_activity).setEnabled(true);
mMemu.findItem(R.id.action_send_post_poll_activity).getIcon().setAlpha(255);
if (submitPollPostEvent.errorMessage == null || submitPollPostEvent.errorMessage.equals("")) {
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitPollPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ Snackbar.make(binding.coordinatorLayoutPostPollActivity, submitPollPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ submitPollPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
index 8df14433..038076c5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
@@ -726,9 +726,16 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
public void insertImageUrl(UploadedImage uploadedImage) {
int start = Math.max(contentEditText.getSelectionStart(), 0);
int end = Math.max(contentEditText.getSelectionEnd(), 0);
- contentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
- "![](" + uploadedImage.imageUrlOrKey + ")",
- 0, "![]()".length() + uploadedImage.imageUrlOrKey.length());
+ int realStart = Math.min(start, end);
+ if (realStart > 0 && contentEditText.getText().toString().charAt(realStart - 1) != '\n') {
+ contentEditText.getText().replace(realStart, Math.max(start, end),
+ "\n![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "\n![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ } else {
+ contentEditText.getText().replace(realStart, Math.max(start, end),
+ "![](" + uploadedImage.imageUrlOrKey + ")\n",
+ 0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length());
+ }
}
@Override
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
index eca017a6..37db8124 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/utils/Utils.java
@@ -408,9 +408,16 @@ public final class Utils {
int start = Math.max(editText.getSelectionStart(), 0);
int end = Math.max(editText.getSelectionEnd(), 0);
- editText.getText().replace(Math.min(start, end), Math.max(start, end),
- "![](" + imageKeyOrError + ")",
- 0, "![]()".length() + imageKeyOrError.length());
+ int realStart = Math.min(start, end);
+ if (realStart > 0 && editText.getText().toString().charAt(realStart - 1) != '\n') {
+ editText.getText().replace(realStart, Math.max(start, end),
+ "\n![](" + imageKeyOrError + ")\n",
+ 0, "\n![]()\n".length() + imageKeyOrError.length());
+ } else {
+ editText.getText().replace(realStart, Math.max(start, end),
+ "![](" + imageKeyOrError + ")\n",
+ 0, "![]()\n".length() + imageKeyOrError.length());
+ }
Snackbar.make(coordinatorLayout, R.string.upload_image_success, Snackbar.LENGTH_LONG).show();
} else {
Toast.makeText(context, R.string.upload_image_failed, Toast.LENGTH_LONG).show();