Код: Выделить всё
@HiltAndroidApp
class MelonFeedApp: Application(), ImageLoaderFactory {
private val imageLoader: ImageLoader by lazy {
ImageLoader(this).newBuilder()
.memoryCachePolicy(CachePolicy.ENABLED)
.memoryCache {
MemoryCache.Builder(this)
.maxSizePercent(0.1)
.strongReferencesEnabled(true)
.build()
}
.diskCachePolicy(CachePolicy.ENABLED)
.diskCache {
DiskCache.Builder()
.maxSizePercent(0.03)
.directory(cacheDir)
.build()
}
.logger(DebugLogger())
.build()
}
override fun newImageLoader(): ImageLoader {
return imageLoader
}
}
Код: Выделить всё
val result by viewModel.profilePicUrl.observeAsState()
result?.let { url ->
AsyncImage(
model = url,
contentDescription = "Profile Picture",
modifier = Modifier
.size(170.dp)
.clip(CircleShape)
.clickable {
showBottomSheet = true
},
)
}
Код: Выделить всё
private val _profilePicUrl = MutableLiveData()
val profilePicUrl = _profilePicUrl
init {
viewModelScope.launch {
_profilePicUrl.value = getUserProfileImage()
}
}
private suspend fun getUserProfileImage(): String? {
return try {
val storageReference = FirebaseStorage.getInstance().reference
val profileImageReference = storageReference.child("profile_images/profilePicture_${auth.currentUser?.uid}")
profileImageReference.downloadUrl.await().toString()
} catch (e: Exception) {
null
}
}
Когда я отключаю Интернет, изображение не загружается из кеша.
И я думаю, это потому, что getUserProfileImage настроен на загрузку его из базы данных.
Также просмотрите мой код и дайте несколько советов.
И может ли кто-нибудь порекомендовать мне несколько хороших документов или видео на YouTube о разнице между MemoryCache и diskCache, а также о том, что лучше, и о некоторых вариантах использования.
Подробнее здесь: https://stackoverflow.com/questions/784 ... ck-compose
Мобильная версия