Skip to content

Commit ccb5d0f

Browse files
Start migrating DownloadRedditVideoService to JobService.
1 parent 48049d7 commit ccb5d0f

File tree

3 files changed

+268
-283
lines changed

3 files changed

+268
-283
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@
179179
<service
180180
android:name=".services.DownloadRedditVideoService"
181181
android:enabled="true"
182+
android:permission="android.permission.BIND_JOB_SERVICE"
182183
android:exported="false" />
183184

184185
<activity

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

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
import ml.docilealligator.infinityforreddit.post.FetchPost;
112112
import ml.docilealligator.infinityforreddit.post.Post;
113113
import ml.docilealligator.infinityforreddit.services.DownloadMediaService;
114+
import ml.docilealligator.infinityforreddit.services.DownloadRedditVideoService;
114115
import ml.docilealligator.infinityforreddit.utils.APIUtils;
115116
import ml.docilealligator.infinityforreddit.utils.SharedPreferencesUtils;
116117
import ml.docilealligator.infinityforreddit.utils.Utils;
@@ -981,31 +982,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
981982
private void download() {
982983
isDownloading = false;
983984

984-
/*Intent intent;
985-
if (videoType != VIDEO_TYPE_NORMAL) {
986-
intent = new Intent(this, DownloadMediaService.class);
987-
if (post.getPostType() == Post.GIF_TYPE) {
988-
intent.putExtra(DownloadMediaService.EXTRA_URL, post.getVideoUrl());
989-
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_GIF);
990-
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, post.getSubredditName()
991-
+ "-" + post.getId() + ".gif");
992-
} else {
993-
intent.putExtra(DownloadMediaService.EXTRA_URL, videoDownloadUrl);
994-
intent.putExtra(DownloadMediaService.EXTRA_MEDIA_TYPE, DownloadMediaService.EXTRA_MEDIA_TYPE_VIDEO);
995-
intent.putExtra(DownloadMediaService.EXTRA_FILE_NAME, videoFileName);
996-
}
997-
998-
intent.putExtra(DownloadMediaService.EXTRA_SUBREDDIT_NAME, subredditName);
999-
intent.putExtra(DownloadMediaService.EXTRA_IS_NSFW, isNSFW);
1000-
} else {
1001-
intent = new Intent(this, DownloadRedditVideoService.class);
1002-
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
1003-
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
1004-
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
1005-
intent.putExtra(DownloadRedditVideoService.EXTRA_IS_NSFW, isNSFW);
1006-
}
1007-
ContextCompat.startForegroundService(this, intent);*/
1008-
1009985
if (videoType != VIDEO_TYPE_NORMAL) {
1010986
PersistableBundle extras = new PersistableBundle();
1011987
if (post.getPostType() == Post.GIF_TYPE) {
@@ -1026,11 +1002,15 @@ private void download() {
10261002
JobInfo jobInfo = DownloadMediaService.constructJobInfo(this, 5000000, extras);
10271003
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
10281004
} else {
1029-
/* intent = new Intent(this, DownloadRedditVideoService.class);
1030-
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
1031-
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
1032-
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
1033-
intent.putExtra(DownloadRedditVideoService.EXTRA_IS_NSFW, isNSFW);*/
1005+
PersistableBundle extras = new PersistableBundle();
1006+
extras.putString(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
1007+
extras.putString(DownloadRedditVideoService.EXTRA_POST_ID, id);
1008+
extras.putString(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
1009+
extras.putInt(DownloadRedditVideoService.EXTRA_IS_NSFW, isNSFW ? 1 : 0);
1010+
1011+
//TODO: contentEstimatedBytes
1012+
JobInfo jobInfo = DownloadRedditVideoService.constructJobInfo(this, 5000000, extras);
1013+
((JobScheduler) getSystemService(Context.JOB_SCHEDULER_SERVICE)).schedule(jobInfo);
10341014
}
10351015

10361016
Toast.makeText(this, R.string.download_started, Toast.LENGTH_SHORT).show();

0 commit comments

Comments
 (0)