Skip to content

Commit

Permalink
Updating changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
QuantumBadger committed Sep 10, 2022
1 parent 680d61f commit e2d6144
Show file tree
Hide file tree
Showing 11 changed files with 324 additions and 5 deletions.
3 changes: 3 additions & 0 deletions assets/changelog-alpha.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/Alpha 320 (2022-09-10)
Use updated RedGIFs API

/Alpha 319 (2022-09-10)
Fixed parse error when viewing deleted posts

Expand Down
1 change: 1 addition & 0 deletions assets/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Find Location: Existing subscriptions now appear immediately with no loading tim
Added preference to keep screen awake (thanks to Thung Yong Han)
Ability to show comment count in post subtitle (thanks to Cameron Merkel)
Ability to hide subreddit header (thanks to Cameron Merkel)
Use updated RedGIFs API
Fixed parse error when viewing deleted posts

103/1.19
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.quantumbadger.redreader.common.datastream.MemoryDataStream;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.http.HTTPBackend;
import org.quantumbadger.redreader.image.RedgifsAPIV2;
import org.quantumbadger.redreader.reddit.api.RedditOAuth;

import java.io.IOException;
Expand Down Expand Up @@ -151,11 +152,13 @@ private void performDownload(final HTTPBackend.Request request) {
}

request.addHeader("Authorization", "bearer " + accessToken.token);

}

if(mInitiator.queueType == CacheRequest.DOWNLOAD_QUEUE_IMGUR_API) {
request.addHeader("Authorization", "Client-ID c3713d9e7674477");

} else if(mInitiator.queueType == CacheRequest.DOWNLOAD_QUEUE_REDGIFS_API_V2) {
request.addHeader("Authorization", "Bearer " + RedgifsAPIV2.getLatestToken());
}

mInitiator.notifyDownloadStarted();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public final class CacheRequest implements Comparable<CacheRequest> {
public static final int DOWNLOAD_QUEUE_IMGUR_API = 1;
public static final int DOWNLOAD_QUEUE_IMMEDIATE = 2;
public static final int DOWNLOAD_QUEUE_IMAGE_PRECACHE = 3;
public static final int DOWNLOAD_QUEUE_REDGIFS_API_V2 = 4;

public static final int REQUEST_FAILURE_CONNECTION = 0;
public static final int REQUEST_FAILURE_REQUEST = 1;
Expand All @@ -61,7 +62,7 @@ public final class CacheRequest implements Comparable<CacheRequest> {

@IntDef({
DOWNLOAD_QUEUE_REDDIT_API, DOWNLOAD_QUEUE_IMGUR_API, DOWNLOAD_QUEUE_IMMEDIATE,
DOWNLOAD_QUEUE_IMAGE_PRECACHE})
DOWNLOAD_QUEUE_IMAGE_PRECACHE, DOWNLOAD_QUEUE_REDGIFS_API_V2})
@Retention(RetentionPolicy.SOURCE)
public @interface DownloadQueueType {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,7 @@ public static final class FileType {
public static final int INLINE_IMAGE_PREVIEW = 203;
public static final int IMAGE_INFO = 300;
}

public static final String OA_CS = "client_secret";
public static final String OA_CI = "client_id";
}
8 changes: 8 additions & 0 deletions src/main/java/org/quantumbadger/redreader/common/General.java
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,14 @@ public static <E> Set<E> hashsetFromArray(@NonNull final E... data) {
return result;
}

@SafeVarargs
@NonNull
public static <E> ArrayList<E> listFromArray(@NonNull final E... data) {
final ArrayList<E> result = new ArrayList<>(data.length);
Collections.addAll(result, data);
return result;
}

