Merge pull request #288 from hnws/master
add support to preview twitter pic directly from clickable link on timeline
This commit is contained in:
commit
54c221dbcc
|
@ -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
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package org.mariotaku.twidere.util.media.preview.provider;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
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) {
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue