mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-24 19:00:26 +01:00
Fix issue with gif search and emoji loading on lowmem devices.
This commit is contained in:
committed by
Cody Henthorne
parent
5e2a3ac644
commit
02d060ca0a
@@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.paging.PagedDataSource;
|
||||
import org.thoughtcrime.securesms.BuildConfig;
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies;
|
||||
import org.thoughtcrime.securesms.giph.model.GiphyImage;
|
||||
import org.thoughtcrime.securesms.giph.model.GiphyResponse;
|
||||
@@ -27,6 +28,20 @@ import okhttp3.Response;
|
||||
*/
|
||||
final class GiphyMp4PagedDataSource implements PagedDataSource<GiphyImage> {
|
||||
|
||||
private static final Uri BASE_GIPHY_URI = Uri.parse("https://api.giphy.com/v1/gifs/")
|
||||
.buildUpon()
|
||||
.appendQueryParameter("api_key", BuildConfig.GIPHY_API_KEY)
|
||||
.build();
|
||||
|
||||
private static final Uri TRENDING_URI = BASE_GIPHY_URI.buildUpon()
|
||||
.appendPath("trending")
|
||||
.build();
|
||||
|
||||
private static final Uri SEARCH_URI = BASE_GIPHY_URI.buildUpon()
|
||||
.appendPath("search")
|
||||
.build();
|
||||
|
||||
|
||||
private static final String TAG = Log.tag(GiphyMp4PagedDataSource.class);
|
||||
|
||||
private final String searchString;
|
||||
@@ -64,7 +79,7 @@ final class GiphyMp4PagedDataSource implements PagedDataSource<GiphyImage> {
|
||||
String url;
|
||||
|
||||
if (TextUtils.isEmpty(searchString)) url = getTrendingUrl(start, length);
|
||||
else url = getSearchUrl(start, length, Uri.encode(searchString));
|
||||
else url = getSearchUrl(start, length, searchString);
|
||||
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
|
||||
@@ -83,10 +98,19 @@ final class GiphyMp4PagedDataSource implements PagedDataSource<GiphyImage> {
|
||||
}
|
||||
|
||||
private String getTrendingUrl(int start, int length) {
|
||||
return "https://api.giphy.com/v1/gifs/trending?api_key=3o6ZsYH6U6Eri53TXy&offset=" + start + "&limit=" + length;
|
||||
return TRENDING_URI.buildUpon()
|
||||
.appendQueryParameter("offset", String.valueOf(start))
|
||||
.appendQueryParameter("limit", String.valueOf(length))
|
||||
.build()
|
||||
.toString();
|
||||
}
|
||||
|
||||
private String getSearchUrl(int start, int length, @NonNull String query) {
|
||||
return "https://api.giphy.com/v1/gifs/search?api_key=3o6ZsYH6U6Eri53TXy&offset=" + start + "&limit=" + length + "&q=" + Uri.encode(query);
|
||||
return SEARCH_URI.buildUpon()
|
||||
.appendQueryParameter("offset", String.valueOf(start))
|
||||
.appendQueryParameter("limit", String.valueOf(length))
|
||||
.appendQueryParameter("q", query)
|
||||
.build()
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user