From 1d294609f5bb472fea0d536ac381359e9d9c4dc0 Mon Sep 17 00:00:00 2001 From: Alex Ning Date: Fri, 26 Apr 2019 21:53:32 +0800 Subject: Unescape HTML for post content and comments. Minor UI fixes. --- .../java/ml/docilealligator/infinityforreddit/ParseComment.java | 3 ++- .../java/ml/docilealligator/infinityforreddit/ParsePost.java | 9 +++++---- .../infinityforreddit/PostRecyclerViewAdapter.java | 7 +------ .../java/ml/docilealligator/infinityforreddit/UserFollowing.java | 5 +++-- .../infinityforreddit/ViewPostDetailActivity.java | 5 ++++- 5 files changed, 15 insertions(+), 14 deletions(-) (limited to 'app/src/main/java/ml') diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java index 970c9ed6..c2808e97 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.os.AsyncTask; +import android.text.Html; import android.util.Log; import org.json.JSONArray; @@ -116,7 +117,7 @@ class ParseComment { boolean isSubmitter = data.getBoolean(JSONUtils.IS_SUBMITTER_KEY); String commentContent = ""; if(!data.isNull(JSONUtils.BODY_HTML_KEY)) { - commentContent = data.getString(JSONUtils.BODY_HTML_KEY); + commentContent = Html.fromHtml(data.getString(JSONUtils.BODY_HTML_KEY).trim()).toString(); } String permalink = data.getString(JSONUtils.PERMALINK_KEY); int score = data.getInt(JSONUtils.SCORE_KEY); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java index f3d92f70..6cb68323 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java @@ -1,6 +1,7 @@ package ml.docilealligator.infinityforreddit; import android.os.AsyncTask; +import android.text.Html; import android.util.Log; import org.json.JSONArray; @@ -148,7 +149,7 @@ class ParsePost { if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { post.setSelfText(""); } else { - post.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()); + post.setSelfText(Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()).toString()); } bestPostData.add(post); } else { @@ -161,7 +162,7 @@ class ParsePost { if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { linkPost.setSelfText(""); } else { - linkPost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()); + linkPost.setSelfText(Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()).toString()); } bestPostData.add(linkPost); } @@ -252,7 +253,7 @@ class ParsePost { if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { textWithImagePost.setSelfText(""); } else { - textWithImagePost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()); + textWithImagePost.setSelfText(Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()).toString()); } bestPostData.add(textWithImagePost); } else { @@ -265,7 +266,7 @@ class ParsePost { if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) { linkPost.setSelfText(""); } else { - linkPost.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()); + linkPost.setSelfText(Html.fromHtml(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim()).toString()); } linkPost.setPreviewWidth(previewWidth); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java index 5b2fecb7..0bc59909 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java @@ -298,7 +298,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter { @@ -325,7 +323,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter { Intent intent = new Intent(ViewPostDetailActivity.this, ViewImageActivity.class); intent.putExtra(ViewImageActivity.IMAGE_URL_KEY, mPost.getUrl()); @@ -304,6 +305,7 @@ public class ViewPostDetailActivity extends AppCompatActivity { break; case Post.NO_PREVIEW_LINK_TYPE: mTypeChip.setText("LINK"); + if(!mPost.getSelfText().equals("")) { mContentMarkdownView.setVisibility(View.VISIBLE); mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText()); @@ -319,7 +321,8 @@ public class ViewPostDetailActivity extends AppCompatActivity { }); break; case Post.TEXT_TYPE: - mTypeChip.setVisibility(View.GONE); + mTypeChip.setText("TEXT"); + if(!mPost.getSelfText().equals("")) { mContentMarkdownView.setVisibility(View.VISIBLE); mContentMarkdownView.setMarkdown(getCustomSpannableConfiguration(), mPost.getSelfText()); -- cgit v1.2.3