From acaece6e3e63fba9f7a38899e3fb3079c9dd12c0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Mon, 14 Sep 2020 09:06:31 +0800 Subject: Viewing comment's full markdown is available. --- app/src/main/AndroidManifest.xml | 8 +- .../Activity/CommentFullMarkdownActivity.java | 249 +++++++++++++++++++++ .../Adapter/CommentAndPostRecyclerViewAdapter.java | 2 + .../CommentsListingRecyclerViewAdapter.java | 1 + .../infinityforreddit/AppComponent.java | 3 + .../CommentMoreBottomSheetFragment.java | 18 ++ .../res/drawable-night/ic_full_markdown_24dp.xml | 9 + .../main/res/drawable/ic_full_markdown_24dp.xml | 9 + .../res/layout/activity_comment_full_markdown.xml | 42 ++++ .../layout/fragment_comment_more_bottom_sheet.xml | 19 ++ app/src/main/res/values/strings.xml | 16 +- 11 files changed, 360 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/ml/docilealligator/infinityforreddit/Activity/CommentFullMarkdownActivity.java create mode 100644 app/src/main/res/drawable-night/ic_full_markdown_24dp.xml create mode 100644 app/src/main/res/drawable/ic_full_markdown_24dp.xml create mode 100644 app/src/main/res/layout/activity_comment_full_markdown.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a35853b4..9d545e5b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,11 +26,15 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:replace="android:label"> - + + android:windowSoftInputMode="adjustResize" /> = Build.VERSION_CODES.M) { + Window window = getWindow(); + + if (isChangeStatusBarIconColor()) { + addOnOffsetChangedListener(appBarLayout); + } + + if (isImmersiveInterface()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { + coordinatorLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | + View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + } else { + window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); + } + adjustToolbar(toolbar); + markdownRecyclerView.setPadding(0, 0, 0, getNavBarHeight()); + } + } + + String commentMarkdown = getIntent().getStringExtra(EXTRA_COMMENT_MARKDOWN); + boolean isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false); + int markdownColor = mCustomThemeWrapper.getCommentColor(); + int linkColor = mCustomThemeWrapper.getLinkColor(); + Markwon markwon = Markwon.builder(this) + .usePlugin(new AbstractMarkwonPlugin() { + @NonNull + @Override + public String processMarkdown(@NonNull String markdown) { + StringBuilder markdownStringBuilder = new StringBuilder(markdown); + Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<"); + Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); + while (matcher.find()) { + markdownStringBuilder.replace(matcher.start(), matcher.start() + 1, ">"); + } + return super.processMarkdown(markdownStringBuilder.toString()); + } + + @Override + public void afterSetText(@NonNull TextView textView) { + textView.setHighlightColor(Color.TRANSPARENT); + SpannableStringBuilder markdownStringBuilder = new SpannableStringBuilder(textView.getText().toString()); + Pattern spoilerPattern = Pattern.compile(">![\\S\\s]*?!<"); + Matcher matcher = spoilerPattern.matcher(markdownStringBuilder); + int start = 0; + boolean find = false; + while (matcher.find(start)) { + find = true; + markdownStringBuilder.delete(matcher.end() - 2, matcher.end()); + markdownStringBuilder.delete(matcher.start(), matcher.start() + 2); + ClickableSpan clickableSpan = new ClickableSpan() { + private boolean isShowing = false; + @Override + public void updateDrawState(@NonNull TextPaint ds) { + if (isShowing) { + super.updateDrawState(ds); + ds.setColor(markdownColor); + } else { + ds.bgColor = markdownColor; + ds.setColor(markdownColor); + } + ds.setUnderlineText(false); + } + + @Override + public void onClick(@NonNull View view) { + isShowing = !isShowing; + view.invalidate(); + } + }; + markdownStringBuilder.setSpan(clickableSpan, matcher.start(), matcher.end() - 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + start = matcher.end() - 4; + } + if (find) { + textView.setText(markdownStringBuilder); + } + } + + @Override + public void beforeSetText(@NonNull TextView textView, @NonNull Spanned markdown) { + textView.setTextColor(markdownColor); + } + + @Override + public void configureConfiguration(@NonNull MarkwonConfiguration.Builder builder) { + builder.linkResolver((view, link) -> { + Intent intent = new Intent(CommentFullMarkdownActivity.this, LinkResolverActivity.class); + Uri uri = Uri.parse(link); + if (uri.getScheme() == null && uri.getHost() == null) { + intent.setData(LinkResolverActivity.getRedditUriByPath(link)); + } else { + intent.setData(uri); + } + intent.putExtra(LinkResolverActivity.EXTRA_IS_NSFW, isNsfw); + startActivity(intent); + }); + } + + @Override + public void configureTheme(@NonNull MarkwonTheme.Builder builder) { + builder.linkColor(linkColor); + } + }) + .usePlugin(StrikethroughPlugin.create()) + .usePlugin(LinkifyPlugin.create(Linkify.WEB_URLS)) + .usePlugin(SimpleExtPlugin.create(plugin -> + plugin.addExtension(1, '^', (configuration, props) -> { + return new SuperscriptSpan(); + }) + ) + ) + .usePlugin(TableEntryPlugin.create(this)) + .build(); + + MarkwonAdapter markwonAdapter = MarkwonAdapter.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(); + LinearLayoutManager linearLayoutManager = new MarkwonLinearLayoutManager(this, new MarkwonLinearLayoutManager.HorizontalScrollViewScrolledListener() { + @Override + public void onScrolledLeft() { + if (mSlidrInterface != null) { + mSlidrInterface.lock(); + } + } + + @Override + public void onScrolledRight() { + if (mSlidrInterface != null) { + mSlidrInterface.unlock(); + } + } + }); + markdownRecyclerView.setLayoutManager(linearLayoutManager); + markdownRecyclerView.setAdapter(markwonAdapter); + markwonAdapter.setMarkdown(markwon, commentMarkdown); + markwonAdapter.notifyDataSetChanged(); + } + + @Override + protected SharedPreferences getDefaultSharedPreferences() { + return mSharedPreferences; + } + + @Override + protected CustomThemeWrapper getCustomThemeWrapper() { + return mCustomThemeWrapper; + } + + @Override + protected void applyCustomTheme() { + coordinatorLayout.setBackgroundColor(mCustomThemeWrapper.getCommentBackgroundColor()); + applyAppBarLayoutAndToolbarTheme(appBarLayout, toolbar); + } +} \ No newline at end of file diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java index d765b067..fec7839a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java @@ -3202,6 +3202,8 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter { + Intent intent = new Intent(activity, CommentFullMarkdownActivity.class); + intent.putExtra(CommentFullMarkdownActivity.EXTRA_IS_NSFW, bundle.getBoolean(EXTRA_IS_NSFW, false)); + intent.putExtra(CommentFullMarkdownActivity.EXTRA_COMMENT_MARKDOWN, bundle.getString(EXTRA_COMMENT_MARKDOWN, "")); + activity.startActivity(intent); + + dismiss(); + }); + reportTextView.setOnClickListener(view -> { Intent intent = new Intent(activity, ReportActivity.class); intent.putExtra(ReportActivity.EXTRA_SUBREDDIT_NAME, comment.getSubredditName()); diff --git a/app/src/main/res/drawable-night/ic_full_markdown_24dp.xml b/app/src/main/res/drawable-night/ic_full_markdown_24dp.xml new file mode 100644 index 00000000..bada8be1 --- /dev/null +++ b/app/src/main/res/drawable-night/ic_full_markdown_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_full_markdown_24dp.xml b/app/src/main/res/drawable/ic_full_markdown_24dp.xml new file mode 100644 index 00000000..494d9579 --- /dev/null +++ b/app/src/main/res/drawable/ic_full_markdown_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/activity_comment_full_markdown.xml b/app/src/main/res/layout/activity_comment_full_markdown.xml new file mode 100644 index 00000000..53ac6ea6 --- /dev/null +++ b/app/src/main/res/layout/activity_comment_full_markdown.xml @@ -0,0 +1,42 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml index 5d8c86d0..6873171b 100644 --- a/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml +++ b/app/src/main/res/layout/fragment_comment_more_bottom_sheet.xml @@ -85,6 +85,25 @@ android:textSize="?attr/font_default" android:fontFamily="?attr/font_family" /> + + Block User Blocked Failed to block user - - Messages - Sync - - - Your signature - Default reply action - - - Sync email periodically - Download incoming attachments - Automatically download attachments for incoming emails - - Only download attachments when manually requested + + View Full Markdown -- cgit v1.2.3