From 9232fe2debdf0b5ccea9ccacfe0867906e11609e Mon Sep 17 00:00:00 2001 From: Mariotaku Lee Date: Mon, 18 Apr 2016 16:59:20 +0800 Subject: [PATCH] improved card media --- .../model/util/ParcelableMediaUtils.java | 40 +++++++++++++------ 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java index 0a47c73ed..3276e0ee1 100644 --- a/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java +++ b/twidere/src/main/java/org/mariotaku/twidere/model/util/ParcelableMediaUtils.java @@ -104,7 +104,8 @@ public class ParcelableMediaUtils { public static ParcelableMedia[] fromStatus(@NonNull final Status status) { final ParcelableMedia[] fromEntities = fromEntities(status); final ParcelableMedia[] fromAttachments = fromAttachments(status); - final ParcelableMedia[] fromCard = fromCard(status.getCard(), status.getUrlEntities()); + final ParcelableMedia[] fromCard = fromCard(status.getCard(), status.getUrlEntities(), + status.getMediaEntities(), status.getExtendedMediaEntities()); final ParcelableMedia[] fromPhoto = fromPhoto(status); final ParcelableMedia[] merged = new ParcelableMedia[fromCard.length + fromAttachments.length + fromEntities.length + fromPhoto.length]; @@ -150,7 +151,10 @@ public class ParcelableMediaUtils { } @NonNull - private static ParcelableMedia[] fromCard(@Nullable CardEntity card, @Nullable UrlEntity[] entities) { + private static ParcelableMedia[] fromCard(@Nullable CardEntity card, + @Nullable UrlEntity[] urlEntities, + @Nullable MediaEntity[] mediaEntities, + @Nullable MediaEntity[] extendedMediaEntities) { if (card == null) return new ParcelableMedia[0]; final String name = card.getName(); if ("animated_gif".equals(name) || "player".equals(name)) { @@ -184,15 +188,7 @@ public class ParcelableMediaUtils { media.width = NumberUtils.toInt(((CardEntity.StringValue) playerWidth).getValue(), -1); media.height = NumberUtils.toInt(((CardEntity.StringValue) playerHeight).getValue(), -1); } - if (entities != null) { - for (UrlEntity entity : entities) { - if (entity.getUrl().equals(media.url)) { - media.start = entity.getStart(); - media.end = entity.getEnd(); - break; - } - } - } + writeLinkInfo(media, urlEntities, mediaEntities, extendedMediaEntities); return new ParcelableMedia[]{media}; } else if ("summary_large_image".equals(name)) { final CardEntity.BindingValue photoImageFullSize = card.getBindingValue("photo_image_full_size"); @@ -211,8 +207,8 @@ public class ParcelableMediaUtils { if (summaryPhotoImage instanceof CardEntity.ImageValue) { media.preview_url = ((CardEntity.ImageValue) summaryPhotoImage).getUrl(); } - if (entities != null) { - for (UrlEntity entity : entities) { + if (urlEntities != null) { + for (UrlEntity entity : urlEntities) { if (entity.getUrl().equals(media.url)) { media.start = entity.getStart(); media.end = entity.getEnd(); @@ -225,6 +221,24 @@ public class ParcelableMediaUtils { return new ParcelableMedia[0]; } + private static void writeLinkInfo(ParcelableMedia media, UrlEntity[]... entities) { + if (entities == null) return; + for (UrlEntity[] array : entities) { + if (array == null) continue; + for (UrlEntity entity : array) { + if (entity.getUrl().equals(media.url)) { + media.page_url = entity.getExpandedUrl(); + if (media.page_url == null) { + media.page_url = media.url; + } + media.start = entity.getStart(); + media.end = entity.getEnd(); + break; + } + } + } + } + private static boolean checkUrl(CardEntity.StringValue value) { if (value == null) return false; final String valueString = value.getValue();