mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 09:28:34 +00:00
Use fallback images for Giphy results.
This commit is contained in:
parent
1f85b1f3d2
commit
b9057a1c11
@ -21,6 +21,7 @@ public class ChunkedImageUrl implements Key {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public ChunkedImageUrl(@NonNull String url, long size) {
|
public ChunkedImageUrl(@NonNull String url, long size) {
|
||||||
|
if (url == null) throw new RuntimeException();
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.size = size;
|
this.size = size;
|
||||||
}
|
}
|
||||||
|
@ -1,27 +1,37 @@
|
|||||||
package org.thoughtcrime.securesms.giph.model;
|
package org.thoughtcrime.securesms.giph.model;
|
||||||
|
|
||||||
|
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
|
|
||||||
public class GiphyImage {
|
public class GiphyImage {
|
||||||
|
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private ImageTypes images;
|
private ImageTypes images;
|
||||||
|
|
||||||
public String getGifUrl() {
|
public String getGifUrl() {
|
||||||
return images.downsized.url;
|
ImageData data = getGifData();
|
||||||
|
return data != null ? data.url : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getGifSize() {
|
public long getGifSize() {
|
||||||
return images.downsized.size;
|
ImageData data = getGifData();
|
||||||
|
return data != null ? data.size : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGifMmsUrl() {
|
public String getGifMmsUrl() {
|
||||||
return images.fixed_height_downsampled.url;
|
ImageData data = getGifMmsData();
|
||||||
|
return data != null ? data.url : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMmsGifSize() {
|
public long getMmsGifSize() {
|
||||||
return images.fixed_height_downsampled.size;
|
ImageData data = getGifMmsData();
|
||||||
|
return data != null ? data.size : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getGifAspectRatio() {
|
public float getGifAspectRatio() {
|
||||||
@ -29,19 +39,45 @@ public class GiphyImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getGifWidth() {
|
public int getGifWidth() {
|
||||||
return images.downsized.width;
|
ImageData data = getGifData();
|
||||||
|
return data != null ? data.width : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getGifHeight() {
|
public int getGifHeight() {
|
||||||
return images.downsized.height;
|
ImageData data = getGifData();
|
||||||
|
return data != null ? data.height : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStillUrl() {
|
public String getStillUrl() {
|
||||||
return images.downsized_still.url;
|
ImageData data = getStillData();
|
||||||
|
return data != null ? data.url : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStillSize() {
|
public long getStillSize() {
|
||||||
return images.downsized_still.size;
|
ImageData data = getStillData();
|
||||||
|
return data != null ? data.size : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable ImageData getGifData() {
|
||||||
|
return getFirstNonEmpty(images.downsized, images.downsized_medium, images.fixed_height, images.fixed_width);
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable ImageData getGifMmsData() {
|
||||||
|
return getFirstNonEmpty(images.fixed_height_downsampled, images.fixed_width_downsampled);
|
||||||
|
}
|
||||||
|
|
||||||
|
private @Nullable ImageData getStillData() {
|
||||||
|
return getFirstNonEmpty(images.downsized_still, images.fixed_height_still, images.fixed_width_still);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @Nullable ImageData getFirstNonEmpty(ImageData... data) {
|
||||||
|
for (ImageData image : data) {
|
||||||
|
if (!TextUtils.isEmpty(image.url)) {
|
||||||
|
return image;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ImageTypes {
|
public static class ImageTypes {
|
||||||
|
@ -6,6 +6,9 @@ import android.net.Uri;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
|
import com.annimon.stream.Stream;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
|
|
||||||
|
|
||||||
@ -59,7 +62,11 @@ public abstract class GiphyLoader extends AsyncLoader<List<GiphyImage>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
|
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
|
||||||
List<GiphyImage> results = giphyResponse.getData();
|
List<GiphyImage> results = Stream.of(giphyResponse.getData())
|
||||||
|
.filterNot(g -> TextUtils.isEmpty(g.getGifUrl()))
|
||||||
|
.filterNot(g -> TextUtils.isEmpty(g.getGifMmsUrl()))
|
||||||
|
.filterNot(g -> TextUtils.isEmpty(g.getStillUrl()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
if (results == null) return new LinkedList<>();
|
if (results == null) return new LinkedList<>();
|
||||||
else return results;
|
else return results;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user