Switch to "apks" apk cache dir, use internal cache when external is not available
This commit is contained in:
parent
8a90687867
commit
4d94295864
@ -76,6 +76,9 @@ import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
|
||||
import android.os.Environment;
|
||||
|
||||
public class AppDetails extends ListActivity {
|
||||
|
||||
@ -841,8 +844,8 @@ public class AppDetails extends ListActivity {
|
||||
public void onClick(DialogInterface dialog,
|
||||
int whichButton) {
|
||||
downloadHandler = new DownloadHandler(app.curApk,
|
||||
repoaddress, DB
|
||||
.getDataPath(getBaseContext()));
|
||||
repoaddress, Utils
|
||||
.getApkCacheDir(getBaseContext()));
|
||||
}
|
||||
});
|
||||
ask_alrt.setNegativeButton(getString(R.string.no),
|
||||
@ -872,7 +875,7 @@ public class AppDetails extends ListActivity {
|
||||
return;
|
||||
}
|
||||
downloadHandler = new DownloadHandler(app.curApk, repoaddress,
|
||||
DB.getDataPath(this));
|
||||
Utils.getApkCacheDir(getBaseContext()));
|
||||
}
|
||||
|
||||
private void removeApk(String id) {
|
||||
|
@ -619,14 +619,6 @@ public class DB {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the local storage (cache) path. This will also create it if
|
||||
* it doesn't exist. It can return null if it's currently unavailable.
|
||||
*/
|
||||
public static File getDataPath(Context ctx) {
|
||||
return ContextCompat.create(ctx).getExternalCacheDir();
|
||||
}
|
||||
|
||||
private Context mContext;
|
||||
private Apk.CompatibilityChecker compatChecker = null;
|
||||
|
||||
|
@ -31,11 +31,13 @@ import android.util.Log;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
import org.fdroid.fdroid.Utils;
|
||||
|
||||
import com.nostra13.universalimageloader.cache.disc.impl.LimitedAgeDiscCache;
|
||||
import com.nostra13.universalimageloader.cache.disc.naming.FileNameGenerator;
|
||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
|
||||
public class FDroidApp extends Application {
|
||||
|
||||
@ -78,14 +80,14 @@ public class FDroidApp extends Application {
|
||||
curTheme = Theme.valueOf(prefs.getString("theme", "dark"));
|
||||
if (!prefs.getBoolean("cacheDownloaded", false)) {
|
||||
|
||||
File local_path = DB.getDataPath(this);
|
||||
File local_path = Utils.getApkCacheDir(this);
|
||||
// Things can be null if the SD card is not ready - we'll just
|
||||
// ignore that and do it next time.
|
||||
if(local_path != null) {
|
||||
if (local_path != null) {
|
||||
File[] files = local_path.listFiles();
|
||||
if(files != null) {
|
||||
for(File f : files) {
|
||||
if(f.getName().endsWith(".apk")) {
|
||||
if (files != null) {
|
||||
for (File f : files) {
|
||||
if (f.getName().endsWith(".apk")) {
|
||||
f.delete();
|
||||
}
|
||||
}
|
||||
@ -101,7 +103,8 @@ public class FDroidApp extends Application {
|
||||
|
||||
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(ctx)
|
||||
.discCache(new LimitedAgeDiscCache(
|
||||
new File(StorageUtils.getCacheDirectory(ctx), "icons"),
|
||||
new File(StorageUtils.getCacheDirectory(ctx, true),
|
||||
"icons"),
|
||||
new FileNameGenerator() {
|
||||
@Override
|
||||
public String generate(String imageUri) {
|
||||
|
@ -26,6 +26,10 @@ import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.nostra13.universalimageloader.utils.StorageUtils;
|
||||
|
||||
public final class Utils {
|
||||
|
||||
public static final int BUFFER_SIZE = 4096;
|
||||
@ -143,4 +147,13 @@ public final class Utils {
|
||||
return count;
|
||||
}
|
||||
|
||||
public static File getApkCacheDir(Context context) {
|
||||
File apkCacheDir = new File(
|
||||
StorageUtils.getCacheDirectory(context, true), "apks");
|
||||
if (!apkCacheDir.exists()) {
|
||||
apkCacheDir.mkdir();
|
||||
}
|
||||
return apkCacheDir;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ class OldContextCompatImpl extends ContextCompat {
|
||||
public File getExternalCacheDir() {
|
||||
File file = new File(Environment.getExternalStorageDirectory(),
|
||||
"Android/data/org.fdroid.fdroid/cache");
|
||||
if(!file.exists())
|
||||
if (!file.exists())
|
||||
file.mkdirs();
|
||||
return file;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user