aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubmitCrosspostActivity.java60
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java110
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java386
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchRemovedPost.java22
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java134
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java165
6 files changed, 510 insertions, 367 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubmitCrosspostActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubmitCrosspostActivity.java
index 4718755b..37a9258b 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubmitCrosspostActivity.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/SubmitCrosspostActivity.java
@@ -37,6 +37,8 @@ import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
+import java.util.ArrayList;
+
import javax.inject.Inject;
import javax.inject.Named;
@@ -257,32 +259,38 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
contentTextView.setVisibility(View.VISIBLE);
contentTextView.setText(post.getUrl());
} else if (post.getPostType() == Post.GIF_TYPE || post.getPostType() == Post.GALLERY_TYPE || post.getPostType() == Post.IMAGE_TYPE) {
- frameLayout.setVisibility(View.VISIBLE);
- mGlide.asBitmap().load(post.getPreviewUrl()).into(new CustomTarget<Bitmap>() {
- @Override
- public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- imageView.setImage(ImageSource.bitmap(resource));
- }
+ Post.Preview preview = getPreview(post);
+ if (preview != null) {
+ frameLayout.setVisibility(View.VISIBLE);
+ mGlide.asBitmap().load(preview.getPreviewUrl()).into(new CustomTarget<Bitmap>() {
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ imageView.setImage(ImageSource.bitmap(resource));
+ }
- @Override
- public void onLoadCleared(@Nullable Drawable placeholder) {
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
- }
- });
+ }
+ });
+ }
} else if (post.getPostType() == Post.VIDEO_TYPE) {
- frameLayout.setVisibility(View.VISIBLE);
- mGlide.asBitmap().load(post.getPreviewUrl()).into(new CustomTarget<Bitmap>() {
- @Override
- public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
- imageView.setImage(ImageSource.bitmap(resource));
- }
+ Post.Preview preview = getPreview(post);
+ if (preview != null) {
+ frameLayout.setVisibility(View.VISIBLE);
+ mGlide.asBitmap().load(preview.getPreviewUrl()).into(new CustomTarget<Bitmap>() {
+ @Override
+ public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
+ imageView.setImage(ImageSource.bitmap(resource));
+ }
- @Override
- public void onLoadCleared(@Nullable Drawable placeholder) {
+ @Override
+ public void onLoadCleared(@Nullable Drawable placeholder) {
- }
- });
- playButton.setVisibility(View.VISIBLE);
+ }
+ });
+ playButton.setVisibility(View.VISIBLE);
+ }
}
iconGifImageView.setOnClickListener(view -> {
@@ -356,6 +364,16 @@ public class SubmitCrosspostActivity extends BaseActivity implements FlairBottom
});
}
+ @Nullable
+ private Post.Preview getPreview(Post post) {
+ ArrayList<Post.Preview> previews = post.getPreviews();
+ if (previews != null && !previews.isEmpty()) {
+ return previews.get(0);
+ }
+
+ return null;
+ }
+
@Override
protected SharedPreferences getDefaultSharedPreferences() {
return mSharedPreferences;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
index bc476b67..d1c417f5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/CommentAndPostRecyclerViewAdapter.java
@@ -829,12 +829,17 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
if (holder instanceof PostDetailVideoAutoplayViewHolder) {
- ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) mPost.getPreviewWidth() / mPost.getPreviewHeight());
((PostDetailVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
- if (mImageViewWidth > mPost.getPreviewWidth()) {
- mGlide.load(mPost.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ Post.Preview preview = getSuitablePreview(mPost.getPreviews());
+ if (preview != null) {
+ ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ } else {
+ mGlide.load(preview.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ }
} else {
- mGlide.load(mPost.getPreviewUrl()).into(((PostDetailVideoAutoplayViewHolder) holder).previewImageView);
+ ((PostDetailVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
@@ -867,8 +872,11 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
} else {
((PostDetailVideoAndGifPreviewHolder) holder).mTypeTextView.setText(mActivity.getString(R.string.video));
}
- ((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth());
- loadImage((PostDetailVideoAndGifPreviewHolder) holder);
+ Post.Preview preview = getSuitablePreview(mPost.getPreviews());
+ if (preview != null) {
+ ((PostDetailVideoAndGifPreviewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
+ loadImage((PostDetailVideoAndGifPreviewHolder) holder, preview);
+ }
} else if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
if (mPost.getPostType() == Post.IMAGE_TYPE) {
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.image);
@@ -876,18 +884,25 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailImageAndGifAutoplayViewHolder) holder).mTypeTextView.setText(R.string.gif);
}
- if (mPost.getPreviewWidth() <= 0 || mPost.getPreviewHeight() <= 0) {
- ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale);
- } else {
- ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth());
+ Post.Preview preview = getSuitablePreview(mPost.getPreviews());
+ if (preview != null) {
+ if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
+ ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.getLayoutParams().height = (int) (400 * mScale);
+ } else {
+ ((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
+ }
+ loadImage((PostDetailImageAndGifAutoplayViewHolder) holder, preview);
}
- loadImage((PostDetailImageAndGifAutoplayViewHolder) holder);
} else if (holder instanceof PostDetailLinkViewHolder) {
String domain = Uri.parse(mPost.getUrl()).getHost();
((PostDetailLinkViewHolder) holder).mLinkTextView.setText(domain);
- ((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) mPost.getPreviewHeight() / (float) mPost.getPreviewWidth());
- loadImage((PostDetailLinkViewHolder) holder);
+ Post.Preview preview = getSuitablePreview(mPost.getPreviews());
+ if (preview != null) {
+ ((PostDetailLinkViewHolder) holder).mImageView.setRatio((float) preview.getPreviewHeight() / (float) preview.getPreviewWidth());
+ loadImage((PostDetailLinkViewHolder) holder, preview);
+ }
+
} else if (holder instanceof PostDetailNoPreviewLinkViewHolder) {
String noPreviewLinkDomain = Uri.parse(mPost.getUrl()).getHost();
((PostDetailNoPreviewLinkViewHolder) holder).mLinkTextView.setText(noPreviewLinkDomain);
@@ -911,12 +926,13 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
mMarkwonAdapter.notifyDataSetChanged();
}
} else if (holder instanceof PostDetailGalleryViewHolder) {
- if (mPost.getPreviewUrl() != null && !mPost.getPreviewUrl().equals("")) {
+ Post.Preview preview = getSuitablePreview(mPost.getPreviews());
+ if (preview != null) {
((PostDetailGalleryViewHolder) holder).mRelativeLayout.setVisibility(View.VISIBLE);
((PostDetailGalleryViewHolder) holder).mImageView
- .setRatio((float) mPost.getPreviewHeight() / mPost.getPreviewWidth());
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
- loadImage((PostDetailGalleryViewHolder) holder);
+ loadImage((PostDetailGalleryViewHolder) holder, preview);
} else {
((PostDetailGalleryViewHolder) holder).mNoPreviewLinkImageView.setVisibility(View.VISIBLE);
}
@@ -1381,9 +1397,43 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
}
}
- private void loadImage(PostDetailBaseViewHolder holder) {
+ @Nullable
+ private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
+ Post.Preview preview;
+ if (!previews.isEmpty()) {
+ preview = previews.get(0);
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 65 * 1000 * 1000) {
+ for (int i = previews.size() - 1; i >= 1; i--) {
+ preview = previews.get(i);
+ if (mImageViewWidth >= preview.getPreviewWidth()) {
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 75 * 1000 * 1000) {
+ return preview;
+ }
+ } else {
+ int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
+ if (mImageViewWidth * height <= 75 * 1000 * 1000) {
+ return preview;
+ }
+ }
+ }
+ }
+
+ int divisor = 2;
+ while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 75 * 1000 * 1000) {
+ preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
+ preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
+ divisor *= 2;
+ }
+
+ return preview;
+ }
+
+ return null;
+ }
+
+ private void loadImage(PostDetailBaseViewHolder holder, @NonNull Post.Preview preview) {
if (holder instanceof PostDetailImageAndGifAutoplayViewHolder) {
- String url = mPost.getPostType() == Post.IMAGE_TYPE ? mPost.getPreviewUrl() : mPost.getUrl();
+ String url = mPost.getPostType() == Post.IMAGE_TYPE ? preview.getPreviewUrl() : mPost.getUrl();
RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url)
.listener(new RequestListener<Drawable>() {
@Override
@@ -1393,7 +1443,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> {
((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE);
((PostDetailImageAndGifAutoplayViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE);
- loadImage(holder);
+ loadImage(holder, preview);
});
return false;
}
@@ -1408,14 +1458,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
- if (mImageViewWidth > mPost.getPreviewWidth()) {
+ if (mImageViewWidth > preview.getPreviewWidth()) {
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailImageAndGifAutoplayViewHolder) holder).mImageView);
}
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1424,7 +1474,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> {
((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE);
((PostDetailVideoAndGifPreviewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE);
- loadImage(holder);
+ loadImage(holder, preview);
});
return false;
}
@@ -1440,14 +1490,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else {
- if (mImageViewWidth > mPost.getPreviewWidth()) {
+ if (mImageViewWidth > preview.getPreviewWidth()) {
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailVideoAndGifPreviewHolder) holder).mImageView);
}
}
} else if (holder instanceof PostDetailLinkViewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1456,7 +1506,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailLinkViewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> {
((PostDetailLinkViewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE);
((PostDetailLinkViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE);
- loadImage(holder);
+ loadImage(holder, preview);
});
return false;
}
@@ -1472,14 +1522,14 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
.into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
- if (mImageViewWidth > mPost.getPreviewWidth()) {
+ if (mImageViewWidth > preview.getPreviewWidth()) {
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailLinkViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailLinkViewHolder) holder).mImageView);
}
}
} else if (holder instanceof PostDetailGalleryViewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(mPost.getPreviewUrl())
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl())
.listener(new RequestListener<Drawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
@@ -1488,7 +1538,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailGalleryViewHolder) holder).mLoadImageErrorTextView.setOnClickListener(view -> {
((PostDetailGalleryViewHolder) holder).mLoadImageProgressBar.setVisibility(View.VISIBLE);
((PostDetailGalleryViewHolder) holder).mLoadImageErrorTextView.setVisibility(View.GONE);
- loadImage(holder);
+ loadImage(holder, preview);
});
return false;
}
@@ -1503,7 +1553,7 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
if ((mPost.isNSFW() && mNeedBlurNsfw && !(mPost.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || (mPost.isSpoiler() && mNeedBlurSpoiler)) {
imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10))).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else {
- if (mImageViewWidth > mPost.getPreviewWidth()) {
+ if (mImageViewWidth > preview.getPreviewWidth()) {
imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostDetailGalleryViewHolder) holder).mImageView);
} else {
imageRequestBuilder.into(((PostDetailGalleryViewHolder) holder).mImageView);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
index 285f6441..86ce0e1c 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Adapter/PostRecyclerViewAdapter.java
@@ -53,6 +53,7 @@ import com.libRG.CustomTextView;
import org.greenrobot.eventbus.EventBus;
+import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -185,6 +186,7 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
private boolean mAutomaticallyTryRedgifs;
private boolean mLongPressToHideToolbarInCompactLayout;
private boolean mCompactLayoutToolbarHiddenByDefault;
+ private boolean mDataSavingMode;
private Drawable mCommentIcon;
private NetworkState networkState;
private ExoCreator mExoCreator;
@@ -562,12 +564,17 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
if (holder instanceof PostVideoAutoplayViewHolder) {
- ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) post.getPreviewWidth() / post.getPreviewHeight());
((PostVideoAutoplayViewHolder) holder).previewImageView.setVisibility(View.VISIBLE);
- if (mImageViewWidth > post.getPreviewWidth()) {
- mGlide.load(post.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ if (preview != null) {
+ ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio((float) preview.getPreviewWidth() / preview.getPreviewHeight());
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ mGlide.load(preview.getPreviewUrl()).override(Target.SIZE_ORIGINAL).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
+ } else {
+ mGlide.load(preview.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
+ }
} else {
- mGlide.load(post.getPreviewUrl()).into(((PostVideoAutoplayViewHolder) holder).previewImageView);
+ ((PostVideoAutoplayViewHolder) holder).aspectRatioFrameLayout.setAspectRatio(1);
}
((PostVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (post.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
@@ -601,13 +608,16 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostVideoAndGifPreviewViewHolder) holder).typeTextView.setText(mActivity.getString(R.string.gif));
}
((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostVideoAndGifPreviewViewHolder) holder).imageView
- .setRatio((float) post.getPreviewHeight() / post.getPreviewWidth());
- loadImage(holder, post);
- if (post.getPreviewWidth() <= 0 || post.getPreviewHeight() <= 0) {
- ((PostVideoAndGifPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- ((PostVideoAndGifPreviewViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ if (preview != null) {
+ ((PostVideoAndGifPreviewViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
+ ((PostVideoAndGifPreviewViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ ((PostVideoAndGifPreviewViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
+ }
+ loadImage(holder, post, preview);
}
} else if (holder instanceof PostImageAndGifAutoplayViewHolder) {
if (post.getPostType() == Post.IMAGE_TYPE) {
@@ -616,32 +626,40 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
((PostImageAndGifAutoplayViewHolder) holder).typeTextView.setText(R.string.gif);
}
((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- if (post.getPreviewWidth() <= 0 || post.getPreviewHeight() <= 0) {
- ((PostImageAndGifAutoplayViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
- ((PostImageAndGifAutoplayViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
- } else {
- ((PostImageAndGifAutoplayViewHolder) holder).imageView
- .setRatio((float) post.getPreviewHeight() / post.getPreviewWidth());
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ if (preview != null) {
+ if (preview.getPreviewWidth() <= 0 || preview.getPreviewHeight() <= 0) {
+ ((PostImageAndGifAutoplayViewHolder) holder).imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
+ ((PostImageAndGifAutoplayViewHolder) holder).imageView.getLayoutParams().height = (int) (400 * mScale);
+ } else {
+ ((PostImageAndGifAutoplayViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ }
+ loadImage(holder, post, preview);
}
- loadImage(holder, post);
} else if (holder instanceof PostLinkTypeViewHolder) {
((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostLinkTypeViewHolder) holder).imageView
- .setRatio((float) post.getPreviewHeight() / post.getPreviewWidth());
- loadImage(holder, post);
+
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ if (preview != null) {
+ ((PostLinkTypeViewHolder) holder).imageView
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
+ loadImage(holder, post, preview);
+ }
String domain = Uri.parse(post.getUrl()).getHost();
((PostLinkTypeViewHolder) holder).linkTextView.setText(domain);
} else if (holder instanceof PostNoPreviewLinkTypeViewHolder) {
((PostNoPreviewLinkTypeViewHolder) holder).linkTextView.setText(Uri.parse(post.getUrl()).getHost());
} else if (holder instanceof PostGalleryTypeViewHolder) {
- if (post.getPreviewUrl() != null && !post.getPreviewUrl().equals("")) {
+ Post.Preview preview = getSuitablePreview(post.getPreviews());
+ if (preview != null) {
((PostGalleryTypeViewHolder) holder).imageWrapperRelativeLayout.setVisibility(View.VISIBLE);
((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
((PostGalleryTypeViewHolder) holder).imageView
- .setRatio((float) post.getPreviewHeight() / post.getPreviewWidth());
+ .setRatio((float) preview.getPreviewHeight() / preview.getPreviewWidth());
- loadImage(holder, post);
+ loadImage(holder, post, preview);
} else {
((PostGalleryTypeViewHolder) holder).noPreviewLinkImageView.setVisibility(View.VISIBLE);
}
@@ -783,11 +801,11 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
if (mCompactLayoutToolbarHiddenByDefault) {
- ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams();
+ ViewGroup.LayoutParams params = ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams();
params.height = 0;
((PostCompactBaseViewHolder) holder).bottomConstraintLayout.setLayoutParams(params);
} else {
- ViewGroup.LayoutParams params = (LinearLayout.LayoutParams) ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams();
+ ViewGroup.LayoutParams params = ((PostCompactBaseViewHolder) holder).bottomConstraintLayout.getLayoutParams();
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
((PostCompactBaseViewHolder) holder).bottomConstraintLayout.setLayoutParams(params);
}
@@ -845,12 +863,15 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
if (post.getPostType() != Post.GIF_TYPE && post.getPostType() != Post.VIDEO_TYPE) {
((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
}
- if (post.getPostType() == Post.GALLERY_TYPE && post.getPreviewUrl() == null || post.getPreviewUrl().equals("")) {
+ if (post.getPostType() == Post.GALLERY_TYPE && post.getPreviews().isEmpty()) {
((PostCompactBaseViewHolder) holder).noPreviewLinkImageFrameLayout.setVisibility(View.VISIBLE);
} else {
((PostCompactBaseViewHolder) holder).imageView.setVisibility(View.VISIBLE);
}
- loadImage(holder, post);
+ ArrayList<Post.Preview> previews = post.getPreviews();
+ if (previews != null && !previews.isEmpty()) {
+ loadImage(holder, post, previews.get(0));
+ }
}
if (mPostType == PostDataSource.TYPE_SUBREDDIT && !mDisplaySubredditName && post.isStickied()) {
@@ -920,157 +941,202 @@ public class PostRecyclerViewAdapter extends PagedListAdapter<Post, RecyclerView
}
}
- private void loadImage(final RecyclerView.ViewHolder holder, final Post post) {
- if (holder instanceof PostImageAndGifAutoplayViewHolder) {
- String url = post.getPostType() == Post.IMAGE_TYPE ? post.getPreviewUrl() : post.getUrl();
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE);
- ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
- ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
- ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- loadImage(holder, post);
- });
- return false;
+ @Nullable
+ private Post.Preview getSuitablePreview(ArrayList<Post.Preview> previews) {
+ Post.Preview preview;
+ if (!previews.isEmpty()) {
+ preview = previews.get(0);
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() >= 65 * 1000 * 1000) {
+ for (int i = previews.size() - 1; i >= 1; i--) {
+ preview = previews.get(i);
+ if (mImageViewWidth >= preview.getPreviewWidth()) {
+ if (preview.getPreviewWidth() * preview.getPreviewHeight() <= 75 * 1000 * 1000) {
+ return preview;
+ }
+ } else {
+ int height = mImageViewWidth / preview.getPreviewWidth() * preview.getPreviewHeight();
+ if (mImageViewWidth * height <= 75 * 1000 * 1000) {
+ return preview;
+ }
+ }
}
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
+ int divisor = 2;
+ while (preview.getPreviewWidth() * preview.getPreviewHeight() / divisor / divisor > 75 * 1000 * 1000) {
+ preview.setPreviewWidth(preview.getPreviewWidth() / divisor);
+ preview.setPreviewHeight(preview.getPreviewHeight() / divisor);
+ divisor *= 2;
+ }
- if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
- .into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
- } else {
- if (mImageViewWidth > post.getPreviewWidth()) {
- imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
+ return preview;
+ }
+
+ return null;
+ }
+
+ private void loadImage(final RecyclerView.ViewHolder holder, final Post post, @NonNull Post.Preview preview) {
+ if (preview != null) {
+ if (holder instanceof PostImageAndGifAutoplayViewHolder) {
+ String url = post.getPostType() == Post.IMAGE_TYPE ? preview.getPreviewUrl() : post.getUrl();
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(url).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
+ ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
+ ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ loadImage(holder, post, preview);
+ });
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostImageAndGifAutoplayViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ ((PostImageAndGifAutoplayViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
+
+ if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
+ .into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
- }
- }
- } else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
- ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
- ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
- ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- loadImage(holder, post);
- });
- return false;
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((PostImageAndGifAutoplayViewHolder) holder).imageView);
+ }
}
+ } else if (holder instanceof PostVideoAndGifPreviewViewHolder) {
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
+ ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
+ ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ loadImage(holder, post, preview);
+ });
+ return false;
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostVideoAndGifPreviewViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ ((PostVideoAndGifPreviewViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
- if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
- .into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
- } else {
- if (mImageViewWidth > post.getPreviewWidth()) {
- imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
+ if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
+ .into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
- }
- }
- } else if (holder instanceof PostLinkTypeViewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
- ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
- ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
- ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- loadImage(holder, post);
- });
- return false;
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((PostVideoAndGifPreviewViewHolder) holder).imageView);
+ }
}
+ } else if (holder instanceof PostLinkTypeViewHolder) {
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
+ ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
+ ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ loadImage(holder, post, preview);
+ });
+ return false;
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostLinkTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ ((PostLinkTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
- if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
- .into(((PostLinkTypeViewHolder) holder).imageView);
- } else {
- if (mImageViewWidth > post.getPreviewWidth()) {
- imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostLinkTypeViewHolder) holder).imageView);
+ if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
+ .into(((PostLinkTypeViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostLinkTypeViewHolder) holder).imageView);
- }
- }
- } else if (holder instanceof PostGalleryTypeViewHolder) {
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(post.getPreviewUrl()).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
- ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
- ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
- ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
- ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- loadImage(holder, post);
- });
- return false;
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostLinkTypeViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((PostLinkTypeViewHolder) holder).imageView);
+ }
}
+ } else if (holder instanceof PostGalleryTypeViewHolder) {
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(preview.getPreviewUrl()).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
+ ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.VISIBLE);
+ ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setOnClickListener(view -> {
+ ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.VISIBLE);
+ ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ loadImage(holder, post, preview);
+ });
+ return false;
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
- ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostGalleryTypeViewHolder) holder).errorRelativeLayout.setVisibility(View.GONE);
+ ((PostGalleryTypeViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
- if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
- imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
- .into(((PostGalleryTypeViewHolder) holder).imageView);
- } else {
- if (mImageViewWidth > post.getPreviewWidth()) {
- imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostGalleryTypeViewHolder) holder).imageView);
+ if ((post.isNSFW() && mNeedBlurNSFW && !(post.getPostType() == Post.GIF_TYPE && mAutoplayNsfwVideos)) || post.isSpoiler() && mNeedBlurSpoiler) {
+ imageRequestBuilder.apply(RequestOptions.bitmapTransform(new BlurTransformation(50, 10)))
+ .into(((PostGalleryTypeViewHolder) holder).imageView);
} else {
- imageRequestBuilder.into(((PostGalleryTypeViewHolder) holder).imageView);
+ if (mImageViewWidth > preview.getPreviewWidth()) {
+ imageRequestBuilder.override(Target.SIZE_ORIGINAL).into(((PostGalleryTypeViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((PostGalleryTypeViewHolder) holder).imageView);
+ }
}
- }
- } else if (holder instanceof PostCompactBaseViewHolder) {
- String previewUrl = post.getThumbnailPreviewUrl().equals("") ? post.getPreviewUrl() : post.getThumbnailPreviewUrl();
- RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(previewUrl)
- .error(R.drawable.ic_error_outline_black_24dp).listener(new RequestListener<Drawable>() {
- @Override
- public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
- ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
+ } else if (holder instanceof PostCompactBaseViewHolder) {
+ String postCompactThumbnailPreviewUrl;
+ ArrayList<Post.Preview> previews = post.getPreviews();
+ if (previews != null && !previews.isEmpty()) {
+ if (previews.size() >= 2) {
+ postCompactThumbnailPreviewUrl = previews.get(1).getPreviewUrl();
+ } else {
+ postCompactThumbnailPreviewUrl = preview.getPreviewUrl();
+ }
- @Override
- public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
- ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE);
- return false;
- }
- });
- if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
- imageRequestBuilder
- .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView);
- } else {
- imageRequestBuilder.into(((PostCompactBaseViewHolder) holder).imageView);
+ RequestBuilder<Drawable> imageRequestBuilder = mGlide.load(postCompactThumbnailPreviewUrl)
+ .error(R.drawable.ic_error_outline_black_24dp).listener(new RequestListener<Drawable>() {
+ @Override
+ public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {
+ ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+
+ @Override
+ public boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {
+ ((PostCompactBaseViewHolder) holder).progressBar.setVisibility(View.GONE);
+ return false;
+ }
+ });
+ if ((post.isNSFW() && mNeedBlurNSFW) || post.isSpoiler() && mNeedBlurSpoiler) {
+ imageRequestBuilder
+ .transform(new BlurTransformation(50, 2)).into(((PostCompactBaseViewHolder) holder).imageView);
+ } else {
+ imageRequestBuilder.into(((PostCompactBaseViewHolder) holder).imageView);
+ }
+ }
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchRemovedPost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchRemovedPost.java
index f24e995b..dd641e6e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchRemovedPost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/FetchRemovedPost.java
@@ -9,8 +9,9 @@ import androidx.annotation.NonNull;
import org.json.JSONException;
import org.json.JSONObject;
+import java.util.ArrayList;
+
import ml.docilealligator.infinityforreddit.API.PushshiftAPI;
-import ml.docilealligator.infinityforreddit.Post.Post;
import ml.docilealligator.infinityforreddit.Utils.JSONUtils;
import ml.docilealligator.infinityforreddit.Utils.Utils;
import retrofit2.Call;
@@ -85,7 +86,24 @@ public class FetchRemovedPost {
}
if (!result.isNull("thumbnail")) {
- post.setThumbnailPreviewUrl(result.getString("thumbnail"));
+ ArrayList<Post.Preview> previews = post.getPreviews();
+ if (previews != null && !previews.isEmpty()) {
+ if (previews.size() >= 2) {
+ Post.Preview preview = previews.get(1);
+ preview.setPreviewUrl(result.getString("thumbnail"));
+ previews.set(1, preview);
+ } else {
+ Post.Preview preview = previews.get(0);
+ preview.setPreviewUrl(result.getString("thumbnail"));
+ previews.set(0, preview);
+ }
+ } else {
+ Post.Preview preview = new Post.Preview(result.getString("thumbnail"), 1, 1);
+ preview.setPreviewUrl(result.getString("thumbnail"));
+ ArrayList<Post.Preview> newPreviews = new ArrayList<>();
+ newPreviews.add(preview);
+ post.setPreviews(newPreviews);
+ }
}
return post;
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java
index 11a08868..4aba1588 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/ParsePost.java
@@ -30,7 +30,7 @@ public class ParsePost {
new ParsePostDataAsyncTask(response, locale, true, parsePostListener).execute();
}
- private static Post parseBasicData(JSONObject data, Locale locale) throws JSONException {
+ private static Post parseBasicData(JSONObject data) throws JSONException {
String id = data.getString(JSONUtils.ID_KEY);
String fullName = data.getString(JSONUtils.NAME_KEY);
String subredditName = data.getString(JSONUtils.SUBREDDIT_KEY);
@@ -108,32 +108,31 @@ public class ParsePost {
String permalink = Html.fromHtml(data.getString(JSONUtils.PERMALINK_KEY)).toString();
- String previewUrl = "";
- String thumbnailPreviewUrl = "";
- int previewWidth = -1;
- int previewHeight = -1;
+ ArrayList<Post.Preview> previews = new ArrayList<>();
if (data.has(JSONUtils.PREVIEW_KEY)) {
JSONObject images = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0);
- previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
+ String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
+ int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY);
+ int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY);
+ previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight));
+
JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY);
- int thumbnailPreviewsLength = thumbnailPreviews.length();
- if (thumbnailPreviewsLength > 0) {
- if (thumbnailPreviewsLength >= 3) {
- thumbnailPreviewUrl = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(2).getString(JSONUtils.URL_KEY);
- } else {
- thumbnailPreviewUrl = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(0).getString(JSONUtils.URL_KEY);
- }
+ for (int i = 0; i < thumbnailPreviews.length(); i++) {
+ JSONObject thumbnailPreview = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(2);
+ String thumbnailPreviewUrl = thumbnailPreview.getString(JSONUtils.URL_KEY);
+ int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY);
+ int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY);
+
+ previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight));
}
- previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY);
- previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY);
}
if (data.has(JSONUtils.CROSSPOST_PARENT_LIST)) {
//Cross post
data = data.getJSONArray(JSONUtils.CROSSPOST_PARENT_LIST).getJSONObject(0);
- Post crosspostParent = parseBasicData(data, locale);
+ Post crosspostParent = parseBasicData(data);
Post post = parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, authorFlair, authorFlairHTMLBuilder.toString(),
- postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight,
+ postTime, title, previews,
score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
spoiler, nsfw, stickied, archived, locked, saved, true);
post.setCrosspostParentId(crosspostParent.getId());
@@ -141,7 +140,7 @@ public class ParsePost {
} else {
return parseData(data, permalink, id, fullName, subredditName, subredditNamePrefixed,
author, authorFlair, authorFlairHTMLBuilder.toString(),
- postTime, title, previewUrl, thumbnailPreviewUrl, previewWidth, previewHeight,
+ postTime, title, previews,
score, voteType, nComments, flair, awardingsBuilder.toString(), nAwards, hidden,
spoiler, nsfw, stickied, archived, locked, saved, false);
}
@@ -150,8 +149,7 @@ public class ParsePost {
private static Post parseData(JSONObject data, String permalink, String id, String fullName,
String subredditName, String subredditNamePrefixed, String author,
String authorFlair, String authorFlairHTML,
- long postTimeMillis, String title, String previewUrl,
- String thumbnailPreviewUrl, int previewWidth, int previewHeight,
+ long postTimeMillis, String title, ArrayList<Post.Preview> previews,
int score, int voteType, int nComments, String flair,
String awards, int nAwards, boolean hidden, boolean spoiler,
boolean nsfw, boolean stickied, boolean archived, boolean locked,
@@ -161,7 +159,7 @@ public class ParsePost {
boolean isVideo = data.getBoolean(JSONUtils.IS_VIDEO_KEY);
String url = Html.fromHtml(data.getString(JSONUtils.URL_KEY)).toString();
- if (!data.has(JSONUtils.PREVIEW_KEY) && previewUrl.equals("")) {
+ if (!data.has(JSONUtils.PREVIEW_KEY) && previews.isEmpty()) {
if (url.contains(permalink)) {
//Text post
int postType = Post.TEXT_TYPE;
@@ -191,19 +189,17 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
} else {
//No preview link post
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, postTimeMillis,
- title, previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
+ title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
@@ -214,9 +210,24 @@ public class ParsePost {
}
}
} else {
- if (previewUrl.equals("")) {
- previewUrl = Html.fromHtml(data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0)
- .getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY)).toString();
+ if (previews.isEmpty()) {
+ if (data.has(JSONUtils.PREVIEW_KEY)) {
+ JSONObject images = data.getJSONObject(JSONUtils.PREVIEW_KEY).getJSONArray(JSONUtils.IMAGES_KEY).getJSONObject(0);
+ String previewUrl = images.getJSONObject(JSONUtils.SOURCE_KEY).getString(JSONUtils.URL_KEY);
+ int previewWidth = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.WIDTH_KEY);
+ int previewHeight = images.getJSONObject(JSONUtils.SOURCE_KEY).getInt(JSONUtils.HEIGHT_KEY);
+ previews.add(new Post.Preview(previewUrl, previewWidth, previewHeight));
+
+ JSONArray thumbnailPreviews = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY);
+ for (int i = 0; i < thumbnailPreviews.length(); i++) {
+ JSONObject thumbnailPreview = images.getJSONArray(JSONUtils.RESOLUTIONS_KEY).getJSONObject(2);
+ String thumbnailPreviewUrl = thumbnailPreview.getString(JSONUtils.URL_KEY);
+ int thumbnailPreviewWidth = thumbnailPreview.getInt(JSONUtils.WIDTH_KEY);
+ int thumbnailPreviewHeight = thumbnailPreview.getInt(JSONUtils.HEIGHT_KEY);
+
+ previews.add(new Post.Preview(thumbnailPreviewUrl, thumbnailPreviewWidth, thumbnailPreviewHeight));
+ }
+ }
}
if (isVideo) {
@@ -227,13 +238,11 @@ public class ParsePost {
String videoDownloadUrl = redditVideoObject.getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
post.setVideoUrl(videoUrl);
post.setVideoDownloadUrl(videoDownloadUrl);
} else if (data.has(JSONUtils.PREVIEW_KEY)) {
@@ -246,12 +255,10 @@ public class ParsePost {
.getJSONObject(JSONUtils.REDDIT_VIDEO_PREVIEW_KEY).getString(JSONUtils.FALLBACK_URL_KEY);
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- previewUrl, thumbnailPreviewUrl, permalink, score, postType, voteType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
post.setVideoUrl(videoUrl);
post.setVideoDownloadUrl(videoDownloadUrl);
} else {
@@ -261,35 +268,31 @@ public class ParsePost {
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, postTimeMillis,
- title, url, thumbnailPreviewUrl, url, permalink, score, postType,
+ title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw,
stickied, archived, locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
} else if (url.endsWith("gif")){
//Gif post
int postType = Post.GIF_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, postTimeMillis,
- title, previewUrl, thumbnailPreviewUrl, url, permalink, score,
+ title, url, permalink, score,
postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
post.setVideoUrl(url);
} else if (url.endsWith("mp4")) {
//Video post
int postType = Post.VIDEO_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
} else {
@@ -303,8 +306,8 @@ public class ParsePost {
awards, nAwards, hidden, spoiler, nsfw, stickied, archived, locked,
saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ //Need attention
+ post.setPreviews(previews);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
post.setSelfText("");
@@ -328,7 +331,7 @@ public class ParsePost {
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
authorFlair, authorFlairHTML, postTimeMillis,
- title, previewUrl, thumbnailPreviewUrl, url, permalink, score,
+ title, url, permalink, score,
postType, voteType, nComments, flair, awards, nAwards, hidden, spoiler,
nsfw, stickied, archived, locked, saved, isCrosspost);
if (data.isNull(JSONUtils.SELFTEXT_KEY)) {
@@ -337,8 +340,7 @@ public class ParsePost {
post.setSelfText(Utils.modifyMarkdown(data.getString(JSONUtils.SELFTEXT_KEY).trim()));
}
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
}
}
}
@@ -348,23 +350,19 @@ public class ParsePost {
int postType = Post.IMAGE_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
} else if (url.endsWith("mp4")) {
//Video post
int postType = Post.VIDEO_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- previewUrl, thumbnailPreviewUrl, url, permalink, score, postType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType,
voteType, nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied,
archived, locked, saved, isCrosspost);
- post.setPreviewWidth(previewWidth);
- post.setPreviewHeight(previewHeight);
+ post.setPreviews(previews);
post.setVideoUrl(url);
post.setVideoDownloadUrl(url);
} else {
@@ -372,10 +370,10 @@ public class ParsePost {
int postType = Post.NO_PREVIEW_LINK_TYPE;
post = new Post(id, fullName, subredditName, subredditNamePrefixed, author,
- authorFlair, authorFlairHTML, postTimeMillis, title,
- url, thumbnailPreviewUrl, url, permalink, score, postType, voteType,
+ authorFlair, authorFlairHTML, postTimeMillis, title, url, permalink, score, postType, voteType,
nComments, flair, awards, nAwards, hidden, spoiler, nsfw, stickied, archived,
locked, saved, isCrosspost);
+ //Need attention
}
}
}
@@ -414,11 +412,9 @@ public class ParsePost {
galleryItemUrl = sourceObject.getString(JSONUtils.MP4_KEY);
}
}
- if ((previewUrl.equals("")) && mimeType.contains("jpg") || mimeType.contains("png")) {
- previewUrl = galleryItemUrl;
- post.setPreviewUrl(previewUrl);
- post.setPreviewWidth(singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY));
- post.setPreviewHeight(singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY));
+ if ((previews.isEmpty()) && mimeType.contains("jpg") || mimeType.contains("png")) {
+ previews.add(new Post.Preview(galleryItemUrl, singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.X_KEY),
+ singleGalleryObject.getJSONObject(JSONUtils.S_KEY).getInt(JSONUtils.Y_KEY)));
}
gallery.add(new Post.Gallery(mimeType, galleryItemUrl, subredditName + "-" + galleryId + "." + mimeType.substring(mimeType.lastIndexOf("/") + 1)));
}
@@ -520,7 +516,7 @@ public class ParsePost {
try {
JSONObject data = allData.getJSONObject(0).getJSONObject(JSONUtils.DATA_KEY);
- post = parseBasicData(data, locale);
+ post = parseBasicData(data);
} catch (JSONException e) {
e.printStackTrace();
parseFailed = true;
@@ -538,7 +534,7 @@ public class ParsePost {
try {
if (allData.getJSONObject(i).getString(JSONUtils.KIND_KEY).equals("t3")) {
JSONObject data = allData.getJSONObject(i).getJSONObject(JSONUtils.DATA_KEY);
- Post post = parseBasicData(data, locale);
+ Post post = parseBasicData(data);
if (!(!nsfw && post.isNSFW())) {
if (filter == PostFragment.EXTRA_NO_FILTER) {
newPosts.add(post);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
index 82c550d5..d2b8748e 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Post/Post.java
@@ -47,8 +47,6 @@ public class Post implements Parcelable {
private String selfText;
private String selfTextPlain;
private String selfTextPlainTrimmed;
- private String previewUrl;
- private String thumbnailPreviewUrl;
private String url;
private String videoUrl;
private String videoDownloadUrl;
@@ -64,8 +62,6 @@ public class Post implements Parcelable {
private int score;
private int postType;
private int voteType;
- private int previewWidth;
- private int previewHeight;
private int nComments;
private boolean hidden;
private boolean spoiler;
@@ -76,11 +72,12 @@ public class Post implements Parcelable {
private boolean saved;
private boolean isCrosspost;
private String crosspostParentId;
+ private ArrayList<Preview> previews = new ArrayList<>();
private ArrayList<Gallery> gallery = new ArrayList<>();
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String author, String authorFlair, String authorFlairHTML,
- long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl,
+ long postTimeMillis, String title,
String permalink, int score, int postType, int voteType, int nComments, String flair,
String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw, boolean stickied,
boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
@@ -94,8 +91,6 @@ public class Post implements Parcelable {
this.authorFlairHTML = authorFlairHTML;
this.postTimeMillis = postTimeMillis;
this.title = title;
- this.previewUrl = previewUrl;
- this.thumbnailPreviewUrl = thumbnailPreviewUrl;
this.permalink = APIUtils.API_BASE_URI + permalink;
this.score = score;
this.postType = postType;
@@ -116,7 +111,7 @@ public class Post implements Parcelable {
public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
String author, String authorFlair, String authorFlairHTML,
- long postTimeMillis, String title, String previewUrl, String thumbnailPreviewUrl,
+ long postTimeMillis, String title,
String url, String permalink, int score, int postType, int voteType, int nComments,
String flair, String awards, int nAwards, boolean hidden, boolean spoiler, boolean nsfw,
boolean stickied, boolean archived, boolean locked, boolean saved, boolean isCrosspost) {
@@ -130,8 +125,6 @@ public class Post implements Parcelable {
this.authorFlairHTML = authorFlairHTML;
this.postTimeMillis = postTimeMillis;
this.title = title;
- this.previewUrl = previewUrl;
- this.thumbnailPreviewUrl = thumbnailPreviewUrl;
this.url = url;
this.permalink = APIUtils.API_BASE_URI + permalink;
this.score = score;
@@ -151,40 +144,6 @@ public class Post implements Parcelable {
this.isCrosspost = isCrosspost;
}
- public Post(String id, String fullName, String subredditName, String subredditNamePrefixed,
- String author, String authorFlair, String authorFlairHTML,
- long postTimeMillis, String title, String permalink, int score, int postType,
- int voteType, int nComments, String flair, String awards, int nAwards, boolean hidden,
- boolean spoiler, boolean nsfw, boolean stickied, boolean archived, boolean locked,
- boolean saved, boolean isCrosspost) {
- this.id = id;
- this.fullName = fullName;
- this.subredditName = subredditName;
- this.subredditNamePrefixed = subredditNamePrefixed;
- this.author = author;
- this.authorNamePrefixed = "u/" + author;
- this.authorFlair = authorFlair;
- this.authorFlairHTML = authorFlairHTML;
- this.postTimeMillis = postTimeMillis;
- this.title = title;
- this.permalink = APIUtils.API_BASE_URI + permalink;
- this.score = score;
- this.postType = postType;
- this.voteType = voteType;
- this.nComments = nComments;
- this.flair = flair;
- this.awards = awards;
- this.nAwards = nAwards;
- this.hidden = hidden;
- this.spoiler = spoiler;
- this.nsfw = nsfw;
- this.stickied = stickied;
- this.archived = archived;
- this.locked = locked;
- this.saved = saved;
- this.isCrosspost = isCrosspost;
- }
-
protected Post(Parcel in) {
id = in.readString();
fullName = in.readString();
@@ -201,8 +160,6 @@ public class Post implements Parcelable {
selfText = in.readString();
selfTextPlain = in.readString();
selfTextPlainTrimmed = in.readString();
- previewUrl = in.readString();
- thumbnailPreviewUrl = in.readString();
url = in.readString();
videoUrl = in.readString();
videoDownloadUrl = in.readString();
@@ -217,8 +174,6 @@ public class Post implements Parcelable {
score = in.readInt();
postType = in.readInt();
voteType = in.readInt();
- previewWidth = in.readInt();
- previewHeight = in.readInt();
nComments = in.readInt();
hidden = in.readByte() != 0;
spoiler = in.readByte() != 0;
@@ -229,6 +184,7 @@ public class Post implements Parcelable {
saved = in.readByte() != 0;
isCrosspost = in.readByte() != 0;
crosspostParentId = in.readString();
+ in.readTypedList(previews, Preview.CREATOR);
in.readTypedList(gallery, Gallery.CREATOR);
}
@@ -321,22 +277,6 @@ public class Post implements Parcelable {
this.selfTextPlainTrimmed = selfTextPlainTrimmed;
}
- public String getPreviewUrl() {
- return previewUrl;
- }
-
- public void setPreviewUrl(String previewUrl) {
- this.previewUrl = previewUrl;
- }
-
- public String getThumbnailPreviewUrl() {
- return thumbnailPreviewUrl;
- }
-
- public void setThumbnailPreviewUrl(String thumbnailPreviewUrl) {
- this.thumbnailPreviewUrl = thumbnailPreviewUrl;
- }
-
public String getUrl() {
return url;
}
@@ -437,22 +377,6 @@ public class Post implements Parcelable {
this.voteType = voteType;
}
- public int getPreviewWidth() {
- return previewWidth;
- }
-
- public void setPreviewWidth(int previewWidth) {
- this.previewWidth = previewWidth;
- }
-
- public int getPreviewHeight() {
- return previewHeight;
- }
-
- public void setPreviewHeight(int previewHeight) {
- this.previewHeight = previewHeight;
- }
-
public int getNComments() {
return nComments;
}
@@ -522,6 +446,14 @@ public class Post implements Parcelable {
this.crosspostParentId = crosspostParentId;
}
+ public ArrayList<Preview> getPreviews() {
+ return previews;
+ }
+
+ public void setPreviews(ArrayList<Preview> previews) {
+ this.previews = previews;
+ }
+
public ArrayList<Gallery> getGallery() {
return gallery;
}
@@ -547,8 +479,6 @@ public class Post implements Parcelable {
parcel.writeString(selfText);
parcel.writeString(selfTextPlain);
parcel.writeString(selfTextPlainTrimmed);
- parcel.writeString(previewUrl);
- parcel.writeString(thumbnailPreviewUrl);
parcel.writeString(url);
parcel.writeString(videoUrl);
parcel.writeString(videoDownloadUrl);
@@ -563,8 +493,6 @@ public class Post implements Parcelable {
parcel.writeInt(score);
parcel.writeInt(postType);
parcel.writeInt(voteType);
- parcel.writeInt(previewWidth);
- parcel.writeInt(previewHeight);
parcel.writeInt(nComments);
parcel.writeByte((byte) (hidden ? 1 : 0));
parcel.writeByte((byte) (spoiler ? 1 : 0));
@@ -575,6 +503,7 @@ public class Post implements Parcelable {
parcel.writeByte((byte) (saved ? 1 : 0));
parcel.writeByte((byte) (isCrosspost ? 1 : 0));
parcel.writeString(crosspostParentId);
+ parcel.writeTypedList(previews);
parcel.writeTypedList(gallery);
}
@@ -591,7 +520,7 @@ public class Post implements Parcelable {
return id.hashCode();
}
- public static class Gallery implements Parcelable{
+ public static class Gallery implements Parcelable {
public static final int TYPE_IMAGE = 0;
public static final int TYPE_GIF = 1;
public static final int TYPE_VIDEO = 2;
@@ -646,4 +575,70 @@ public class Post implements Parcelable {
parcel.writeInt(mediaType);
}
}
+
+ public static class Preview implements Parcelable {
+ private String previewUrl;
+ private int previewWidth;
+ private int previewHeight;
+
+ public Preview(String previewUrl, int previewWidth, int previewHeight) {
+ this.previewUrl = previewUrl;
+ this.previewWidth = previewWidth;
+ this.previewHeight = previewHeight;
+ }
+
+ protected Preview(Parcel in) {
+ previewUrl = in.readString();
+ previewWidth = in.readInt();
+ previewHeight = in.readInt();
+ }
+
+ public static final Creator<Preview> CREATOR = new Creator<Preview>() {
+ @Override
+ public Preview createFromParcel(Parcel in) {
+ return new Preview(in);
+ }
+
+ @Override
+ public Preview[] newArray(int size) {
+ return new Preview[size];
+ }
+ };
+
+ public String getPreviewUrl() {
+ return previewUrl;
+ }
+
+ public void setPreviewUrl(String previewUrl) {
+ this.previewUrl = previewUrl;
+ }
+
+ public int getPreviewWidth() {
+ return previewWidth;
+ }
+
+ public void setPreviewWidth(int previewWidth) {
+ this.previewWidth = previewWidth;
+ }
+
+ public int getPreviewHeight() {
+ return previewHeight;
+ }
+
+ public void setPreviewHeight(int previewHeight) {
+ this.previewHeight = previewHeight;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel parcel, int i) {
+ parcel.writeString(previewUrl);
+ parcel.writeInt(previewWidth);
+ parcel.writeInt(previewHeight);
+ }
+ }
}