diff --git a/app/src/main/java/io/plaidapp/data/api/dribbble/model/Images.java b/app/src/main/java/io/plaidapp/data/api/dribbble/model/Images.java index c3a3ac522..dd36304ba 100644 --- a/app/src/main/java/io/plaidapp/data/api/dribbble/model/Images.java +++ b/app/src/main/java/io/plaidapp/data/api/dribbble/model/Images.java @@ -25,18 +25,9 @@ */ public class Images implements Parcelable { - @SuppressWarnings("unused") - public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { - @Override - public Images createFromParcel(Parcel in) { - return new Images(in); - } + private static final int[] NORMAL_IMAGE_SIZE = new int[] { 400, 300 }; + private static final int[] TWO_X_IMAGE_SIZE = new int[] { 800, 600 }; - @Override - public Images[] newArray(int size) { - return new Images[size]; - } - }; public final String hidpi; public final String normal; public final String teaser; @@ -57,6 +48,10 @@ public String best() { return !TextUtils.isEmpty(hidpi) ? hidpi : normal; } + public int[] bestSize() { + return !TextUtils.isEmpty(hidpi) ? TWO_X_IMAGE_SIZE : NORMAL_IMAGE_SIZE; + } + @Override public int describeContents() { return 0; @@ -68,4 +63,18 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeString(normal); dest.writeString(teaser); } + + @SuppressWarnings("unused") + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + @Override + public Images createFromParcel(Parcel in) { + return new Images(in); + } + + @Override + public Images[] newArray(int size) { + return new Images[size]; + } + }; + } diff --git a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java index 7c4e5fa7d..e3ac94092 100644 --- a/app/src/main/java/io/plaidapp/ui/DribbbleShot.java +++ b/app/src/main/java/io/plaidapp/ui/DribbbleShot.java @@ -188,11 +188,13 @@ public void onDragDismissed() { }; // load the main image + final int[] imageSize = shot.images.bestSize(); Glide.with(this) .load(shot.images.best()) .listener(shotLoadListener) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .priority(Priority.IMMEDIATE) + .override(imageSize[0], imageSize[1]) .into(imageView); imageView.setOnClickListener(shotClick); shotSpacer.setOnClickListener(shotClick); diff --git a/app/src/main/java/io/plaidapp/ui/FeedAdapter.java b/app/src/main/java/io/plaidapp/ui/FeedAdapter.java index 46f74d3fd..849efc112 100644 --- a/app/src/main/java/io/plaidapp/ui/FeedAdapter.java +++ b/app/src/main/java/io/plaidapp/ui/FeedAdapter.java @@ -83,7 +83,6 @@ public class FeedAdapter extends RecyclerView.Adapter { private static final int TYPE_DRIBBBLE_SHOT = 1; private static final int TYPE_PRODUCT_HUNT_POST = 2; private static final int TYPE_LOADING_MORE = -1; - private static final int MAX_IMAGE_CACHE_WIDTH = 1440; public static final float DUPE_WEIGHT_BOOST = 0.4f; // we need to hold on to an activity ref for the shared element transitions :/ @@ -127,7 +126,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType layoutInflater.inflate(R.layout.designer_news_story_item, parent, false), pocketIsInstalled); case TYPE_DRIBBBLE_SHOT: - ensureShotImageWidth(parent); return new DribbbleShotHolder( layoutInflater.inflate(R.layout.dribbble_shot_item, parent, false)); case TYPE_PRODUCT_HUNT_POST: @@ -282,6 +280,7 @@ private void bindDribbbleShotView(final Shot shot, final DribbbleShotHolder holder, final int position) { final BadgedFourThreeImageView iv = (BadgedFourThreeImageView) holder.itemView; + final int[] imageSize = shot.images.bestSize(); Glide.with(host) .load(shot.images.best()) .listener(new RequestListener() { @@ -333,7 +332,8 @@ public boolean onException(Exception e, String model, Target .placeholder(shotLoadingPlaceholders[position % shotLoadingPlaceholders.length]) .diskCacheStrategy(DiskCacheStrategy.SOURCE) .fitCenter() - .into(new DribbbleTarget(iv, false, shotWidth)); + .override(imageSize[0], imageSize[1]) + .into(new DribbbleTarget(iv, false)); iv.setOnClickListener(new View.OnClickListener() { @Override @@ -558,17 +558,6 @@ public int getItemCount() { return getDataItemCount() + 1; } - /** - * We override the image size as we want to cache images at device width for a smooth - * transition from the home grid to the detail screen - */ - private void ensureShotImageWidth(View view) { - if (shotWidth == 0) { - // constrain to a max width to reduce OutOfMemory errors! - shotWidth = Math.min(view.getRootView().getWidth(), MAX_IMAGE_CACHE_WIDTH); - } - } - /** * The shared element transition to dribbble shots & dn stories can intersect with the FAB. * This can cause a strange layers-passing-through-each-other effect, especially on return. diff --git a/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java b/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java index cc190ce89..ebc37fd64 100644 --- a/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java +++ b/app/src/main/java/io/plaidapp/util/glide/DribbbleTarget.java @@ -41,18 +41,9 @@ public class DribbbleTarget extends GlideDrawableImageViewTarget implements private final boolean playGifs; - // we override the image size as we want to cache images at device width for a smooth - // transition from the home grid to the detail screen - private final int imageWidth; - private final int imageHeight; - - public DribbbleTarget(BadgedFourThreeImageView view, - boolean playGifs, - int imageWidth) { + public DribbbleTarget(BadgedFourThreeImageView view, boolean playGifs) { super(view); this.playGifs = playGifs; - this.imageWidth = imageWidth; - this.imageHeight = imageWidth * 3 / 4; } @Override @@ -109,9 +100,4 @@ public void onGenerated(Palette palette) { ContextCompat.getColor(getView().getContext(), R.color.mid_grey), true)); } - @Override - public void getSize(SizeReadyCallback cb) { - cb.onSizeReady(imageWidth, imageHeight); - } - }