aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java43
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java9
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java13
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java34
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java22
5 files changed, 80 insertions, 41 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java
index 19dc8a9c..16e27ff5 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatOrRedgifsVideoLinks.java
@@ -2,17 +2,15 @@ package ml.docilealligator.infinityforreddit;
import android.os.Handler;
-import androidx.annotation.NonNull;
-
import org.json.JSONException;
import org.json.JSONObject;
+import java.io.IOException;
import java.util.concurrent.Executor;
import ml.docilealligator.infinityforreddit.apis.GfycatAPI;
import ml.docilealligator.infinityforreddit.utils.JSONUtils;
import retrofit2.Call;
-import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
@@ -32,45 +30,42 @@ public class FetchGfycatOrRedgifsVideoLinks {
public static void fetchGfycatOrRedgifsVideoLinks(Executor executor, Handler handler, Retrofit gfycatRetrofit,
String gfycatId,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
- gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ executor.execute(() -> {
+ try {
+ Response<String> response = gfycatRetrofit.create(GfycatAPI.class).getGfycatData(gfycatId).execute();
if (response.isSuccessful()) {
- parseGfycatVideoLinks(executor, handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
+ parseGfycatVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {
- fetchGfycatOrRedgifsVideoLinksListener.failed(response.code());
+ handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(response.code()));
}
- }
-
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
- fetchGfycatOrRedgifsVideoLinksListener.failed(-1);
+ } catch (IOException e) {
+ e.printStackTrace();
+ handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(-1));
}
});
+
}
public void fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(Executor executor, Handler handler,
Retrofit gfycatRetrofit, Retrofit redgifsRetrofit,
String gfycatId, boolean isGfycatVideo,
boolean automaticallyTryRedgifs) {
- gfycatCall = (isGfycatVideo ? gfycatRetrofit : redgifsRetrofit).create(GfycatAPI.class).getGfycatData(gfycatId);
- gfycatCall.enqueue(new Callback<String>() {
- @Override
- public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) {
+ executor.execute(() -> {
+ gfycatCall = (isGfycatVideo ? gfycatRetrofit : redgifsRetrofit).create(GfycatAPI.class).getGfycatData(gfycatId);
+ try {
+ Response<String> response = gfycatCall.execute();
if (response.isSuccessful()) {
- parseGfycatVideoLinks(executor, handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
+ parseGfycatVideoLinks(handler, response.body(), fetchGfycatOrRedgifsVideoLinksListener);
} else {
if (response.code() == 404 && isGfycatVideo && automaticallyTryRedgifs) {
fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(executor, handler, gfycatRetrofit,
redgifsRetrofit, gfycatId, false, false);
} else {
- fetchGfycatOrRedgifsVideoLinksListener.failed(response.code());
+ handler.post(() -> fetchGfycatOrRedgifsVideoLinksListener.failed(response.code()));
}
}
- }
-
- @Override
- public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) {
+ } catch (IOException e) {
+ e.printStackTrace();
fetchGfycatOrRedgifsVideoLinksListener.failed(-1);
}
});
@@ -82,7 +77,7 @@ public class FetchGfycatOrRedgifsVideoLinks {
}
}
- private static void parseGfycatVideoLinks(Executor executor, Handler handler, String response,
+ private static void parseGfycatVideoLinks(Handler handler, String response,
FetchGfycatOrRedgifsVideoLinksListener fetchGfycatOrRedgifsVideoLinksListener) {
try {
JSONObject jsonObject = new JSONObject(response);
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
index dd1172a8..4157db56 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java
@@ -1624,6 +1624,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
intent.setData(Uri.parse(mPost.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
}
+ } else if (mPost.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
} else {
intent.setData(Uri.parse(mPost.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, mPost.getVideoDownloadUrl());
@@ -1835,6 +1838,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (mPost.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ } else if (mPost.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
} else {
intent.setData(Uri.parse(mPost.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
@@ -2154,6 +2160,9 @@ public class PostDetailRecyclerViewAdapter extends RecyclerView.Adapter<Recycler
} else if (mPost.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, mPost.getGfycatId());
+ } else if (mPost.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, mPost.getStreamableShortCode());
} else {
intent.setData(Uri.parse(mPost.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, mPost.getSubredditName());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
index d821ddb8..92547c66 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java
@@ -69,14 +69,12 @@ import jp.wasabeef.glide.transformations.BlurTransformation;
import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
import ml.docilealligator.infinityforreddit.FetchGfycatOrRedgifsVideoLinks;
import ml.docilealligator.infinityforreddit.MarkPostAsReadInterface;
-import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.R;
+import ml.docilealligator.infinityforreddit.SaveMemoryCenterInisdeDownsampleStrategy;
import ml.docilealligator.infinityforreddit.SaveThing;
import ml.docilealligator.infinityforreddit.VoteThing;
-import ml.docilealligator.infinityforreddit.activities.BaseActivity;
import ml.docilealligator.infinityforreddit.activities.FilteredPostsActivity;
import ml.docilealligator.infinityforreddit.activities.LinkResolverActivity;
-import ml.docilealligator.infinityforreddit.activities.SearchResultActivity;
import ml.docilealligator.infinityforreddit.activities.ViewImageOrGifActivity;
import ml.docilealligator.infinityforreddit.activities.ViewPostDetailActivity;
import ml.docilealligator.infinityforreddit.activities.ViewRedditGalleryActivity;
@@ -1891,6 +1889,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
} else if (post.isRedgifs()) {
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_REDGIFS);
intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, post.getGfycatId());
+ } else if (post.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
} else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_SUBREDDIT, post.getSubredditName());
@@ -2626,6 +2627,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
+ } else if (post.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
} else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
@@ -3907,6 +3911,9 @@ public class PostRecyclerViewAdapter extends PagingDataAdapter<Post, RecyclerVie
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
}
+ } else if (post.isStreamable()) {
+ intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_STREAMABLE);
+ intent.putExtra(ViewVideoActivity.EXTRA_STREAMABLE_SHORT_CODE, post.getStreamableShortCode());
} else {
intent.setData(Uri.parse(post.getVideoUrl()));
intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_DOWNLOAD_URL, post.getVideoDownloadUrl());
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
index 834db92f..5e51d9c7 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/ParsePost.java
@@ -598,20 +598,26 @@ public class ParsePost {
Uri uri = Uri.parse(url);
String authority = uri.getAuthority();
- // Gyfcat ids must be lowercase to resolve to a video through the api, we are not
- // guaranteed to get an id that is all lowercase.
- String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
-
- if (authority != null && (authority.contains("gfycat.com"))) {
- post.setPostType(Post.VIDEO_TYPE);
- post.setIsGfycat(true);
- post.setVideoUrl(url);
- post.setGfycatId(gfycatId);
- } else if (authority != null && authority.contains("redgifs.com")) {
- post.setPostType(Post.VIDEO_TYPE);
- post.setIsRedgifs(true);
- post.setVideoUrl(url);
- post.setGfycatId(gfycatId);
+ if (authority != null) {
+ if (authority.contains("gfycat.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsGfycat(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.contains("redgifs.com")) {
+ String gfycatId = url.substring(url.lastIndexOf("/") + 1).toLowerCase();
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsRedgifs(true);
+ post.setVideoUrl(url);
+ post.setGfycatId(gfycatId);
+ } else if (authority.equals("streamable.com")) {
+ String shortCode = url.substring(url.lastIndexOf("/") + 1);
+ post.setPostType(Post.VIDEO_TYPE);
+ post.setIsStreamable(true);
+ post.setVideoUrl(url);
+ post.setStreamableShortCode(shortCode);
+ }
}
}
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
index ce096362..69c93030 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/post/Post.java
@@ -51,8 +51,10 @@ public class Post implements Parcelable {
private String videoUrl;
private String videoDownloadUrl;
private String gfycatId;
+ private String streamableShortCode;
private boolean isGfycat;
private boolean isRedgifs;
+ private boolean isStreamable;
private boolean loadGfyOrRedgifsVideoSuccess;
private String permalink;
private String flair;
@@ -172,8 +174,10 @@ public class Post implements Parcelable {
videoUrl = in.readString();
videoDownloadUrl = in.readString();
gfycatId = in.readString();
+ streamableShortCode = in.readString();
isGfycat = in.readByte() != 0;
isRedgifs = in.readByte() != 0;
+ isStreamable = in.readByte() != 0;
loadGfyOrRedgifsVideoSuccess = in.readByte() != 0;
permalink = in.readString();
flair = in.readString();
@@ -321,6 +325,14 @@ public class Post implements Parcelable {
this.gfycatId = gfycatId;
}
+ public String getStreamableShortCode() {
+ return streamableShortCode;
+ }
+
+ public void setStreamableShortCode(String shortCode) {
+ this.streamableShortCode = shortCode;
+ }
+
public boolean isGfycat() {
return isGfycat;
}
@@ -337,6 +349,14 @@ public class Post implements Parcelable {
this.isRedgifs = isRedgifs;
}
+ public boolean isStreamable() {
+ return isStreamable;
+ }
+
+ public void setIsStreamable(boolean isStreamable) {
+ this.isStreamable = isStreamable;
+ }
+
public boolean isLoadGfycatOrRedgifsVideoSuccess() {
return loadGfyOrRedgifsVideoSuccess;
}
@@ -532,8 +552,10 @@ public class Post implements Parcelable {
parcel.writeString(videoUrl);
parcel.writeString(videoDownloadUrl);
parcel.writeString(gfycatId);
+ parcel.writeString(streamableShortCode);
parcel.writeByte((byte) (isGfycat ? 1 : 0));
parcel.writeByte((byte) (isRedgifs ? 1 : 0));
+ parcel.writeByte((byte) (isStreamable ? 1 : 0));
parcel.writeByte((byte) (loadGfyOrRedgifsVideoSuccess ? 1 : 0));
parcel.writeString(permalink);
parcel.writeString(flair);