From 2c1f4aea9db1bdc9787cc912742ece92beab9960 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 10 Nov 2020 22:41:22 +0900 Subject: [PATCH] Replace gif with webp for animated media --- app/build.gradle | 5 +++-- .../DirectMessageAnimatedMediaViewHolder.java | 15 ++++----------- .../DirectMessageItemViewHolder.java | 3 ++- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 08fa6400..269c200d 100755 --- a/app/build.gradle +++ b/app/build.gradle @@ -45,7 +45,7 @@ configurations.all { } dependencies { - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.0' def appcompat_version = "1.2.0" def nav_version = '2.3.1' @@ -74,7 +74,8 @@ dependencies { implementation 'org.jsoup:jsoup:1.13.1' implementation 'com.facebook.fresco:fresco:2.3.0' - implementation 'com.facebook.fresco:animated-gif:2.3.0' + implementation 'com.facebook.fresco:animated-webp:2.3.0' + implementation 'com.facebook.fresco:webpsupport:2.3.0' implementation 'com.squareup.retrofit2:retrofit:2.9.0' implementation 'com.squareup.retrofit2:converter-scalars:2.9.0' diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageAnimatedMediaViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageAnimatedMediaViewHolder.java index 17d00739..65ed59af 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageAnimatedMediaViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageAnimatedMediaViewHolder.java @@ -1,6 +1,5 @@ package awais.instagrabber.adapters.viewholder.directmessages; -import android.net.Uri; import android.view.View; import android.view.ViewGroup; @@ -8,9 +7,6 @@ import androidx.annotation.NonNull; import androidx.core.util.Pair; import com.facebook.drawee.backends.pipeline.Fresco; -import com.facebook.imagepipeline.common.ResizeOptions; -import com.facebook.imagepipeline.request.ImageRequest; -import com.facebook.imagepipeline.request.ImageRequestBuilder; import awais.instagrabber.R; import awais.instagrabber.databinding.LayoutDmAnimatedMediaBinding; @@ -31,15 +27,15 @@ public class DirectMessageAnimatedMediaViewHolder extends DirectMessageItemViewH super(baseBinding, onClickListener); this.binding = binding; maxHeight = itemView.getResources().getDimensionPixelSize(R.dimen.dm_media_img_max_height); - maxWidth = (int) (Utils.displayMetrics.widthPixels - Utils.convertDpToPx(64) - getItemMargin()); + maxWidth = Utils.displayMetrics.widthPixels - Utils.convertDpToPx(64) - getItemMargin(); setItemView(binding.getRoot()); - removeElevation(); + setupForAnimatedMedia(); } @Override public void bindItem(final DirectItemModel directItemModel) { final DirectItemModel.DirectItemAnimatedMediaModel animatedMediaModel = directItemModel.getAnimatedMediaModel(); - final String url = animatedMediaModel.getGifUrl(); + final String url = animatedMediaModel.getWebpUrl(); final Pair widthHeight = NumberUtils.calculateWidthHeight( animatedMediaModel.getHeight(), animatedMediaModel.getWidth(), @@ -53,11 +49,8 @@ public class DirectMessageAnimatedMediaViewHolder extends DirectMessageItemViewH layoutParams.width = width; layoutParams.height = height; binding.ivAnimatedMessage.requestLayout(); - final ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url)) - .setResizeOptions(ResizeOptions.forDimensions(width, height)) - .build(); binding.ivAnimatedMessage.setController(Fresco.newDraweeControllerBuilder() - .setImageRequest(request) + .setUri(url) .setAutoPlayAnimations(true) .build()); } diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageItemViewHolder.java index 675b3f6d..3f3011c0 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageItemViewHolder.java @@ -93,7 +93,8 @@ public abstract class DirectMessageItemViewHolder extends RecyclerView.ViewHolde return null; } - protected void removeElevation() { + protected void setupForAnimatedMedia() { binding.messageCard.setCardElevation(0); + binding.messageCard.setCardBackgroundColor(itemView.getResources().getColor(android.R.color.transparent)); } }