Browse Source
Various DM fixes (check description)
Various DM fixes (check description)
Use new download flow. Fix blank space at top when scrolling. Fix animated media.renovate/org.robolectric-robolectric-4.x
Ammar Githam
4 years ago
12 changed files with 151 additions and 82 deletions
-
1app/build.gradle
-
9app/src/main/java/awais/instagrabber/activities/MainActivity.java
-
35app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageAnimatedMediaViewHolder.java
-
8app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageItemViewHolder.java
-
2app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectMessageMediaViewHolder.java
-
59app/src/main/java/awais/instagrabber/fragments/directmessages/DirectMessageThreadFragment.java
-
53app/src/main/java/awais/instagrabber/utils/DownloadUtils.java
-
24app/src/main/java/awais/instagrabber/utils/NumberUtils.java
-
23app/src/main/res/layout/fragment_direct_messages_thread.xml
-
4app/src/main/res/layout/layout_dm_animated_media.xml
-
11app/src/main/res/layout/layout_dm_base.xml
-
4app/src/main/res/layout/layout_dm_media.xml
@ -1,33 +1,64 @@ |
|||
package awais.instagrabber.adapters.viewholder.directmessages; |
|||
|
|||
import android.net.Uri; |
|||
import android.view.View; |
|||
import android.view.ViewGroup; |
|||
|
|||
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; |
|||
import awais.instagrabber.databinding.LayoutDmBaseBinding; |
|||
import awais.instagrabber.models.direct_messages.DirectItemModel; |
|||
import awais.instagrabber.utils.NumberUtils; |
|||
import awais.instagrabber.utils.Utils; |
|||
|
|||
public class DirectMessageAnimatedMediaViewHolder extends DirectMessageItemViewHolder { |
|||
|
|||
private final LayoutDmAnimatedMediaBinding binding; |
|||
private final int maxHeight; |
|||
private final int maxWidth; |
|||
|
|||
public DirectMessageAnimatedMediaViewHolder(@NonNull final LayoutDmBaseBinding baseBinding, |
|||
@NonNull final LayoutDmAnimatedMediaBinding binding, |
|||
final View.OnClickListener onClickListener) { |
|||
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()); |
|||
setItemView(binding.getRoot()); |
|||
removeElevation(); |
|||
} |
|||
|
|||
@Override |
|||
public void bindItem(final DirectItemModel directItemModel) { |
|||
final DirectItemModel.DirectItemAnimatedMediaModel animatedMediaModel = directItemModel.getAnimatedMediaModel(); |
|||
final String url = animatedMediaModel.getGifUrl(); |
|||
final Pair<Integer, Integer> widthHeight = NumberUtils.calculateWidthHeight( |
|||
animatedMediaModel.getHeight(), |
|||
animatedMediaModel.getWidth(), |
|||
maxHeight, |
|||
maxWidth |
|||
); |
|||
binding.ivAnimatedMessage.setVisibility(View.VISIBLE); |
|||
final ViewGroup.LayoutParams layoutParams = binding.ivAnimatedMessage.getLayoutParams(); |
|||
final int width = widthHeight.first != null ? widthHeight.first : 0; |
|||
final int height = widthHeight.second != null ? widthHeight.second : 0; |
|||
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() |
|||
.setUri(directItemModel.getAnimatedMediaModel().getGifUrl()) |
|||
.setImageRequest(request) |
|||
.setAutoPlayAnimations(true) |
|||
.build()); |
|||
binding.ivAnimatedMessage.setVisibility(View.VISIBLE); |
|||
} |
|||
} |
@ -1,5 +1,7 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<com.facebook.drawee.view.SimpleDraweeView xmlns:android="http://schemas.android.com/apk/res/android" |
|||
xmlns:app="http://schemas.android.com/apk/res-auto" |
|||
android:id="@+id/ivAnimatedMessage" |
|||
android:layout_width="match_parent" |
|||
android:layout_height="@dimen/dm_media_img_max_height" /> |
|||
android:layout_height="@dimen/dm_media_img_max_height" |
|||
app:actualImageScaleType="fitXY" /> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue