Skip to content

Commit

Permalink
Replace custom image loader usage with image loader dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Sep 16, 2023
1 parent acbbab7 commit 38f283e
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 378 deletions.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,30 @@
*/
package dev.sasikanth.rss.reader.di

import dev.sasikanth.rss.reader.components.AndroidImageLoader
import dev.sasikanth.rss.reader.components.ImageLoader
import android.content.Context
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.component.setupDefaultComponents
import com.seiko.imageloader.defaultImageResultMemoryCache
import com.seiko.imageloader.option.androidContext
import dev.sasikanth.rss.reader.di.scopes.AppScope
import me.tatarka.inject.annotations.Provides
import okio.Path.Companion.toOkioPath

actual interface ImageLoaderComponent {

@Provides fun AndroidImageLoader.bind(): ImageLoader = this
@Provides
@AppScope
fun providesImageLoader(context: Context): ImageLoader {
return ImageLoader {
options { androidContext(context) }
components { setupDefaultComponents() }
interceptor {
defaultImageResultMemoryCache()
diskCacheConfig {
directory(context.cacheDir.resolve("image_cache").toOkioPath())
maxSizeBytes(512L * 1024 * 1024) // 512MB
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.Children
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.StackAnimation
import com.arkivanov.decompose.extensions.compose.jetbrains.stack.animation.plus
import com.arkivanov.essenty.backhandler.BackHandler
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.LocalImageLoader
import dev.sasikanth.rss.reader.bookmarks.ui.BookmarksScreen
import dev.sasikanth.rss.reader.components.DynamicContentTheme
import dev.sasikanth.rss.reader.components.ImageLoader
import dev.sasikanth.rss.reader.components.LocalImageLoader
import dev.sasikanth.rss.reader.components.rememberDynamicColorState
import dev.sasikanth.rss.reader.home.ui.HomeScreen
import dev.sasikanth.rss.reader.repository.BrowserType
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,39 @@
*/
package dev.sasikanth.rss.reader.components

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Box
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.layout.ContentScale
import com.seiko.imageloader.model.ImageRequest
import com.seiko.imageloader.option.SizeResolver
import com.seiko.imageloader.rememberImagePainter

@Composable
expect fun AsyncImage(
fun AsyncImage(
url: String,
contentDescription: String?,
contentScale: ContentScale = ContentScale.Fit,
contentScale: ContentScale = ContentScale.Crop,
modifier: Modifier = Modifier,
)
size: Size = Size(1024f, 1024f)
) {
val request =
remember(url) {
ImageRequest {
data(url)
size(SizeResolver(size))
}
}
val painter = rememberImagePainter(request)
Box(modifier) {
Image(
modifier = Modifier.matchParentSize(),
painter = painter,
contentDescription = contentDescription,
contentScale = contentScale,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,15 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import com.seiko.imageloader.ImageLoader
import com.seiko.imageloader.LocalImageLoader
import com.seiko.imageloader.asImageBitmap
import com.seiko.imageloader.model.ImageRequest
import com.seiko.imageloader.model.ImageResult
import com.seiko.imageloader.option.SizeResolver
import dev.sasikanth.material.color.utilities.dynamiccolor.DynamicColor
import dev.sasikanth.material.color.utilities.dynamiccolor.MaterialDynamicColors
import dev.sasikanth.material.color.utilities.dynamiccolor.ToneDeltaConstraint
Expand All @@ -39,6 +46,8 @@ import dev.sasikanth.material.color.utilities.scheme.SchemeContent
import dev.sasikanth.material.color.utilities.score.Score
import dev.sasikanth.rss.reader.ui.AppTheme
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.withContext

private const val TINTED_BACKGROUND = "tinted_background"
Expand Down Expand Up @@ -279,9 +288,15 @@ class DynamicColorState(
return cached
}

val image = imageLoader?.getImage(url, size = 128)
return if (image != null) {
extractColorsFromImage(image)
val imageRequest = ImageRequest {
data(url)
size(SizeResolver(Size(128f, 128f)))
}
val imageResult =
imageLoader?.async(imageRequest)?.filterIsInstance<ImageResult.Bitmap>()?.first()

return if (imageResult != null) {
extractColorsFromImage(imageResult.bitmap.asImageBitmap())
.let { colorsMap ->
return@let if (colorsMap.isNotEmpty()) {
DynamicColors(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package dev.sasikanth.rss.reader.di

import dev.sasikanth.rss.reader.components.ImageLoader
import dev.sasikanth.rss.reader.di.scopes.AppScope
import dev.sasikanth.rss.reader.initializers.Initializer
import dev.sasikanth.rss.reader.network.NetworkComponent
Expand All @@ -27,8 +26,6 @@ import me.tatarka.inject.annotations.Provides
abstract class SharedApplicationComponent :
DataComponent, ImageLoaderComponent, SentryComponent, NetworkComponent {

abstract val imageLoader: ImageLoader

abstract val initializers: Set<Initializer>

@Provides @AppScope fun DefaultDispatchersProvider.bind(): DispatchersProvider = this
Expand Down

This file was deleted.

Loading

0 comments on commit 38f283e

Please sign in to comment.