aboutsummaryrefslogtreecommitdiff
path: root/app/src
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-20 16:08:48 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-20 16:08:48 +0000
commit80058ff6ab192b830b39566ee07a5903c450cf6c (patch)
tree154cac141fd52fd7c2ec7054113372a09732d808 /app/src
parent0fa03cba2150a2225677d6abe611c63510e428ee (diff)
downloadinfinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar.gz
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar.bz2
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar.lz
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar.xz
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.tar.zst
infinity-for-reddit-80058ff6ab192b830b39566ee07a5903c450cf6c.zip
Load comment and post content text in HTML form instead of String. Fixed a bug that the icon of subreddits was not parsed properly in ParseSubredditData class.
Diffstat (limited to 'app/src')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java8
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java7
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java6
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java6
-rw-r--r--app/src/main/res/layout/activity_view_post_detail.xml6
-rw-r--r--app/src/main/res/layout/item_post_comment.xml6
8 files changed, 30 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
index eef1a004..8af5a765 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/CommentRecyclerViewAdapter.java
@@ -14,6 +14,8 @@ import android.widget.Toast;
import com.android.volley.RequestQueue;
+import org.sufficientlysecure.htmltextview.HtmlTextView;
+
import java.util.ArrayList;
class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
@@ -40,7 +42,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
((CommentViewHolder) holder).authorTextView.setText(mCommentData.get(position).getAuthor());
((CommentViewHolder) holder).commentTimeTextView.setText(mCommentData.get(position).getCommentTime());
- ((CommentViewHolder) holder).commentTextView.setText(mCommentData.get(position).getCommentContent());
+ ((CommentViewHolder) holder).commentHtmlTextView.setHtml(mCommentData.get(position).getCommentContent());
((CommentViewHolder) holder).scoreTextView.setText(Integer.toString(mCommentData.get(position).getScore()));
switch (mCommentData.get(position).getVoteType()) {
@@ -180,7 +182,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
private class CommentViewHolder extends RecyclerView.ViewHolder {
private TextView authorTextView;
private TextView commentTimeTextView;
- private TextView commentTextView;
+ private HtmlTextView commentHtmlTextView;
private ImageView upvoteButton;
private ImageView downvoteButton;
private TextView scoreTextView;
@@ -190,7 +192,7 @@ class CommentRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
super(itemView);
authorTextView = itemView.findViewById(R.id.author_text_view_item_post_comment);
commentTimeTextView = itemView.findViewById(R.id.comment_time_text_view_item_post_comment);
- commentTextView = itemView.findViewById(R.id.comment_text_view_item_post_comment);
+ commentHtmlTextView = itemView.findViewById(R.id.comment_html_text_view_item_post_comment);
upvoteButton = itemView.findViewById(R.id.plus_button_item_post_comment);
downvoteButton = itemView.findViewById(R.id.minus_button_item_post_comment);
scoreTextView = itemView.findViewById(R.id.score_text_view_item_post_comment);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
index 81d2a77f..d798f8dc 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/JSONUtils.java
@@ -13,7 +13,7 @@ class JSONUtils {
static final String TITLE_KEY = "title";
static final String NAME_KEY = "name";
static final String SUBREDDIT_NAME_PREFIX_KEY = "subreddit_name_prefixed";
- static final String SELF_TEXT_KEY = "selftext";
+ static final String SELFTEXT_HTML_KEY = "selftext_html";
static final String AUTHOR_KEY = "author";
static final String DOMAIN_KEY = "domain";
static final String LINK_FLAIR_TEXT_KEY = "link_flair_text";
@@ -44,7 +44,7 @@ class JSONUtils {
static final String REDDIT_VIDEO_PREVIEW_KEY = "reddit_video_preview";
static final String IS_REDDIT_MEDIA_DOMAIN = "is_reddit_media_domain";
static final String STICKIED_KEY = "stickied";
- static final String BODY_KEY = "body";
+ static final String BODY_HTML_KEY = "body_html";
static final String COLLAPSED_KEY = "collapsed";
static final String IS_SUBMITTER_KEY = "is_submitter";
static final String REPLIES_KEY = "replies";
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
index 686a4874..4f3781b0 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseComment.java
@@ -72,7 +72,7 @@ class ParseComment {
String fullName = data.getString(JSONUtils.LINK_ID);
String author = data.getString(JSONUtils.AUTHOR_KEY);
boolean isSubmitter = data.getBoolean(JSONUtils.IS_SUBMITTER_KEY);
- String commentContent = data.getString(JSONUtils.BODY_KEY);
+ String commentContent = data.getString(JSONUtils.BODY_HTML_KEY);
String permalink = data.getString(JSONUtils.PERMALINK_KEY);
int score = data.getInt(JSONUtils.SCORE_KEY);
long submitTime = data.getLong(JSONUtils.CREATED_UTC_KEY) * 1000;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index aed3a1fc..b2fbb420 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -130,7 +130,12 @@ class ParsePost {
Log.i("text", Integer.toString(i));
int postType = PostData.TEXT_TYPE;
PostData postData = new PostData(id, fullName, subredditName, formattedPostTime, title, permalink, score, postType, voteType, nsfw);
- postData.setSelfText(data.getString(JSONUtils.SELF_TEXT_KEY).trim());
+ if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
+ postData.setSelfText("");
+ } else {
+ postData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ }
+ postData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
bestPostData.add(postData);
} else {
//No preview link post
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
index 3c31be30..47fa851e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParseSubredditData.java
@@ -46,6 +46,12 @@ class ParseSubredditData {
String description = data.getString(JSONUtils.PUBLIC_DESCRIPTION).trim();
String bannerImageUrl = data.getString(JSONUtils.BANNER_IMG_KEY);
String iconImageUrl = data.getString(JSONUtils.ICON_IMG_KEY);
+ if(iconImageUrl.equals("") || iconImageUrl.equals("null")) {
+ iconImageUrl = data.getString(JSONUtils.COMMUNITY_ICON_KEY);
+ if(iconImageUrl.equals("null")) {
+ iconImageUrl = "";
+ }
+ }
int nSubscribers = data.getInt(JSONUtils.SUBSCRIBERS_KEY);
int nCurrentOnlineSubscribers = data.getInt(JSONUtils.ACTIVE_USER_COUNT);
subredditData = new SubredditData(id, subredditFullName, iconImageUrl, bannerImageUrl, description, nSubscribers);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index e5a66601..51912948 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -32,6 +32,8 @@ import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
+import org.sufficientlysecure.htmltextview.HtmlTextView;
+
import java.util.ArrayList;
import de.hdodenhof.circleimageview.CircleImageView;
@@ -77,7 +79,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
CircleImageView subredditIconCircleImageView = findViewById(R.id.subreddit_icon_circle_image_view_view_post_detail);
TextView postTimeTextView = findViewById(R.id.post_time_text_view_view_post_detail);
TextView subredditTextView = findViewById(R.id.subreddit_text_view_view_post_detail);
- TextView contentTextView = findViewById(R.id.content_text_view_view_post_detail);
+ HtmlTextView contentTextView = findViewById(R.id.content_html_text_view_view_post_detail);
TextView typeTextView = findViewById(R.id.type_text_view_view_post_detail);
TextView nsfwTextView = findViewById(R.id.nsfw_text_view_view_post_detail);
RelativeLayout relativeLayout = findViewById(R.id.image_view_wrapper_view_post_detail);
@@ -294,7 +296,7 @@ public class ViewPostDetailActivity extends AppCompatActivity {
typeTextView.setText("TEXT");
if(!mPostData.getSelfText().equals("")) {
contentTextView.setVisibility(View.VISIBLE);
- contentTextView.setText(mPostData.getSelfText());
+ contentTextView.setHtml(mPostData.getSelfText());
}
}
queryComment();
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 e696acf3..d3b0b3ce 100644
--- a/app/src/main/res/layout/activity_view_post_detail.xml
+++ b/app/src/main/res/layout/activity_view_post_detail.xml
@@ -74,8 +74,8 @@
android:textColor="#000000"
android:textSize="18sp" />
- <TextView
- android:id="@+id/content_text_view_view_post_detail"
+ <org.sufficientlysecure.htmltextview.HtmlTextView
+ android:id="@+id/content_html_text_view_view_post_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
@@ -84,7 +84,7 @@
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
- android:textSize="16sp"
+ android:textAppearance="@android:style/TextAppearance.Small"
android:visibility="gone" />
<RelativeLayout
diff --git a/app/src/main/res/layout/item_post_comment.xml b/app/src/main/res/layout/item_post_comment.xml
index 25f0ef81..c1421084 100644
--- a/app/src/main/res/layout/item_post_comment.xml
+++ b/app/src/main/res/layout/item_post_comment.xml
@@ -32,8 +32,8 @@
</LinearLayout>
- <TextView
- android:id="@+id/comment_text_view_item_post_comment"
+ <org.sufficientlysecure.htmltextview.HtmlTextView
+ android:id="@+id/comment_html_text_view_item_post_comment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
@@ -41,7 +41,7 @@
android:layout_marginStart="32dp"
android:layout_marginRight="32dp"
android:layout_marginEnd="32dp"
- android:textColor="#000000"/>
+ android:textAppearance="@android:style/TextAppearance.Small"/>
<RelativeLayout
android:id="@+id/relative_layout_item_post_comment"