mirror of
https://github.com/KokaKiwi/BarInsta
synced 2024-11-22 14:47:29 +00:00
parent
85953352b9
commit
cea09771d6
@ -89,7 +89,7 @@ public class DirectItemMediaShareViewHolder extends DirectItemViewHolder {
|
|||||||
|
|
||||||
private void setupPreview(@NonNull final Media media,
|
private void setupPreview(@NonNull final Media media,
|
||||||
final MessageDirection messageDirection) {
|
final MessageDirection messageDirection) {
|
||||||
final String url = ResponseBodyUtils.getThumbUrl(media.getImageVersions2());
|
final String url = ResponseBodyUtils.getThumbUrl(media);
|
||||||
if (Objects.equals(url, binding.mediaPreview.getTag())) {
|
if (Objects.equals(url, binding.mediaPreview.getTag())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -66,9 +66,7 @@ public class DirectItemMediaViewHolder extends DirectItemViewHolder {
|
|||||||
binding.mediaPreview.requestLayout();
|
binding.mediaPreview.requestLayout();
|
||||||
binding.bgTime.getLayoutParams().width = width;
|
binding.bgTime.getLayoutParams().width = width;
|
||||||
binding.bgTime.requestLayout();
|
binding.bgTime.requestLayout();
|
||||||
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
final String thumbUrl = ResponseBodyUtils.getThumbUrl(media);
|
||||||
if (imageVersions2 == null) return;
|
|
||||||
final String thumbUrl = ResponseBodyUtils.getThumbUrl(imageVersions2);
|
|
||||||
binding.mediaPreview.setImageURI(thumbUrl);
|
binding.mediaPreview.setImageURI(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,8 +86,7 @@ public class DirectItemProfileViewHolder extends DirectItemViewHolder {
|
|||||||
for (int i = 0; i < previewMedias.size(); i++) {
|
for (int i = 0; i < previewMedias.size(); i++) {
|
||||||
final Media previewMedia = previewMedias.get(i);
|
final Media previewMedia = previewMedias.get(i);
|
||||||
if (previewMedia == null) continue;
|
if (previewMedia == null) continue;
|
||||||
final ImageVersions2 imageVersions2 = previewMedia.getImageVersions2();
|
final String url = ResponseBodyUtils.getThumbUrl(previewMedia);
|
||||||
final String url = ResponseBodyUtils.getThumbUrl(imageVersions2);
|
|
||||||
if (url == null) continue;
|
if (url == null) continue;
|
||||||
previewViews.get(i).setImageURI(url);
|
previewViews.get(i).setImageURI(url);
|
||||||
}
|
}
|
||||||
|
@ -180,9 +180,7 @@ public class DirectItemRavenMediaViewHolder extends DirectItemViewHolder {
|
|||||||
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
binding.preview.requestLayout();
|
binding.preview.requestLayout();
|
||||||
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
final String thumbUrl = ResponseBodyUtils.getThumbUrl(media);
|
||||||
if (imageVersions2 == null) return;
|
|
||||||
final String thumbUrl = ResponseBodyUtils.getThumbUrl(imageVersions2);
|
|
||||||
binding.preview.setImageURI(thumbUrl);
|
binding.preview.setImageURI(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,9 +162,7 @@ public class DirectItemReelShareViewHolder extends DirectItemViewHolder {
|
|||||||
binding.preview.setHierarchy(new GenericDraweeHierarchyBuilder(itemView.getResources())
|
binding.preview.setHierarchy(new GenericDraweeHierarchyBuilder(itemView.getResources())
|
||||||
.setRoundingParams(roundingParams)
|
.setRoundingParams(roundingParams)
|
||||||
.build());
|
.build());
|
||||||
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
final String thumbUrl = ResponseBodyUtils.getThumbUrl(media);
|
||||||
if (imageVersions2 == null) return;
|
|
||||||
final String thumbUrl = ResponseBodyUtils.getThumbUrl(imageVersions2);
|
|
||||||
binding.preview.setImageURI(thumbUrl);
|
binding.preview.setImageURI(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +86,7 @@ public class DirectItemStoryShareViewHolder extends DirectItemViewHolder {
|
|||||||
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
layoutParams.width = widthHeight.first != null ? widthHeight.first : 0;
|
||||||
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
layoutParams.height = widthHeight.second != null ? widthHeight.second : 0;
|
||||||
binding.ivMediaPreview.requestLayout();
|
binding.ivMediaPreview.requestLayout();
|
||||||
final ImageVersions2 imageVersions2 = storyShareMedia.getImageVersions2();
|
final String thumbUrl = ResponseBodyUtils.getThumbUrl(storyShareMedia);
|
||||||
if (imageVersions2 == null) return;
|
|
||||||
final String thumbUrl = ResponseBodyUtils.getThumbUrl(imageVersions2);
|
|
||||||
binding.ivMediaPreview.setImageURI(thumbUrl);
|
binding.ivMediaPreview.setImageURI(thumbUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -242,10 +242,10 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple
|
|||||||
text = replied.getPlaceholder().getMessage();
|
text = replied.getPlaceholder().getMessage();
|
||||||
break;
|
break;
|
||||||
case MEDIA:
|
case MEDIA:
|
||||||
url = ResponseBodyUtils.getThumbUrl(replied.getMedia().getImageVersions2());
|
url = ResponseBodyUtils.getThumbUrl(replied.getMedia());
|
||||||
break;
|
break;
|
||||||
case RAVEN_MEDIA:
|
case RAVEN_MEDIA:
|
||||||
url = ResponseBodyUtils.getThumbUrl(replied.getVisualMedia().getMedia().getImageVersions2());
|
url = ResponseBodyUtils.getThumbUrl(replied.getVisualMedia().getMedia());
|
||||||
break;
|
break;
|
||||||
case VOICE_MEDIA:
|
case VOICE_MEDIA:
|
||||||
text = resources.getString(R.string.voice_message);
|
text = resources.getString(R.string.voice_message);
|
||||||
@ -255,7 +255,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple
|
|||||||
if (mediaShare.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
|
if (mediaShare.getMediaType() == MediaItemType.MEDIA_TYPE_SLIDER) {
|
||||||
mediaShare = mediaShare.getCarouselMedia().get(0);
|
mediaShare = mediaShare.getCarouselMedia().get(0);
|
||||||
}
|
}
|
||||||
url = ResponseBodyUtils.getThumbUrl(mediaShare.getImageVersions2());
|
url = ResponseBodyUtils.getThumbUrl(mediaShare);
|
||||||
break;
|
break;
|
||||||
case REEL_SHARE:
|
case REEL_SHARE:
|
||||||
text = replied.getReelShare().getText();
|
text = replied.getReelShare().getText();
|
||||||
|
@ -13,6 +13,7 @@ import org.json.JSONObject;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import awais.instagrabber.BuildConfig;
|
import awais.instagrabber.BuildConfig;
|
||||||
import awais.instagrabber.models.StoryModel;
|
import awais.instagrabber.models.StoryModel;
|
||||||
@ -1094,29 +1095,24 @@ public final class ResponseBodyUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String getThumbUrl(final Media media) {
|
public static String getThumbUrl(final Media media) {
|
||||||
if (media == null) {
|
return getImageCandidate(media, CandidateType.THUMBNAIL);
|
||||||
return null;
|
|
||||||
}
|
|
||||||
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
|
||||||
return getThumbUrl(imageVersions2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getThumbUrl(final ImageVersions2 imageVersions2) {
|
|
||||||
if (imageVersions2 == null) return null;
|
|
||||||
final List<MediaCandidate> candidates = imageVersions2.getCandidates();
|
|
||||||
if (candidates == null || candidates.isEmpty()) return null;
|
|
||||||
final MediaCandidate mediaCandidate = candidates.get(candidates.size() - 1);
|
|
||||||
if (mediaCandidate == null) return null;
|
|
||||||
return mediaCandidate.getUrl();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getImageUrl(final Media media) {
|
public static String getImageUrl(final Media media) {
|
||||||
|
return getImageCandidate(media, CandidateType.DOWNLOAD);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getImageCandidate(final Media media, final CandidateType type) {
|
||||||
if (media == null) return null;
|
if (media == null) return null;
|
||||||
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
final ImageVersions2 imageVersions2 = media.getImageVersions2();
|
||||||
if (imageVersions2 == null) return null;
|
if (imageVersions2 == null) return null;
|
||||||
final List<MediaCandidate> candidates = imageVersions2.getCandidates();
|
final List<MediaCandidate> candidates = imageVersions2.getCandidates();
|
||||||
if (candidates == null || candidates.isEmpty()) return null;
|
if (candidates == null || candidates.isEmpty()) return null;
|
||||||
final MediaCandidate candidate = candidates.get(0);
|
final List<MediaCandidate> sortedCandidates = candidates.stream()
|
||||||
|
.sorted((c1, c2) -> Integer.compare(c2.getWidth(), c1.getWidth()))
|
||||||
|
.filter(c -> c.getWidth() < type.getValue())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
final MediaCandidate candidate = sortedCandidates.get(0);
|
||||||
if (candidate == null) return null;
|
if (candidate == null) return null;
|
||||||
return candidate.getUrl();
|
return candidate.getUrl();
|
||||||
}
|
}
|
||||||
@ -1133,4 +1129,19 @@ public final class ResponseBodyUtils {
|
|||||||
model.setVideoUrl(data.getString("dash_playback_url"));
|
model.setVideoUrl(data.getString("dash_playback_url"));
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private enum CandidateType {
|
||||||
|
THUMBNAIL(1000),
|
||||||
|
DOWNLOAD(10000);
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
CandidateType(final int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user