diff options
author | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-19 19:17:39 +0000 |
---|---|---|
committer | Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> | 2024-03-19 19:17:39 +0000 |
commit | 601fea22a6ed1d3919f289cd6b0816f34cdbda55 (patch) | |
tree | b1d247d49dfcb2fb3227fad6f1f04e27cc6bf6d2 /app/src/main/java/ml/docilealligator/infinityforreddit | |
parent | 951c893d77e7a8e0ef3e6852e2d1fc2d6489ab33 (diff) | |
download | infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar.gz infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar.bz2 infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar.lz infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar.xz infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.tar.zst infinity-for-reddit-601fea22a6ed1d3919f289cd6b0816f34cdbda55.zip |
Fix spoiler cannot be shown in FullMarkdownActivity.
Diffstat (limited to 'app/src/main/java/ml/docilealligator/infinityforreddit')
15 files changed, 54 insertions, 86 deletions
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 3760b4cb..7add2a34 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/CommentActivity.java @@ -240,7 +240,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA Markwon postBodyMarkwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, parentTextColor, parentSpoilerBackgroundColor, null); - CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); markwonAdapter.setOnLongClickListener(view -> { Utils.hideKeyboard(CommentActivity.this); CopyTextBottomSheetFragment.show(getSupportFragmentManager(), @@ -403,7 +403,7 @@ public class CommentActivity extends BaseActivity implements UploadImageEnabledA return true; } else if (itemId == R.id.action_preview_comment_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.commentCommentEditText.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_MARKDOWN, binding.commentCommentEditText.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (itemId == R.id.action_send_comment_activity) { 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 6a1fe4e6..b23d9797 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditCommentActivity.java @@ -215,7 +215,7 @@ public class EditCommentActivity extends BaseActivity implements UploadImageEnab public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_preview_edit_comment_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.commentEditTextEditCommentActivity.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_MARKDOWN, binding.commentEditTextEditCommentActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (item.getItemId() == R.id.action_send_edit_comment_activity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java index acb06634..b880f5d9 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/EditPostActivity.java @@ -200,7 +200,7 @@ public class EditPostActivity extends BaseActivity implements UploadImageEnabled public boolean onOptionsItemSelected(@NonNull MenuItem item) { if (item.getItemId() == R.id.action_preview_edit_post_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.postContentEditTextEditPostActivity.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_MARKDOWN, binding.postContentEditTextEditPostActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (item.getItemId() == R.id.action_send_edit_post_activity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java index 8ec7258d..66133e1d 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/FullMarkdownActivity.java @@ -18,7 +18,6 @@ import androidx.appcompat.widget.Toolbar; import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.recyclerview.widget.RecyclerView; -import com.bumptech.glide.Glide; import com.google.android.material.appbar.AppBarLayout; import com.google.android.material.appbar.CollapsingToolbarLayout; @@ -38,24 +37,18 @@ import io.noties.markwon.core.MarkwonTheme; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.customtheme.CustomThemeWrapper; -import ml.docilealligator.infinityforreddit.events.ChangeNetworkStatusEvent; -import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.customviews.LinearLayoutManagerBugFixed; import ml.docilealligator.infinityforreddit.customviews.SwipeLockInterface; import ml.docilealligator.infinityforreddit.customviews.SwipeLockLinearLayoutManager; import ml.docilealligator.infinityforreddit.customviews.slidr.Slidr; import ml.docilealligator.infinityforreddit.events.SwitchAccountEvent; -import ml.docilealligator.infinityforreddit.markdown.EmoteCloseBracketInlineProcessor; -import ml.docilealligator.infinityforreddit.markdown.EmotePlugin; -import ml.docilealligator.infinityforreddit.markdown.ImageAndGifEntry; -import ml.docilealligator.infinityforreddit.markdown.ImageAndGifPlugin; +import ml.docilealligator.infinityforreddit.markdown.CustomMarkwonAdapter; import ml.docilealligator.infinityforreddit.markdown.MarkdownUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; -import ml.docilealligator.infinityforreddit.utils.Utils; public class FullMarkdownActivity extends BaseActivity { - public static final String EXTRA_COMMENT_MARKDOWN = "ECM"; + public static final String EXTRA_MARKDOWN = "EM"; public static final String EXTRA_IS_NSFW = "EIN"; public static final String EXTRA_SUBMIT_POST = "ESP"; @@ -77,8 +70,6 @@ public class FullMarkdownActivity extends BaseActivity { SharedPreferences mCurrentAccountSharedPreferences; @Inject CustomThemeWrapper mCustomThemeWrapper; - private EmotePlugin emotePlugin; - private ImageAndGifEntry imageAndGifEntry; @Override protected void onCreate(Bundle savedInstanceState) { @@ -120,11 +111,9 @@ public class FullMarkdownActivity extends BaseActivity { } } - String commentMarkdown = getIntent().getStringExtra(EXTRA_COMMENT_MARKDOWN); + String markdown = getIntent().getStringExtra(EXTRA_MARKDOWN); boolean isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false); int markdownColor = mCustomThemeWrapper.getCommentColor(); - int spoilerBackgroundColor = markdownColor | 0xFF000000; - int linkColor = mCustomThemeWrapper.getLinkColor(); MarkwonPlugin miscPlugin = new AbstractMarkwonPlugin() { @Override public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { @@ -147,37 +136,13 @@ public class FullMarkdownActivity extends BaseActivity { @Override public void configureTheme(@NonNull MarkwonTheme.Builder builder) { - builder.linkColor(linkColor); + builder.linkColor(mCustomThemeWrapper.getLinkColor()); } }; - EmoteCloseBracketInlineProcessor emoteCloseBracketInlineProcessor = new EmoteCloseBracketInlineProcessor(); - emotePlugin = EmotePlugin.create(this, mediaMetadata -> { - Intent intent = new Intent(this, ViewImageOrGifActivity.class); - if (mediaMetadata.isGIF) { - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); - } else { - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); - } - intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, isNsfw); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); - }); - ImageAndGifPlugin imageAndGifPlugin = new ImageAndGifPlugin(); - imageAndGifEntry = new ImageAndGifEntry(this, - Glide.with(this), mediaMetadata -> { - Intent intent = new Intent(this, ViewImageOrGifActivity.class); - if (mediaMetadata.isGIF) { - intent.putExtra(ViewImageOrGifActivity.EXTRA_GIF_URL_KEY, mediaMetadata.original.url); - } else { - intent.putExtra(ViewImageOrGifActivity.EXTRA_IMAGE_URL_KEY, mediaMetadata.original.url); - } - intent.putExtra(ViewImageOrGifActivity.EXTRA_IS_NSFW, isNsfw); - intent.putExtra(ViewImageOrGifActivity.EXTRA_FILE_NAME_KEY, mediaMetadata.fileName); - }); - Markwon markwon = MarkdownUtils.createFullRedditMarkwon(this, - miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, - spoilerBackgroundColor, null); + Markwon markwon = MarkdownUtils.createContentPreviewRedditMarkwon(this, miscPlugin, markdownColor, + markdownColor | 0xFF000000); - CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { @@ -195,7 +160,7 @@ public class FullMarkdownActivity extends BaseActivity { }); markdownRecyclerView.setLayoutManager(linearLayoutManager); markdownRecyclerView.setAdapter(markwonAdapter); - markwonAdapter.setMarkdown(markwon, commentMarkdown); + markwonAdapter.setMarkdown(markwon, markdown); // noinspection NotifyDataSetChanged markwonAdapter.notifyDataSetChanged(); } @@ -257,18 +222,4 @@ public class FullMarkdownActivity extends BaseActivity { finish(); } } - - @Subscribe - public void onChangeNetworkStatusEvent(ChangeNetworkStatusEvent changeNetworkStatusEvent) { - String dataSavingMode = mSharedPreferences.getString(SharedPreferencesUtils.DATA_SAVING_MODE, SharedPreferencesUtils.DATA_SAVING_MODE_OFF); - if (dataSavingMode.equals(SharedPreferencesUtils.DATA_SAVING_MODE_ONLY_ON_CELLULAR_DATA)) { - if (emotePlugin != null) { - emotePlugin.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR); - } - - if (imageAndGifEntry != null) { - imageAndGifEntry.setDataSavingMode(changeNetworkStatusEvent.connectedNetwork == Utils.NETWORK_TYPE_CELLULAR); - } - } - } }
\ No newline at end of file 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 872d288f..91939e61 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostPollActivity.java @@ -551,11 +551,8 @@ public class PostPollActivity extends BaseActivity implements FlairBottomSheetFr return true; } else if (itemId == R.id.action_preview_post_poll_activity) { Intent intent = new Intent(this, FullMarkdownActivity.class); - intent.putExtra(FullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, binding.postContentEditTextPostPollActivity.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_MARKDOWN, binding.postContentEditTextPostPollActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); - if (!uploadedImages.isEmpty()) { - intent.putParcelableArrayListExtra("test", uploadedImages); - } startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (itemId == R.id.action_send_post_poll_activity) { submitPost(item); 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 b7a88b41..26ee62f7 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/PostTextActivity.java @@ -476,11 +476,8 @@ 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, binding.postTextContentEditTextPostTextActivity.getText().toString()); + intent.putExtra(FullMarkdownActivity.EXTRA_MARKDOWN, binding.postTextContentEditTextPostTextActivity.getText().toString()); intent.putExtra(FullMarkdownActivity.EXTRA_SUBMIT_POST, true); - if (!uploadedImages.isEmpty()) { - intent.putParcelableArrayListExtra("test", uploadedImages); - } startActivityForResult(intent, MARKDOWN_PREVIEW_REQUEST_CODE); } else if (itemId == R.id.action_send_post_text_activity) { submitPost(item); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java index 11053c09..ecc37d68 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/WikiActivity.java @@ -216,7 +216,7 @@ public class WikiActivity extends BaseActivity { markwon = MarkdownUtils.createFullRedditMarkwon(this, miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry); + markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); LinearLayoutManagerBugFixed linearLayoutManager = new SwipeLockLinearLayoutManager(this, new SwipeLockInterface() { @Override public void lockSwipe() { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java index bc764aa4..1bc8ec14 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsListingRecyclerViewAdapter.java @@ -562,7 +562,7 @@ public class CommentsListingRecyclerViewAdapter extends PagedListAdapter<Comment } }); commentMarkdownView.setLayoutManager(linearLayoutManager); - markwonAdapter = MarkdownUtils.createCustomTablesAdapter(mImageAndGifEntry); + markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry); markwonAdapter.setOnClickListener(view -> { if (view instanceof SpoilerOnClickTextView) { if (((SpoilerOnClickTextView) view).isSpoilerOnClick()) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java index 4dd77296..2c4c21a8 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentsRecyclerViewAdapter.java @@ -1339,7 +1339,7 @@ public class CommentsRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerVi } }); commentMarkdownView.setLayoutManager(linearLayoutManager); - mMarkwonAdapter = MarkdownUtils.createCustomTablesAdapter(mImageAndGifEntry); + mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry); commentMarkdownView.setAdapter(mMarkwonAdapter); itemView.setBackgroundColor(mCommentBackgroundColor); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java index c46091fa..959a4cd3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java @@ -416,7 +416,7 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler activity.startActivity(intent); } }); - mMarkwonAdapter = MarkdownUtils.createCustomTablesAdapter(mImageAndGifEntry); + mMarkwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(mImageAndGifEntry); } public void setCanStartActivity(boolean canStartActivity) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java index 510c4a35..d7cea869 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/RulesRecyclerViewAdapter.java @@ -177,7 +177,7 @@ public class RulesRecyclerViewAdapter extends RecyclerView.Adapter<RulesRecycler if (activity.typeface != null) { shortNameTextView.setTypeface(activity.typeface); } - markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry); + markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); SwipeLockLinearLayoutManager swipeLockLinearLayoutManager = new SwipeLockLinearLayoutManager(activity, new SwipeLockInterface() { @Override diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java index 419ace1b..1a187bff 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/SidebarFragment.java @@ -183,7 +183,7 @@ public class SidebarFragment extends Fragment { Markwon markwon = MarkdownUtils.createFullRedditMarkwon(activity, miscPlugin, emoteCloseBracketInlineProcessor, emotePlugin, imageAndGifPlugin, markdownColor, spoilerBackgroundColor, onLinkLongClickListener); - CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAdapter(imageAndGifEntry); + CustomMarkwonAdapter markwonAdapter = MarkdownUtils.createCustomTablesAndImagesAdapter(imageAndGifEntry); markwonAdapter.setOnLongClickListener(view -> { if (sidebarDescription != null && !sidebarDescription.equals("")) { Bundle bundle = new Bundle(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java index d3cd46a3..e83d5597 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/CustomMarkwonAdapter.java @@ -89,13 +89,6 @@ public class CustomMarkwonAdapter extends MarkwonAdapter { public void setParsedMarkdown(@NonNull Markwon markwon, @NonNull List<Node> nodes) { // clear all entries before applying - /*try { - JSONObject object = new RichTextJSONConverter().constructRichTextJSON(nodes); - Log.i("asdf", "s" + object); - } catch (JSONException e) { - throw new RuntimeException(e); - }*/ - defaultEntry.clear(); for (int i = 0, size = entries.size(); i < size; i++) { diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java index b7eacc61..4c3fd287 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/MarkdownUtils.java @@ -58,8 +58,8 @@ public class MarkdownUtils { } @NonNull - public static Markwon createPostSubmissionRedditMarkwon(@NonNull Context context, - @NonNull UploadedImagePlugin uploadedImagePlugin) { + public static Markwon createContentSubmissionRedditMarkwon(@NonNull Context context, + @NonNull UploadedImagePlugin uploadedImagePlugin) { return Markwon.builder(context) .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { plugin.excludeInlineProcessor(HtmlInlineProcessor.class); @@ -76,6 +76,27 @@ public class MarkdownUtils { } @NonNull + public static Markwon createContentPreviewRedditMarkwon(@NonNull Context context, + @NonNull MarkwonPlugin miscPlugin, + int markdownColor, + int spoilerBackgroundColor) { + return Markwon.builder(context) + .usePlugin(MarkwonInlineParserPlugin.create(plugin -> { + plugin.excludeInlineProcessor(HtmlInlineProcessor.class); + plugin.excludeInlineProcessor(BangInlineProcessor.class); + })) + .usePlugin(miscPlugin) + .usePlugin(SuperscriptPlugin.create()) + .usePlugin(SpoilerParserPlugin.create(markdownColor, spoilerBackgroundColor)) + .usePlugin(RedditHeadingPlugin.create()) + .usePlugin(StrikethroughPlugin.create()) + .usePlugin(MovementMethodPlugin.create(new SpoilerAwareMovementMethod())) + .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) + .usePlugin(TableEntryPlugin.create(context)) + .build(); + } + + @NonNull public static Markwon createDescriptionMarkwon(Context context, MarkwonPlugin miscPlugin, EvenBetterLinkMovementMethod.OnLinkLongClickListener onLinkLongClickListener) { return Markwon.builder(context) @@ -117,7 +138,7 @@ public class MarkdownUtils { * Creates a CustomMarkwonAdapter configured with support for tables and images. */ @NonNull - public static CustomMarkwonAdapter createCustomTablesAdapter(ImageAndGifEntry imageAndGifEntry) { + public static CustomMarkwonAdapter createCustomTablesAndImagesAdapter(ImageAndGifEntry imageAndGifEntry) { return CustomMarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) .include(TableBlock.class, TableEntry.create(builder -> builder .tableLayout(R.layout.adapter_table_block, R.id.table_layout) @@ -125,4 +146,13 @@ public class MarkdownUtils { .include(ImageAndGifBlock.class, imageAndGifEntry) .build(); } + + @NonNull + public static CustomMarkwonAdapter createCustomTablesAdapter() { + return CustomMarkwonAdapter.builder(R.layout.adapter_default_entry, R.id.text) + .include(TableBlock.class, TableEntry.create(builder -> builder + .tableLayout(R.layout.adapter_table_block, R.id.table_layout) + .textLayoutIsRoot(R.layout.view_table_entry_cell))) + .build(); + } } 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 5034ce54..f021e3fe 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/markdown/RichTextJSONConverter.java @@ -111,7 +111,7 @@ public class RichTextJSONConverter implements Visitor { List<UploadedImage> uploadedImages) throws JSONException { UploadedImagePlugin uploadedImagePlugin = new UploadedImagePlugin(); uploadedImagePlugin.setUploadedImages(uploadedImages); - Markwon markwon = MarkdownUtils.createPostSubmissionRedditMarkwon( + Markwon markwon = MarkdownUtils.createContentSubmissionRedditMarkwon( context, uploadedImagePlugin); List<Node> nodes = MarkwonReducer.directChildren().reduce(markwon.parse(markdown)); |