From 7564c0501ab4f27830c934d20d3555f74cbdcf20 Mon Sep 17 00:00:00 2001 From: lt Date: Mon, 22 Apr 2024 21:49:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=BF=E7=A8=8B?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E7=9A=84ConcurrentModificationException?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../commonMain/kotlin/com/lt/common/App.kt | 26 +++++++++++++++++++ desktop/src/jvmMain/kotlin/Main.kt | 4 ++- gradle/wrapper/gradle-wrapper.properties | 2 +- .../cache/ImageLruMemoryCache.kt | 8 +++--- 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/common/src/commonMain/kotlin/com/lt/common/App.kt b/common/src/commonMain/kotlin/com/lt/common/App.kt index 51ada7f..c148020 100644 --- a/common/src/commonMain/kotlin/com/lt/common/App.kt +++ b/common/src/commonMain/kotlin/com/lt/common/App.kt @@ -17,6 +17,10 @@ package com.lt.common import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.size import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.LazyListState @@ -54,3 +58,25 @@ fun App( } } } + +val moreImages = mutableListOf().apply { + repeat(9999) { + add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fbkimg.cdn.bcebos.com%2Fpic%2Ff9198618367adab44aed43580398a41c8701a18b4ed1&refer=http%3A%2F%2Fbkimg.cdn.bcebos.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1651992355&t=0eb27c606fc381fdaaaca828505ac114&a=$it&b=") + } +} + +//更多图片测试 +@Composable +fun MoreImage() { + LazyColumn(Modifier.fillMaxSize()) { + items(moreImages) { + Row(Modifier.height(50.dp)) { + repeat(10) { i -> + Image( + rememberImagePainter(it + i), "", Modifier.weight(1f).fillMaxHeight() + ) + } + } + } + } +} diff --git a/desktop/src/jvmMain/kotlin/Main.kt b/desktop/src/jvmMain/kotlin/Main.kt index a510fdd..2cd5bcd 100644 --- a/desktop/src/jvmMain/kotlin/Main.kt +++ b/desktop/src/jvmMain/kotlin/Main.kt @@ -34,6 +34,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Window import androidx.compose.ui.window.application import com.lt.common.App +import com.lt.common.MoreImage import com.lt.load_the_image.LoadTheImageManager import com.lt.load_the_image.loader.DataToBeLoaded import com.lt.load_the_image.rememberImagePainter @@ -46,7 +47,8 @@ fun main() { Window(onCloseRequest = ::exitApplication) { MaterialTheme { //TestLazyList() - UI() + //UI() + MoreImage() } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 142305f..71f1462 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -16,6 +16,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists \ No newline at end of file diff --git a/load-the-image/src/main/java/com/lt/load_the_image/cache/ImageLruMemoryCache.kt b/load-the-image/src/main/java/com/lt/load_the_image/cache/ImageLruMemoryCache.kt index e9915d0..a852fa2 100644 --- a/load-the-image/src/main/java/com/lt/load_the_image/cache/ImageLruMemoryCache.kt +++ b/load-the-image/src/main/java/com/lt/load_the_image/cache/ImageLruMemoryCache.kt @@ -16,8 +16,6 @@ package com.lt.load_the_image.cache -import java.util.Collections - /** * creator: lt 2022/4/8 lt.dygzs@qq.com * effect : Memory cache configuration of network image, cache use LRU @@ -27,13 +25,12 @@ open class ImageLruMemoryCache( private val maxMemorySize: Long = getMemoryWithOnePercent() ) : ImageCache { //image lru cache - private val cacheMap = Collections.synchronizedMap( - LinkedHashMap(35, 1f, true) - ) + private val cacheMap = LinkedHashMap(35, 1f, true) //image cache byte size sum private var cacheSize: Long = 0 + @Synchronized override fun saveCache(url: String, t: ByteArray) { if (t.size > maxMemorySize) return @@ -45,6 +42,7 @@ open class ImageLruMemoryCache( } } + @Synchronized override fun getCache(url: String): ByteArray? { return cacheMap[url] }