Skip to content

Commit

Permalink
[FEAT/#306] 배너 조회 API 매핑
Browse files Browse the repository at this point in the history
  • Loading branch information
arinming committed Jan 4, 2025
1 parent 7e52504 commit 9f149eb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.terning.domain.search.entity.SearchBanner
fun SearchBannersResponseDto.toSearchBannerList(): List<SearchBanner> {
return banners.map {
SearchBanner(
imageRes = it.imageUrl,
imageUrl = it.imageUrl,
url = it.link,
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.terning.domain.search.entity

data class SearchBanner(
val imageRes: String,
val imageUrl: String,
val url: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fun SearchScreen(
LazyColumn {
item {
ImageSlider(
images = bannerList,
searchBanners = bannerList,
onAdvertisementClick = onAdvertisementClick,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,34 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import coil3.compose.AsyncImage
import coil3.request.ImageRequest
import coil3.request.crossfade
import com.terning.core.designsystem.extension.noRippleClickable
import com.terning.core.designsystem.theme.Grey200
import com.terning.domain.search.entity.SearchBanner
import kotlinx.coroutines.delay

@Composable
fun ImageSlider(
modifier: Modifier = Modifier,
images: List<com.terning.domain.search.entity.SearchBanner>,
searchBanners: List<SearchBanner>,
onAdvertisementClick: (Int) -> Unit,
) {
val pagerState = rememberPagerState(
initialPage = 0,
pageCount = { if (images.isEmpty()) 0 else Int.MAX_VALUE }
pageCount = { Int.MAX_VALUE }
)
val autoScroll = remember { mutableStateOf(true) }

LaunchedEffect(autoScroll.value) {
if (autoScroll.value) {
while (true) {
delay(2500)
if (!pagerState.isScrollInProgress && images.isNotEmpty()) {
val nextPage = (pagerState.currentPage + 1) % images.size
if (!pagerState.isScrollInProgress) {
val nextPage = pagerState.currentPage + 1
pagerState.animateScrollToPage(nextPage)
}
}
Expand All @@ -50,7 +54,7 @@ fun ImageSlider(
.background(Grey200),
horizontalAlignment = Alignment.CenterHorizontally
) {
if (images.isNotEmpty()) {
if (searchBanners.isNotEmpty()) {
Box(
modifier = modifier,
contentAlignment = Alignment.BottomCenter
Expand All @@ -60,20 +64,23 @@ fun ImageSlider(
modifier = modifier,
beyondViewportPageCount = 1
) { currentPage ->
val pageIndex = currentPage % images.size
val pageIndex = currentPage % searchBanners.size
AsyncImage(
model = images[pageIndex].url,
model = ImageRequest.Builder(LocalContext.current)
.data(searchBanners[pageIndex].imageUrl)
.crossfade(true)
.build(),
contentDescription = null,
modifier = modifier
.fillMaxWidth()
.height(112.dp)
.noRippleClickable { onAdvertisementClick(pageIndex) },
contentScale = ContentScale.Crop
contentScale = ContentScale.Crop,
)
}
DotsIndicator(
pageCount = images.size,
currentPage = pagerState.currentPage % images.size
pageCount = searchBanners.size,
currentPage = pagerState.currentPage % searchBanners.size
)
}
}
Expand Down

0 comments on commit 9f149eb

Please sign in to comment.