Skip to content

Commit

Permalink
Performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
D4rK7355608 committed Jun 30, 2024
1 parent c763704 commit 3ae7a23
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions app/src/main/kotlin/com/d4rk/cleaner/ui/home/HomeComposable.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,20 @@ fun HomeComposable() {
val isAnalyzing by viewModel.isAnalyzing.observeAsState(false)
val selectedFileCount by viewModel.selectedFileCount.collectAsState()

val imageLoader = ImageLoader.Builder(context)
.memoryCache {
MemoryCache.Builder(context)
.maxSizePercent(0.24)
.build()
}
.diskCache {
DiskCache.Builder()
.directory(context.cacheDir.resolve("image_cache"))
.maxSizePercent(0.02)
.build()
}
.build()

val launchScanningKey = remember { mutableStateOf(false) }

Column(
Expand Down Expand Up @@ -112,7 +126,7 @@ fun HomeComposable() {
.size(128.dp, 66.dp)
)
} else {
AnalyzeComposable(launchScanningKey)
AnalyzeComposable(launchScanningKey, imageLoader)
}
}
Row(
Expand Down Expand Up @@ -212,7 +226,7 @@ fun HomeComposable() {
* @param viewModel The HomeViewModel instance used to interact with the data and business logic.
*/
@Composable
fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>) {
fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>, imageLoader: ImageLoader) {
val viewModel: HomeViewModel = viewModel()
val files by viewModel.scannedFiles.asFlow().collectAsState(initial = listOf())

Expand Down Expand Up @@ -247,7 +261,7 @@ fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>) {
modifier = Modifier.padding(8.dp)
) {
items(files) { file ->
FileCard(file = file, viewModel = viewModel)
FileCard(file = file, viewModel = viewModel, imageLoader = imageLoader)
}
}
}
Expand Down Expand Up @@ -282,24 +296,10 @@ fun AnalyzeComposable(launchScanningKey: MutableState<Boolean>) {


@Composable
fun FileCard(file: File, viewModel: HomeViewModel) {
fun FileCard(file: File, viewModel: HomeViewModel, imageLoader: ImageLoader) {
val context = LocalContext.current
val fileExtension = getFileExtension(file.name)

val imageLoader = ImageLoader.Builder(context)
.memoryCache {
MemoryCache.Builder(context)
.maxSizePercent(0.24)
.build()
}
.diskCache {
DiskCache.Builder()
.directory(context.cacheDir.resolve("image_cache"))
.maxSizePercent(0.02)
.build()
}
.build()

val thumbnail = remember(file.absolutePath) {
getVideoThumbnail(file.absolutePath, thumbnailWidth = 64, thumbnailHeight = 64)
}
Expand Down Expand Up @@ -330,6 +330,7 @@ fun FileCard(file: File, viewModel: HomeViewModel) {
}
}
)
.size(64)
.crossfade(true)
.build(),
imageLoader = imageLoader,
Expand Down

0 comments on commit 3ae7a23

Please sign in to comment.