diff options
author | Alex Ning <chineseperson5@gmail.com> | 2020-05-28 14:16:07 +0000 |
---|---|---|
committer | Alex Ning <chineseperson5@gmail.com> | 2020-05-28 14:16:07 +0000 |
commit | 066956971a802d1456716141ee798033e0c1d60f (patch) | |
tree | 81549197f88f41c21101b8b4c17dbd680cdea2fc /app/src/main | |
parent | 8d715956cb4b9462aa85df009f7946edb46737b5 (diff) | |
download | infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar.gz infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar.bz2 infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar.lz infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar.xz infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.tar.zst infinity-for-reddit-066956971a802d1456716141ee798033e0c1d60f.zip |
Support viewing gfycat videos in app.
Diffstat (limited to 'app/src/main')
10 files changed, 260 insertions, 71 deletions
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 08f83a69..98d07788 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -21,10 +21,11 @@ android:theme="@style/AppTheme" android:usesCleartextTraffic="true" tools:replace="android:label"> - <activity android:name=".Activity.ReportActivity" + <activity + android:name=".Activity.ReportActivity" android:label="@string/report_activity_label" android:parentActivityName=".Activity.MainActivity" - android:theme="@style/AppTheme.NoActionBar"/> + android:theme="@style/AppTheme.NoActionBar" /> <activity android:name=".Activity.SelectedSubredditsActivity" android:label="@string/selected_subeddits_activity_label" diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java index 6719fe54..52c6ddc3 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/LinkResolverActivity.java @@ -38,6 +38,7 @@ public class LinkResolverActivity extends AppCompatActivity { private static final String MULTIREDDIT_PATTERN = "/user/\\w+/m/\\w+/?"; private static final String MULTIREDDIT_PATTERN_2 = "/[rR]/(\\w+\\+?)+/?"; private static final String REDD_IT_POST_PATTERN = "/\\w+/?"; + private static final String GFYCAT_PATTERN = "/[\\w-]+$"; @Inject @Named("default") @@ -78,78 +79,89 @@ public class LinkResolverActivity extends AppCompatActivity { String authority = uri.getAuthority(); List<String> segments = uri.getPathSegments(); - if (authority != null && (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app"))) { - if (authority.equals("reddit.app.link") && path.isEmpty()) { - String redirect = uri.getQueryParameter("$og_redirect"); - handleUri(Uri.parse(redirect)); - } else if (path.isEmpty()) { - Intent intent = new Intent(this, MainActivity.class); - startActivity(intent); - } else if (path.matches(POST_PATTERN)) { - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + if (authority != null) { + if (authority.contains("reddit.com") || authority.contains("redd.it") || authority.contains("reddit.app")) { + if (authority.equals("reddit.app.link") && path.isEmpty()) { + String redirect = uri.getQueryParameter("$og_redirect"); + handleUri(Uri.parse(redirect)); + } else if (path.isEmpty()) { + Intent intent = new Intent(this, MainActivity.class); startActivity(intent); - } else { - deepLinkError(uri); - } - } else if (path.matches(COMMENT_PATTERN)) { - int commentsIndex = segments.lastIndexOf("comments"); - if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + } else if (path.matches(POST_PATTERN)) { + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(COMMENT_PATTERN)) { + int commentsIndex = segments.lastIndexOf("comments"); + if (commentsIndex >= 0 && commentsIndex < segments.size() - 1) { + Intent intent = new Intent(this, ViewPostDetailActivity.class); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); + intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + deepLinkError(uri); + } + } else if (path.matches(SUBREDDIT_PATTERN)) { + String subredditName = path.substring(3); + if (subredditName.equals("popular") || subredditName.equals("all")) { + Intent intent = new Intent(this, MainActivity.class); + intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); + intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); + intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else { + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } + } else if (path.matches(USER_PATTERN)) { + Intent intent = new Intent(this, ViewUserDetailActivity.class); + intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); + intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (path.matches(SIDEBAR_PATTERN)) { + Intent intent = new Intent(this, ViewSidebarActivity.class); + intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN)) { + Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); + intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); + startActivity(intent); + } else if (path.matches(MULTIREDDIT_PATTERN_2)) { + String subredditName = path.substring(3); + Intent intent = new Intent(this, ViewSubredditDetailActivity.class); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); + intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + startActivity(intent); + } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, segments.get(commentsIndex + 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_SINGLE_COMMENT_ID, segments.get(segments.size() - 1)); - intent.putExtra(ViewPostDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewPostDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); startActivity(intent); } else { deepLinkError(uri); } - } else if (path.matches(SUBREDDIT_PATTERN)) { - String subredditName = path.substring(3); - if (subredditName.equals("popular") || subredditName.equals("all")) { - Intent intent = new Intent(this, MainActivity.class); - intent.putExtra(MainActivity.EXTRA_POST_TYPE, subredditName); - intent.putExtra(MainActivity.EXTRA_MESSSAGE_FULLNAME, messageFullname); - intent.putExtra(MainActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); + } else if (authority.contains("gfycat.com")) { + if (path.matches(GFYCAT_PATTERN)) { + Intent intent = new Intent(this, ViewVideoActivity.class); + intent.putExtra(ViewVideoActivity.EXTRA_GFYCAT_ID, path.substring(1)); + intent.putExtra(ViewVideoActivity.EXTRA_VIDEO_TYPE, ViewVideoActivity.VIDEO_TYPE_GFYCAT); startActivity(intent); } else { - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, path.substring(3)); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); + deepLinkError(uri); } - } else if (path.matches(USER_PATTERN)) { - Intent intent = new Intent(this, ViewUserDetailActivity.class); - intent.putExtra(ViewUserDetailActivity.EXTRA_USER_NAME_KEY, segments.get(1)); - intent.putExtra(ViewUserDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewUserDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (path.matches(SIDEBAR_PATTERN)) { - Intent intent = new Intent(this, ViewSidebarActivity.class); - intent.putExtra(ViewSidebarActivity.EXTRA_SUBREDDIT_NAME, path.substring(3, path.length() - 14)); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN)) { - Intent intent = new Intent(this, ViewMultiRedditDetailActivity.class); - intent.putExtra(ViewMultiRedditDetailActivity.EXTRA_MULTIREDDIT_PATH, path); - startActivity(intent); - } else if (path.matches(MULTIREDDIT_PATTERN_2)) { - String subredditName = path.substring(3); - Intent intent = new Intent(this, ViewSubredditDetailActivity.class); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_SUBREDDIT_NAME_KEY, subredditName); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_MESSAGE_FULLNAME, messageFullname); - intent.putExtra(ViewSubredditDetailActivity.EXTRA_NEW_ACCOUNT_NAME, newAccountName); - startActivity(intent); - } else if (authority.equals("redd.it") && path.matches(REDD_IT_POST_PATTERN)) { - Intent intent = new Intent(this, ViewPostDetailActivity.class); - intent.putExtra(ViewPostDetailActivity.EXTRA_POST_ID, path.substring(1)); - startActivity(intent); - } else { - deepLinkError(uri); } } else { deepLinkError(uri); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java index 00f9e848..324acbfb 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Activity/ViewVideoActivity.java @@ -40,7 +40,9 @@ import com.github.pwittchen.swipe.library.rx2.Swipe; import com.google.android.exoplayer2.ExoPlayerFactory; import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.SimpleExoPlayer; +import com.google.android.exoplayer2.source.ProgressiveMediaSource; import com.google.android.exoplayer2.source.TrackGroupArray; +import com.google.android.exoplayer2.source.dash.DashMediaSource; import com.google.android.exoplayer2.source.hls.HlsMediaSource; import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection; import com.google.android.exoplayer2.trackselection.DefaultTrackSelector; @@ -49,6 +51,7 @@ import com.google.android.exoplayer2.trackselection.TrackSelectionArray; import com.google.android.exoplayer2.trackselection.TrackSelector; import com.google.android.exoplayer2.ui.PlayerView; import com.google.android.exoplayer2.upstream.DataSource; +import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory; import com.google.android.exoplayer2.upstream.DefaultHttpDataSourceFactory; import com.google.android.exoplayer2.util.Util; @@ -59,9 +62,11 @@ import javax.inject.Named; import butterknife.BindView; import butterknife.ButterKnife; +import ml.docilealligator.infinityforreddit.FetchGfycatVideoLinks; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils; +import retrofit2.Retrofit; public class ViewVideoActivity extends AppCompatActivity { @@ -70,8 +75,14 @@ public class ViewVideoActivity extends AppCompatActivity { public static final String EXTRA_ID = "EI"; public static final String EXTRA_POST_TITLE = "EPT"; public static final String EXTRA_PROGRESS_SECONDS = "EPS"; + public static final String EXTRA_VIDEO_TYPE = "EVT"; + public static final String EXTRA_GFYCAT_ID = "EGI"; + public static final int VIDEO_TYPE_GFYCAT = 1; + private static final int VIDEO_TYPE_NORMAL = 0; private static final int PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 0; private static final String IS_MUTE_STATE = "IMS"; + private static final String VIDEO_DOWNLOAD_URL_STATE = "VDUS"; + private static final String VIDEO_URI_STATE = "VUS"; @BindView(R.id.relative_layout_view_video_activity) RelativeLayout relativeLayout; @BindView(R.id.player_view_view_video_activity) @@ -97,6 +108,10 @@ public class ViewVideoActivity extends AppCompatActivity { private long resumePosition = -1; @Inject + @Named("gfycat") + Retrofit gfycatRetrofit; + + @Inject @Named("default") SharedPreferences mSharedPreferences; @@ -133,8 +148,6 @@ public class ViewVideoActivity extends AppCompatActivity { Intent intent = getIntent(); mVideoUri = intent.getData(); - videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL); - videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4"; postTitle = intent.getStringExtra(EXTRA_POST_TITLE); if (savedInstanceState == null) { resumePosition = intent.getLongExtra(EXTRA_PROGRESS_SECONDS, -1); @@ -319,11 +332,57 @@ public class ViewVideoActivity extends AppCompatActivity { TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory); player = ExoPlayerFactory.newSimpleInstance(this, trackSelector); videoPlayerView.setPlayer(player); - // Produces DataSource instances through which media data is loaded. - dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity")); - // Prepare the player with the source. - player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); + if (getIntent().getIntExtra(EXTRA_VIDEO_TYPE, VIDEO_TYPE_NORMAL) == VIDEO_TYPE_GFYCAT) { + if (savedInstanceState != null) { + String videoUrl = savedInstanceState.getString(VIDEO_URI_STATE); + if (videoUrl != null) { + mVideoUri = Uri.parse(videoUrl); + videoDownloadUrl = savedInstanceState.getString(VIDEO_DOWNLOAD_URL_STATE); + } + } + if (mVideoUri == null) { + String gfycatId = intent.getStringExtra(EXTRA_GFYCAT_ID); + if (gfycatId != null && gfycatId.contains("-")) { + gfycatId = gfycatId.substring(0, gfycatId.indexOf('-')); + } + videoFileName = "Gfycat-" + gfycatId + ".mp4"; + FetchGfycatVideoLinks.fetchGfycatVideoLinks(gfycatRetrofit, gfycatId, + new FetchGfycatVideoLinks.FetchGfycatVideoLinksListener() { + @Override + public void success(String webm, String mp4) { + mVideoUri = Uri.parse(webm); + videoDownloadUrl = mp4; + dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this, + Util.getUserAgent(ViewVideoActivity.this, "Infinity")); + player.prepare(new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); + preparePlayer(savedInstanceState); + } + + @Override + public void failed() { + Toast.makeText(ViewVideoActivity.this, R.string.fetch_gfycat_video_failed, Toast.LENGTH_SHORT).show(); + } + }); + } else { + dataSourceFactory = new DefaultDataSourceFactory(ViewVideoActivity.this, + Util.getUserAgent(ViewVideoActivity.this, "Infinity")); + player.prepare(new DashMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); + preparePlayer(savedInstanceState); + } + } else { + videoDownloadUrl = intent.getStringExtra(EXTRA_VIDEO_DOWNLOAD_URL); + videoFileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_ID) + ".mp4"; + // Produces DataSource instances through which media data is loaded. + dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "Infinity")); + // Prepare the player with the source. + player.prepare(new HlsMediaSource.Factory(dataSourceFactory).createMediaSource(mVideoUri)); + } + + preparePlayer(savedInstanceState); + } + + private void preparePlayer(Bundle savedInstanceState) { player.setRepeatMode(Player.REPEAT_MODE_ALL); if (resumePosition > 0) { player.seekTo(resumePosition); @@ -405,6 +464,11 @@ public class ViewVideoActivity extends AppCompatActivity { finish(); return true; case R.id.action_download_view_video_activity: + if (videoDownloadUrl == null) { + Toast.makeText(this, R.string.fetching_video_info_please_wait, Toast.LENGTH_SHORT).show(); + return true; + } + isDownloading = true; if (Build.VERSION.SDK_INT >= 23) { if (ContextCompat.checkSelfPermission(this, @@ -512,5 +576,9 @@ public class ViewVideoActivity extends AppCompatActivity { protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putBoolean(IS_MUTE_STATE, isMute); + if (mVideoUri != null) { + outState.putString(VIDEO_URI_STATE, mVideoUri.toString()); + outState.putString(VIDEO_DOWNLOAD_URL_STATE, videoDownloadUrl); + } } } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java index a15c01ab..e65d435e 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/AppModule.java @@ -91,6 +91,16 @@ class AppModule { } @Provides + @Named("gfycat") + @Singleton + Retrofit provideGfycatRetrofit() { + return new Retrofit.Builder() + .baseUrl(RedditUtils.GFYCAT_API_BASE_URI) + .addConverterFactory(ScalarsConverterFactory.create()) + .build(); + } + + @Provides @Singleton OkHttpClient provideOkHttpClient(@Named("no_oauth") Retrofit retrofit, RedditDataRoomDatabase accountRoomDatabase) { OkHttpClient.Builder okHttpClientBuilder = new OkHttpClient.Builder(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java new file mode 100644 index 00000000..49f823f9 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/FetchGfycatVideoLinks.java @@ -0,0 +1,78 @@ +package ml.docilealligator.infinityforreddit; + +import android.os.AsyncTask; + +import androidx.annotation.NonNull; + +import org.json.JSONException; +import org.json.JSONObject; + +import ml.docilealligator.infinityforreddit.Utils.JSONUtils; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Response; +import retrofit2.Retrofit; + +public class FetchGfycatVideoLinks { + public interface FetchGfycatVideoLinksListener { + void success(String webm, String mp4); + void failed(); + } + + public static void fetchGfycatVideoLinks(Retrofit gfycatRetrofit, String gfycatId, + FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener) { + gfycatRetrofit.create(GfycatAPI.class).getSubredditData(gfycatId).enqueue(new Callback<String>() { + @Override + public void onResponse(@NonNull Call<String> call, @NonNull Response<String> response) { + if (response.isSuccessful()) { + new ParseGfycatVideoLinksAsyncTask(response.body(), fetchGfycatVideoLinksListener).execute(); + } else { + fetchGfycatVideoLinksListener.failed(); + } + } + + @Override + public void onFailure(@NonNull Call<String> call, @NonNull Throwable t) { + fetchGfycatVideoLinksListener.failed(); + } + }); + } + + private static class ParseGfycatVideoLinksAsyncTask extends AsyncTask<Void, Void, Void> { + + private String response; + private String webm; + private String mp4; + private boolean parseFailed = false; + private FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener; + + ParseGfycatVideoLinksAsyncTask(String response, FetchGfycatVideoLinksListener fetchGfycatVideoLinksListener) { + this.response = response; + this.fetchGfycatVideoLinksListener = fetchGfycatVideoLinksListener; + } + + @Override + protected Void doInBackground(Void... voids) { + try { + JSONObject jsonObject = new JSONObject(response); + webm = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.WEBM_URL_KEY); + mp4 = jsonObject.getJSONObject(JSONUtils.GFY_ITEM_KEY).getString(JSONUtils.MP4_URL_KEY); + } catch (JSONException e) { + e.printStackTrace(); + parseFailed = true; + } + + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + super.onPostExecute(aVoid); + if (parseFailed) { + fetchGfycatVideoLinksListener.failed(); + } else { + fetchGfycatVideoLinksListener.success(webm, mp4); + } + } + } +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/GfycatAPI.java b/app/src/main/java/ml/docilealligator/infinityforreddit/GfycatAPI.java new file mode 100644 index 00000000..0ea675e3 --- /dev/null +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/GfycatAPI.java @@ -0,0 +1,10 @@ +package ml.docilealligator.infinityforreddit; + +import retrofit2.Call; +import retrofit2.http.GET; +import retrofit2.http.Path; + +public interface GfycatAPI { + @GET("{gfyid}") + Call<String> getSubredditData(@Path("gfyid") String gfyId); +} diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java index ab3081b9..57064f39 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/JSONUtils.java @@ -106,4 +106,7 @@ public class JSONUtils { public static final String PATH_KEY = "path"; public static final String ALL_AWARDINGS_KEY = "all_awardings"; public static final String RESIZED_ICONS_KEY = "resized_icons"; + public static final String GFY_ITEM_KEY = "gfyItem"; + public static final String MP4_URL_KEY = "mp4Url"; + public static final String WEBM_URL_KEY = "webmUrl"; } diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/RedditUtils.java b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/RedditUtils.java index b42cbff1..5d901277 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/RedditUtils.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/Utils/RedditUtils.java @@ -18,6 +18,7 @@ public class RedditUtils { public static final String API_BASE_URI = "https://www.reddit.com"; public static final String API_UPLOAD_MEDIA_URI = "https://reddit-uploaded-media.s3-accelerate.amazonaws.com"; public static final String API_UPLOAD_VIDEO_URI = "https://reddit-uploaded-video.s3-accelerate.amazonaws.com"; + public static final String GFYCAT_API_BASE_URI = "https://api.gfycat.com/v1/gfycats/"; public static final String CLIENT_ID_KEY = "client_id"; public static final String CLIENT_ID = ""; diff --git a/app/src/main/res/values/attr.xml b/app/src/main/res/values/attr.xml index 59df6280..f9b5058b 100644 --- a/app/src/main/res/values/attr.xml +++ b/app/src/main/res/values/attr.xml @@ -37,4 +37,7 @@ <attr name="backgroundColor" format="color"/> <attr name="cardViewBackgroundColor" format="color"/> </declare-styleable> + + <attr name="backIconAlpha"/> + <attr name="iconsAlpha"/> </resources>
\ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b44a5157..8a695ffd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -731,4 +731,7 @@ <string name="home">Home</string> <string name="popular">Popular</string> + <string name="fetch_gfycat_video_failed">Fetch Gfycat video failed</string> + <string name="fetching_video_info_please_wait">Fetching video info. Please wait.</string> + </resources> |