From f0b149ce82cf11df1f5cf84c7d644e5e670ad0b2 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Wed, 9 Jan 2019 10:05:20 +0800 Subject: Use MarkwonView (a markdown library) instead of HtmlTextView to display post content and comments. --- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes app/build.gradle | 4 +++- .../CommentMultiLevelRecyclerViewAdapter.java | 7 +++--- .../infinityforreddit/ViewPostDetailActivity.java | 26 ++++++++++----------- .../main/res/layout/activity_view_post_detail.xml | 7 ++---- .../res/layout/activity_view_subreddit_detail.xml | 18 ++++---------- app/src/main/res/layout/item_post_comment.xml | 7 +++--- app/src/main/res/values/strings.xml | 2 ++ 8 files changed, 31 insertions(+), 40 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 3ba2f49b..20d483cc 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/app/build.gradle b/app/build.gradle index 903953de..43ead6ce 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -59,7 +59,6 @@ dependencies { annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion" implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'io.reactivex.rxjava2:rxjava:2.2.0' - implementation 'org.sufficientlysecure:html-textview:3.6' implementation 'com.squareup.retrofit2:retrofit:2.4.0' implementation 'com.squareup.retrofit2:converter-scalars:2.4.0' implementation 'jp.wasabeef:glide-transformations:4.0.0' @@ -72,4 +71,7 @@ dependencies { implementation 'com.felipecsl:gifimageview:2.2.0' implementation "android.arch.paging:runtime:1.0.1" implementation "com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE" + implementation "ru.noties:markwon:2.0.1" + implementation "ru.noties:markwon-syntax-highlight:2.0.1" + implementation "ru.noties:markwon-view:2.0.1" } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java index bb95b2f6..3e3c655c 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentMultiLevelRecyclerViewAdapter.java @@ -18,8 +18,6 @@ import com.multilevelview.MultiLevelAdapter; import com.multilevelview.MultiLevelRecyclerView; import com.multilevelview.models.RecyclerViewItem; -import org.sufficientlysecure.htmltextview.HtmlTextView; - import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -27,6 +25,7 @@ import java.util.Locale; import butterknife.BindView; import butterknife.ButterKnife; import retrofit2.Retrofit; +import ru.noties.markwon.view.MarkwonView; class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { private Context mContext; @@ -67,7 +66,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { ((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor()); ((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime()); - ((CommentViewHolder) holder).commentHtmlTextView.setHtml(commentItem.getCommentContent()); + ((CommentViewHolder) holder).commentMarkdownView.setMarkdown(commentItem.getCommentContent()); ((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(commentItem.getScore())); ((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16; @@ -260,7 +259,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { class CommentViewHolder extends RecyclerView.ViewHolder { @BindView(R.id.author_text_view_item_post_comment) TextView authorTextView; @BindView(R.id.comment_time_text_view_item_post_comment) TextView commentTimeTextView; - @BindView(R.id.comment_html_text_view_item_post_comment) HtmlTextView commentHtmlTextView; + @BindView(R.id.comment_markdown_view_item_post_comment) MarkwonView commentMarkdownView; @BindView(R.id.plus_button_item_post_comment) ImageView upvoteButton; @BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView; @BindView(R.id.minus_button_item_post_comment) ImageView downvoteButton; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java index de7b7992..1b3a9f90 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java @@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.ColorFilter; +import android.graphics.PorterDuff; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -36,8 +37,6 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar; import com.multilevelview.MultiLevelRecyclerView; import com.santalu.aspectratioimageview.AspectRatioImageView; -import org.sufficientlysecure.htmltextview.HtmlTextView; - import java.util.ArrayList; import java.util.List; @@ -50,6 +49,7 @@ import butterknife.ButterKnife; import de.hdodenhof.circleimageview.CircleImageView; import jp.wasabeef.glide.transformations.BlurTransformation; import retrofit2.Retrofit; +import ru.noties.markwon.view.MarkwonView; public class ViewPostDetailActivity extends AppCompatActivity { @@ -66,7 +66,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { @BindView(R.id.subreddit_icon_circle_image_view_view_post_detail) CircleImageView mSubredditIconCircleImageView; @BindView(R.id.post_time_text_view_view_post_detail) TextView mPostTimeTextView; @BindView(R.id.subreddit_text_view_view_post_detail) TextView mSubredditTextView; - @BindView(R.id.content_html_text_view_view_post_detail) HtmlTextView mContentTextView; + @BindView(R.id.content_markdown_view_view_post_detail) MarkwonView mContentMarkdownView; @BindView(R.id.type_text_view_view_post_detail) Chip mTypeChip; @BindView(R.id.gilded_image_view_view_post_detail) ImageView mGildedImageView; @BindView(R.id.gilded_number_text_view_view_post_detail) TextView mGildedNumberTextView; @@ -151,11 +151,11 @@ public class ViewPostDetailActivity extends AppCompatActivity { switch (mPost.getVoteType()) { case 1: //Upvote - mUpvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); + mUpvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); break; case -1: //Downvote - mDownvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + mDownvoteButton.setColorFilter(ContextCompat.getColor(this, R.color.minusButtonColor), PorterDuff.Mode.SRC_IN); break; } @@ -268,8 +268,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { case Post.NO_PREVIEW_LINK_TYPE: mTypeChip.setText("LINK"); if(!mPost.getSelfText().equals("")) { - mContentTextView.setVisibility(View.VISIBLE); - mContentTextView.setHtml(mPost.getSelfText()); + mContentMarkdownView.setVisibility(View.VISIBLE); + mContentMarkdownView.setMarkdown(mPost.getSelfText()); } mNoPreviewLinkImageView.setVisibility(View.VISIBLE); mNoPreviewLinkImageView.setOnClickListener(view -> { @@ -284,8 +284,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { case Post.TEXT_TYPE: mTypeChip.setVisibility(View.GONE); if(!mPost.getSelfText().equals("")) { - mContentTextView.setVisibility(View.VISIBLE); - mContentTextView.setHtml(mPost.getSelfText()); + mContentMarkdownView.setVisibility(View.VISIBLE); + mContentMarkdownView.setMarkdown(mPost.getSelfText()); } break; } @@ -298,7 +298,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mDownvoteButton.clearColorFilter(); if (mUpvoteButton.getColorFilter() == null) { - mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); + mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); if(isDownvotedBefore) { mScoreTextView.setText(Integer.toString(mPost.getScore() + 2)); } else { @@ -340,7 +340,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); mScoreTextView.setText(Integer.toString(mPost.getScore() + 1)); - mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN); + mUpvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.colorPrimary), PorterDuff.Mode.SRC_IN); mPost.setScore(mPost.getScore() + 1); } }, mPost.getFullName(), RedditUtils.DIR_UNVOTE); @@ -354,7 +354,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { mUpvoteButton.clearColorFilter(); if (mDownvoteButton.getColorFilter() == null) { - mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), PorterDuff.Mode.SRC_IN); if (isUpvotedBefore) { mScoreTextView.setText(Integer.toString(mPost.getScore() - 2)); } else { @@ -395,7 +395,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { @Override public void onVoteThingFail() { Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); - mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN); + mDownvoteButton.setColorFilter(ContextCompat.getColor(ViewPostDetailActivity.this, R.color.minusButtonColor), PorterDuff.Mode.SRC_IN); mScoreTextView.setText(Integer.toString(mPost.getScore())); mPost.setScore(mPost.getScore()); } diff --git a/app/src/main/res/layout/activity_view_post_detail.xml b/app/src/main/res/layout/activity_view_post_detail.xml index 5880a9d3..bb2bd0e2 100644 --- a/app/src/main/res/layout/activity_view_post_detail.xml +++ b/app/src/main/res/layout/activity_view_post_detail.xml @@ -70,16 +70,13 @@ android:textColor="#000000" android:textSize="18sp" /> - + android:layout_height="180dp" + android:contentDescription="@string/content_description_banner_imageview" /> - - diff --git a/app/src/main/res/layout/item_post_comment.xml b/app/src/main/res/layout/item_post_comment.xml index 6981b955..e047d214 100644 --- a/app/src/main/res/layout/item_post_comment.xml +++ b/app/src/main/res/layout/item_post_comment.xml @@ -40,15 +40,14 @@ - + android:layout_marginBottom="8dp"/> Subscribe Failed Unsubscribed" Unsubscribe Failed + + Subreddit Banner Image -- cgit v1.2.3