generated from amosproj/amos202Xss0Y-projname
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from amosproj/gui/feature/disable-nav-buttons
feat(gui): disable the navigation buttons if their actions are not possible
- Loading branch information
Showing
5 changed files
with
103 additions
and
52 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package logic.caches | ||
|
||
import androidx.compose.ui.graphics.ImageBitmap | ||
|
||
/** | ||
* A class that caches thumbnails for the timeline. | ||
* | ||
* @param getImages A function that returns the thumbnails for a given diff index. | ||
*/ | ||
class ThumbnailCache(val maxCacheSize: Int, val getImages: (Int) -> List<ImageBitmap>) { | ||
private val cache = mutableMapOf<Int, List<ImageBitmap>>() | ||
|
||
// kind of a queue of diff indices ordered by most recently used | ||
private val recentlyUsed = mutableListOf<Int>() | ||
|
||
/** | ||
* Returns the thumbnails for a given diff index. | ||
* | ||
* If the thumbnails are not already cached, they are loaded via the `getImages` function and cached. | ||
* | ||
* @param index [Int] containing the index of the diff. | ||
* @return [List]<[ImageBitmap]> containing the thumbnails for the given diff index. | ||
*/ | ||
fun get(index: Int): List<ImageBitmap> { | ||
recentlyUsed.remove(index) | ||
|
||
if (!cache.containsKey(index)) { | ||
cache[index] = getImages(index) | ||
} | ||
|
||
// if the queue is full, remove the least recently used item | ||
if (recentlyUsed.size >= maxCacheSize) { | ||
cache.remove(recentlyUsed.removeAt(0)) | ||
} | ||
|
||
recentlyUsed.add(index) | ||
return cache[index]!! | ||
} | ||
} |
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