-
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.
- Loading branch information
Showing
7 changed files
with
115 additions
and
128 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
11 changes: 4 additions & 7 deletions
11
features/ui-common/src/main/java/com/pluu/webtoon/utils/ImageViewExt.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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
package com.pluu.webtoon.utils | ||
|
||
import com.bumptech.glide.load.model.GlideUrl | ||
import com.bumptech.glide.load.model.LazyHeaders | ||
import okhttp3.Headers | ||
|
||
const val userAgent = | ||
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1" | ||
|
||
fun String.glideUrl(): GlideUrl = GlideUrl( | ||
this, LazyHeaders.Builder() | ||
.addHeader("User-Agent", userAgent) | ||
.build() | ||
) | ||
val userAgentHeader = Headers.Builder() | ||
.set("User-Agent", userAgent) | ||
.build() |
67 changes: 67 additions & 0 deletions
67
features/ui-common/src/main/java/com/pluu/webtoon/utils/ToonImage.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,67 @@ | ||
package com.pluu.webtoon.utils | ||
|
||
import androidx.compose.foundation.Image | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.material3.CircularProgressIndicator | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.ColorFilter | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.layout.ContentScale | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.painterResource | ||
import coil.request.ImageRequest | ||
import com.pluu.webtoon.ui.compose.theme.themeRed | ||
import com.pluu.webtoon.ui_common.R | ||
import com.skydoves.landscapist.ImageOptions | ||
import com.skydoves.landscapist.coil.CoilImage | ||
import com.skydoves.landscapist.coil.CoilImageState | ||
|
||
@Composable | ||
fun ToonImage( | ||
imageUrl: () -> String, | ||
modifier: Modifier = Modifier, | ||
imageOptions: ImageOptions = ImageOptions( | ||
contentScale = ContentScale.Crop, | ||
alignment = Alignment.Center | ||
), | ||
onImageStateChanged: (CoilImageState) -> Unit = {}, | ||
previewPlaceholder: Painter? = null, | ||
loading: @Composable (BoxScope.(imageState: CoilImageState.Loading) -> Unit)? = { | ||
CircularProgressIndicator( | ||
modifier = Modifier | ||
.matchParentSize() | ||
.wrapContentSize(), | ||
color = themeRed | ||
) | ||
}, | ||
success: @Composable (BoxScope.(imageState: CoilImageState.Success, painter: Painter) -> Unit)? = null, | ||
failure: @Composable (BoxScope.(imageState: CoilImageState.Failure) -> Unit)? = { | ||
Image( | ||
painter = painterResource(R.drawable.ic_sentiment_very_dissatisfied_48), | ||
colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.onSurface), | ||
contentDescription = null | ||
) | ||
} | ||
) { | ||
val context = LocalContext.current | ||
CoilImage( | ||
imageRequest = { | ||
ImageRequest.Builder(context) | ||
.data(imageUrl.invoke()) | ||
.headers(userAgentHeader) | ||
.crossfade(true) | ||
.build() | ||
}, | ||
modifier = modifier, | ||
imageOptions = imageOptions, | ||
onImageStateChanged = onImageStateChanged, | ||
previewPlaceholder = previewPlaceholder, | ||
loading = loading, | ||
success = success, | ||
failure = failure | ||
) | ||
} |
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
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