Skip to content

Commit

Permalink
feat: 아이템 선택 시 해당 아이템에 맞는 정보가 화면에 불러와진다
Browse files Browse the repository at this point in the history
  • Loading branch information
SeongHoonC committed Feb 5, 2024
1 parent 16565df commit 15bfa76
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ class FestivalListPopularViewHolder(val binding: ItemFestivalListPopularBinding)
PopularFestivalViewPagerAdapter(
foregroundViewPager = binding.vpPopularFestivalForeground,
backgroundViewPager = binding.vpPopularFestivalBackground,
)
) { item ->
binding.item = item
binding.tvPopularFestivalArtistsName.text =
item.artists.joinToString(ARTIST_NAME_JOIN_SEPARATOR) { it.name }
}

init {
TabLayoutMediator(
Expand All @@ -27,6 +31,8 @@ class FestivalListPopularViewHolder(val binding: ItemFestivalListPopularBinding)
}

companion object {
private const val ARTIST_NAME_JOIN_SEPARATOR = ", "

fun of(parent: ViewGroup): FestivalListPopularViewHolder {
val binding = ItemFestivalListPopularBinding.inflate(
LayoutInflater.from(parent.context),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import kotlin.math.abs
class PopularFestivalViewPagerAdapter(
foregroundViewPager: ViewPager2,
backgroundViewPager: ViewPager2,
private val onPopularFestivalSelected: (FestivalItemUiState) -> Unit,
) {

private val popularFestivals = mutableListOf<FestivalItemUiState>()
private val foregroundAdapter: PopularFestivalForegroundAdapter =
PopularFestivalForegroundAdapter()
private val backgroundAdapter: PopularFestivalBackgroundAdapter =
Expand Down Expand Up @@ -63,9 +65,11 @@ class PopularFestivalViewPagerAdapter(
viewPager.offscreenPageLimit = limit
}

fun submitList(popularFestivals: List<FestivalItemUiState>) {
foregroundAdapter.submitList(popularFestivals)
backgroundAdapter.submitList(popularFestivals)
fun submitList(festivals: List<FestivalItemUiState>) {
popularFestivals.clear()
popularFestivals.addAll(festivals)
foregroundAdapter.submitList(festivals)
backgroundAdapter.submitList(festivals)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.festago.festago.presentation.ui.home.festivallist.popularfestival.foreground

import android.content.res.Resources
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -14,26 +13,9 @@ class PopularFestivalForegroundViewHolder(

fun bind(item: FestivalItemUiState) {
binding.item = item
binding.ivPopularFestivalImage.outlineProvider
binding.tvPopularFestivalArtistsName.text =
item.artists.joinToString(ARTIST_NAME_JOIN_SEPARATOR) { it.name }
setImageSizeFlexibleToScreenWidth()
}

private fun setImageSizeFlexibleToScreenWidth() {
val imageSize = Resources.getSystem().configuration.screenWidthDp - MINUS_TO_IMAGE_SIZE
val density = Resources.getSystem().displayMetrics.density

binding.ivPopularFestivalImage.layoutParams.apply {
this.width = (imageSize * density + ROUNDUP_CONDITION).toInt()
this.height = (imageSize * density + ROUNDUP_CONDITION).toInt()
}
}

companion object {
private const val MINUS_TO_IMAGE_SIZE = 160
private const val ROUNDUP_CONDITION = 0.5f
private const val ARTIST_NAME_JOIN_SEPARATOR = ", "

fun of(parent: ViewGroup): PopularFestivalForegroundViewHolder {
val binding = ItemPopularFestivalForegroundBinding.inflate(
Expand Down

0 comments on commit 15bfa76

Please sign in to comment.