@SafeVarargs
public static <E> E nullAlternative(
final E... values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.quantumbadger.redreader.image.RedditGalleryAPI;
import org.quantumbadger.redreader.image.RedditVideosAPI;
import org.quantumbadger.redreader.image.RedgifsAPI;
import org.quantumbadger.redreader.image.RedgifsAPIV2;
import org.quantumbadger.redreader.image.StreamableAPI;
import org.quantumbadger.redreader.reddit.things.RedditPost;
import org.quantumbadger.redreader.reddit.url.ComposeMessageURL;
Expand Down Expand Up @@ -995,7 +996,50 @@ public static void getImageInfo(
if(matchRedgifs.find()) {
final String imgId = matchRedgifs.group(1);
if(imgId.length() > 5) {
RedgifsAPI.getImageInfo(context, imgId, priority, listener);
RedgifsAPIV2.getImageInfo(
context,
imgId,
priority,
new ImageInfoRetryListener(listener) {

@Override
public void onFailure(
final int type,
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<FailedRequestBody> body) {

Log.e(
"getImageInfo",
"RedGifs V2 failed, trying V1 (" + readableMessage + ")",
t);

RedgifsAPI.getImageInfo(
context,
imgId,
priority,
new ImageInfoRetryListener(listener) {
@Override
public void onFailure(
final int type,
final Throwable t,
final Integer status,
final String readableMessage,
@NonNull final Optional<FailedRequestBody> body) {

// Retry V2 so that the final error which is logged
// relates to the V2 API
Log.e(
"getImageInfo",
"RedGifs V1 also failed, retrying V2",
t);

RedgifsAPIV2.getImageInfo(context, imgId, priority, listener);
}
});
}
});
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.quantumbadger.redreader.http.body;

import androidx.annotation.NonNull;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.http.PostField;

import java.util.ArrayList;
Expand All @@ -30,6 +31,10 @@ public class HTTPRequestBodyPostFields implements HTTPRequestBody {
public HTTPRequestBodyPostFields() {
}

public HTTPRequestBodyPostFields(final PostField... fields) {
this(General.listFromArray(fields));
}

public HTTPRequestBodyPostFields(@NonNull final Collection<PostField> postFields) {
mPostFields.addAll(postFields);
}
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/org/quantumbadger/redreader/image/ImageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,36 @@ public static ImageInfo parseDeviantArt(final JsonObject object) {
null);
}

public static ImageInfo parseRedgifsV2(final JsonObject object) {

final Long width = object.getLong("width");
final Long height = object.getLong("height");

final String urlOriginal = object.getStringAtPath("urls", "hd")
.orElse(object.getStringAtPath("urls", "sd"))
.orThrow(() -> new RuntimeException("No URL found"));

@Nullable final Boolean hasAudio = object.getBoolean("hasAudio");

@Nullable final String urlPreview = object.getStringAtPath("urls", "poster").orElseNull();

return new ImageInfo(
urlOriginal,
null,
null,
null,
"video/mp4",
true,
width,
height,
null,
MediaType.VIDEO,
HasAudio.fromBoolean(hasAudio),
urlPreview,
null,
null);
}

@Override
public int describeContents() {
return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
import org.quantumbadger.redreader.cache.CacheManager;
import org.quantumbadger.redreader.cache.CacheRequest;
import org.quantumbadger.redreader.cache.CacheRequestJSONParser;
import org.quantumbadger.redreader.cache.downloadstrategy.DownloadStrategyIfNotCached;
import org.quantumbadger.redreader.cache.downloadstrategy.DownloadStrategyIfTimestampOutsideBounds;
import org.quantumbadger.redreader.common.Constants;
import org.quantumbadger.redreader.common.General;
import org.quantumbadger.redreader.common.Optional;
import org.quantumbadger.redreader.common.Priority;
import org.quantumbadger.redreader.common.RRTime;
import org.quantumbadger.redreader.common.TimestampBound;
import org.quantumbadger.redreader.http.FailedRequestBody;
import org.quantumbadger.redreader.jsonwrap.JsonObject;
import org.quantumbadger.redreader.jsonwrap.JsonValue;
Expand All @@ -50,7 +52,9 @@ public static void getImageInfo(
RedditAccountManager.getAnon(),
null,
priority,
DownloadStrategyIfNotCached.INSTANCE,
// RedGifs links expire after an undocumented period of time
new DownloadStrategyIfTimestampOutsideBounds(
TimestampBound.notOlderThan(RRTime.minsToMs(10))),
Constants.FileType.IMAGE_INFO,
CacheRequest.DOWNLOAD_QUEUE_IMMEDIATE,
context,
Expand Down

0 comments on commit e2d6144

Please sign in to comment.