-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use own cache for bitmaps instead of coil (#265)
* Use own cache for bitmaps instead of coil * Fix detekt
- Loading branch information
1 parent
07de196
commit 41cfaa9
Showing
6 changed files
with
41 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/com/michaeltroger/gruenerpass/cache/BitmapCache.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.michaeltroger.gruenerpass.cache | ||
|
||
import android.graphics.Bitmap | ||
import android.util.LruCache | ||
|
||
object BitmapCache { | ||
@Suppress("MagicNumber") | ||
val memoryCache: LruCache<String, Bitmap> by lazy { | ||
val maxMemory = (Runtime.getRuntime().maxMemory() / 1024).toInt() | ||
|
||
// Use 1/8th of the available memory for this memory cache. | ||
val cacheSize = maxMemory / 8 | ||
|
||
object : LruCache<String, Bitmap>(cacheSize) { | ||
|
||
override fun sizeOf(key: String, bitmap: Bitmap): Int { | ||
// The cache size will be measured in kilobytes rather than | ||
// number of items. | ||
return bitmap.byteCount / 1024 | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters