mirror of
https://github.com/TwidereProject/Twidere-Android
synced 2024-12-12 08:36:14 +01:00
add support to preview twitter pic directly from clickable link on timeline
This commit is contained in:
parent
bba95cafbc
commit
4133acbde1
@ -10,6 +10,7 @@ import org.mariotaku.twidere.model.ParcelableMedia;
|
|||||||
import org.mariotaku.twidere.util.HtmlLinkExtractor;
|
import org.mariotaku.twidere.util.HtmlLinkExtractor;
|
||||||
import org.mariotaku.twidere.util.media.preview.provider.InstagramProvider;
|
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.Provider;
|
||||||
|
import org.mariotaku.twidere.util.media.preview.provider.TwitterPicProvider;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -22,7 +23,8 @@ import java.util.List;
|
|||||||
public class PreviewMediaExtractor {
|
public class PreviewMediaExtractor {
|
||||||
|
|
||||||
private static final Provider[] sProviders = {
|
private static final Provider[] sProviders = {
|
||||||
new InstagramProvider()
|
new InstagramProvider(),
|
||||||
|
new TwitterPicProvider()
|
||||||
};
|
};
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user