Unescape HTML for post content and comments. Minor UI fixes.

This commit is contained in:
Alex Ning 2019-04-26 21:53:32 +08:00
parent 6bd4b41f8c
commit 1d294609f5
10 changed files with 34 additions and 44 deletions

Binary file not shown.

View File

@ -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'

View File

@ -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);

View File

@ -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);

View File

@ -298,7 +298,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
switch (post.getPostType()) {
case Post.IMAGE_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.VISIBLE);
((DataViewHolder) holder).typeChip.setText("IMAGE");
final String imageUrl = post.getUrl();
@ -312,7 +311,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
break;
case Post.LINK_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.VISIBLE);
((DataViewHolder) holder).typeChip.setText("LINK");
((DataViewHolder) holder).imageView.setOnClickListener(view -> {
@ -325,7 +323,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
break;
case Post.GIF_VIDEO_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.VISIBLE);
((DataViewHolder) holder).typeChip.setText("GIF");
final Uri gifVideoUri = Uri.parse(post.getVideoUrl());
@ -344,7 +341,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
break;
case Post.VIDEO_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.VISIBLE);
((DataViewHolder) holder).typeChip.setText("VIDEO");
final Uri videoUri = Uri.parse(post.getVideoUrl());
@ -363,7 +359,6 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
break;
case Post.NO_PREVIEW_LINK_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.VISIBLE);
((DataViewHolder) holder).typeChip.setText("LINK");
final String noPreviewLinkUrl = post.getUrl();
((DataViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
@ -377,7 +372,7 @@ class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView.ViewHo
});
break;
case Post.TEXT_TYPE:
((DataViewHolder) holder).typeChip.setVisibility(View.GONE);
((DataViewHolder) holder).typeChip.setText("TEXT");
break;
}

View File

@ -2,9 +2,10 @@ package ml.docilealligator.infinityforreddit;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import android.util.Log;
import androidx.annotation.NonNull;
import java.util.HashMap;
import java.util.Map;
@ -109,7 +110,7 @@ class UserFollowing {
if(isSubscribing) {
subscribedUserDao.insert(subscribedUserData);
} else {
subscribedUserDao.deleteSubscribedUser(userName);;
subscribedUserDao.deleteSubscribedUser(userName);
}
return null;
}

View File

@ -245,6 +245,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
switch (mPost.getPostType()) {
case Post.IMAGE_TYPE:
mTypeChip.setText("IMAGE");
mImageView.setOnClickListener(view -> {
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());

View File

@ -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" />
<RelativeLayout
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:paddingTop="16dp">
<com.google.android.material.chip.Chip
android:id="@+id/type_text_view_view_post_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:textSize="12sp"
android:textColor="@android:color/white"
android:layout_centerVertical="true"
app:chipBackgroundColor="@color/colorPrimaryDark"/>
@ -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"/>
<TextView
android:id="@+id/gilded_number_text_view_view_post_detail"
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_view_post_detail"
android:layout_centerVertical="true"
android:visibility="gone"
android:textSize="20sp"
android:textColor="@color/gold"/>
@ -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"/>
</RelativeLayout>

View File

@ -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"/>
<RelativeLayout
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:paddingTop="16dp">
<com.google.android.material.chip.Chip
android:id="@+id/type_text_view_item_best_post"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:textSize="12sp"
android:textColor="@android:color/white"
android:layout_centerVertical="true"
app:chipBackgroundColor="@color/colorPrimaryDark"/>
app:chipBackgroundColor="@color/colorPrimaryDark" />
<ImageView
android:id="@+id/gilded_image_view_item_best_post"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_toEndOf="@id/type_text_view_item_best_post"
android:layout_marginTop="8dp"
android:layout_centerVertical="true"
android:visibility="gone"/>
@ -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"