Skip to content

Commit 3552a9a

Browse files
Add an option to download all media in a gallery in ViewRedditGalleryActivity.
1 parent 4aa37ad commit 3552a9a

File tree

8 files changed

+40
-18
lines changed

8 files changed

+40
-18
lines changed

app/src/main/java/ml/docilealligator/infinityforreddit/activities/ViewRedditGalleryActivity.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_NO;
66
import static androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_YES;
77

8+
import android.app.job.JobInfo;
9+
import android.app.job.JobScheduler;
10+
import android.content.Context;
811
import android.content.SharedPreferences;
912
import android.content.res.Configuration;
1013
import android.graphics.Typeface;
@@ -49,14 +52,13 @@
4952
import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryImageOrGifFragment;
5053
import ml.docilealligator.infinityforreddit.fragments.ViewRedditGalleryVideoFragment;
5154
import ml.docilealligator.infinityforreddit.post.Post;
55+
import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
5256
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
5357
import ml.docilealligator.infinityforreddit.utils.Utils;
5458

5559
public class ViewRedditGalleryActivity extends AppCompatActivity implements SetAsWallpaperCallback, CustomFontReceiver {
5660

57-
public static final String EXTRA_REDDIT_GALLERY = "ERG";
58-
public static final String EXTRA_SUBREDDIT_NAME = "ESN";
59-
public static final String EXTRA_IS_NSFW = "EIN";
61+
public static final String EXTRA_POST = "EP";
6062
public static final String EXTRA_GALLERY_ITEM_INDEX = "EGII";
6163

6264
@Inject
@@ -66,6 +68,7 @@ public class ViewRedditGalleryActivity extends AppCompatActivity implements SetA
6668
Executor executor;
6769
public Typeface typeface;
6870
private SectionsPagerAdapter sectionsPagerAdapter;
71+
private Post post;
6972
private ArrayList<Post.Gallery> gallery;
7073
private String subredditName;
7174
private boolean isNsfw;
@@ -144,13 +147,18 @@ protected void onCreate(Bundle savedInstanceState) {
144147
getSupportActionBar().hide();
145148
}
146149

147-
gallery = getIntent().getParcelableArrayListExtra(EXTRA_REDDIT_GALLERY);
150+
post = getIntent().getParcelableExtra(EXTRA_POST);
151+
if (post == null) {
152+
finish();
153+
return;
154+
}
155+
gallery = post.getGallery();
148156
if (gallery == null || gallery.isEmpty()) {
149157
finish();
150158
return;
151159
}
152-
subredditName = getIntent().getStringExtra(EXTRA_SUBREDDIT_NAME);
153-
isNsfw = getIntent().getBooleanExtra(EXTRA_IS_NSFW, false);
160+
subredditName = post.getSubredditName();
161+
isNsfw = post.isNSFW();
154162

155163
if (sharedPreferences.getBoolean(SharedPreferencesUtils.SWIPE_VERTICALLY_TO_GO_BACK_FROM_MEDIA, true)) {
156164
binding.getRoot().setOnDragDismissedListener(dragDirection -> {
@@ -201,6 +209,10 @@ private void setToolbarTitle(int position) {
201209

202210
@Override
203211
public boolean onCreateOptionsMenu(Menu menu) {
212+
getMenuInflater().inflate(R.menu.view_reddit_gallery_activity, menu);
213+
for (int i = 0; i < menu.size(); i++) {
214+
Utils.setTitleWithCustomFontToMenuItem(typeface, menu.getItem(i), null);
215+
}
204216
return true;
205217
}
206218

@@ -209,6 +221,13 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
209221
if (item.getItemId() == android.R.id.home) {
210222
finish();
211223
return true;
224+
} else if (item.getItemId() == R.id.action_download_all_gallery_media_view_reddit_gallery_activity) {
225+
//TODO: contentEstimatedBytes
226+
JobInfo jobInfo = DownloadMediaService.constructGalleryDownloadAllImagesJobInfo(this, 5000000, post);
227+
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
228+
229+
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();
230+
return true;
212231
}
213232

214233
return false;

app/src/main/java/ml/docilealligator/infinityforreddit/adapters/HistoryPostRecyclerViewAdapter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2537,9 +2537,7 @@ private void openMedia(Post post, int galleryItemIndex, long videoProgress) {
25372537
mActivity.startActivity(intent);
25382538
} else if (post.getPostType() == Post.GALLERY_TYPE) {
25392539
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
2540-
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
2541-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
2542-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_IS_NSFW, post.isNSFW());
2540+
intent.putExtra(ViewRedditGalleryActivity.EXTRA_POST, post);
25432541
intent.putExtra(ViewRedditGalleryActivity.EXTRA_GALLERY_ITEM_INDEX, galleryItemIndex);
25442542
mActivity.startActivity(intent);
25452543
}

app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostDetailRecyclerViewAdapter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,9 +1112,7 @@ private void openMedia(Post post, int galleryItemIndex, long videoProgress) {
11121112
mActivity.startActivity(intent);
11131113
} else if (post.getPostType() == Post.GALLERY_TYPE) {
11141114
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
1115-
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
1116-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
1117-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_IS_NSFW, post.isNSFW());
1115+
intent.putExtra(ViewRedditGalleryActivity.EXTRA_POST, post);
11181116
intent.putExtra(ViewRedditGalleryActivity.EXTRA_GALLERY_ITEM_INDEX, galleryItemIndex);
11191117
mActivity.startActivity(intent);
11201118
}

app/src/main/java/ml/docilealligator/infinityforreddit/adapters/PostRecyclerViewAdapter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,9 +2665,7 @@ private void openMedia(Post post, int galleryItemIndex, long videoProgress) {
26652665
mActivity.startActivity(intent);
26662666
} else if (post.getPostType() == Post.GALLERY_TYPE) {
26672667
Intent intent = new Intent(mActivity, ViewRedditGalleryActivity.class);
2668-
intent.putParcelableArrayListExtra(ViewRedditGalleryActivity.EXTRA_REDDIT_GALLERY, post.getGallery());
2669-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_SUBREDDIT_NAME, post.getSubredditName());
2670-
intent.putExtra(ViewRedditGalleryActivity.EXTRA_IS_NSFW, post.isNSFW());
2668+
intent.putExtra(ViewRedditGalleryActivity.EXTRA_POST, post);
26712669
intent.putExtra(ViewRedditGalleryActivity.EXTRA_GALLERY_ITEM_INDEX, galleryItemIndex);
26722670
mActivity.startActivity(intent);
26732671
}

app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewRedditGalleryVideoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
214214
requestPermissionAndDownload();
215215
return true;
216216
} else if (item.getItemId() == R.id.action_playback_speed_view_reddit_gallery_video_fragment) {
217-
217+
changePlaybackSpeed();
218218
return true;
219219
}
220220
return false;

app/src/main/res/layout/fragment_post_options_bottom_sheet.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
android:paddingTop="16dp"
127127
android:paddingEnd="32dp"
128128
android:paddingBottom="16dp"
129-
android:text="@string/action_download_gallery"
129+
android:text="@string/action_download_all_gallery_media"
130130
android:textColor="?attr/primaryTextColor"
131131
android:textSize="?attr/font_default"
132132
android:visibility="gone"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
<item
5+
android:id="@+id/action_download_all_gallery_media_view_reddit_gallery_activity"
6+
android:orderInCategory="10"
7+
android:title="@string/action_download_all_gallery_media"
8+
app:showAsAction="never" />
9+
</menu>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
<string name="action_more_options">More Options</string>
100100
<string name="action_add_to_home_screen">Add to Home screen</string>
101101
<string name="action_reset_fab_position">Reset FAB position</string>
102-
<string name="action_download_gallery">Download gallery</string>
102+
<string name="action_download_all_gallery_media">Download All Gallery Media</string>
103103

104104
<string name="parse_json_response_error">Error occurred when parsing the JSON response</string>
105105
<string name="retrieve_token_error">Error Retrieving the token</string>

0 commit comments

Comments
 (0)