From 4799a09b42bb6762d2d14363a3c4a68dd7b041b6 Mon Sep 17 00:00:00 2001 From: Docile-Alligator <25734209+Docile-Alligator@users.noreply.github.com> Date: Wed, 18 Sep 2024 13:13:24 -0400 Subject: [PATCH] Use the better constructJobInfo() in DownloadMediaService when downloading media in an imgur album. --- .../fragments/ViewImgurImageFragment.java | 10 ++-------- .../fragments/ViewImgurVideoFragment.java | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java index a201210ea..4ce6827bd 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurImageFragment.java @@ -12,7 +12,6 @@ import android.os.Build; import android.os.Bundle; import android.os.Handler; -import android.os.PersistableBundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -43,7 +42,6 @@ import javax.inject.Inject; import ml.docilealligator.infinityforreddit.BuildConfig; -import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.SetAsWallpaperCallback; @@ -51,6 +49,7 @@ import ml.docilealligator.infinityforreddit.asynctasks.SaveBitmapImageToFile; import ml.docilealligator.infinityforreddit.bottomsheetfragments.SetAsWallpaperBottomSheetFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentViewImgurImageBinding; +import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.Utils; @@ -224,13 +223,8 @@ private void requestPermissionAndDownload() { private void download() { isDownloading = false; - PersistableBundle extras = new PersistableBundle(); - extras.putString(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); - extras.putInt(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_IMAGE); - extras.putString(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); - //TODO: contentEstimatedBytes - JobInfo jobInfo = DownloadMediaService.constructJobInfo(activity, 5000000, extras); + JobInfo jobInfo = DownloadMediaService.constructJobInfo(activity, 5000000, imgurMedia); ((JobScheduler) activity.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show(); diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java index e3b5b8acc..0d0c7212a 100644 --- a/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java +++ b/app/src/main/java/ml/docilealligator/infinityforreddit/fragments/ViewImgurVideoFragment.java @@ -11,7 +11,6 @@ import android.media.AudioManager; import android.os.Build; import android.os.Bundle; -import android.os.PersistableBundle; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; @@ -49,12 +48,12 @@ import javax.inject.Inject; import javax.inject.Named; -import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.Infinity; import ml.docilealligator.infinityforreddit.R; import ml.docilealligator.infinityforreddit.activities.ViewImgurMediaActivity; import ml.docilealligator.infinityforreddit.bottomsheetfragments.PlaybackSpeedBottomSheetFragment; import ml.docilealligator.infinityforreddit.databinding.FragmentViewImgurVideoBinding; +import ml.docilealligator.infinityforreddit.post.ImgurMedia; import ml.docilealligator.infinityforreddit.services.DownloadMediaService; import ml.docilealligator.infinityforreddit.utils.APIUtils; import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils; @@ -260,13 +259,8 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis private void download() { isDownloading = false; - PersistableBundle extras = new PersistableBundle(); - extras.putString(DownloadMediaService.EXTRA_URL, imgurMedia.getLink()); - extras.putInt(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO); - extras.putString(DownloadMediaService.EXTRA_FILE_NAME, imgurMedia.getFileName()); - //TODO: contentEstimatedBytes - JobInfo jobInfo = DownloadMediaService.constructJobInfo(activity, 5000000, extras); + JobInfo jobInfo = DownloadMediaService.constructJobInfo(activity, 5000000, imgurMedia); ((JobScheduler) activity.getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo); Toast.makeText(activity, R.string.download_started, Toast.LENGTH_SHORT).show();