Use MarkwonView (a markdown library) instead of HtmlTextView to display post content and comments.

This commit is contained in:
Alex Ning 2019-01-09 10:05:20 +08:00
parent 38be0ba01f
commit f0b149ce82
8 changed files with 31 additions and 40 deletions

Binary file not shown.

View File

@ -59,7 +59,6 @@ dependencies {
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion" annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0' implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.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:retrofit:2.4.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.4.0' implementation 'com.squareup.retrofit2:converter-scalars:2.4.0'
implementation 'jp.wasabeef:glide-transformations:4.0.0' implementation 'jp.wasabeef:glide-transformations:4.0.0'
@ -72,4 +71,7 @@ dependencies {
implementation 'com.felipecsl:gifimageview:2.2.0' implementation 'com.felipecsl:gifimageview:2.2.0'
implementation "android.arch.paging:runtime:1.0.1" implementation "android.arch.paging:runtime:1.0.1"
implementation "com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE" 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"
} }

View File

@ -18,8 +18,6 @@ import com.multilevelview.MultiLevelAdapter;
import com.multilevelview.MultiLevelRecyclerView; import com.multilevelview.MultiLevelRecyclerView;
import com.multilevelview.models.RecyclerViewItem; import com.multilevelview.models.RecyclerViewItem;
import org.sufficientlysecure.htmltextview.HtmlTextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -27,6 +25,7 @@ import java.util.Locale;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import ru.noties.markwon.view.MarkwonView;
class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter { class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
private Context mContext; private Context mContext;
@ -67,7 +66,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor()); ((CommentViewHolder) holder).authorTextView.setText(commentItem.getAuthor());
((CommentViewHolder) holder).commentTimeTextView.setText(commentItem.getCommentTime()); ((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).scoreTextView.setText(Integer.toString(commentItem.getScore()));
((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16; ((CommentViewHolder) holder).verticalBlock.getLayoutParams().width = commentItem.getDepth() * 16;
@ -260,7 +259,7 @@ class CommentMultiLevelRecyclerViewAdapter extends MultiLevelAdapter {
class CommentViewHolder extends RecyclerView.ViewHolder { class CommentViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.author_text_view_item_post_comment) TextView authorTextView; @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_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.plus_button_item_post_comment) ImageView upvoteButton;
@BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView; @BindView(R.id.score_text_view_item_post_comment) TextView scoreTextView;
@BindView(R.id.minus_button_item_post_comment) ImageView downvoteButton; @BindView(R.id.minus_button_item_post_comment) ImageView downvoteButton;

View File

@ -3,6 +3,7 @@ package ml.docilealligator.infinityforreddit;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.ColorFilter; import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
@ -36,8 +37,6 @@ import com.lsjwzh.widget.materialloadingprogressbar.CircleProgressBar;
import com.multilevelview.MultiLevelRecyclerView; import com.multilevelview.MultiLevelRecyclerView;
import com.santalu.aspectratioimageview.AspectRatioImageView; import com.santalu.aspectratioimageview.AspectRatioImageView;
import org.sufficientlysecure.htmltextview.HtmlTextView;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -50,6 +49,7 @@ import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView; import de.hdodenhof.circleimageview.CircleImageView;
import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.BlurTransformation;
import retrofit2.Retrofit; import retrofit2.Retrofit;
import ru.noties.markwon.view.MarkwonView;
public class ViewPostDetailActivity extends AppCompatActivity { 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.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.post_time_text_view_view_post_detail) TextView mPostTimeTextView;
@BindView(R.id.subreddit_text_view_view_post_detail) TextView mSubredditTextView; @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.type_text_view_view_post_detail) Chip mTypeChip;
@BindView(R.id.gilded_image_view_view_post_detail) ImageView mGildedImageView; @BindView(R.id.gilded_image_view_view_post_detail) ImageView mGildedImageView;
@BindView(R.id.gilded_number_text_view_view_post_detail) TextView mGildedNumberTextView; @BindView(R.id.gilded_number_text_view_view_post_detail) TextView mGildedNumberTextView;
@ -151,11 +151,11 @@ public class ViewPostDetailActivity extends AppCompatActivity {
switch (mPost.getVoteType()) { switch (mPost.getVoteType()) {
case 1: case 1:
//Upvote //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; break;
case -1: case -1:
//Downvote //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; break;
} }
@ -268,8 +268,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
case Post.NO_PREVIEW_LINK_TYPE: case Post.NO_PREVIEW_LINK_TYPE:
mTypeChip.setText("LINK"); mTypeChip.setText("LINK");
if(!mPost.getSelfText().equals("")) { if(!mPost.getSelfText().equals("")) {
mContentTextView.setVisibility(View.VISIBLE); mContentMarkdownView.setVisibility(View.VISIBLE);
mContentTextView.setHtml(mPost.getSelfText()); mContentMarkdownView.setMarkdown(mPost.getSelfText());
} }
mNoPreviewLinkImageView.setVisibility(View.VISIBLE); mNoPreviewLinkImageView.setVisibility(View.VISIBLE);
mNoPreviewLinkImageView.setOnClickListener(view -> { mNoPreviewLinkImageView.setOnClickListener(view -> {
@ -284,8 +284,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
case Post.TEXT_TYPE: case Post.TEXT_TYPE:
mTypeChip.setVisibility(View.GONE); mTypeChip.setVisibility(View.GONE);
if(!mPost.getSelfText().equals("")) { if(!mPost.getSelfText().equals("")) {
mContentTextView.setVisibility(View.VISIBLE); mContentMarkdownView.setVisibility(View.VISIBLE);
mContentTextView.setHtml(mPost.getSelfText()); mContentMarkdownView.setMarkdown(mPost.getSelfText());
} }
break; break;
} }
@ -298,7 +298,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mDownvoteButton.clearColorFilter(); mDownvoteButton.clearColorFilter();
if (mUpvoteButton.getColorFilter() == null) { 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) { if(isDownvotedBefore) {
mScoreTextView.setText(Integer.toString(mPost.getScore() + 2)); mScoreTextView.setText(Integer.toString(mPost.getScore() + 2));
} else { } else {
@ -340,7 +340,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show();
mScoreTextView.setText(Integer.toString(mPost.getScore() + 1)); 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.setScore(mPost.getScore() + 1);
} }
}, mPost.getFullName(), RedditUtils.DIR_UNVOTE); }, mPost.getFullName(), RedditUtils.DIR_UNVOTE);
@ -354,7 +354,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mUpvoteButton.clearColorFilter(); mUpvoteButton.clearColorFilter();
if (mDownvoteButton.getColorFilter() == null) { 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) { if (isUpvotedBefore) {
mScoreTextView.setText(Integer.toString(mPost.getScore() - 2)); mScoreTextView.setText(Integer.toString(mPost.getScore() - 2));
} else { } else {
@ -395,7 +395,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
@Override @Override
public void onVoteThingFail() { public void onVoteThingFail() {
Toast.makeText(ViewPostDetailActivity.this, "Cannot unvote this post", Toast.LENGTH_SHORT).show(); 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())); mScoreTextView.setText(Integer.toString(mPost.getScore()));
mPost.setScore(mPost.getScore()); mPost.setScore(mPost.getScore());
} }

View File

@ -70,16 +70,13 @@
android:textColor="#000000" android:textColor="#000000"
android:textSize="18sp" /> android:textSize="18sp" />
<org.sufficientlysecure.htmltextview.HtmlTextView <ru.noties.markwon.view.MarkwonView
android:id="@+id/content_html_text_view_view_post_detail" android:id="@+id/content_markdown_view_view_post_detail"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginEnd="16dp" android:layout_marginEnd="16dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:textAppearance="@android:style/TextAppearance.Small"
android:visibility="gone" /> android:visibility="gone" />
<RelativeLayout <RelativeLayout

View File

@ -29,7 +29,8 @@
android:id="@+id/banner_image_view_view_subreddit_detail_activity" android:id="@+id/banner_image_view_view_subreddit_detail_activity"
android:layout_width="match_parent" android:layout_width="match_parent"
android:scaleType="centerCrop" android:scaleType="centerCrop"
android:layout_height="180dp" /> android:layout_height="180dp"
android:contentDescription="@string/content_description_banner_imageview" />
<com.felipecsl.gifimageview.library.GifImageView <com.felipecsl.gifimageview.library.GifImageView
android:id="@+id/icon_gif_image_view_view_subreddit_detail_activity" android:id="@+id/icon_gif_image_view_view_subreddit_detail_activity"
@ -58,6 +59,7 @@
android:id="@+id/subreddit_name_text_view_view_subreddit_detail_activity" android:id="@+id/subreddit_name_text_view_view_subreddit_detail_activity"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
android:textSize="18sp" android:textSize="18sp"
android:textColor="@color/colorAccent" android:textColor="@color/colorAccent"
@ -70,17 +72,6 @@
android:textColor="@android:color/white" android:textColor="@android:color/white"
android:layout_gravity="center_horizontal"/> android:layout_gravity="center_horizontal"/>
<!--<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
</RelativeLayout>-->
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
@ -91,6 +82,8 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="@android:color/black" android:textColor="@android:color/black"
android:layout_alignParentStart="true"
android:layout_toStartOf="@id/online_subscriber_count_text_view_view_subreddit_detail_activity"
android:layout_marginBottom="16dp"/> android:layout_marginBottom="16dp"/>
<TextView <TextView
@ -98,7 +91,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:layout_toStartOf="@id/subscriber_count_text_view_view_subreddit_detail_activity"
android:textColor="@android:color/black" /> android:textColor="@android:color/black" />
</RelativeLayout> </RelativeLayout>

View File

@ -40,15 +40,14 @@
</LinearLayout> </LinearLayout>
<org.sufficientlysecure.htmltextview.HtmlTextView <ru.noties.markwon.view.MarkwonView
android:id="@+id/comment_html_text_view_item_post_comment" android:id="@+id/comment_markdown_view_item_post_comment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginStart="32dp" android:layout_marginStart="32dp"
android:layout_marginEnd="32dp" android:layout_marginEnd="32dp"
android:layout_marginBottom="8dp" android:layout_marginBottom="8dp"/>
android:textAppearance="@android:style/TextAppearance.Small"/>
<RelativeLayout <RelativeLayout
android:id="@+id/relative_layout_item_post_comment" android:id="@+id/relative_layout_item_post_comment"

View File

@ -125,4 +125,6 @@
<string name="subscribe_failed">Subscribe Failed</string> <string name="subscribe_failed">Subscribe Failed</string>
<string name="unsubscribed">Unsubscribed</string>" <string name="unsubscribed">Unsubscribed</string>"
<string name="unsubscribe_failed">Unsubscribe Failed</string> <string name="unsubscribe_failed">Unsubscribe Failed</string>
<string name="content_description_banner_imageview">Subreddit Banner Image</string>
</resources> </resources>