aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2018-08-24 02:38:37 +0000
committerAlex Ning <chineseperson5@gmail.com>2018-08-24 02:38:37 +0000
commitd83ded01933d653ac7ea62e9f5f9c4915263a5ca (patch)
tree77bb0898c7bcdc54de7a049611ab6e527b9a444c /app/src/main/java
parentf90bd4d1cce5f5ca523e4cae395a652a67811615 (diff)
downloadinfinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar.gz
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar.bz2
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar.lz
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar.xz
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.tar.zst
infinity-for-reddit-d83ded01933d653ac7ea62e9f5f9c4915263a5ca.zip
Display a thumbtack icon if the post is stickied on top. Display a gold icon and the number of gold if the post is gilded. Load subreddit icons in LoadSubredditIconAsyncTaskListener instead of loading the icons in onPostExecute() of LoadSubredditIconAsyncTask in order to avoid loading icons on a destroyed activity when start the Activity and then press back or up button immediately.
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java28
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java48
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java4
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java91
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java51
6 files changed, 186 insertions, 70 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
index 928951fc..97795c54 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/LoadSubredditIconAsyncTask.java
@@ -1,31 +1,22 @@
package ml.docilealligator.infinityforreddit;
-import android.content.Context;
import android.os.AsyncTask;
-import com.bumptech.glide.Glide;
-
-import java.lang.ref.WeakReference;
-
-import de.hdodenhof.circleimageview.CircleImageView;
-
class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
- private final WeakReference<Context> contextWeakReference;
- private final WeakReference<CircleImageView> circleImageViewWeakReference;
+ interface LoadSubredditIconAsyncTaskListener {
+ void loadIconSuccess(String iconImageUrl);
+ }
private SubredditDao subredditDao;
private String subredditName;
private String iconImageUrl;
- private PostData postData;
+ private LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener;
- LoadSubredditIconAsyncTask(Context context, CircleImageView iconImageView,
- SubredditDao subredditDao, String subredditName,
- PostData postData) {
- contextWeakReference = new WeakReference<>(context);
- circleImageViewWeakReference = new WeakReference<>(iconImageView);
+ LoadSubredditIconAsyncTask(SubredditDao subredditDao, String subredditName,
+ LoadSubredditIconAsyncTaskListener loadSubredditIconAsyncTaskListener) {
this.subredditDao = subredditDao;
this.subredditName = subredditName;
- this.postData = postData;
+ this.loadSubredditIconAsyncTaskListener = loadSubredditIconAsyncTaskListener;
}
@Override
@@ -41,7 +32,8 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPostExecute(Void aVoid) {
super.onPostExecute(aVoid);
- Context context = contextWeakReference.get();
+ loadSubredditIconAsyncTaskListener.loadIconSuccess(iconImageUrl);
+ /*Context context = contextWeakReference.get();
CircleImageView circleImageView = circleImageViewWeakReference.get();
if(context != null && circleImageView != null) {
@@ -52,6 +44,6 @@ class LoadSubredditIconAsyncTask extends AsyncTask<Void, Void, Void> {
}
}
- postData.setSubredditIconUrl(iconImageUrl);
+ postData.setSubredditIconUrl(iconImageUrl);*/
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
index caebd825..ffc2be9b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ParsePost.java
@@ -70,7 +70,9 @@ class ParsePost {
String title = data.getString(JSONUtils.TITLE_KEY);
int score = data.getInt(JSONUtils.SCORE_KEY);
int voteType;
+ int gilded = data.getInt(JSONUtils.GILDED_KEY);
boolean nsfw = data.getBoolean(JSONUtils.NSFW_KEY);
+ boolean stickied = data.getBoolean(JSONUtils.STICKIED_KEY);
if(data.isNull(JSONUtils.LIKES_KEY)) {
voteType = 0;
@@ -93,10 +95,10 @@ class ParsePost {
//Cross post
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
parseData(data, permalink, newPostData, id, fullName, subredditName,
- formattedPostTime, title, previewUrl, score, voteType, nsfw, i);
+ formattedPostTime, title, previewUrl, score, voteType, gilded, nsfw, stickied, i);
} else {
parseData(data, permalink, newPostData, id, fullName, subredditName,
- formattedPostTime, title, previewUrl, score, voteType, nsfw, i);
+ formattedPostTime, title, previewUrl, score, voteType, gilded, nsfw, stickied, i);
}
}
} catch (JSONException e) {
@@ -119,8 +121,9 @@ class ParsePost {
}
private void parseData(JSONObject data, String permalink, ArrayList<PostData> bestPostData,
- String id, String fullName, String subredditName, String formattedPostTime, String title,
- String previewUrl, int score, int voteType, boolean nsfw, int i) throws JSONException {
+ String id, String fullName, String subredditName, String formattedPostTime,
+ String title, String previewUrl, int score, int voteType, int gilded,
+ boolean nsfw, boolean stickied, int i) throws JSONException {
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
String url = data.getString(JSONUtils.URL_KEY);
@@ -129,7 +132,8 @@ class ParsePost {
//Text post
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 postData = new PostData(id, fullName, subredditName, formattedPostTime,
+ title, permalink, score, postType, voteType, gilded, nsfw, stickied);
if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
postData.setSelfText("");
} else {
@@ -140,7 +144,13 @@ class ParsePost {
//No preview link post
Log.i("no preview link", Integer.toString(i));
int postType = PostData.NO_PREVIEW_LINK_TYPE;
- PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
+ PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime,
+ title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied);
+ if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
+ linkPostData.setSelfText("");
+ } else {
+ linkPostData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ }
bestPostData.add(linkPostData);
}
} else if(isVideo) {
@@ -150,7 +160,8 @@ class ParsePost {
int postType = PostData.VIDEO_TYPE;
String videoUrl = redditVideoObject.getString(JSONUtils.DASH_URL_KEY);
- PostData videoPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true);
+ PostData videoPostData = new PostData(id, fullName, subredditName, formattedPostTime,
+ title, previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, true);
videoPostData.setVideoUrl(videoUrl);
videoPostData.setDownloadableGifOrVideo(false);
@@ -164,7 +175,8 @@ class ParsePost {
int postType = PostData.GIF_VIDEO_TYPE;
String videoUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.MP4_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
String gifDownloadUrl = variations.getJSONObject(JSONUtils.VARIANTS_KEY).getJSONObject(JSONUtils.GIF_KEY).getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
- PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, false);
+ PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title,
+ previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, false);
post.setVideoUrl(videoUrl);
post.setDownloadableGifOrVideo(true);
@@ -178,7 +190,8 @@ class ParsePost {
String videoUrl = data.getJSONObject(JSONUtils.PREVIEW_KEY)
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.DASH_URL_KEY);
- PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, permalink, score, postType, voteType, nsfw, true);
+ PostData post = new PostData(id, fullName, subredditName, formattedPostTime, title,
+ previewUrl, permalink, score, postType, voteType, gilded, nsfw, stickied, true);
post.setVideoUrl(videoUrl);
post.setDownloadableGifOrVideo(false);
@@ -189,12 +202,19 @@ class ParsePost {
//Image post
Log.i("image", Integer.toString(i));
int postType = PostData.IMAGE_TYPE;
- bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
+ bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime,
+ title, url, url, permalink, score, postType, voteType, gilded, nsfw, stickied));
} else {
//Link post
Log.i("link", Integer.toString(i));
int postType = PostData.LINK_TYPE;
- PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
+ PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime,
+ title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied);
+ if(data.isNull(JSONUtils.SELFTEXT_HTML_KEY)) {
+ linkPostData.setSelfText("");
+ } else {
+ linkPostData.setSelfText(data.getString(JSONUtils.SELFTEXT_HTML_KEY).trim());
+ }
bestPostData.add(linkPostData);
}
}
@@ -203,12 +223,14 @@ class ParsePost {
//Image post
Log.i("CP no preview image", Integer.toString(i));
int postType = PostData.IMAGE_TYPE;
- bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title, url, url, permalink, score, postType, voteType, nsfw));
+ bestPostData.add(new PostData(id, fullName, subredditName, formattedPostTime, title,
+ url, url, permalink, score, postType, voteType, gilded, nsfw, stickied));
} else {
//Link post
Log.i("CP no preview link", Integer.toString(i));
int postType = PostData.LINK_TYPE;
- PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime, title, previewUrl, url, permalink, score, postType, voteType, nsfw);
+ PostData linkPostData = new PostData(id, fullName, subredditName, formattedPostTime,
+ title, previewUrl, url, permalink, score, postType, voteType, gilded, nsfw, stickied);
bestPostData.add(linkPostData);
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
index c91cc333..0626088f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostData.java
@@ -30,11 +30,15 @@ class PostData implements Parcelable {
private int score;
private int postType;
private int voteType;
+ private int gilded;
private boolean nsfw;
+ private boolean stickied;
private boolean isDashVideo;
private boolean isDownloadableGifOrVideo;
- PostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String permalink, int score, int postType, int voteType, boolean nsfw, boolean isDashVideo) {
+ PostData(String id, String fullName, String subredditName, String postTime, String title,
+ String previewUrl, String permalink, int score, int postType, int voteType, int gilded,
+ boolean nsfw, boolean stickied, boolean isDashVideo) {
this.id = id;
this.fullName = fullName;
this.subredditName = subredditName;
@@ -45,11 +49,15 @@ class PostData implements Parcelable {
this.score = score;
this.postType = postType;
this.voteType = voteType;
+ this.gilded = gilded;
this.nsfw = nsfw;
+ this.stickied = stickied;
this.isDashVideo = isDashVideo;
}
- PostData(String id, String fullName, String subredditName, String postTime, String title, String previewUrl, String url, String permalink, int score, int postType, int voteType, boolean nsfw) {
+ PostData(String id, String fullName, String subredditName, String postTime, String title,
+ String previewUrl, String url, String permalink, int score, int postType, int voteType,
+ int gilded, boolean nsfw, boolean stickied) {
this.id = id;
this.fullName = fullName;
this.subredditName = subredditName;
@@ -61,10 +69,14 @@ class PostData implements Parcelable {
this.score = score;
this.postType = postType;
this.voteType = voteType;
+ this.gilded = gilded;
this.nsfw = nsfw;
+ this.stickied = stickied;
}
- PostData(String id, String fullName, String subredditName, String postTime, String title, String permalink, int score, int postType, int voteType, boolean nsfw) {
+ PostData(String id, String fullName, String subredditName, String postTime, String title,
+ String permalink, int score, int postType, int voteType, int gilded, boolean nsfw,
+ boolean stickied) {
this.id = id;
this.fullName = fullName;
this.subredditName = subredditName;
@@ -74,7 +86,9 @@ class PostData implements Parcelable {
this.score = score;
this.postType = postType;
this.voteType = voteType;
+ this.gilded = gilded;
this.nsfw = nsfw;
+ this.stickied = stickied;
}
protected PostData(Parcel in) {
@@ -93,7 +107,9 @@ class PostData implements Parcelable {
score = in.readInt();
postType = in.readInt();
voteType = in.readInt();
+ gilded = in.readInt();
nsfw = in.readByte() != 0;
+ stickied = in.readByte() != 0;
isDashVideo = in.readByte() != 0;
isDownloadableGifOrVideo = in.readByte() != 0;
}
@@ -198,7 +214,11 @@ class PostData implements Parcelable {
return voteType;
}
- public boolean getNSFW() {
+ public int getGilded() {
+ return gilded;
+ }
+
+ public boolean isNSFW() {
return nsfw;
}
@@ -219,6 +239,10 @@ class PostData implements Parcelable {
return isDownloadableGifOrVideo;
}
+ public boolean isStickied() {
+ return stickied;
+ }
+
@Override
public void writeToParcel(Parcel parcel, int i) {
parcel.writeString(id);
@@ -236,7 +260,9 @@ class PostData implements Parcelable {
parcel.writeInt(score);
parcel.writeInt(postType);
parcel.writeInt(voteType);
+ parcel.writeInt(gilded);
parcel.writeByte((byte) (nsfw ? 1 : 0));
+ parcel.writeByte((byte) (stickied ? 1 : 0));
parcel.writeByte((byte) (isDashVideo ? 1 : 0));
parcel.writeByte((byte) (isDownloadableGifOrVideo ? 1 : 0));
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
index 49220d94..e8b10896 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostFragment.java
@@ -188,10 +188,6 @@ public class PostFragment extends Fragment {
mProgressBar.setVisibility(View.VISIBLE);
- /*Uri uri = Uri.parse(RedditUtils.OAUTH_API_BASE_URI + RedditUtils.BEST_POST_SUFFIX)
- .buildUpon().appendQueryParameter(RedditUtils.RAW_JSON_KEY, RedditUtils.RAW_JSON_VALUE)
- .build();*/
-
StringRequest postRequest = new StringRequest(Request.Method.GET, mQueryPostUrl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
index 933af11d..724fb753 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/PostRecyclerViewAdapter.java
@@ -86,22 +86,36 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
}
@Override
- public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, final int position) {
+ public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if(holder instanceof DataViewHolder) {
if(mPostData.get(position) == null) {
Log.i("is null", Integer.toString(position));
} else {
- final String id = mPostData.get(position).getFullName();
- final String subredditName = mPostData.get(position).getSubredditName();
- final String postTime = mPostData.get(position).getPostTime();
- final String title = mPostData.get(position).getTitle();
- final String permalink = mPostData.get(position).getPermalink();
- int voteType = mPostData.get(position).getVoteType();
- boolean nsfw = mPostData.get(position).getNSFW();
-
- if(mPostData.get(position).getSubredditIconUrl() == null) {
- new LoadSubredditIconAsyncTask(mContext, ((DataViewHolder) holder).subredditIconCircleImageView,
- subredditDao, subredditName, mPostData.get(position)).execute();
+ final String id = mPostData.get(holder.getAdapterPosition()).getFullName();
+ final String subredditName = mPostData.get(holder.getAdapterPosition()).getSubredditName();
+ final String postTime = mPostData.get(holder.getAdapterPosition()).getPostTime();
+ final String title = mPostData.get(holder.getAdapterPosition()).getTitle();
+ final String permalink = mPostData.get(holder.getAdapterPosition()).getPermalink();
+ int voteType = mPostData.get(holder.getAdapterPosition()).getVoteType();
+ int gilded = mPostData.get(holder.getAdapterPosition()).getGilded();
+ boolean nsfw = mPostData.get(holder.getAdapterPosition()).isNSFW();
+
+ if(mPostData.get(holder.getAdapterPosition()).getSubredditIconUrl() == null) {
+ new LoadSubredditIconAsyncTask(subredditDao, subredditName,
+ new LoadSubredditIconAsyncTask.LoadSubredditIconAsyncTaskListener() {
+ @Override
+ public void loadIconSuccess(String iconImageUrl) {
+ if(!iconImageUrl.equals("")) {
+ Glide.with(mContext).load(iconImageUrl)
+ .into(((DataViewHolder) holder).subredditIconCircleImageView);
+ } else {
+ Glide.with(mContext).load(R.drawable.subreddit_default_icon)
+ .into(((DataViewHolder) holder).subredditIconCircleImageView);
+ }
+
+ mPostData.get(holder.getAdapterPosition()).setSubredditIconUrl(iconImageUrl);
+ }
+ }).execute();
} else if(!mPostData.get(position).getSubredditIconUrl().equals("")) {
glide.load(mPostData.get(position).getSubredditIconUrl()).into(((DataViewHolder) holder).subredditIconCircleImageView);
} else {
@@ -115,7 +129,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
canStartActivity = false;
Intent intent = new Intent(mContext, ViewPostDetailActivity.class);
intent.putExtra(ViewPostDetailActivity.EXTRA_TITLE, title);
- intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, mPostData.get(position));
+ intent.putExtra(ViewPostDetailActivity.EXTRA_POST_DATA, mPostData.get(holder.getAdapterPosition()));
mContext.startActivity(intent);
}
}
@@ -126,6 +140,14 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
((DataViewHolder) holder).titleTextView.setText(title);
((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore()));
+ if(gilded > 0) {
+ ((DataViewHolder) holder).gildedImageView.setVisibility(View.VISIBLE);
+ glide.load(R.drawable.gold).into(((DataViewHolder) holder).gildedImageView);
+ ((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.VISIBLE);
+ String gildedNumber = mContext.getResources().getString(R.string.gilded, gilded);
+ ((DataViewHolder) holder).gildedNumberTextView.setText(gildedNumber);
+ }
+
if(nsfw) {
((DataViewHolder) holder).nsfwTextView.setVisibility(View.VISIBLE);
}
@@ -147,6 +169,11 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
((DataViewHolder) holder).imageView.setVisibility(View.VISIBLE);
}
+ if(mPostData.get(position).isStickied()) {
+ ((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.VISIBLE);
+ glide.load(R.drawable.thumbtack).into(((DataViewHolder) holder).stickiedPostImageView);
+ }
+
switch (mPostData.get(position).getPostType()) {
case PostData.IMAGE_TYPE:
((DataViewHolder) holder).typeTextView.setText("IMAGE");
@@ -229,10 +256,10 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
Intent intent = new Intent(mContext, ViewVideoActivity.class);
intent.setData(gifVideoUri);
intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
- intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
- intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
- if(mPostData.get(position).isDownloadableGifOrVideo()) {
- intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(holder.getAdapterPosition()).isDashVideo());
+ intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(holder.getAdapterPosition()).isDownloadableGifOrVideo());
+ if(mPostData.get(holder.getAdapterPosition()).isDownloadableGifOrVideo()) {
+ intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(holder.getAdapterPosition()).getGifOrVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
intent.putExtra(ViewVideoActivity.ID_KEY, id);
}
@@ -265,10 +292,10 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
Intent intent = new Intent(mContext, ViewVideoActivity.class);
intent.setData(videoUri);
intent.putExtra(ViewVideoActivity.TITLE_KEY, title);
- intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(position).isDashVideo());
- intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(position).isDownloadableGifOrVideo());
- if(mPostData.get(position).isDownloadableGifOrVideo()) {
- intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(position).getGifOrVideoDownloadUrl());
+ intent.putExtra(ViewVideoActivity.IS_DASH_VIDEO_KEY, mPostData.get(holder.getAdapterPosition()).isDashVideo());
+ intent.putExtra(ViewVideoActivity.IS_DOWNLOADABLE_KEY, mPostData.get(holder.getAdapterPosition()).isDownloadableGifOrVideo());
+ if(mPostData.get(holder.getAdapterPosition()).isDownloadableGifOrVideo()) {
+ intent.putExtra(ViewVideoActivity.DOWNLOAD_URL_KEY, mPostData.get(holder.getAdapterPosition()).getGifOrVideoDownloadUrl());
intent.putExtra(ViewVideoActivity.SUBREDDIT_KEY, subredditName);
intent.putExtra(ViewVideoActivity.ID_KEY, id);
}
@@ -307,9 +334,9 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
if (((DataViewHolder) holder).upvoteButton.getColorFilter() == null) {
((DataViewHolder) holder).upvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.colorPrimary), android.graphics.PorterDuff.Mode.SRC_IN);
if(isDownvotedBefore) {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 2));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() + 2));
} else {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 1));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() + 1));
}
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@@ -334,7 +361,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
} else {
//Upvoted before
((DataViewHolder) holder).upvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 1));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() - 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
@@ -365,9 +392,9 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
if (((DataViewHolder) holder).downvoteButton.getColorFilter() == null) {
((DataViewHolder) holder).downvoteButton.setColorFilter(ContextCompat.getColor(mContext, R.color.minusButtonColor), android.graphics.PorterDuff.Mode.SRC_IN);
if (isUpvotedBefore) {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 2));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() - 2));
} else {
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() - 1));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() - 1));
}
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@@ -392,7 +419,7 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
} else {
//Down voted before
((DataViewHolder) holder).downvoteButton.clearColorFilter();
- ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(position).getScore() + 1));
+ ((DataViewHolder) holder).scoreTextView.setText(Integer.toString(mPostData.get(holder.getAdapterPosition()).getScore() + 1));
new VoteThing(mContext, mVoteThingRequestQueue, mAcquireAccessTokenRequestQueue).votePost(new VoteThing.VoteThingListener() {
@Override
@@ -471,9 +498,12 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
private CardView cardView;
private CircleImageView subredditIconCircleImageView;
private TextView subredditNameTextView;
+ private ImageView stickiedPostImageView;
private TextView postTimeTextView;
private TextView titleTextView;
private TextView typeTextView;
+ private ImageView gildedImageView;
+ private TextView gildedNumberTextView;
private TextView nsfwTextView;
private RelativeLayout relativeLayout;
private ProgressBar progressBar;
@@ -489,9 +519,12 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
cardView = itemView.findViewById(R.id.card_view_view_post_detail);
subredditIconCircleImageView = itemView.findViewById(R.id.subreddit_icon_circle_image_view_best_post_item);
subredditNameTextView = itemView.findViewById(R.id.subreddit_text_view_best_post_item);
+ stickiedPostImageView = itemView.findViewById(R.id.stickied_post_image_view_best_post_item);
postTimeTextView = itemView.findViewById(R.id.post_time_text_view_best_post_item);
titleTextView = itemView.findViewById(R.id.title_text_view_best_post_item);
typeTextView = itemView.findViewById(R.id.type_text_view_item_best_post);
+ gildedImageView = itemView.findViewById(R.id.gilded_image_view_item_best_post);
+ gildedNumberTextView = itemView.findViewById(R.id.gilded_number_text_view_item_best_post);
nsfwTextView = itemView.findViewById(R.id.nsfw_text_view_item_best_post);
relativeLayout = itemView.findViewById(R.id.image_view_wrapper_item_best_post);
progressBar = itemView.findViewById(R.id.progress_bar_best_post_item);
@@ -522,7 +555,11 @@ class PostRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHold
public void onViewRecycled(@NonNull RecyclerView.ViewHolder holder) {
if(holder instanceof DataViewHolder) {
glide.clear(((DataViewHolder) holder).imageView);
+ glide.clear(((DataViewHolder) holder).subredditIconCircleImageView);
+ ((DataViewHolder) holder).stickiedPostImageView.setVisibility(View.GONE);
((DataViewHolder) holder).relativeLayout.setVisibility(View.GONE);
+ ((DataViewHolder) holder).gildedNumberTextView.setVisibility(View.GONE);
+ glide.clear(((DataViewHolder) holder).gildedImageView);
((DataViewHolder) holder).nsfwTextView.setVisibility(View.GONE);
((DataViewHolder) holder).progressBar.setVisibility(View.GONE);
((DataViewHolder) holder).imageView.setVisibility(View.GONE);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
index ff467f4c..8ebb175e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/ViewPostDetailActivity.java
@@ -57,6 +57,8 @@ public class ViewPostDetailActivity extends AppCompatActivity {
private LinearLayout mNoCommentWrapperLinearLayout;
private ImageView mNoCommentImageView;
+ private LoadSubredditIconAsyncTask mLoadSubredditIconAsyncTask;
+
private RequestQueue mVoteThingRequestQueue;
private RequestQueue mAcquireAccessTokenRequestQueue;
private RequestQueue mCommentQueue;
@@ -76,11 +78,13 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mCoordinatorLayout = findViewById(R.id.coordinator_layout_view_post_detail);
- CircleImageView subredditIconCircleImageView = findViewById(R.id.subreddit_icon_circle_image_view_view_post_detail);
+ final 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);
HtmlTextView contentTextView = findViewById(R.id.content_html_text_view_view_post_detail);
TextView typeTextView = findViewById(R.id.type_text_view_view_post_detail);
+ ImageView gildedImageView = findViewById(R.id.gilded_image_view_view_post_detail);
+ TextView gildedNumberTextView = findViewById(R.id.gilded_number_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);
final ProgressBar progressBar = findViewById(R.id.progress_bar_view_post_detail);
@@ -100,9 +104,23 @@ public class ViewPostDetailActivity extends AppCompatActivity {
mNoCommentImageView = findViewById(R.id.no_comment_image_view_view_post_detail);
if(mPostData.getSubredditIconUrl() == null) {
- new LoadSubredditIconAsyncTask(this, subredditIconCircleImageView,
+ mLoadSubredditIconAsyncTask = new LoadSubredditIconAsyncTask(
SubredditRoomDatabase.getDatabase(this).subredditDao(), mPostData.getSubredditName(),
- mPostData).execute();
+ new LoadSubredditIconAsyncTask.LoadSubredditIconAsyncTaskListener() {
+ @Override
+ public void loadIconSuccess(String iconImageUrl) {
+ if(!iconImageUrl.equals("")) {
+ Glide.with(ViewPostDetailActivity.this).load(iconImageUrl)
+ .into(subredditIconCircleImageView);
+ } else {
+ Glide.with(ViewPostDetailActivity.this).load(R.drawable.subreddit_default_icon)
+ .into(subredditIconCircleImageView);
+ }
+
+ mPostData.setSubredditIconUrl(iconImageUrl);
+ }
+ });
+ mLoadSubredditIconAsyncTask.execute();
} else if(!mPostData.getSubredditIconUrl().equals("")) {
Glide.with(this).load(mPostData.getSubredditIconUrl()).into(subredditIconCircleImageView);
} else {
@@ -129,7 +147,16 @@ public class ViewPostDetailActivity extends AppCompatActivity {
subredditTextView.setText(mPostData.getSubredditName());
postTimeTextView.setText(mPostData.getPostTime());
- if(mPostData.getNSFW()) {
+
+ if(mPostData.getGilded() > 0) {
+ gildedImageView.setVisibility(View.VISIBLE);
+ Glide.with(this).load(R.drawable.gold).into(gildedImageView);
+ gildedNumberTextView.setVisibility(View.VISIBLE);
+ String gildedNumber = getResources().getString(R.string.gilded, mPostData.getGilded());
+ gildedNumberTextView.setText(gildedNumber);
+ }
+
+ if(mPostData.isNSFW()) {
nsfwTextView.setVisibility(View.VISIBLE);
}
scoreTextView.setText(Integer.toString(mPostData.getScore()));
@@ -177,6 +204,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
case PostData.LINK_TYPE:
relativeLayout.setVisibility(View.VISIBLE);
typeTextView.setText("LINK");
+ if(!mPostData.getSelfText().equals("")) {
+ contentTextView.setVisibility(View.VISIBLE);
+ contentTextView.setHtml(mPostData.getSelfText());
+ }
String linkPreviewUrl = mPostData.getPreviewUrl();
Glide.with(this).load(linkPreviewUrl).listener(new RequestListener<Drawable>() {
@Override
@@ -279,6 +310,10 @@ public class ViewPostDetailActivity extends AppCompatActivity {
break;
case PostData.NO_PREVIEW_LINK_TYPE:
typeTextView.setText("LINK");
+ if(!mPostData.getSelfText().equals("")) {
+ contentTextView.setVisibility(View.VISIBLE);
+ contentTextView.setHtml(mPostData.getSelfText());
+ }
noPreviewLinkImageView.setVisibility(View.VISIBLE);
noPreviewLinkImageView.setOnClickListener(new View.OnClickListener() {
@Override
@@ -535,4 +570,12 @@ public class ViewPostDetailActivity extends AppCompatActivity {
finish();
}
}
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ if(mLoadSubredditIconAsyncTask != null) {
+ mLoadSubredditIconAsyncTask.cancel(true);
+ }
+ }
}