From 3552a9a490c64eec8e56f55fef2b359bcdabe5d1 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:01:23 -0400 Subject: Add an option to download all media in a gallery in ViewRedditGalleryActivity. --- .../activities/ViewRedditGalleryActivity.java | 31 +++++++++++++++++----- .../adapters/HistoryPostRecyclerViewAdapter.java | 4 +-- .../adapters/PostDetailRecyclerViewAdapter.java | 4 +-- .../adapters/PostRecyclerViewAdapter.java | 4 +-- .../fragments/ViewRedditGalleryVideoFragment.java | 2 +- .../layout/fragment_post_options_bottom_sheet.xml | 2 +- .../main/res/menu/view_reddit_gallery_activity.xml | 9 +++++++ app/src/main/res/values/strings.xml | 2 +- 8 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/menu/view_reddit_gallery_activity.xml diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java index 14005615..2dfe1ddc 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java @@ -5,6 +5,9 @@ import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO; import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES; +import android.app.job.JobInfo; +import android.app.job.JobScheduler; +import android.content.Context; import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Typeface; @@ -49,14 +52,13 @@ import ml.docilealligator.infinityforreddit.font.TitleFontStyle; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryImageOrGifFragment; import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment; import ml.docilealligator.infinityforreddit.post.Post; +import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; import ml.docilealligator.infinityforreddit.utils.Utils; public class ViewRedditGalleryActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver { - public static final String EXTRA_REDDIT_GALLERY = "ERG"; - public static final String EXTRA_SUBREDDIT_NAME = "ESN"; - public static final String EXTRA_IS_NSFW = "EIN"; + public static final String EXTRA_POST = "EP"; public static final String EXTRA_GALLERY_ITEM_INDEX = "EGII"; @Inject @@ -66,6 +68,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA Executor executor; public Typeface typeface; private SectionsPagerAdapter sectionsPagerAdapter; + private Post post; private ArrayList gallery; private String subredditName; private boolean isNsfw; @@ -144,13 +147,18 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA getSupportActionBar().hide(); } - gallery = getIntent().getParcelableArrayListExtra(EXTRA_REDDIT_GALLERY); + post = getIntent().getParcelableExtra(EXTRA_POST); + if (post == null) { + finish(); + return; + } + gallery = post.getGallery(); if (gallery == null || gallery.isEmpty()) { finish(); return; } - subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME); - isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false); + subredditName = post.getSubredditName(); + isNsfw = post.isNSFW(); if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) { binding.getRoot().setOnDragDismissedListener(dragDirection -> { @@ -201,6 +209,10 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA @Override public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.view_reddit_gallery_activity, menu); + for (int i = 0; i < menu.size(); i++) { + Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null); + } return true; } @@ -209,6 +221,13 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA if (item.getItemId() == android.R.id.home) { finish(); return true; + } else if (item.getItemId() == R.id.action_download_all_gallery_media_view_reddit_gallery_activity) { + //TODO: contentEstimatedBytes + JobInfo jobInfo = DownloadMediaService.constructGalleryDownloadAllImagesJobInfo(this, 5000000, post); + ((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo); + + Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show(); + return true; } return false; diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java index a7e01054..8b6ca8d1 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java @@ -2537,9 +2537,7 @@ public class HistoryPostRecyclerViewAdapter extends PagingDataAdapter + + + \ 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 fcb7d0b0..481aefe5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -99,7 +99,7 @@ More Options Add to Home screen Reset FAB position - Download gallery + Download All Gallery Media Error occurred when parsing the JSON response Error Retrieving the token -- cgit v1.2.3