-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: Migrate to Glide for image loading and update dependencies
This commit refactors the image loading logic to use Glide instead of Coil in several areas and updates related dependencies. - Replaced Coil with Glide for image loading in `NotificationFragment`, `SettingsFragment`, `OtakuCustomListScreen`, `ImportListScreen`, `ViewVideosFragment`, `CoverCard`, and `OtakuComposableUtils`. - Created new composables `CustomGlideImage`, `CoilImage` and `ImageLoaderChoice` to manage image loading using Glide and Coil. - Updated dependencies: - Added `coilOkHttp` dependency. - Removed lifecycle from image requests. - Added `httpHeaders` for image requests. - Added NetworkHeaders in the `ReaderComposeImage`. - Updated Glide to version 1.0.3. - Updated `landscapist-glide` to version 2.3.2. - Updated `androidx.lifecycle:lifecycle-compose` to version 2.7.0. - Replaced `SubcomposeAsyncImage` with `GlideImage` where appropriate. - Updated the placeholder handling to use `rememberDrawablePainter`. - Improved code organization by creating specific composables for different image loading scenarios. - Removed unnecessary image request builders. - Updated `libs.versions.toml`.
- Loading branch information
jacobrein
committed
Feb 5, 2025
1 parent
ab8ab88
commit 92651b6
Showing
14 changed files
with
236 additions
and
162 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
42 changes: 42 additions & 0 deletions
42
...rc/main/java/com/programmersbox/uiviews/presentation/components/imageloaders/CoilImage.kt
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,42 @@ | ||
package com.programmersbox.uiviews.presentation.components.imageloaders | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import coil3.compose.AsyncImage | ||
import coil3.network.NetworkHeaders | ||
import coil3.network.httpHeaders | ||
import coil3.request.ImageRequest | ||
import coil3.request.crossfade | ||
import coil3.request.error | ||
import coil3.request.placeholder | ||
|
||
@Composable | ||
fun CoilImage( | ||
imageUrl: String, | ||
headers: Map<String, Any> = emptyMap(), | ||
name: String, | ||
placeHolder: Int, | ||
modifier: Modifier = Modifier, | ||
error: Int = placeHolder, | ||
contentScale: ContentScale = ContentScale.FillBounds, | ||
) { | ||
AsyncImage( | ||
model = ImageRequest.Builder(LocalContext.current) | ||
.data(imageUrl) | ||
.crossfade(true) | ||
.httpHeaders( | ||
NetworkHeaders | ||
.Builder() | ||
.apply { headers.forEach { add(it.key, it.value.toString()) } } | ||
.build() | ||
) | ||
.placeholder(placeHolder) | ||
.error(error) | ||
.build(), | ||
contentScale = contentScale, | ||
contentDescription = name, | ||
modifier = modifier | ||
) | ||
} |
68 changes: 68 additions & 0 deletions
68
...c/main/java/com/programmersbox/uiviews/presentation/components/imageloaders/GlideImage.kt
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,68 @@ | ||
package com.programmersbox.uiviews.presentation.components.imageloaders | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.res.painterResource | ||
import com.bumptech.glide.load.model.GlideUrl | ||
import com.skydoves.landscapist.ImageOptions | ||
import com.skydoves.landscapist.glide.GlideImage | ||
|
||
@Composable | ||
fun CustomGlideImage( | ||
imageUrl: String, | ||
name: String, | ||
modifier: Modifier = Modifier, | ||
headers: Map<String, Any> = emptyMap(), | ||
placeHolder: Int, | ||
error: Int = placeHolder, | ||
contentScale: ContentScale = ContentScale.FillBounds, | ||
) { | ||
val url = remember(imageUrl) { GlideUrl(imageUrl) { headers.mapValues { it.value.toString() } } } | ||
|
||
GlideImage( | ||
imageModel = { url }, | ||
imageOptions = ImageOptions( | ||
contentScale = contentScale, | ||
contentDescription = name, | ||
), | ||
loading = { | ||
Image(painter = painterResource(placeHolder), contentDescription = name) | ||
}, | ||
failure = { | ||
Image(painter = painterResource(error), contentDescription = name) | ||
}, | ||
modifier = modifier | ||
) | ||
} | ||
|
||
@Composable | ||
fun CustomGlideImage( | ||
imageUrl: String, | ||
name: String, | ||
modifier: Modifier = Modifier, | ||
headers: Map<String, Any> = emptyMap(), | ||
placeHolder: Painter, | ||
error: Painter = placeHolder, | ||
contentScale: ContentScale = ContentScale.FillBounds, | ||
) { | ||
val url = remember(imageUrl) { GlideUrl(imageUrl) { headers.mapValues { it.value.toString() } } } | ||
|
||
GlideImage( | ||
imageModel = { url }, | ||
imageOptions = ImageOptions( | ||
contentScale = contentScale, | ||
contentDescription = name, | ||
), | ||
loading = { | ||
Image(painter = placeHolder, contentDescription = name) | ||
}, | ||
failure = { | ||
Image(painter = error, contentDescription = name) | ||
}, | ||
modifier = modifier | ||
) | ||
} |
48 changes: 48 additions & 0 deletions
48
...java/com/programmersbox/uiviews/presentation/components/imageloaders/ImageLoaderChoice.kt
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,48 @@ | ||
package com.programmersbox.uiviews.presentation.components.imageloaders | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.layout.ContentScale | ||
|
||
@Composable | ||
fun ImageLoaderChoice( | ||
imageUrl: String, | ||
name: String, | ||
modifier: Modifier = Modifier, | ||
headers: Map<String, Any> = emptyMap(), | ||
placeHolder: Int, | ||
error: Int = placeHolder, | ||
contentScale: ContentScale = ContentScale.FillBounds, | ||
) { | ||
CustomGlideImage( | ||
imageUrl = imageUrl, | ||
name = name, | ||
modifier = modifier, | ||
headers = headers, | ||
placeHolder = placeHolder, | ||
error = error, | ||
contentScale = contentScale, | ||
) | ||
} | ||
|
||
@Composable | ||
fun ImageLoaderChoice( | ||
imageUrl: String, | ||
name: String, | ||
modifier: Modifier = Modifier, | ||
headers: Map<String, Any> = emptyMap(), | ||
placeHolder: Painter, | ||
error: Painter = placeHolder, | ||
contentScale: ContentScale = ContentScale.FillBounds, | ||
) { | ||
CustomGlideImage( | ||
imageUrl = imageUrl, | ||
name = name, | ||
modifier = modifier, | ||
headers = headers, | ||
placeHolder = placeHolder, | ||
error = error, | ||
contentScale = contentScale, | ||
) | ||
} |
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
Oops, something went wrong.