From 020ec70221cc1ab513459770009207021084ed4c Mon Sep 17 00:00:00 2001 From: gdlbo <41114720+gdlbo@users.noreply.github.com> Date: Sat, 20 Aug 2022 15:24:08 +0300 Subject: [PATCH] fixed stories and vid downloading --- .../ru/vtosters/lite/downloaders/StoryDownloader.java | 6 ++++-- .../ru/vtosters/lite/downloaders/VideoDownloader.java | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/ru/vtosters/lite/downloaders/StoryDownloader.java b/app/src/main/java/ru/vtosters/lite/downloaders/StoryDownloader.java index 3fbebe2f6..287374997 100644 --- a/app/src/main/java/ru/vtosters/lite/downloaders/StoryDownloader.java +++ b/app/src/main/java/ru/vtosters/lite/downloaders/StoryDownloader.java @@ -12,6 +12,7 @@ import android.os.Environment; import com.vk.dto.common.ImageSize; import com.vk.dto.stories.model.StoryEntry; +import java.io.File; import java.util.List; public class StoryDownloader { @@ -23,8 +24,9 @@ public class StoryDownloader { String url = imageSizes.get(imageSizes.size() - 1).url; DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); - request.setTitle("photo" + story.E.a); - request.setDestinationInExternalPublicDir(getPhotosDir().getAbsolutePath(), "/Stories/" + story.E.a + ".jpg"); + request.setTitle("photo" + story.E.a + ".jpg"); + request.setDestinationInExternalPublicDir(getPhotosDir().getName(), "photo" + story.E.a + ".jpg"); + request.allowScanningByMediaScanner(); ((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); return; } diff --git a/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java b/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java index 95261b079..3edfbc14b 100644 --- a/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java +++ b/app/src/main/java/ru/vtosters/lite/downloaders/VideoDownloader.java @@ -15,6 +15,7 @@ import android.net.Uri; import android.os.Environment; import android.widget.Toast; +import com.vk.core.dialogs.alert.VkAlertDialog; import com.vk.core.dialogs.bottomsheet.MenuBottomSheetAction; import com.vk.core.util.ToastUtils; import com.vk.dto.common.VideoFile; @@ -106,18 +107,20 @@ public class VideoDownloader { DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setTitle(videoFile.toString()); - request.setDestinationInExternalPublicDir(getVideosDir().getAbsolutePath(), videoFile + ".mp4"); + request.allowScanningByMediaScanner(); + request.setDestinationInExternalPublicDir(getVideosDir().getName(), videoFile + ".mp4"); ((DownloadManager) getGlobalContext().getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); return; } - var builder = new AlertDialog.Builder(context); + var builder = new VkAlertDialog.Builder(context); builder.setItems(max, ((dialog, which) -> { var url = urls.get(which); DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); request.setTitle(videoFile.toString()); - request.setDestinationInExternalPublicDir(getVideosDir().getAbsolutePath(), videoFile + ".mp4"); + request.allowScanningByMediaScanner(); + request.setDestinationInExternalPublicDir(getVideosDir().getName(), videoFile + ".mp4"); ((DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE)).enqueue(request); })); builder.show();