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.
This commit is contained in:
parent
7c0c5b2490
commit
be727ae7c0
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user