use of org.thoughtcrime.securesms.giph.model.GiphyImage in project Signal-Android by WhisperSystems.
the class GiphyLoader method loadPage.
@NonNull
public List<GiphyImage> loadPage(int offset) {
try {
String url;
if (TextUtils.isEmpty(searchString))
url = String.format(getTrendingUrl(), offset);
else
url = String.format(getSearchUrl(), offset, Uri.encode(searchString));
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
List<GiphyImage> results = giphyResponse.getData();
if (results == null)
return new LinkedList<>();
else
return results;
} catch (IOException e) {
Log.w(TAG, e);
return new LinkedList<>();
}
}
use of org.thoughtcrime.securesms.giph.model.GiphyImage in project Signal-Android by signalapp.
the class GiphyAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(GiphyViewHolder holder, int position) {
GiphyImage image = images.get(position);
holder.modelReady = false;
holder.image = image;
holder.thumbnail.setAspectRatio(image.getGifAspectRatio());
holder.gifProgress.setVisibility(View.GONE);
RequestBuilder<Drawable> thumbnailRequest = GlideApp.with(context).load(new GiphyPaddedUrl(image.getStillUrl(), image.getStillSize())).diskCacheStrategy(DiskCacheStrategy.ALL);
if (Util.isLowMemory(context)) {
glideRequests.load(new GiphyPaddedUrl(image.getStillUrl(), image.getStillSize())).placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))).diskCacheStrategy(DiskCacheStrategy.ALL).listener(holder).into(holder.thumbnail);
holder.setModelReady();
} else {
glideRequests.load(new GiphyPaddedUrl(image.getGifUrl(), image.getGifSize())).thumbnail(thumbnailRequest).placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))).diskCacheStrategy(DiskCacheStrategy.ALL).listener(holder).into(holder.thumbnail);
}
}
use of org.thoughtcrime.securesms.giph.model.GiphyImage in project Signal-Android by WhisperSystems.
the class GiphyAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(GiphyViewHolder holder, int position) {
GiphyImage image = images.get(position);
holder.modelReady = false;
holder.image = image;
holder.thumbnail.setAspectRatio(image.getGifAspectRatio());
holder.gifProgress.setVisibility(View.GONE);
DrawableRequestBuilder<String> thumbnailRequest = Glide.with(context).load(image.getStillUrl());
if (Util.isLowMemory(context)) {
Glide.with(context).load(image.getStillUrl()).placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.thumbnail);
holder.setModelReady();
} else {
Glide.with(context).load(image.getGifUrl()).thumbnail(thumbnailRequest).placeholder(new ColorDrawable(Util.getRandomElement(MaterialColor.values()).toConversationColor(context))).diskCacheStrategy(DiskCacheStrategy.ALL).listener(holder).into(holder.thumbnail);
}
}
use of org.thoughtcrime.securesms.giph.model.GiphyImage in project Signal-Android by signalapp.
the class GiphyLoader method loadPage.
@NonNull
public List<GiphyImage> loadPage(int offset) {
try {
String url;
if (TextUtils.isEmpty(searchString))
url = String.format(getTrendingUrl(), offset);
else
url = String.format(getSearchUrl(), offset, Uri.encode(searchString));
Request request = new Request.Builder().url(url).build();
Response response = client.newCall(request).execute();
if (!response.isSuccessful()) {
throw new IOException("Unexpected code " + response);
}
GiphyResponse giphyResponse = JsonUtils.fromJson(response.body().byteStream(), GiphyResponse.class);
List<GiphyImage> results = giphyResponse.getData();
if (results == null)
return new LinkedList<>();
else
return results;
} catch (IOException e) {
Log.w(TAG, e);
return new LinkedList<>();
}
}
Aggregations