aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java279
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java20
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java2
-rw-r--r--app/src/main/res/drawable/ic_superscript_24dp.xml5
-rw-r--r--app/src/main/res/layout/activity_post_text.xml1
-rw-r--r--app/src/main/res/layout/fragment_uploaded_images_bottom_sheet.xml20
-rw-r--r--app/src/main/res/values/strings.xml7
8 files changed, 180 insertions, 188 deletions
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 81f41bd5..b7a88b41 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java
@@ -13,30 +13,19 @@ 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 androidx.recyclerview.widget.RecyclerView;
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.snackbar.Snackbar;
-import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
@@ -49,8 +38,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;
import ml.docilealligator.infinityforreddit.Infinity;
@@ -66,12 +53,12 @@ import ml.docilealligator.infinityforreddit.bottomsheetfragments.FlairBottomShee
import ml.docilealligator.infinityforreddit.bottomsheetfragments.UploadedImagesBottomSheetFragment;
import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper;
import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed;
+import ml.docilealligator.infinityforreddit.databinding.ActivityPostTextBinding;
import ml.docilealligator.infinityforreddit.events.SubmitTextOrLinkPostEvent;
import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent;
import ml.docilealligator.infinityforreddit.services.SubmitPostService;
import ml.docilealligator.infinityforreddit.utils.APIUtils;
import ml.docilealligator.infinityforreddit.utils.Utils;
-import pl.droidsonroids.gif.GifImageView;
import retrofit2.Retrofit;
public class PostTextActivity extends BaseActivity implements FlairBottomSheetFragment.FlairSelectionCallback,
@@ -97,46 +84,6 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private static final int CAPTURE_IMAGE_REQUEST_CODE = 200;
private static final int MARKDOWN_PREVIEW_REQUEST_CODE = 300;
- @BindView(R.id.coordinator_layout_post_text_activity)
- CoordinatorLayout coordinatorLayout;
- @BindView(R.id.appbar_layout_post_text_activity)
- AppBarLayout appBarLayout;
- @BindView(R.id.toolbar_post_text_activity)
- Toolbar toolbar;
- @BindView(R.id.account_linear_layout_post_text_activity)
- LinearLayout accountLinearLayout;
- @BindView(R.id.account_icon_gif_image_view_post_text_activity)
- GifImageView accountIconImageView;
- @BindView(R.id.account_name_text_view_post_text_activity)
- TextView accountNameTextView;
- @BindView(R.id.subreddit_icon_gif_image_view_post_text_activity)
- GifImageView iconGifImageView;
- @BindView(R.id.subreddit_name_text_view_post_text_activity)
- TextView subredditNameTextView;
- @BindView(R.id.rules_button_post_text_activity)
- MaterialButton rulesButton;
- @BindView(R.id.divider_1_post_text_activity)
- MaterialDivider divider1;
- @BindView(R.id.flair_custom_text_view_post_text_activity)
- CustomTextView flairTextView;
- @BindView(R.id.spoiler_custom_text_view_post_text_activity)
- CustomTextView spoilerTextView;
- @BindView(R.id.nsfw_custom_text_view_post_text_activity)
- CustomTextView nsfwTextView;
- @BindView(R.id.receive_post_reply_notifications_linear_layout_post_text_activity)
- LinearLayout receivePostReplyNotificationsLinearLayout;
- @BindView(R.id.receive_post_reply_notifications_text_view_post_text_activity)
- TextView receivePostReplyNotificationsTextView;
- @BindView(R.id.receive_post_reply_notifications_switch_material_post_text_activity)
- MaterialSwitch receivePostReplyNotificationsSwitchMaterial;
- @BindView(R.id.divider_2_post_text_activity)
- MaterialDivider divider2;
- @BindView(R.id.post_title_edit_text_post_text_activity)
- EditText titleEditText;
- @BindView(R.id.post_text_content_edit_text_post_text_activity)
- EditText contentEditText;
- @BindView(R.id.markdown_bottom_bar_recycler_view_post_text_activity)
- RecyclerView markdownBottomBarRecyclerView;
@Inject
@Named("no_oauth")
Retrofit mRetrofit;
@@ -182,6 +129,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private Snackbar mPostingSnackbar;
private Uri capturedImageUri;
private ArrayList<UploadedImage> uploadedImages = new ArrayList<>();
+ private ActivityPostTextBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -191,24 +139,23 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_post_text);
-
- ButterKnife.bind(this);
+ binding = ActivityPostTextBinding.inflate(getLayoutInflater());
+ setContentView(binding.getRoot());
EventBus.getDefault().register(this);
applyCustomTheme();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && isChangeStatusBarIconColor()) {
- addOnOffsetChangedListener(appBarLayout);
+ addOnOffsetChangedListener(binding.appbarLayoutPostTextActivity);
}
- setSupportActionBar(toolbar);
+ setSupportActionBar(binding.toolbarPostTextActivity);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mGlide = Glide.with(this);
- mPostingSnackbar = Snackbar.make(coordinatorLayout, R.string.posting, Snackbar.LENGTH_INDEFINITE);
+ mPostingSnackbar = Snackbar.make(binding.coordinatorLayoutPostTextActivity, R.string.posting, Snackbar.LENGTH_INDEFINITE);
resources = getResources();
@@ -230,17 +177,17 @@ public class PostTextActivity 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.accountIconGifImageViewPostTextActivity);
- accountNameTextView.setText(selectedAccount.getAccountName());
+ binding.accountNameTextViewPostTextActivity.setText(selectedAccount.getAccountName());
} else {
loadCurrentAccount();
}
if (subredditName != null) {
- subredditNameTextView.setTextColor(primaryTextColor);
- subredditNameTextView.setText(subredditName);
- flairTextView.setVisibility(View.VISIBLE);
+ binding.subredditNameTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostTextActivity.setText(subredditName);
+ binding.flairCustomTextViewPostTextActivity.setVisibility(View.VISIBLE);
if (!loadSubredditIconSuccessful) {
loadSubredditIcon();
}
@@ -252,20 +199,20 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
}
if (flair != null) {
- flairTextView.setText(flair.getText());
- flairTextView.setBackgroundColor(flairBackgroundColor);
- flairTextView.setBorderColor(flairBackgroundColor);
- flairTextView.setTextColor(flairTextColor);
+ binding.flairCustomTextViewPostTextActivity.setText(flair.getText());
+ binding.flairCustomTextViewPostTextActivity.setBackgroundColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostTextActivity.setBorderColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostTextActivity.setTextColor(flairTextColor);
}
if (isSpoiler) {
- spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
- spoilerTextView.setBorderColor(spoilerBackgroundColor);
- spoilerTextView.setTextColor(spoilerTextColor);
+ binding.spoilerCustomTextViewPostTextActivity.setBackgroundColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostTextActivity.setBorderColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostTextActivity.setTextColor(spoilerTextColor);
}
if (isNSFW) {
- nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
- nsfwTextView.setBorderColor(nsfwBackgroundColor);
- nsfwTextView.setTextColor(nsfwTextColor);
+ binding.nsfwCustomTextViewPostTextActivity.setBackgroundColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostTextActivity.setBorderColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostTextActivity.setTextColor(nsfwTextColor);
}
} else {
isPosting = false;
@@ -276,38 +223,36 @@ public class PostTextActivity 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.subredditNameTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostTextActivity.setText(subredditName);
+ binding.flairCustomTextViewPostTextActivity.setVisibility(View.VISIBLE);
loadSubredditIcon();
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(iconGifImageView);
+ .into(binding.subredditIconGifImageViewPostTextActivity);
}
String text = getIntent().getStringExtra(EXTRA_CONTENT);
if (text != null) {
- contentEditText.setText(text);
+ binding.postTextContentEditTextPostTextActivity.setText(text);
}
}
- accountLinearLayout.setOnClickListener(view -> {
+ binding.accountLinearLayoutPostTextActivity.setOnClickListener(view -> {
AccountChooserBottomSheetFragment fragment = new AccountChooserBottomSheetFragment();
fragment.show(getSupportFragmentManager(), fragment.getTag());
});
- iconGifImageView.setOnClickListener(view -> subredditNameTextView.performClick());
-
- subredditNameTextView.setOnClickListener(view -> {
+ binding.subredditRelativeLayoutPostTextActivity.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.rulesButtonPostTextActivity.setOnClickListener(view -> {
if (subredditName == null) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostTextActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(this, RulesActivity.class);
if (subredditIsUser) {
@@ -319,7 +264,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
}
});
- flairTextView.setOnClickListener(view -> {
+ binding.flairCustomTextViewPostTextActivity.setOnClickListener(view -> {
if (flair == null) {
flairSelectionBottomSheetFragment = new FlairBottomSheetFragment();
Bundle bundle = new Bundle();
@@ -331,41 +276,41 @@ public class PostTextActivity 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.flairCustomTextViewPostTextActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.flairCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.flairCustomTextViewPostTextActivity.setText(getString(R.string.flair));
flair = null;
}
});
- spoilerTextView.setOnClickListener(view -> {
+ binding.spoilerCustomTextViewPostTextActivity.setOnClickListener(view -> {
if (!isSpoiler) {
- spoilerTextView.setBackgroundColor(spoilerBackgroundColor);
- spoilerTextView.setBorderColor(spoilerBackgroundColor);
- spoilerTextView.setTextColor(spoilerTextColor);
+ binding.spoilerCustomTextViewPostTextActivity.setBackgroundColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostTextActivity.setBorderColor(spoilerBackgroundColor);
+ binding.spoilerCustomTextViewPostTextActivity.setTextColor(spoilerTextColor);
isSpoiler = true;
} else {
- spoilerTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- spoilerTextView.setTextColor(primaryTextColor);
+ binding.spoilerCustomTextViewPostTextActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.spoilerCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
isSpoiler = false;
}
});
- nsfwTextView.setOnClickListener(view -> {
+ binding.nsfwCustomTextViewPostTextActivity.setOnClickListener(view -> {
if (!isNSFW) {
- nsfwTextView.setBackgroundColor(nsfwBackgroundColor);
- nsfwTextView.setBorderColor(nsfwBackgroundColor);
- nsfwTextView.setTextColor(nsfwTextColor);
+ binding.nsfwCustomTextViewPostTextActivity.setBackgroundColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostTextActivity.setBorderColor(nsfwBackgroundColor);
+ binding.nsfwCustomTextViewPostTextActivity.setTextColor(nsfwTextColor);
isNSFW = true;
} else {
- nsfwTextView.setBackgroundColor(resources.getColor(android.R.color.transparent));
- nsfwTextView.setTextColor(primaryTextColor);
+ binding.nsfwCustomTextViewPostTextActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.nsfwCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
isNSFW = false;
}
});
- receivePostReplyNotificationsLinearLayout.setOnClickListener(view -> {
- receivePostReplyNotificationsSwitchMaterial.performClick();
+ binding.receivePostReplyNotificationsLinearLayoutPostTextActivity.setOnClickListener(view -> {
+ binding.receivePostReplyNotificationsSwitchMaterialPostTextActivity.performClick();
});
MarkdownBottomBarRecyclerViewAdapter adapter = new MarkdownBottomBarRecyclerViewAdapter(
@@ -374,7 +319,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
@Override
public void onClick(int item) {
MarkdownBottomBarRecyclerViewAdapter.bindEditTextWithItemClickListener(
- PostTextActivity.this, contentEditText, item);
+ PostTextActivity.this, binding.postTextContentEditTextPostTextActivity, item);
}
@Override
@@ -389,9 +334,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
}
});
- markdownBottomBarRecyclerView.setLayoutManager(new LinearLayoutManagerBugFixed(this,
+ binding.markdownBottomBarRecyclerViewPostTextActivity.setLayoutManager(new LinearLayoutManagerBugFixed(this,
LinearLayoutManager.HORIZONTAL, false));
- markdownBottomBarRecyclerView.setAdapter(adapter);
+ binding.markdownBottomBarRecyclerViewPostTextActivity.setAdapter(adapter);
}
private void loadCurrentAccount() {
@@ -405,9 +350,9 @@ public class PostTextActivity 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.accountIconGifImageViewPostTextActivity);
- accountNameTextView.setText(account.getAccountName());
+ binding.accountNameTextViewPostTextActivity.setText(account.getAccountName());
}
});
});
@@ -430,42 +375,42 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
@Override
protected void applyCustomTheme() {
- coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
- applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(appBarLayout, null, toolbar);
+ binding.coordinatorLayoutPostTextActivity.setBackgroundColor(mCustomThemeWrapper.getBackgroundColor());
+ applyAppBarLayoutAndCollapsingToolbarLayoutAndToolbarTheme(binding.appbarLayoutPostTextActivity, null, binding.toolbarPostTextActivity);
primaryTextColor = mCustomThemeWrapper.getPrimaryTextColor();
- accountNameTextView.setTextColor(primaryTextColor);
+ binding.accountNameTextViewPostTextActivity.setTextColor(primaryTextColor);
int secondaryTextColor = mCustomThemeWrapper.getSecondaryTextColor();
- subredditNameTextView.setTextColor(secondaryTextColor);
- rulesButton.setTextColor(mCustomThemeWrapper.getButtonTextColor());
- rulesButton.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
- receivePostReplyNotificationsTextView.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostTextActivity.setTextColor(secondaryTextColor);
+ binding.rulesButtonPostTextActivity.setTextColor(mCustomThemeWrapper.getButtonTextColor());
+ binding.rulesButtonPostTextActivity.setBackgroundColor(mCustomThemeWrapper.getColorPrimaryLightTheme());
+ binding.receivePostReplyNotificationsTextViewPostTextActivity.setTextColor(primaryTextColor);
int dividerColor = mCustomThemeWrapper.getDividerColor();
- divider1.setDividerColor(dividerColor);
- divider2.setDividerColor(dividerColor);
+ binding.divider1PostTextActivity.setDividerColor(dividerColor);
+ binding.divider2PostTextActivity.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);
- contentEditText.setTextColor(primaryTextColor);
- contentEditText.setHintTextColor(secondaryTextColor);
+ binding.flairCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.spoilerCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.nsfwCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.postTitleEditTextPostTextActivity.setTextColor(primaryTextColor);
+ binding.postTitleEditTextPostTextActivity.setHintTextColor(secondaryTextColor);
+ binding.postTextContentEditTextPostTextActivity.setTextColor(primaryTextColor);
+ binding.postTextContentEditTextPostTextActivity.setHintTextColor(secondaryTextColor);
if (typeface != null) {
- subredditNameTextView.setTypeface(typeface);
- rulesButton.setTypeface(typeface);
- receivePostReplyNotificationsTextView.setTypeface(typeface);
- flairTextView.setTypeface(typeface);
- spoilerTextView.setTypeface(typeface);
- nsfwTextView.setTypeface(typeface);
- titleEditText.setTypeface(typeface);
+ binding.subredditNameTextViewPostTextActivity.setTypeface(typeface);
+ binding.rulesButtonPostTextActivity.setTypeface(typeface);
+ binding.receivePostReplyNotificationsTextViewPostTextActivity.setTypeface(typeface);
+ binding.flairCustomTextViewPostTextActivity.setTypeface(typeface);
+ binding.spoilerCustomTextViewPostTextActivity.setTypeface(typeface);
+ binding.nsfwCustomTextViewPostTextActivity.setTypeface(typeface);
+ binding.postTitleEditTextPostTextActivity.setTypeface(typeface);
}
if (contentTypeface != null) {
- contentEditText.setTypeface(typeface);
+ binding.postTextContentEditTextPostTextActivity.setTypeface(typeface);
}
}
@@ -475,11 +420,11 @@ public class PostTextActivity 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.subredditIconGifImageViewPostTextActivity);
} else {
mGlide.load(R.drawable.subreddit_default_icon)
.apply(RequestOptions.bitmapTransform(new RoundedCornersTransformation(72, 0)))
- .into(iconGifImageView);
+ .into(binding.subredditIconGifImageViewPostTextActivity);
}
}
@@ -522,7 +467,7 @@ public class PostTextActivity 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("") || !contentEditText.getText().toString().equals("")) {
+ if (!binding.postTitleEditTextPostTextActivity.getText().toString().equals("") || !binding.postTextContentEditTextPostTextActivity.getText().toString().equals("")) {
promptAlertDialog(R.string.discard, R.string.discard_detail);
return true;
}
@@ -531,7 +476,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
return true;
} else if (itemId == R.id.action_preview_post_text_activity) {
Intent intent = new Intent(this, FullMarkdownActivity.class);
- intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, contentEditText.getText().toString());
+ intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.postTextContentEditTextPostTextActivity.getText().toString());
intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true);
if (!uploadedImages.isEmpty()) {
intent.putParcelableArrayListExtra("test", uploadedImages);
@@ -547,12 +492,12 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
private void submitPost(MenuItem item) {
if (!subredditSelected) {
- Snackbar.make(coordinatorLayout, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostTextActivity, R.string.select_a_subreddit, Snackbar.LENGTH_SHORT).show();
return;
}
- if (titleEditText.getText() == null || titleEditText.getText().toString().equals("")) {
- Snackbar.make(coordinatorLayout, R.string.title_required, Snackbar.LENGTH_SHORT).show();
+ if (binding.postTitleEditTextPostTextActivity.getText() == null || binding.postTitleEditTextPostTextActivity.getText().toString().equals("")) {
+ Snackbar.make(binding.coordinatorLayoutPostTextActivity, R.string.title_required, Snackbar.LENGTH_SHORT).show();
return;
}
@@ -567,16 +512,16 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
String subredditName;
if (subredditIsUser) {
- subredditName = "u_" + subredditNameTextView.getText().toString();
+ subredditName = "u_" + binding.subredditNameTextViewPostTextActivity.getText().toString();
} else {
- subredditName = subredditNameTextView.getText().toString();
+ subredditName = binding.subredditNameTextViewPostTextActivity.getText().toString();
}
Intent intent = new Intent(this, SubmitPostService.class);
intent.putExtra(SubmitPostService.EXTRA_ACCOUNT, selectedAccount);
intent.putExtra(SubmitPostService.EXTRA_SUBREDDIT_NAME, subredditName);
- intent.putExtra(SubmitPostService.EXTRA_TITLE, titleEditText.getText().toString());
- intent.putExtra(SubmitPostService.EXTRA_CONTENT, contentEditText.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_TITLE, binding.postTitleEditTextPostTextActivity.getText().toString());
+ intent.putExtra(SubmitPostService.EXTRA_CONTENT, binding.postTextContentEditTextPostTextActivity.getText().toString());
if (!uploadedImages.isEmpty()) {
intent.putExtra(SubmitPostService.EXTRA_IS_RICHTEXT_JSON, true);
intent.putExtra(SubmitPostService.EXTRA_UPLOADED_IMAGES, uploadedImages);
@@ -586,7 +531,7 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
intent.putExtra(SubmitPostService.EXTRA_FLAIR, flair);
intent.putExtra(SubmitPostService.EXTRA_IS_SPOILER, isSpoiler);
intent.putExtra(SubmitPostService.EXTRA_IS_NSFW, isNSFW);
- intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, receivePostReplyNotificationsSwitchMaterial.isChecked());
+ intent.putExtra(SubmitPostService.EXTRA_RECEIVE_POST_REPLY_NOTIFICATIONS, binding.receivePostReplyNotificationsSwitchMaterialPostTextActivity.isChecked());
intent.putExtra(SubmitPostService.EXTRA_POST_TYPE, SubmitPostService.EXTRA_POST_TEXT_OR_LINK);
ContextCompat.startForegroundService(this, intent);
}
@@ -596,7 +541,7 @@ public class PostTextActivity 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("") || !contentEditText.getText().toString().equals("")) {
+ if (!binding.postTitleEditTextPostTextActivity.getText().toString().equals("") || !binding.postTextContentEditTextPostTextActivity.getText().toString().equals("")) {
promptAlertDialog(R.string.discard, R.string.discard_detail);
} else {
finish();
@@ -630,14 +575,14 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
subredditSelected = true;
subredditIsUser = data.getExtras().getBoolean(SubredditSelectionActivity.EXTRA_RETURN_SUBREDDIT_IS_USER);
- subredditNameTextView.setTextColor(primaryTextColor);
- subredditNameTextView.setText(subredditName);
+ binding.subredditNameTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.subredditNameTextViewPostTextActivity.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.flairCustomTextViewPostTextActivity.setVisibility(View.VISIBLE);
+ binding.flairCustomTextViewPostTextActivity.setBackgroundColor(resources.getColor(android.R.color.transparent));
+ binding.flairCustomTextViewPostTextActivity.setTextColor(primaryTextColor);
+ binding.flairCustomTextViewPostTextActivity.setText(getString(R.string.flair));
flair = null;
} else if (requestCode == PICK_IMAGE_REQUEST_CODE) {
@@ -646,10 +591,10 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
return;
}
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
- accessToken, contentEditText, coordinatorLayout, data.getData(), uploadedImages);
+ accessToken, binding.postTextContentEditTextPostTextActivity, binding.coordinatorLayoutPostTextActivity, data.getData(), uploadedImages);
} else if (requestCode == CAPTURE_IMAGE_REQUEST_CODE) {
Utils.uploadImageToReddit(this, mExecutor, mOauthRetrofit, mUploadMediaRetrofit,
- accessToken, contentEditText, coordinatorLayout, capturedImageUri, uploadedImages);
+ accessToken, binding.postTextContentEditTextPostTextActivity, binding.coordinatorLayoutPostTextActivity, capturedImageUri, uploadedImages);
} else if (requestCode == MARKDOWN_PREVIEW_REQUEST_CODE) {
submitPost(mMenu.findItem(R.id.action_send_post_text_activity));
}
@@ -666,10 +611,10 @@ public class PostTextActivity 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.flairCustomTextViewPostTextActivity.setText(flair.getText());
+ binding.flairCustomTextViewPostTextActivity.setBackgroundColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostTextActivity.setBorderColor(flairBackgroundColor);
+ binding.flairCustomTextViewPostTextActivity.setTextColor(flairTextColor);
}
@Subscribe
@@ -690,9 +635,9 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
mMenu.findItem(R.id.action_send_post_text_activity).setEnabled(true);
mMenu.findItem(R.id.action_send_post_text_activity).getIcon().setAlpha(255);
if (submitTextOrLinkPostEvent.errorMessage == null || submitTextOrLinkPostEvent.errorMessage.equals("")) {
- Snackbar.make(coordinatorLayout, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
+ Snackbar.make(binding.coordinatorLayoutPostTextActivity, R.string.post_failed, Snackbar.LENGTH_SHORT).show();
} else {
- Snackbar.make(coordinatorLayout, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ Snackbar.make(binding.coordinatorLayoutPostTextActivity, submitTextOrLinkPostEvent.errorMessage.substring(0, 1).toUpperCase()
+ submitTextOrLinkPostEvent.errorMessage.substring(1), Snackbar.LENGTH_SHORT).show();
}
}
@@ -724,15 +669,15 @@ public class PostTextActivity extends BaseActivity implements FlairBottomSheetFr
@Override
public void insertImageUrl(UploadedImage uploadedImage) {
- int start = Math.max(contentEditText.getSelectionStart(), 0);
- int end = Math.max(contentEditText.getSelectionEnd(), 0);
+ int start = Math.max(binding.postTextContentEditTextPostTextActivity.getSelectionStart(), 0);
+ int end = Math.max(binding.postTextContentEditTextPostTextActivity.getSelectionEnd(), 0);
int realStart = Math.min(start, end);
- if (realStart > 0 && contentEditText.getText().toString().charAt(realStart - 1) != '\n') {
- contentEditText.getText().replace(realStart, Math.max(start, end),
+ if (realStart > 0 && binding.postTextContentEditTextPostTextActivity.getText().toString().charAt(realStart - 1) != '\n') {
+ binding.postTextContentEditTextPostTextActivity.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),
+ binding.postTextContentEditTextPostTextActivity.getText().replace(realStart, Math.max(start, end),
"![](" + uploadedImage.imageUrlOrKey + ")\n",
0, "![]()\n".length() + uploadedImage.imageUrlOrKey.length());
}
@@ -747,9 +692,9 @@ public class PostTextActivity 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.accountIconGifImageViewPostTextActivity);
- accountNameTextView.setText(selectedAccount.getAccountName());
+ binding.accountNameTextViewPostTextActivity.setText(selectedAccount.getAccountName());
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
index 11720b1b..ac99ad82 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/MarkdownBottomBarRecyclerViewAdapter.java
@@ -23,15 +23,16 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
public static final int ITALIC = 1;
public static final int LINK = 2;
public static final int STRIKE_THROUGH = 3;
- public static final int HEADER = 4;
- public static final int ORDERED_LIST = 5;
- public static final int UNORDERED_LIST = 6;
- public static final int SPOILER = 7;
- public static final int QUOTE = 8;
- public static final int CODE_BLOCK = 9;
- public static final int UPLOAD_IMAGE = 10;
+ public static final int SUPERSCRIPT = 4;
+ public static final int HEADER = 5;
+ public static final int ORDERED_LIST = 6;
+ public static final int UNORDERED_LIST = 7;
+ public static final int SPOILER = 8;
+ public static final int QUOTE = 9;
+ public static final int CODE_BLOCK = 10;
+ public static final int UPLOAD_IMAGE = 11;
- private static final int ITEM_COUNT = 10;
+ private static final int ITEM_COUNT = 11;
private final CustomThemeWrapper customThemeWrapper;
private final boolean canUploadImage;
@@ -77,6 +78,9 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
case STRIKE_THROUGH:
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_strikethrough_black_24dp);
break;
+ case SUPERSCRIPT:
+ ((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_superscript_24dp);
+ break;
case HEADER:
((MarkdownBottomBarItemViewHolder) holder).imageView.setImageResource(R.drawable.ic_title_24dp);
break;
@@ -181,6 +185,20 @@ public class MarkdownBottomBarRecyclerViewAdapter extends RecyclerView.Adapter<R
}
break;
}
+ case MarkdownBottomBarRecyclerViewAdapter.SUPERSCRIPT: {
+ int start = Math.max(commentEditText.getSelectionStart(), 0);
+ int end = Math.max(commentEditText.getSelectionEnd(), 0);
+ if (end != start) {
+ String currentSelection = commentEditText.getText().subSequence(start, end).toString();
+ commentEditText.getText().replace(Math.min(start, end), Math.max(start, end),
+ "^(" + currentSelection + ")", 0, "^()".length() + currentSelection.length());
+ } else {
+ commentEditText.getText().replace(start, end,
+ "^()", 0, "^()".length());
+ commentEditText.setSelection(start + "^(".length());
+ }
+ break;
+ }
case MarkdownBottomBarRecyclerViewAdapter.HEADER: {
View dialogView = activity.getLayoutInflater().inflate(R.layout.dialog_select_header, null);
Slider seekBar = dialogView.findViewById(R.id.seek_bar_dialog_select_header);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
index d8b9cd31..5034ce54 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java
@@ -594,15 +594,19 @@ public class RichTextJSONConverter implements Visitor {
Superscript must use ^(), not ^ right now.
*/
Node child = customNode.getFirstChild();
- while (child != null) {
- JSONArray format = getFormatArray(customNode);
- if (format != null) {
- formats.add(format);
- }
+ if (child == null) {
+ //It may be ^Superscript
+ } else {
+ while (child != null) {
+ JSONArray format = getFormatArray(customNode);
+ if (format != null) {
+ formats.add(format);
+ }
- Node next = child.getNext();
- child.unlink();
- child = next;
+ Node next = child.getNext();
+ child.unlink();
+ child = next;
+ }
}
} else if (customNode instanceof SpoilerNode) {
//Spoiler cannot have styles
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java
index 20a56327..d171c336 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/SuperscriptPlugin.java
@@ -218,7 +218,7 @@ public class SuperscriptPlugin extends AbstractMarkwonPlugin {
@Override
public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) {
- if (superscriptOpeningList.size() == 0 || !(markdown instanceof Spannable)) {
+ if (superscriptOpeningList.isEmpty() || !(markdown instanceof Spannable)) {
return;
}
diff --git a/app/src/main/res/drawable/ic_superscript_24dp.xml b/app/src/main/res/drawable/ic_superscript_24dp.xml
new file mode 100644
index 00000000..616bf137
--- /dev/null
+++ b/app/src/main/res/drawable/ic_superscript_24dp.xml
@@ -0,0 +1,5 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
+
+ <path android:fillColor="@android:color/black" android:pathData="M10.51,12.73L7.3,7.72C6.82,6.97 7.35,6 8.23,6h0c0.39,0 0.74,0.2 0.95,0.53l2.76,4.46h0.12l2.74,-4.45C15,6.2 15.36,6 15.75,6h0c0.88,0 1.42,0.98 0.94,1.72l-3.23,5l3.55,5.55C17.5,19.02 16.96,20 16.08,20h0c-0.38,0 -0.74,-0.2 -0.95,-0.52l-3.07,-4.89h-0.12l-3.07,4.89C8.66,19.8 8.31,20 7.92,20h0c-0.88,0 -1.42,-0.97 -0.94,-1.72L10.51,12.73zM23,8.5L23,8.5C23,8.22 22.78,8 22.5,8c0,0 0,0 0,0H20V7h2c0.55,0 1,-0.45 1,-1V5c0,-0.55 -0.45,-1 -1,-1h-2.5C19.22,4 19,4.22 19,4.5v0C19,4.78 19.22,5 19.5,5H22v1h-2c-0.55,0 -1,0.45 -1,1v1c0,0.55 0.45,1 1,1h2.5C22.78,9 23,8.78 23,8.5z"/>
+
+</vector>
diff --git a/app/src/main/res/layout/activity_post_text.xml b/app/src/main/res/layout/activity_post_text.xml
index 41bfef50..8ae4fcb4 100644
--- a/app/src/main/res/layout/activity_post_text.xml
+++ b/app/src/main/res/layout/activity_post_text.xml
@@ -67,6 +67,7 @@
</LinearLayout>
<RelativeLayout
+ android:id="@+id/subreddit_relative_layout_post_text_activity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp"
diff --git a/app/src/main/res/layout/fragment_uploaded_images_bottom_sheet.xml b/app/src/main/res/layout/fragment_uploaded_images_bottom_sheet.xml
index f3e96ef5..8c846541 100644
--- a/app/src/main/res/layout/fragment_uploaded_images_bottom_sheet.xml
+++ b/app/src/main/res/layout/fragment_uploaded_images_bottom_sheet.xml
@@ -19,15 +19,26 @@
android:textSize="?attr/font_18"
android:textColor="?attr/primaryTextColor" />
- <LinearLayout
+ <TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:gravity="end">
+ android:paddingTop="16dp"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:text="@string/uploaded_images_explanation"
+ android:fontFamily="?attr/font_family"
+ android:textSize="?attr/font_default"
+ android:textColor="?attr/secondaryTextColor" />
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="@+id/capture_button_uploaded_images_bottom_sheet_fragment"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:layout_weight="1"
android:layout_margin="16dp"
android:backgroundTint="@color/colorPrimary"
android:textColor="#FFFFFF"
@@ -35,8 +46,9 @@
<com.google.android.material.button.MaterialButton
android:id="@+id/upload_button_uploaded_images_bottom_sheet_fragment"
- android:layout_width="wrap_content"
+ android:layout_width="0dp"
android:layout_height="wrap_content"
+ android:layout_weight="1"
android:layout_margin="16dp"
android:backgroundTint="@color/colorPrimary"
android:textColor="#FFFFFF"
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 8c2b0890..5dce1f90 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1215,6 +1215,13 @@
<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,
+ 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>
<string name="select_image">Select an Image</string>
<string name="capture">Capture</string>
<string name="uploading_image">Uploading</string>