add support to preview twitter pic directly from clickable link on timeline

This commit is contained in:
Eric Liu 2016-01-16 18:42:57 +08:00
parent bba95cafbc
commit 4133acbde1
2 changed files with 52 additions and 1 deletions

View File

@ -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

View File

@ -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);
}
}