From 8a21093c14b24f25621e76f69101e890f001fc16 Mon Sep 17 00:00:00 2001 From: aurora32s Date: Sun, 8 Oct 2023 21:09:49 +0900 Subject: [PATCH] =?UTF-8?q?[UI]=20#119=20-=20=ED=99=88=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=EC=97=90=20=EC=9D=B4=EB=B2=A4=ED=8A=B8=20=EB=A6=AC?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=95=84=EC=9D=B4=ED=85=9C=20UI=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../peonlee/common/ext/LocalDateExtension.kt | 7 ++ .../main/java/com/peonlee/model/ListItem.kt | 3 +- .../core/ui/designsystem/chip/SmallChip.kt | 7 ++ .../java/com/peonlee/home/HomeViewModel.kt | 4 +- .../com/peonlee/home/adapter/HomeAdapter.kt | 7 ++ .../viewholder/event/EventViewHolder.kt | 55 ++++++++++++++ .../peonlee/home/model/event/EventUiModel.kt | 30 ++++++++ .../main/res/layout/list_item_home_event.xml | 76 +++++++++++++++++++ feature/home/src/main/res/values/strings.xml | 3 + 9 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 core/common/src/main/java/com/peonlee/common/ext/LocalDateExtension.kt create mode 100644 feature/home/src/main/java/com/peonlee/home/adapter/viewholder/event/EventViewHolder.kt create mode 100644 feature/home/src/main/java/com/peonlee/home/model/event/EventUiModel.kt create mode 100644 feature/home/src/main/res/layout/list_item_home_event.xml diff --git a/core/common/src/main/java/com/peonlee/common/ext/LocalDateExtension.kt b/core/common/src/main/java/com/peonlee/common/ext/LocalDateExtension.kt new file mode 100644 index 00000000..c19f242d --- /dev/null +++ b/core/common/src/main/java/com/peonlee/common/ext/LocalDateExtension.kt @@ -0,0 +1,7 @@ +package com.peonlee.common.ext + +import java.time.LocalDate + +fun LocalDate.format(separator: String): String { + return listOf(year, monthValue, dayOfMonth).joinToString(separator = separator) +} diff --git a/core/model/src/main/java/com/peonlee/model/ListItem.kt b/core/model/src/main/java/com/peonlee/model/ListItem.kt index 30a8445a..269b40fb 100644 --- a/core/model/src/main/java/com/peonlee/model/ListItem.kt +++ b/core/model/src/main/java/com/peonlee/model/ListItem.kt @@ -14,5 +14,6 @@ enum class MainHomeViewType { DIVIDER, // 구분선 CONDITIONAL_PRODUCTS, // 조건별 상품 리스트 RECENT_REVIEW, // 최신 리뷰 - EVENT_BY_STORE + EVENT_BY_STORE, + EVENT // 이벤트 } diff --git a/core/ui/src/main/java/com/peonlee/core/ui/designsystem/chip/SmallChip.kt b/core/ui/src/main/java/com/peonlee/core/ui/designsystem/chip/SmallChip.kt index 01705fdb..b55c3019 100644 --- a/core/ui/src/main/java/com/peonlee/core/ui/designsystem/chip/SmallChip.kt +++ b/core/ui/src/main/java/com/peonlee/core/ui/designsystem/chip/SmallChip.kt @@ -17,6 +17,13 @@ class SmallChip( styleable = R.styleable.SmallChip ) { + override var text: String = "" + get() = super.text + set(value) { + binding.tvSmallChipTitle.text = value + field = value + } + init { applyAttributes(attributeSet) } diff --git a/feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt b/feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt index 63619c35..6edea3bd 100644 --- a/feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt +++ b/feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt @@ -7,6 +7,8 @@ import com.peonlee.data.model.Product import com.peonlee.data.model.home.HomeComment import com.peonlee.domain.login.GetHomeProductUseCase import com.peonlee.home.model.divider.HomeDividerUiModel +import com.peonlee.home.model.event.EVENT_DUMMY +import com.peonlee.home.model.event.EventUiModel import com.peonlee.home.model.product.ConditionalProductsUiModel import com.peonlee.home.model.product.EventByStoresUiModel import com.peonlee.home.model.product.ProductsByStoreUiModel @@ -91,6 +93,6 @@ class HomeViewModel @Inject constructor( return listOf( HomeDividerUiModel(id = 10), TitleUiModel(id = 11, title = "진행중인 이벤트") - ) + ) + EVENT_DUMMY } } diff --git a/feature/home/src/main/java/com/peonlee/home/adapter/HomeAdapter.kt b/feature/home/src/main/java/com/peonlee/home/adapter/HomeAdapter.kt index 06e7dfa7..0bf9f851 100644 --- a/feature/home/src/main/java/com/peonlee/home/adapter/HomeAdapter.kt +++ b/feature/home/src/main/java/com/peonlee/home/adapter/HomeAdapter.kt @@ -6,6 +6,7 @@ import com.peonlee.core.ui.Navigator import com.peonlee.core.ui.adapter.MultiTypeListAdapter import com.peonlee.core.ui.viewholder.CommonViewHolder import com.peonlee.home.adapter.viewholder.divider.HomeDividerViewHolder +import com.peonlee.home.adapter.viewholder.event.EventViewHolder import com.peonlee.home.adapter.viewholder.product.ConditionalProductsViewHolder import com.peonlee.home.adapter.viewholder.product.EventByStoresViewHolder import com.peonlee.home.adapter.viewholder.review.RecentReviewViewHolder @@ -13,6 +14,7 @@ import com.peonlee.home.adapter.viewholder.title.TitleViewHolder import com.peonlee.home.databinding.ListItemConditionalProductsBinding import com.peonlee.home.databinding.ListItemEventStoresBinding import com.peonlee.home.databinding.ListItemHomeDividerBinding +import com.peonlee.home.databinding.ListItemHomeEventBinding import com.peonlee.home.databinding.ListItemRecentReviewBinding import com.peonlee.home.databinding.ListItemTitleBinding import com.peonlee.model.MainHomeListItem @@ -45,6 +47,11 @@ class HomeAdapter( navigator, moveToStoreExplore ) + + MainHomeViewType.EVENT -> EventViewHolder( + ListItemHomeEventBinding.inflate(inflater, parent, false), + navigator + ) } } } diff --git a/feature/home/src/main/java/com/peonlee/home/adapter/viewholder/event/EventViewHolder.kt b/feature/home/src/main/java/com/peonlee/home/adapter/viewholder/event/EventViewHolder.kt new file mode 100644 index 00000000..56c6caf8 --- /dev/null +++ b/feature/home/src/main/java/com/peonlee/home/adapter/viewholder/event/EventViewHolder.kt @@ -0,0 +1,55 @@ +package com.peonlee.home.adapter.viewholder.event + +import coil.load +import com.peonlee.common.ext.format +import com.peonlee.core.ui.Navigator +import com.peonlee.core.ui.extensions.getStringWithArgs +import com.peonlee.core.ui.viewholder.CommonViewHolder +import com.peonlee.home.databinding.ListItemHomeEventBinding +import com.peonlee.home.model.event.EventUiModel +import com.peonlee.model.type.StoreType +import java.time.LocalDate +import java.time.temporal.ChronoUnit +import com.peonlee.core.ui.R as UR +import com.peonlee.home.R as HR + +/** + * 홈 화면 event item + */ +class EventViewHolder( + private val binding: ListItemHomeEventBinding, + private val navigator: Navigator +) : CommonViewHolder(binding) { + override fun onBindView(item: EventUiModel) { + with(binding) { + txtStore.text = item.store.storeName + imgStore.setImageResource(getIconByStore(item.store)) + + // 이벤트 정보 + imgEvent.load(item.imageUrl) + txtEvent.text = item.title + txtDuration.text = getStringWithArgs( + HR.string.item_event_duration, + item.startedDate.format("."), + item.endedDate.format(".") + ) + val extraDays = ChronoUnit.DAYS.between(LocalDate.now(), item.endedDate) + txtExtra.text = getStringWithArgs( + HR.string.item_event_extra, + when { + extraDays < 0L -> "종료" + extraDays == 0L -> "Day" + else -> extraDays.toString() + } + ) + } + } + + companion object { + private fun getIconByStore(storeType: StoreType): Int = when (storeType) { + StoreType.CU -> UR.drawable.ic_store_cu + StoreType.GS25 -> UR.drawable.ic_store_gs25 + StoreType.SEVEN -> UR.drawable.ic_store_seveneleven + } + } +} diff --git a/feature/home/src/main/java/com/peonlee/home/model/event/EventUiModel.kt b/feature/home/src/main/java/com/peonlee/home/model/event/EventUiModel.kt new file mode 100644 index 00000000..75fc56bb --- /dev/null +++ b/feature/home/src/main/java/com/peonlee/home/model/event/EventUiModel.kt @@ -0,0 +1,30 @@ +package com.peonlee.home.model.event + +import com.peonlee.model.MainHomeListItem +import com.peonlee.model.MainHomeViewType +import com.peonlee.model.type.StoreType +import java.time.LocalDate + +/** + * 홈 화면에 필요한 이벤트 탭 + */ +data class EventUiModel( + override val id: Long, + override val viewType: MainHomeViewType = MainHomeViewType.EVENT, + val title: String, // 제목 + val imageUrl: String, // 이벤트 이미지 경로 + val store: StoreType, // 편의점 + val startedDate: LocalDate, // 시작 날짜 + val endedDate: LocalDate // 끝나는 날짜 +) : MainHomeListItem + +val EVENT_DUMMY = (0..2).map { + EventUiModel( + id = it.toLong() * 10000000, + title = "이벤트 $it", + imageUrl = "https://www.7-eleven.co.kr/upload/event//thumbnail/20230926132326644r210.jpg", + store = StoreType.SEVEN, + startedDate = LocalDate.now().minusDays(10), + endedDate = LocalDate.now().plusDays(it.toLong()) + ) +} diff --git a/feature/home/src/main/res/layout/list_item_home_event.xml b/feature/home/src/main/res/layout/list_item_home_event.xml new file mode 100644 index 00000000..739dc00c --- /dev/null +++ b/feature/home/src/main/res/layout/list_item_home_event.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/feature/home/src/main/res/values/strings.xml b/feature/home/src/main/res/values/strings.xml index 429426ce..81913b5b 100644 --- a/feature/home/src/main/res/values/strings.xml +++ b/feature/home/src/main/res/values/strings.xml @@ -6,4 +6,7 @@ %s · %s 또 먹을거에요 또 안사먹어요 + + %s ~ %s + D-%s \ No newline at end of file