mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2025-01-02 14:27:10 +01:00
Use DownloadVideoService to download videos.
This commit is contained in:
parent
74a4206cd2
commit
4b4785171c
@ -35,7 +35,7 @@
|
|||||||
android:windowSoftInputMode="adjustResize" />
|
android:windowSoftInputMode="adjustResize" />
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".Service.DownloadRedditVideoService"
|
android:name=".Service.DownloadVideoService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import retrofit2.http.GET;
|
|||||||
import retrofit2.http.Streaming;
|
import retrofit2.http.Streaming;
|
||||||
import retrofit2.http.Url;
|
import retrofit2.http.Url;
|
||||||
|
|
||||||
public interface DownloadRedditVideo {
|
public interface DownloadVideo {
|
||||||
@Streaming
|
@Streaming
|
||||||
@GET()
|
@GET()
|
||||||
Call<ResponseBody> downloadFile(@Url String fileUrl);
|
Call<ResponseBody> downloadFile(@Url String fileUrl);
|
@ -62,7 +62,7 @@ import ml.docilealligator.infinityforreddit.Infinity;
|
|||||||
import ml.docilealligator.infinityforreddit.MediaDownloader;
|
import ml.docilealligator.infinityforreddit.MediaDownloader;
|
||||||
import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
|
import ml.docilealligator.infinityforreddit.MediaDownloaderImpl;
|
||||||
import ml.docilealligator.infinityforreddit.R;
|
import ml.docilealligator.infinityforreddit.R;
|
||||||
import ml.docilealligator.infinityforreddit.Service.DownloadRedditVideoService;
|
import ml.docilealligator.infinityforreddit.Service.DownloadVideoService;
|
||||||
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
import ml.docilealligator.infinityforreddit.Utils.SharedPreferencesUtils;
|
||||||
import retrofit2.Retrofit;
|
import retrofit2.Retrofit;
|
||||||
|
|
||||||
@ -436,10 +436,11 @@ public class ViewVideoActivity extends AppCompatActivity {
|
|||||||
if (videoType != VIDEO_TYPE_NORMAL) {
|
if (videoType != VIDEO_TYPE_NORMAL) {
|
||||||
mediaDownloader.download(videoDownloadUrl, videoFileName, this);
|
mediaDownloader.download(videoDownloadUrl, videoFileName, this);
|
||||||
} else {
|
} else {
|
||||||
Intent intent = new Intent(this, DownloadRedditVideoService.class);
|
Intent intent = new Intent(this, DownloadVideoService.class);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
|
intent.putExtra(DownloadVideoService.EXTRA_VIDEO_URL, videoDownloadUrl);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_POST_ID, id);
|
intent.putExtra(DownloadVideoService.EXTRA_POST_ID, id);
|
||||||
intent.putExtra(DownloadRedditVideoService.EXTRA_SUBREDDIT, subredditName);
|
intent.putExtra(DownloadVideoService.EXTRA_SUBREDDIT, subredditName);
|
||||||
|
intent.putExtra(DownloadVideoService.EXTRA_IS_REDDIT_VIDEO, true);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
startForegroundService(intent);
|
startForegroundService(intent);
|
||||||
|
@ -54,7 +54,7 @@ import ml.docilealligator.infinityforreddit.Fragment.SubscribedSubredditsListing
|
|||||||
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.UserListingFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.ViewImgurVideoFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.ViewImgurVideoFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Fragment.ViewRedditGalleryVideoFragment;
|
import ml.docilealligator.infinityforreddit.Fragment.ViewRedditGalleryVideoFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Service.DownloadRedditVideoService;
|
import ml.docilealligator.infinityforreddit.Service.DownloadVideoService;
|
||||||
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
|
import ml.docilealligator.infinityforreddit.Service.SubmitPostService;
|
||||||
import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment;
|
import ml.docilealligator.infinityforreddit.Settings.AdvancedPreferenceFragment;
|
||||||
import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment;
|
import ml.docilealligator.infinityforreddit.Settings.CustomizeMainPageTabsFragment;
|
||||||
@ -173,7 +173,7 @@ public interface AppComponent {
|
|||||||
|
|
||||||
void inject(ViewImgurVideoFragment viewImgurVideoFragment);
|
void inject(ViewImgurVideoFragment viewImgurVideoFragment);
|
||||||
|
|
||||||
void inject(DownloadRedditVideoService downloadRedditVideoService);
|
void inject(DownloadVideoService downloadVideoService);
|
||||||
|
|
||||||
void inject(MultiRedditListingFragment multiRedditListingFragment);
|
void inject(MultiRedditListingFragment multiRedditListingFragment);
|
||||||
|
|
||||||
|
@ -1,19 +1,17 @@
|
|||||||
package ml.docilealligator.infinityforreddit;
|
package ml.docilealligator.infinityforreddit;
|
||||||
|
|
||||||
import android.app.DownloadManager;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.content.Intent;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Environment;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import ml.docilealligator.infinityforreddit.Service.DownloadVideoService;
|
||||||
|
|
||||||
public class MediaDownloaderImpl implements MediaDownloader {
|
public class MediaDownloaderImpl implements MediaDownloader {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void download(String url, String fileName, Context ctx) {
|
public void download(String url, String fileName, Context ctx) {
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
/*DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
||||||
request.setTitle(fileName);
|
request.setTitle(fileName);
|
||||||
|
|
||||||
request.allowScanningByMediaScanner();
|
request.allowScanningByMediaScanner();
|
||||||
@ -53,6 +51,19 @@ public class MediaDownloaderImpl implements MediaDownloader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
manager.enqueue(request);
|
manager.enqueue(request);
|
||||||
|
Toast.makeText(ctx, R.string.download_started, Toast.LENGTH_SHORT).show();*/
|
||||||
|
|
||||||
|
|
||||||
|
Intent intent = new Intent(ctx, DownloadVideoService.class);
|
||||||
|
intent.putExtra(DownloadVideoService.EXTRA_VIDEO_URL, url);
|
||||||
|
intent.putExtra(DownloadVideoService.EXTRA_FILE_NAME, fileName);
|
||||||
|
intent.putExtra(DownloadVideoService.EXTRA_IS_REDDIT_VIDEO, false);
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
|
ctx.startForegroundService(intent);
|
||||||
|
} else {
|
||||||
|
ctx.startService(intent);
|
||||||
|
}
|
||||||
Toast.makeText(ctx, R.string.download_started, Toast.LENGTH_SHORT).show();
|
Toast.makeText(ctx, R.string.download_started, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,8 +13,11 @@ public class NotificationUtils {
|
|||||||
static final String CHANNEL_NEW_MESSAGES = "New Messages";
|
static final String CHANNEL_NEW_MESSAGES = "New Messages";
|
||||||
public static final String CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO = "download_reddit_video";
|
public static final String CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO = "download_reddit_video";
|
||||||
public static final String CHANNEL_DOWNLOAD_REDDIT_VIDEO = "Download Reddit Video";
|
public static final String CHANNEL_DOWNLOAD_REDDIT_VIDEO = "Download Reddit Video";
|
||||||
|
public static final String CHANNEL_ID_DOWNLOAD_VIDEO = "download_video";
|
||||||
|
public static final String CHANNEL_DOWNLOAD_VIDEO = "Download Video";
|
||||||
public static final int SUBMIT_POST_SERVICE_NOTIFICATION_ID = 10000;
|
public static final int SUBMIT_POST_SERVICE_NOTIFICATION_ID = 10000;
|
||||||
public static final int DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID = 20000;
|
public static final int DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID = 20000;
|
||||||
|
public static final int DOWNLOAD_VIDEO_NOTIFICATION_ID = 30000;
|
||||||
|
|
||||||
private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0;
|
private static final int SUMMARY_BASE_ID_UNREAD_MESSAGE = 0;
|
||||||
private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1;
|
private static final int NOTIFICATION_BASE_ID_UNREAD_MESSAGE = 1;
|
||||||
|
@ -39,7 +39,7 @@ import java.nio.ByteBuffer;
|
|||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Named;
|
import javax.inject.Named;
|
||||||
|
|
||||||
import ml.docilealligator.infinityforreddit.API.DownloadRedditVideo;
|
import ml.docilealligator.infinityforreddit.API.DownloadVideo;
|
||||||
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
import ml.docilealligator.infinityforreddit.CustomTheme.CustomThemeWrapper;
|
||||||
import ml.docilealligator.infinityforreddit.Event.DownloadRedditVideoEvent;
|
import ml.docilealligator.infinityforreddit.Event.DownloadRedditVideoEvent;
|
||||||
import ml.docilealligator.infinityforreddit.Infinity;
|
import ml.docilealligator.infinityforreddit.Infinity;
|
||||||
@ -53,11 +53,13 @@ import retrofit2.Retrofit;
|
|||||||
|
|
||||||
import static android.os.Environment.getExternalStoragePublicDirectory;
|
import static android.os.Environment.getExternalStoragePublicDirectory;
|
||||||
|
|
||||||
public class DownloadRedditVideoService extends Service {
|
public class DownloadVideoService extends Service {
|
||||||
|
|
||||||
public static final String EXTRA_VIDEO_URL = "EVU";
|
public static final String EXTRA_VIDEO_URL = "EVU";
|
||||||
public static final String EXTRA_SUBREDDIT = "ES";
|
public static final String EXTRA_SUBREDDIT = "ES";
|
||||||
public static final String EXTRA_POST_ID = "EPI";
|
public static final String EXTRA_POST_ID = "EPI";
|
||||||
|
public static final String EXTRA_IS_REDDIT_VIDEO = "EIRV";
|
||||||
|
public static final String EXTRA_FILE_NAME = "EFN";
|
||||||
|
|
||||||
private static final int NO_ERROR = -1;
|
private static final int NO_ERROR = -1;
|
||||||
private static final int ERROR_CANNOT_GET_CACHE_DIRECTORY = 0;
|
private static final int ERROR_CANNOT_GET_CACHE_DIRECTORY = 0;
|
||||||
@ -67,6 +69,8 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
private static final int ERROR_MUX_FAILED = 4;
|
private static final int ERROR_MUX_FAILED = 4;
|
||||||
private static final int ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE = 5;
|
private static final int ERROR_MUXED_VIDEO_FILE_CANNOT_SAVE = 5;
|
||||||
|
|
||||||
|
private boolean isRedditVideo;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named("download_reddit_video")
|
@Named("download_reddit_video")
|
||||||
Retrofit retrofit;
|
Retrofit retrofit;
|
||||||
@ -74,7 +78,7 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
CustomThemeWrapper mCustomThemeWrapper;
|
CustomThemeWrapper mCustomThemeWrapper;
|
||||||
String resultFile;
|
String resultFile;
|
||||||
|
|
||||||
public DownloadRedditVideoService() {
|
public DownloadVideoService() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -86,63 +90,107 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
((Infinity) getApplication()).getAppComponent().inject(this);
|
((Infinity) getApplication()).getAppComponent().inject(this);
|
||||||
|
|
||||||
|
isRedditVideo = intent.getBooleanExtra(EXTRA_IS_REDDIT_VIDEO, false);
|
||||||
String videoUrl = intent.getStringExtra(EXTRA_VIDEO_URL);
|
String videoUrl = intent.getStringExtra(EXTRA_VIDEO_URL);
|
||||||
String audioUrl = videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/audio";
|
String audioUrl = isRedditVideo ? videoUrl.substring(0, videoUrl.lastIndexOf('/')) + "/audio" : "";
|
||||||
|
String fileName;
|
||||||
|
if (isRedditVideo) {
|
||||||
|
fileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_POST_ID);
|
||||||
|
} else {
|
||||||
|
fileName = intent.getStringExtra(EXTRA_FILE_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
NotificationChannel serviceChannel = new NotificationChannel(
|
NotificationChannel serviceChannel;
|
||||||
NotificationUtils.CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO,
|
if (isRedditVideo) {
|
||||||
NotificationUtils.CHANNEL_DOWNLOAD_REDDIT_VIDEO,
|
serviceChannel = new NotificationChannel(
|
||||||
NotificationManager.IMPORTANCE_LOW
|
NotificationUtils.CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO,
|
||||||
);
|
NotificationUtils.CHANNEL_DOWNLOAD_REDDIT_VIDEO,
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
serviceChannel = new NotificationChannel(
|
||||||
|
NotificationUtils.CHANNEL_ID_DOWNLOAD_VIDEO,
|
||||||
|
NotificationUtils.CHANNEL_DOWNLOAD_VIDEO,
|
||||||
|
NotificationManager.IMPORTANCE_LOW
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
|
NotificationManagerCompat manager = NotificationManagerCompat.from(this);
|
||||||
manager.createNotificationChannel(serviceChannel);
|
manager.createNotificationChannel(serviceChannel);
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = intent.getStringExtra(EXTRA_SUBREDDIT) + "-" + intent.getStringExtra(EXTRA_POST_ID);
|
if (isRedditVideo) {
|
||||||
|
startForeground(
|
||||||
|
NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID,
|
||||||
|
createNotification(R.string.downloading_reddit_video, fileName + ".mp4", null)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
startForeground(
|
||||||
|
NotificationUtils.DOWNLOAD_VIDEO_NOTIFICATION_ID,
|
||||||
|
createNotification(R.string.downloading_video, fileName, null)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
startForeground(
|
DownloadVideo downloadVideo = retrofit.create(DownloadVideo.class);
|
||||||
NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID,
|
|
||||||
createNotification(R.string.downloading_reddit_video, fileName + ".mp4", null)
|
|
||||||
);
|
|
||||||
|
|
||||||
DownloadRedditVideo downloadRedditVideo = retrofit.create(DownloadRedditVideo.class);
|
|
||||||
|
|
||||||
File directory = getExternalCacheDir();
|
File directory = getExternalCacheDir();
|
||||||
String destinationFileName = fileName + ".mp4";
|
String destinationFileName = fileName + ".mp4";
|
||||||
if (directory != null) {
|
if (directory != null) {
|
||||||
String directoryPath = directory.getAbsolutePath() + "/";
|
String directoryPath = directory.getAbsolutePath() + "/";
|
||||||
downloadRedditVideo.downloadFile(videoUrl).enqueue(new Callback<ResponseBody>() {
|
downloadVideo.downloadFile(videoUrl).enqueue(new Callback<ResponseBody>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> videoResponse) {
|
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> videoResponse) {
|
||||||
if (videoResponse.isSuccessful() && videoResponse.body() != null) {
|
if (videoResponse.isSuccessful() && videoResponse.body() != null) {
|
||||||
updateNotification(R.string.downloading_reddit_video_audio_track, destinationFileName, null);
|
if (isRedditVideo) {
|
||||||
downloadRedditVideo.downloadFile(audioUrl).enqueue(new Callback<ResponseBody>() {
|
updateNotification(R.string.downloading_reddit_video_audio_track, destinationFileName, null);
|
||||||
@Override
|
downloadVideo.downloadFile(audioUrl).enqueue(new Callback<ResponseBody>() {
|
||||||
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> audioResponse) {
|
@Override
|
||||||
if (audioResponse.isSuccessful() && audioResponse.body() != null) {
|
public void onResponse(@NonNull Call<ResponseBody> call, @NonNull Response<ResponseBody> audioResponse) {
|
||||||
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
if (audioResponse.isSuccessful() && audioResponse.body() != null) {
|
||||||
String audioFilePath = directoryPath + fileName + "-cache.mp3";
|
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
||||||
String outputFilePath = directoryPath + fileName + ".mp4";
|
String audioFilePath = directoryPath + fileName + "-cache.mp3";
|
||||||
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
String outputFilePath = directoryPath + fileName + ".mp4";
|
||||||
audioResponse.body(), videoFilePath, audioFilePath, outputFilePath,
|
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
||||||
destinationFileName, getContentResolver(),
|
audioResponse.body(), videoFilePath, audioFilePath, outputFilePath,
|
||||||
new SaveTempMuxAndCopyAsyncTask.SaveTempMuxAndCopyAsyncTaskListener() {
|
destinationFileName, getContentResolver(),
|
||||||
@Override
|
new SaveTempMuxAndCopyAsyncTask.SaveTempMuxAndCopyAsyncTaskListener() {
|
||||||
public void finished(Uri destinationFileUri, int errorCode) {
|
@Override
|
||||||
new File(videoFilePath).delete();
|
public void finished(Uri destinationFileUri, int errorCode) {
|
||||||
new File(audioFilePath).delete();
|
new File(videoFilePath).delete();
|
||||||
new File(outputFilePath).delete();
|
new File(audioFilePath).delete();
|
||||||
downloadFinished(destinationFileUri, destinationFileName, errorCode);
|
new File(outputFilePath).delete();
|
||||||
}
|
downloadFinished(destinationFileUri, destinationFileName, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateProgressNotification(int stringResId) {
|
public void updateProgressNotification(int stringResId) {
|
||||||
updateNotification(stringResId, destinationFileName, null);
|
updateNotification(stringResId, destinationFileName, null);
|
||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
} else {
|
} else {
|
||||||
|
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
||||||
|
String destinationFileName = fileName + ".mp4";
|
||||||
|
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
||||||
|
null, videoFilePath, null, null,
|
||||||
|
destinationFileName, getContentResolver(),
|
||||||
|
new SaveTempMuxAndCopyAsyncTask.SaveTempMuxAndCopyAsyncTaskListener() {
|
||||||
|
@Override
|
||||||
|
public void finished(Uri destinationFileUri, int errorCode) {
|
||||||
|
new File(videoFilePath).delete();
|
||||||
|
downloadFinished(destinationFileUri, destinationFileName, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateProgressNotification(int stringResId) {
|
||||||
|
updateNotification(stringResId, destinationFileName, null);
|
||||||
|
}
|
||||||
|
}).execute();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
||||||
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
||||||
String destinationFileName = fileName + ".mp4";
|
String destinationFileName = fileName + ".mp4";
|
||||||
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
||||||
@ -161,29 +209,25 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
}
|
}
|
||||||
}).execute();
|
}).execute();
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
String videoFilePath = directoryPath + fileName;
|
||||||
|
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
||||||
|
null, videoFilePath, null, null,
|
||||||
|
fileName, getContentResolver(),
|
||||||
|
new SaveTempMuxAndCopyAsyncTask.SaveTempMuxAndCopyAsyncTaskListener() {
|
||||||
|
@Override
|
||||||
|
public void finished(Uri destinationFileUri, int errorCode) {
|
||||||
|
new File(videoFilePath).delete();
|
||||||
|
downloadFinished(destinationFileUri, fileName, errorCode);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NonNull Call<ResponseBody> call, @NonNull Throwable t) {
|
public void updateProgressNotification(int stringResId) {
|
||||||
String videoFilePath = directoryPath + fileName + "-cache.mp4";
|
updateNotification(stringResId, fileName, null);
|
||||||
String destinationFileName = fileName + ".mp4";
|
}
|
||||||
new SaveTempMuxAndCopyAsyncTask(videoResponse.body(),
|
}).execute();
|
||||||
null, videoFilePath, null, null,
|
}
|
||||||
destinationFileName, getContentResolver(),
|
|
||||||
new SaveTempMuxAndCopyAsyncTask.SaveTempMuxAndCopyAsyncTaskListener() {
|
|
||||||
@Override
|
|
||||||
public void finished(Uri destinationFileUri, int errorCode) {
|
|
||||||
new File(videoFilePath).delete();
|
|
||||||
downloadFinished(destinationFileUri, destinationFileName, errorCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateProgressNotification(int stringResId) {
|
|
||||||
updateNotification(stringResId, destinationFileName, null);
|
|
||||||
}
|
|
||||||
}).execute();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
downloadFinished(null, destinationFileName, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD);
|
downloadFinished(null, destinationFileName, ERROR_VIDEO_FILE_CANNOT_DOWNLOAD);
|
||||||
}
|
}
|
||||||
@ -241,7 +285,12 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Notification createNotification(int stringResId, String fileName, PendingIntent pendingIntent) {
|
private Notification createNotification(int stringResId, String fileName, PendingIntent pendingIntent) {
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO);
|
NotificationCompat.Builder builder;
|
||||||
|
if (isRedditVideo) {
|
||||||
|
builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_DOWNLOAD_REDDIT_VIDEO);
|
||||||
|
} else {
|
||||||
|
builder = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_ID_DOWNLOAD_VIDEO);
|
||||||
|
}
|
||||||
builder.setContentTitle(fileName).setContentText(getString(stringResId));
|
builder.setContentTitle(fileName).setContentText(getString(stringResId));
|
||||||
if (pendingIntent != null) {
|
if (pendingIntent != null) {
|
||||||
builder.setContentIntent(pendingIntent);
|
builder.setContentIntent(pendingIntent);
|
||||||
@ -254,8 +303,13 @@ public class DownloadRedditVideoService extends Service {
|
|||||||
private void updateNotification(int stringResId, String fileName, PendingIntent pendingIntent) {
|
private void updateNotification(int stringResId, String fileName, PendingIntent pendingIntent) {
|
||||||
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
if (notificationManager != null) {
|
if (notificationManager != null) {
|
||||||
notificationManager.notify(NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID,
|
if (isRedditVideo) {
|
||||||
createNotification(stringResId, fileName, pendingIntent));
|
notificationManager.notify(NotificationUtils.DOWNLOAD_REDDIT_VIDEO_NOTIFICATION_ID,
|
||||||
|
createNotification(stringResId, fileName, pendingIntent));
|
||||||
|
} else {
|
||||||
|
notificationManager.notify(NotificationUtils.DOWNLOAD_VIDEO_NOTIFICATION_ID,
|
||||||
|
createNotification(stringResId, fileName, pendingIntent));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="application_name">Infinity</string>
|
<string name="application_name" translatable="false">Infinity</string>
|
||||||
<string name="login_activity_label">Login</string>
|
<string name="login_activity_label">Login</string>
|
||||||
<string name="search_activity_label">Search</string>
|
<string name="search_activity_label">Search</string>
|
||||||
<string name="comment_activity_label">Send Comment</string>
|
<string name="comment_activity_label">Send Comment</string>
|
||||||
@ -125,9 +125,6 @@
|
|||||||
<string name="cannot_fetch_sidebar">Cannot fetch sidebar</string>
|
<string name="cannot_fetch_sidebar">Cannot fetch sidebar</string>
|
||||||
<string name="cannot_fetch_multireddit">Cannot fetch multireddit info</string>
|
<string name="cannot_fetch_multireddit">Cannot fetch multireddit info</string>
|
||||||
|
|
||||||
<string name="gilded_count">x%1$d</string>
|
|
||||||
<string name="title_activity_view_user_detail">ViewUserDetailActivity</string>
|
|
||||||
|
|
||||||
<string name="subscribe">Subscribe</string>
|
<string name="subscribe">Subscribe</string>
|
||||||
<string name="unsubscribe">Unsubscribe</string>
|
<string name="unsubscribe">Unsubscribe</string>
|
||||||
<string name="subscribed">Subscribed</string>"
|
<string name="subscribed">Subscribed</string>"
|
||||||
@ -765,7 +762,7 @@
|
|||||||
<string name="parse_theme_failed">Parse Theme Failed</string>
|
<string name="parse_theme_failed">Parse Theme Failed</string>
|
||||||
<string name="share_theme_to_subreddit_dialog_title">Share it to r/Infinity_For_Reddit?</string>
|
<string name="share_theme_to_subreddit_dialog_title">Share it to r/Infinity_For_Reddit?</string>
|
||||||
<string name="share_theme_to_subreddit_dialog_message">The theme configuration is copied!
|
<string name="share_theme_to_subreddit_dialog_message">The theme configuration is copied!
|
||||||
Do you want to share it to r/Infinity so that other people can use it?</string>
|
Do you want to share it to r/Infinity_For_Reddit so that other people can use it?</string>
|
||||||
<string name="duplicate_theme_name_dialog_title">Duplicate Theme Found</string>
|
<string name="duplicate_theme_name_dialog_title">Duplicate Theme Found</string>
|
||||||
<string name="duplicate_theme_name_dialog_message">A theme in the database is also called %1$s. Do you want to change the name of this imported theme?</string>
|
<string name="duplicate_theme_name_dialog_message">A theme in the database is also called %1$s. Do you want to change the name of this imported theme?</string>
|
||||||
<string name="rename">Rename</string>
|
<string name="rename">Rename</string>
|
||||||
@ -837,6 +834,7 @@
|
|||||||
<string name="downloading_reddit_video_failed_cannot_save_audio">Download failed: cannot save audio to cache directory</string>
|
<string name="downloading_reddit_video_failed_cannot_save_audio">Download failed: cannot save audio to cache directory</string>
|
||||||
<string name="downloading_reddit_video_failed_cannot_mux">Download failed: cannot mux video and audio</string>
|
<string name="downloading_reddit_video_failed_cannot_mux">Download failed: cannot mux video and audio</string>
|
||||||
<string name="downloading_reddit_video_failed_cannot_save_mux_video">Download failed: cannot save the video to public directory</string>
|
<string name="downloading_reddit_video_failed_cannot_save_mux_video">Download failed: cannot save the video to public directory</string>
|
||||||
|
<string name="downloading_video">Downloading Video</string>
|
||||||
|
|
||||||
<string name="wallpaper_set">Wallpaper set</string>
|
<string name="wallpaper_set">Wallpaper set</string>
|
||||||
<string name="error_set_wallpaper">Cannot set wallpaper</string>
|
<string name="error_set_wallpaper">Cannot set wallpaper</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user