From 4133acbde1c49b2453b15d5911088e4246b7495c Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 16 Jan 2016 18:42:57 +0800 Subject: [PATCH 1/2] add support to preview twitter pic directly from clickable link on timeline --- .../media/preview/PreviewMediaExtractor.java | 4 +- .../preview/provider/TwitterPicProvider.java | 49 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/PreviewMediaExtractor.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/PreviewMediaExtractor.java index 2537de7ec..a1eb3a904 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/PreviewMediaExtractor.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/PreviewMediaExtractor.java @@ -10,6 +10,7 @@ import org.mariotaku.twidere.model.ParcelableMedia; import org.mariotaku.twidere.util.HtmlLinkExtractor; import org.mariotaku.twidere.util.media.preview.provider.InstagramProvider; import org.mariotaku.twidere.util.media.preview.provider.Provider; +import org.mariotaku.twidere.util.media.preview.provider.TwitterPicProvider; import java.io.IOException; import java.util.ArrayList; @@ -22,7 +23,8 @@ import java.util.List; public class PreviewMediaExtractor { private static final Provider[] sProviders = { - new InstagramProvider() + new InstagramProvider(), + new TwitterPicProvider() }; @Nullable diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java new file mode 100644 index 000000000..4f72cfba6 --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java @@ -0,0 +1,49 @@ +package org.mariotaku.twidere.util.media.preview.provider; + +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.util.Log; + +import org.mariotaku.restfu.http.RestHttpClient; +import org.mariotaku.twidere.model.ParcelableMedia; +import org.mariotaku.twidere.util.media.preview.PreviewMediaExtractor; + +import java.util.List; +import java.util.Locale; + +/** + * Created by darkwhite on 1/16/16. + */ +public class TwitterPicProvider implements Provider { + @Override + public boolean supports(@NonNull String link) { + final String authority = PreviewMediaExtractor.getAuthority(link); + return "pbs.twimg.com".equals(authority) || "abs.twing.com".equals(authority); + } + + @Nullable + @Override + public ParcelableMedia from(@NonNull String link) { + Log.i("image viewer","from() called with: " + "link = [" + link + "]"); + final Uri uri = Uri.parse(link); + final ParcelableMedia media = new ParcelableMedia(); + media.type = ParcelableMedia.Type.TYPE_IMAGE; + media.url = link; + if (link.contains("profile")) { + media.preview_url = link; + media.media_url = link; + } else { + media.preview_url = String.format(Locale.ROOT, "%s:medium", link); + media.media_url = String.format(Locale.ROOT, "%s:orig", link); + } + + return media; + } + + @Nullable + @Override + public ParcelableMedia from(@NonNull String link, @NonNull RestHttpClient client, @Nullable Object extra) { + return from(link); + } +} From 55fc8b70306463b784748fd1ecb659b6446bbcfc Mon Sep 17 00:00:00 2001 From: Eric Liu Date: Sat, 16 Jan 2016 18:45:47 +0800 Subject: [PATCH 2/2] add support to preview twitter pic directly from clickable link on timeline, remove logging --- .../twidere/util/media/preview/provider/TwitterPicProvider.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java index 4f72cfba6..123e5a54c 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/util/media/preview/provider/TwitterPicProvider.java @@ -3,7 +3,6 @@ package org.mariotaku.twidere.util.media.preview.provider; import android.net.Uri; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.util.Log; import org.mariotaku.restfu.http.RestHttpClient; import org.mariotaku.twidere.model.ParcelableMedia; @@ -25,7 +24,6 @@ public class TwitterPicProvider implements Provider { @Nullable @Override public ParcelableMedia from(@NonNull String link) { - Log.i("image viewer","from() called with: " + "link = [" + link + "]"); final Uri uri = Uri.parse(link); final ParcelableMedia media = new ParcelableMedia(); media.type = ParcelableMedia.Type.TYPE_IMAGE;