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.

This commit is contained in:
Alex Ning 2018-08-21 00:08:48 +08:00
parent 0fa03cba21
commit 80058ff6ab
10 changed files with 32 additions and 15 deletions

View File

@ -24,6 +24,7 @@ repositories {
}
mavenCentral()
google()
jcenter()
}
dependencies {
@ -54,4 +55,5 @@ dependencies {
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
implementation 'org.sufficientlysecure:html-textview:3.6'
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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