From ddb911624cfcc5f475fa4d28e453dd7180382b3f Mon Sep 17 00:00:00 2001 From: Austin Huang Date: Fri, 2 Apr 2021 17:26:44 -0400 Subject: [PATCH] dm attachment filename issue --- .../instagrabber/utils/DownloadUtils.java | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java index 85f45a21..12b46b35 100644 --- a/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DownloadUtils.java @@ -98,19 +98,19 @@ public final class DownloadUtils { // } // } - private static void dmDownloadImpl(@NonNull final Context context, - @Nullable final String username, - final String modelId, - final String url) { - final File dir = getDownloadDir(context, username); - if (dir.exists() || dir.mkdirs()) { - download(context, - url, - getDownloadSaveFile(dir, modelId, url).getAbsolutePath()); - return; - } - Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show(); - } +// private static void dmDownloadImpl(@NonNull final Context context, +// @Nullable final String username, +// final String modelId, +// final String url) { +// final File dir = getDownloadDir(context, username); +// if (dir.exists() || dir.mkdirs()) { +// download(context, +// url, +// getDownloadSaveFile(dir, modelId, url).getAbsolutePath()); +// return; +// } +// Toast.makeText(context, R.string.error_creating_folders, Toast.LENGTH_SHORT).show(); +// } @NonNull private static File getDownloadSaveFile(final File finalDir, @@ -297,7 +297,14 @@ public final class DownloadUtils { case MEDIA_TYPE_IMAGE: case MEDIA_TYPE_VIDEO: { final String url = getUrlOfType(media); - final File file = getDownloadSaveFile(downloadDir, media.getCode(), url); + String fileName = media.getId(); + if (mediaUser != null) { + fileName = mediaUser.getUsername() + "_" + fileName; + } + if (!TextUtils.isEmpty(media.getCode())) { + fileName = media.getCode(); + } + final File file = getDownloadSaveFile(downloadDir, fileName, url); map.put(url, file.getAbsolutePath()); break; }