improved on storage running low
This commit is contained in:
parent
4580ff8aa5
commit
a4a6237aeb
|
@ -171,8 +171,8 @@ dependencies {
|
|||
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'
|
||||
compile 'jp.wasabeef:glide-transformations:2.0.1'
|
||||
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.22'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.22'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:base:0.9.23'
|
||||
compile 'com.github.mariotaku.MediaViewerLibrary:subsample-image-view:0.9.23'
|
||||
compile 'com.github.mariotaku:SQLiteQB:0.9.10'
|
||||
compile "com.github.mariotaku.ObjectCursor:core:${libVersions['ObjectCursor']}"
|
||||
compile 'com.github.mariotaku:MultiValueSwitch:0.9.7'
|
||||
|
@ -182,7 +182,7 @@ dependencies {
|
|||
compile "com.github.mariotaku.CommonsLibrary:text:${libVersions['MariotakuCommons']}"
|
||||
compile "com.github.mariotaku.CommonsLibrary:text-kotlin:${libVersions['MariotakuCommons']}"
|
||||
compile 'com.github.mariotaku:KPreferences:0.9.5'
|
||||
compile 'com.github.mariotaku:Chameleon:0.9.15'
|
||||
compile 'com.github.mariotaku:Chameleon:0.9.16'
|
||||
|
||||
compile "org.jetbrains.kotlin:kotlin-stdlib:${libVersions['Kotlin']}"
|
||||
compile 'nl.komponents.kovenant:kovenant:3.3.0'
|
||||
|
|
|
@ -462,13 +462,18 @@ public final class Utils implements Constants {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public static File getExternalCacheDir(final Context context, final String cacheDirName) {
|
||||
public static File getExternalCacheDir(final Context context, final String cacheDirName,
|
||||
final long sizeInBytes) {
|
||||
if (context == null) throw new NullPointerException();
|
||||
final File externalCacheDir = context.getExternalCacheDir();
|
||||
if (externalCacheDir == null) return null;
|
||||
final File cacheDir = new File(externalCacheDir, cacheDirName);
|
||||
if (sizeInBytes > 0 && externalCacheDir.getFreeSpace() < sizeInBytes / 10) {
|
||||
// Less then 10% space available
|
||||
return null;
|
||||
}
|
||||
if (cacheDir.isDirectory() || cacheDir.mkdirs()) return cacheDir;
|
||||
return new File(context.getCacheDir(), cacheDirName);
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getLocalizedNumber(final Locale locale, final Number number) {
|
||||
|
@ -493,14 +498,6 @@ public final class Utils implements Constants {
|
|||
return list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
public static String getNormalTwitterProfileImage(final String url) {
|
||||
return getTwitterProfileImageOfSize(url, "normal");
|
||||
}
|
||||
|
||||
public static Uri getNotificationUri(final int tableId, final Uri def) {
|
||||
return def;
|
||||
}
|
||||
|
||||
public static String getOriginalTwitterProfileImage(final String url) {
|
||||
if (url == null) return null;
|
||||
final Matcher matcher = PATTERN_TWITTER_PROFILE_IMAGES.matcher(url);
|
||||
|
@ -613,8 +610,7 @@ public final class Utils implements Constants {
|
|||
}
|
||||
|
||||
|
||||
public static String getTwitterProfileImageOfSize(final String url, final String size) {
|
||||
if (url == null) return null;
|
||||
public static String getTwitterProfileImageOfSize(@NonNull final String url, @NonNull final String size) {
|
||||
final Matcher matcher = PATTERN_TWITTER_PROFILE_IMAGES.matcher(url);
|
||||
if (matcher.matches()) {
|
||||
return matcher.replaceFirst("$1$2/profile_images/$3/$4_" + size + "$6");
|
||||
|
|
|
@ -39,7 +39,13 @@ fun RequestManager.loadProfileImage(
|
|||
@ImageShapeStyle style: Int = ImageShapeStyle.SHAPE_CIRCLE,
|
||||
size: String? = null
|
||||
): DrawableRequestBuilder<String?> {
|
||||
return configureLoadProfileImage(context, style) { load(Utils.getTwitterProfileImageOfSize(url, size)) }
|
||||
return configureLoadProfileImage(context, style) {
|
||||
if (url == null || size == null) {
|
||||
return@configureLoadProfileImage load(url)
|
||||
} else {
|
||||
return@configureLoadProfileImage load(Utils.getTwitterProfileImageOfSize(url, size))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun RequestManager.loadProfileImage(context: Context, resourceId: Int,
|
||||
|
|
|
@ -57,9 +57,12 @@ class DiskLRUFileCache(val cacheDir: File) : FileCache {
|
|||
cache?.remove(hash(key))
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
override fun save(key: String, stream: InputStream, extra: ByteArray?, listener: FileCache.CopyListener?) {
|
||||
val editor = cache?.edit(hash(key)) ?: return
|
||||
val hashedKey = hash(key)
|
||||
val editor = cache?.edit(hashedKey) ?: throw IOException("Unable to open cache for $key")
|
||||
|
||||
try {
|
||||
editor.getFile(0).outputStream().use {
|
||||
var bytesCopied: Int = 0
|
||||
val buffer = ByteArray(8192)
|
||||
|
@ -68,7 +71,6 @@ class DiskLRUFileCache(val cacheDir: File) : FileCache {
|
|||
it.write(buffer, 0, bytes)
|
||||
bytesCopied += bytes
|
||||
if (listener != null && !listener.onCopied(bytesCopied)) {
|
||||
editor.abort()
|
||||
return
|
||||
}
|
||||
bytes = stream.read(buffer)
|
||||
|
@ -78,6 +80,9 @@ class DiskLRUFileCache(val cacheDir: File) : FileCache {
|
|||
editor.getFile(1).writeBytes(extra)
|
||||
}
|
||||
editor.commit()
|
||||
} finally {
|
||||
editor.abortUnlessCommitted()
|
||||
}
|
||||
}
|
||||
|
||||
private fun hash(key: String): String {
|
||||
|
|
|
@ -311,7 +311,7 @@ class ApplicationModule(private val application: Application) {
|
|||
fun cache(preferences: SharedPreferencesWrapper): Cache {
|
||||
val cacheSizeMB = preferences.getInt(KEY_CACHE_SIZE_LIMIT, 300).coerceIn(100..500)
|
||||
// Convert to bytes
|
||||
return Cache(getCacheDir("network"), cacheSizeMB * 1048576L)
|
||||
return Cache(getCacheDir("network", cacheSizeMB * 1048576L), cacheSizeMB * 1048576L)
|
||||
}
|
||||
|
||||
@Provides
|
||||
|
@ -323,17 +323,17 @@ class ApplicationModule(private val application: Application) {
|
|||
@Provides
|
||||
@Singleton
|
||||
fun jsonCache(): JsonCache {
|
||||
return JsonCache(getCacheDir("json"))
|
||||
return JsonCache(getCacheDir("json", 100 * 1048576L))
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun fileCache(): FileCache {
|
||||
return DiskLRUFileCache(getCacheDir("media"))
|
||||
return DiskLRUFileCache(getCacheDir("media", 100 * 1048576L))
|
||||
}
|
||||
|
||||
private fun getCacheDir(dirName: String): File {
|
||||
return Utils.getExternalCacheDir(application, dirName) ?:
|
||||
private fun getCacheDir(dirName: String, sizeInBytes: Long): File {
|
||||
return Utils.getExternalCacheDir(application, dirName, sizeInBytes) ?:
|
||||
Utils.getInternalCacheDir(application, dirName)
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,8 @@
|
|||
android:id="@+id/videoView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center"/>
|
||||
android:layout_gravity="center"
|
||||
android:background="@android:color/black"/>
|
||||
|
||||
</com.commonsware.cwac.layouts.AspectLockedFrameLayout>
|
||||
|
||||
|
|
Loading…
Reference in New Issue