Merge branch 'fix-feature-image' into 'master'

Fix feature images from only displaying the first one loaded.

See merge request !510
This commit is contained in:
Hans-Christoph Steiner 2017-05-09 12:02:14 +00:00
commit 6c9d4f899e
4 changed files with 14 additions and 6 deletions

View File

@ -136,7 +136,7 @@ public class CleanCacheService extends IntentService {
* Delete cached icons that have not been accessed in over a year. * Delete cached icons that have not been accessed in over a year.
*/ */
private void deleteOldIcons() { private void deleteOldIcons() {
clearOldFiles(Utils.getIconsCacheDir(this), TimeUnit.DAYS.toMillis(365)); clearOldFiles(Utils.getImageCacheDir(this), TimeUnit.DAYS.toMillis(365));
} }
/** /**

View File

@ -54,6 +54,7 @@ import org.fdroid.fdroid.compat.PRNGFixes;
import org.fdroid.fdroid.data.AppProvider; import org.fdroid.fdroid.data.AppProvider;
import org.fdroid.fdroid.data.InstalledAppProviderService; import org.fdroid.fdroid.data.InstalledAppProviderService;
import org.fdroid.fdroid.data.Repo; import org.fdroid.fdroid.data.Repo;
import org.fdroid.fdroid.data.SanitizedFile;
import org.fdroid.fdroid.installer.InstallHistoryService; import org.fdroid.fdroid.installer.InstallHistoryService;
import org.fdroid.fdroid.net.ImageLoaderForUIL; import org.fdroid.fdroid.net.ImageLoaderForUIL;
import org.fdroid.fdroid.net.WifiStateChangeService; import org.fdroid.fdroid.net.WifiStateChangeService;
@ -274,7 +275,7 @@ public class FDroidApp extends Application {
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext()) ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.imageDownloader(new ImageLoaderForUIL(getApplicationContext())) .imageDownloader(new ImageLoaderForUIL(getApplicationContext()))
.diskCache(new LimitedAgeDiskCache( .diskCache(new LimitedAgeDiskCache(
Utils.getIconsCacheDir(this), Utils.getImageCacheDir(this),
null, null,
new FileNameGenerator() { new FileNameGenerator() {
@Override @Override
@ -282,7 +283,7 @@ public class FDroidApp extends Application {
if (TextUtils.isEmpty(imageUri)) { if (TextUtils.isEmpty(imageUri)) {
return "null"; return "null";
} else { } else {
return imageUri.substring(imageUri.lastIndexOf('/') + 1); return SanitizedFile.sanitizeFileName(Uri.parse(imageUri).getPath().replaceAll("/", "-"));
} }
} }
}, },

View File

@ -124,9 +124,9 @@ public final class Utils {
} }
/** /**
* @return the directory where cached icons are stored * @return the directory where cached icons/feature graphics/screenshots are stored
*/ */
public static File getIconsCacheDir(Context context) { public static File getImageCacheDir(Context context) {
File cacheDir = StorageUtils.getCacheDirectory(context.getApplicationContext(), true); File cacheDir = StorageUtils.getCacheDirectory(context.getApplicationContext(), true);
return new File(cacheDir, "icons"); return new File(cacheDir, "icons");
} }

View File

@ -11,13 +11,20 @@ import java.io.File;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class SanitizedFile extends File { public class SanitizedFile extends File {
/**
* Removes anything that is not an alpha numeric character, or one of "-", ".", or "_".
*/
public static String sanitizeFileName(String name) {
return name.replaceAll("[^A-Za-z0-9-._]", "");
}
/** /**
* The "name" argument is assumed to be a file name, _not including any path separators_. * The "name" argument is assumed to be a file name, _not including any path separators_.
* If it is a relative path to be appended to "parent", such as "/blah/sneh.txt", then * If it is a relative path to be appended to "parent", such as "/blah/sneh.txt", then
* the forward slashes will be removed and it will be assumed you meant "blahsneh.txt". * the forward slashes will be removed and it will be assumed you meant "blahsneh.txt".
*/ */
public SanitizedFile(File parent, String name) { public SanitizedFile(File parent, String name) {
super(parent, name.replaceAll("[^A-Za-z0-9-._]", "")); super(parent, sanitizeFileName(name));
} }
/** /**