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. --- .idea/caches/build_file_checksums.ser | Bin 533 -> 533 bytes .idea/caches/gradle_models.ser | Bin 252290 -> 252290 bytes app/build.gradle | 4 ++-- .../infinityforreddit/ParseComment.java | 3 ++- .../infinityforreddit/ParsePost.java | 9 +++---- .../infinityforreddit/PostRecyclerViewAdapter.java | 7 +----- .../infinityforreddit/UserFollowing.java | 5 ++-- .../infinityforreddit/ViewPostDetailActivity.java | 5 +++- .../main/res/layout/activity_view_post_detail.xml | 26 +++++++++------------ app/src/main/res/layout/item_post.xml | 19 +++++---------- 10 files changed, 34 insertions(+), 44 deletions(-) diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index 94a9af7a..7da048ff 100644 Binary files a/.idea/caches/build_file_checksums.ser and b/.idea/caches/build_file_checksums.ser differ diff --git a/.idea/caches/gradle_models.ser b/.idea/caches/gradle_models.ser index 3646acb5..0dc3e377 100644 Binary files a/.idea/caches/gradle_models.ser and b/.idea/caches/gradle_models.ser differ diff --git a/app/build.gradle b/app/build.gradle index 82064ea1..6fe85a03 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -39,8 +39,8 @@ dependencies { implementation 'androidx.legacy:legacy-support-v4:1.0.0' implementation 'androidx.legacy:legacy-support-v13:1.0.0' testImplementation 'junit:junit:4.12' - androidTestImplementation 'androidx.test:runner:1.2.0-alpha03' - androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03' + androidTestImplementation 'androidx.test:runner:1.2.0-alpha04' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha04' implementation 'com.google.android.exoplayer:exoplayer:2.9.6' implementation 'com.google.android.exoplayer:exoplayer-dash:2.9.6' implementation 'androidx.browser:browser:1.0.0' 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()); 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 1a0be45d..26239fef 100644 --- a/app/src/main/res/layout/activity_view_post_detail.xml +++ b/app/src/main/res/layout/activity_view_post_detail.xml @@ -73,10 +73,8 @@ android:id="@+id/title_text_view_view_post_detail" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" - android:layout_marginStart="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp" android:textColor="#000000" android:textSize="18sp" /> @@ -84,24 +82,23 @@ android:id="@+id/content_markdown_view_view_post_detail" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" - android:layout_marginStart="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp" android:layout_marginTop="16dp" android:visibility="gone" /> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:paddingTop="16dp"> @@ -110,18 +107,18 @@ android:id="@+id/gilded_image_view_view_post_detail" android:layout_width="24dp" android:layout_height="24dp" - android:layout_marginTop="8dp" android:layout_toEndOf="@id/type_text_view_view_post_detail" + android:layout_centerVertical="true" android:visibility="gone"/> @@ -130,11 +127,10 @@ android:id="@+id/crosspost_image_view_view_post_detail" android:layout_width="24dp" android:layout_height="24dp" - android:layout_marginTop="8dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" - android:layout_toStartOf="@id/nsfw_text_view_item_best_post" android:layout_toEndOf="@id/gilded_number_text_view_view_post_detail" + android:layout_centerVertical="true" android:src="@drawable/crosspost" android:tint="@color/colorAccent" android:visibility="gone"/> @@ -145,10 +141,10 @@ android:layout_height="wrap_content" android:text="@string/nsfw" android:layout_alignParentEnd="true" - android:layout_marginTop="8dp" android:layout_marginStart="8dp" android:textColor="@android:color/white" android:visibility="gone" + android:layout_centerVertical="true" app:chipBackgroundColor="@color/colorAccent"/> diff --git a/app/src/main/res/layout/item_post.xml b/app/src/main/res/layout/item_post.xml index 9d94cb2a..45024d78 100644 --- a/app/src/main/res/layout/item_post.xml +++ b/app/src/main/res/layout/item_post.xml @@ -71,34 +71,32 @@ android:id="@+id/title_text_view_best_post_item" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_marginStart="16dp" - android:layout_marginEnd="16dp" + android:paddingStart="16dp" + android:paddingEnd="16dp" android:textSize="18sp" android:textColor="#000000"/> + android:paddingStart="16dp" + android:paddingEnd="16dp" + android:paddingTop="16dp"> + app:chipBackgroundColor="@color/colorPrimaryDark" /> @@ -106,7 +104,6 @@ android:id="@+id/gilded_number_text_view_item_best_post" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="8dp" android:layout_marginStart="4dp" android:layout_marginEnd="8dp" android:layout_toEndOf="@id/gilded_image_view_item_best_post" @@ -119,10 +116,8 @@ android:id="@+id/crosspost_image_view_item_best_post" android:layout_width="24dp" android:layout_height="24dp" - android:layout_marginTop="8dp" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" - android:layout_toStartOf="@id/nsfw_text_view_item_best_post" android:layout_toEndOf="@id/gilded_number_text_view_item_best_post" android:src="@drawable/crosspost" android:tint="@color/colorAccent" @@ -135,9 +130,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentEnd="true" - android:layout_marginTop="8dp" android:layout_marginStart="8dp" - android:textSize="12sp" android:textColor="@android:color/white" android:visibility="gone" android:layout_centerVertical="true" -- cgit v1.2.3