aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Ning <chineseperson5@gmail.com>2020-11-19 15:42:37 +0000
committerAlex Ning <chineseperson5@gmail.com>2020-11-19 15:42:37 +0000
commit1a8e888243782d042969134375cebb8bcd3b1af5 (patch)
tree0c79960fe2f2aea7008f8b786d585eba8e9c4cc6
parent4904d46cb27b019d08a2be8c9eb3f64c6bc98afe (diff)
downloadinfinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar.gz
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar.bz2
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar.lz
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar.xz
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.tar.zst
infinity-for-reddit-1a8e888243782d042969134375cebb8bcd3b1af5.zip
Fix crash when downloading media. Run AsyncTask in parallel in DownloadMediaService and DownloadRedditVideoService.
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java2
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java14
-rw-r--r--app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java9
3 files changed, 10 insertions, 15 deletions
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java
index 42c6b706..6204934f 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/adapters/CommentAndPostRecyclerViewAdapter.java
@@ -862,7 +862,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
((PostDetailVideoAutoplayViewHolder) holder).setVolume(mMuteAutoplayingVideos || (mPost.isNSFW() && mMuteNSFWVideo) ? 0f : 1f);
if (mPost.isGfycat() || mPost.isRedgifs() && !mPost.isLoadGfyOrRedgifsVideoSuccess()) {
- ((PostDetailVideoAutoplayViewHolder) holder).mTypeTextView.setText("GFYCAT");
((PostDetailVideoAutoplayViewHolder) holder).fetchGfycatOrRedgifsVideoLinks = new FetchGfycatOrRedgifsVideoLinks(new FetchGfycatOrRedgifsVideoLinks.FetchGfycatOrRedgifsVideoLinksListener() {
@Override
public void success(String webm, String mp4) {
@@ -881,7 +880,6 @@ public class CommentAndPostRecyclerViewAdapter extends RecyclerView.Adapter<Recy
.fetchGfycatOrRedgifsVideoLinksInRecyclerViewAdapter(mGfycatRetrofit, mRedgifsRetrofit,
mPost.getGfycatId(), mPost.isGfycat(), mAutomaticallyTryRedgifs);
} else {
- ((PostDetailVideoAutoplayViewHolder) holder).mTypeTextView.setText("VIDEO");
((PostDetailVideoAutoplayViewHolder) holder).bindVideoUri(Uri.parse(mPost.getVideoUrl()));
}
} else if (holder instanceof PostDetailVideoAndGifPreviewHolder) {
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
index 2f2eef38..bd650cbe 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadMediaService.java
@@ -178,8 +178,7 @@ public class DownloadMediaService extends Service {
NotificationManager.IMPORTANCE_LOW
);
- NotificationManagerCompat manager = NotificationManagerCompat.from(this);
- manager.createNotificationChannel(serviceChannel);
+ notificationManager.createNotificationChannel(serviceChannel);
}
switch (mediaType) {
@@ -275,7 +274,7 @@ public class DownloadMediaService extends Service {
new SaveImageOrGifAndCopyToExternalStorageAsyncTask(response.body(), mediaType,
isDefaultDestination, fileName[0], destinationFileUriString, getContentResolver(),
- (destinationFileUri, errorCode) -> downloadFinished(destinationFileUri, errorCode)).execute();
+ (destinationFileUri, errorCode) -> downloadFinished(destinationFileUri, errorCode)).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@@ -289,8 +288,7 @@ public class DownloadMediaService extends Service {
}
private Notification createNotification(String fileName) {
- builder.setContentTitle(fileName).setContentText(getString(R.string.downloading))
- .setProgress(100, 0, false);
+ builder.setContentTitle(fileName).setContentText(getString(R.string.downloading)).setProgress(100, 0, false);
return builder.setSmallIcon(R.drawable.ic_notification)
.setColor(mCustomThemeWrapper.getColorPrimaryLightTheme())
.build();
@@ -424,9 +422,9 @@ public class DownloadMediaService extends Service {
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, destinationFileName);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, mediaType == EXTRA_MEDIA_TYPE_VIDEO ? "video/*" : "image/*");
contentValues.put(MediaStore.MediaColumns.RELATIVE_PATH, destinationFileUriString);
- contentValues.put(MediaStore.Images.Media.IS_PENDING, 1);
+ contentValues.put(mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.IS_PENDING : MediaStore.Images.Media.IS_PENDING, 1);
- final Uri contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
+ final Uri contentUri = mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.EXTERNAL_CONTENT_URI : MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Uri uri = contentResolver.insert(contentUri, contentValues);
if (uri == null) {
@@ -446,7 +444,7 @@ public class DownloadMediaService extends Service {
stream.write(buf, 0, len);
}
contentValues.clear();
- contentValues.put(MediaStore.Images.Media.IS_PENDING, 0);
+ contentValues.put(mediaType == EXTRA_MEDIA_TYPE_VIDEO ? MediaStore.Video.Media.IS_PENDING : MediaStore.Images.Media.IS_PENDING, 0);
contentResolver.update(uri, contentValues, null, null);
destinationFileUriString = uri.toString();
}
diff --git a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
index c68be79b..5b744a9d 100644
--- a/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
+++ b/app/src/main/java/ml/docilealligator/infinityforreddit/services/DownloadRedditVideoService.java
@@ -138,8 +138,7 @@ public class DownloadRedditVideoService extends Service {
NotificationManager.IMPORTANCE_LOW
);
- NotificationManagerCompat manager = NotificationManagerCompat.from(this);
- manager.createNotificationChannel(serviceChannel);
+ notificationManager.createNotificationChannel(serviceChannel);
}
startForeground(
@@ -246,7 +245,7 @@ public class DownloadRedditVideoService extends Service {
public void updateProgressNotification(int stringResId) {
updateNotification(stringResId, -1, null);
}
- }).execute();
+ }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} else {
String videoFilePath = directoryPath + fileNameWithoutExtension[0] + "-cache.mp4";
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
@@ -264,7 +263,7 @@ public class DownloadRedditVideoService extends Service {
public void updateProgressNotification(int stringResId) {
updateNotification(stringResId, -1, null);
}
- }).execute();
+ }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@@ -286,7 +285,7 @@ public class DownloadRedditVideoService extends Service {
public void updateProgressNotification(int stringResId) {
updateNotification(stringResId, -1, null);
}
- }).execute();
+ }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
} else {