Search in sources :

Example 1 with GiphyImage

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<>();
    }
}
Also used : GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) Response(okhttp3.Response) GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) Request(okhttp3.Request) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Example 2 with GiphyImage

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);
    }
}
Also used : GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) ColorDrawable(android.graphics.drawable.ColorDrawable) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) GiphyPaddedUrl(org.thoughtcrime.securesms.giph.model.GiphyPaddedUrl)

Example 3 with GiphyImage

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);
    }
}
Also used : GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) ColorDrawable(android.graphics.drawable.ColorDrawable)

Example 4 with GiphyImage

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<>();
    }
}
Also used : GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) Response(okhttp3.Response) GiphyResponse(org.thoughtcrime.securesms.giph.model.GiphyResponse) GiphyImage(org.thoughtcrime.securesms.giph.model.GiphyImage) Request(okhttp3.Request) IOException(java.io.IOException) NonNull(android.support.annotation.NonNull)

Aggregations

GiphyImage (org.thoughtcrime.securesms.giph.model.GiphyImage)4 ColorDrawable (android.graphics.drawable.ColorDrawable)2 NonNull (android.support.annotation.NonNull)2 IOException (java.io.IOException)2 Request (okhttp3.Request)2 Response (okhttp3.Response)2 GiphyResponse (org.thoughtcrime.securesms.giph.model.GiphyResponse)2 Drawable (android.graphics.drawable.Drawable)1 GiphyPaddedUrl (org.thoughtcrime.securesms.giph.model.GiphyPaddedUrl)1