Fix video downloader
This commit is contained in:
@@ -103,9 +103,9 @@ public class VideoDownloader {
|
|||||||
max[i] = list.get(i);
|
max[i] = list.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context == null) context = LifecycleUtils.getCurrentActivity();
|
final Context finalContext = context != null ? context : LifecycleUtils.getCurrentActivity();
|
||||||
|
|
||||||
var adapter = new ArrayAdapter(context, android.R.layout.simple_list_item_1, max) {
|
var adapter = new ArrayAdapter(finalContext, android.R.layout.simple_list_item_1, max) {
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
TextView textView = (TextView) super.getView(position, convertView, parent);
|
TextView textView = (TextView) super.getView(position, convertView, parent);
|
||||||
@@ -114,15 +114,18 @@ public class VideoDownloader {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
new VkAlertDialog.Builder(context)
|
new VkAlertDialog.Builder(finalContext)
|
||||||
.setAdapter(adapter, (dialog, which) -> {
|
.setAdapter(adapter, (dialog, which) -> {
|
||||||
var url = urls.get(which);
|
try {
|
||||||
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
|
var url = urls.get(which);
|
||||||
request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
|
var request = new DownloadManager.Request(Uri.parse(url))
|
||||||
request.setTitle(videoFile.toString());
|
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
|
||||||
request.allowScanningByMediaScanner();
|
.setTitle(videoFile.toString())
|
||||||
request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
.setDestinationInExternalPublicDir(Environment.DIRECTORY_MOVIES, videoFile + ".mp4");
|
||||||
((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
request.allowScanningByMediaScanner();
|
||||||
|
((DownloadManager) finalContext.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request);
|
||||||
|
} catch (Throwable ignored) {
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user