From be727ae7c01406d58b80bfb286ddfd4b7bb49990 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Mon, 29 May 2017 16:18:23 +1000 Subject: [PATCH] Fix missing category images. Even though the categoyr mage loader explicitly says not to cache images on disk (because they are not coming from the network anyway), UIL still uses the `FilenameGenerator` to come up with a disk cache name. Because the file name generator takes the "path" of the URL being downloaded, and the categories are loaded like "drawable://2134234", there is no path. As such, the file name ends up being meaningless. This results in the image loader testing for the existance of the file on disk (even though we asked not to cache on disk), and then failing with an IOException (that gets swallowed). By providing a meaningful name from the file name generator, it now works as expected. Fixes #1039. --- .../main/java/org/fdroid/fdroid/FDroidApp.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java index 2ea3acd60..50ea77b56 100644 --- a/app/src/main/java/org/fdroid/fdroid/FDroidApp.java +++ b/app/src/main/java/org/fdroid/fdroid/FDroidApp.java @@ -35,6 +35,7 @@ import android.net.Uri; import android.os.Build; import android.os.Environment; import android.os.StrictMode; +import android.support.annotation.NonNull; import android.text.TextUtils; import android.util.Log; import android.widget.Toast; @@ -279,13 +280,23 @@ public class FDroidApp extends Application { Utils.getImageCacheDir(this), null, new FileNameGenerator() { + @NonNull @Override public String generate(String imageUri) { if (TextUtils.isEmpty(imageUri)) { return "null"; - } else { - return SanitizedFile.sanitizeFileName(Uri.parse(imageUri).getPath().replaceAll("/", "-")); } + + String fileNameToSanitize; + Uri uri = Uri.parse(imageUri); + if (TextUtils.isEmpty(uri.getPath())) { + // e.g. files with a URL like "drawable://213083835209" used by the category backgrounds. + fileNameToSanitize = imageUri.replaceAll("[:/]", ""); + } else { + fileNameToSanitize = uri.getPath().replace("/", "-"); + } + + return SanitizedFile.sanitizeFileName(fileNameToSanitize); } }, // 30 days in secs: 30*24*60*60 = 2592000