Skip to content

Commit

Permalink
[UI] #119 - 홈 화면에 이벤트 리스트 아이템 UI 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
aurora32s committed Oct 8, 2023
1 parent fd9dd76 commit 8a21093
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -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)
}
3 changes: 2 additions & 1 deletion core/model/src/main/java/com/peonlee/model/ListItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ enum class MainHomeViewType {
DIVIDER, // 구분선
CONDITIONAL_PRODUCTS, // 조건별 상품 리스트
RECENT_REVIEW, // 최신 리뷰
EVENT_BY_STORE
EVENT_BY_STORE,
EVENT // 이벤트
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
4 changes: 3 additions & 1 deletion feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -91,6 +93,6 @@ class HomeViewModel @Inject constructor(
return listOf(
HomeDividerUiModel(id = 10),
TitleUiModel(id = 11, title = "진행중인 이벤트")
)
) + EVENT_DUMMY
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ 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
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
Expand Down Expand Up @@ -45,6 +47,11 @@ class HomeAdapter(
navigator,
moveToStoreExplore
)

MainHomeViewType.EVENT -> EventViewHolder(
ListItemHomeEventBinding.inflate(inflater, parent, false),
navigator
)
}
}
}
Original file line number Diff line number Diff line change
@@ -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<EventUiModel>(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
}
}
}
Original file line number Diff line number Diff line change
@@ -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())
)
}
76 changes: 76 additions & 0 deletions feature/home/src/main/res/layout/list_item_home_event.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingHorizontal="18dp"
android:paddingVertical="12dp">

<androidx.cardview.widget.CardView
android:id="@+id/layoutEventImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:cardCornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/imgEvent"
android:layout_width="100dp"
android:layout_height="100dp" />
</androidx.cardview.widget.CardView>

<ImageView
android:id="@+id/imgStore"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginStart="12dp"
android:src="@drawable/ic_store_seveneleven"
app:layout_constraintBottom_toBottomOf="@id/txtExtra"
app:layout_constraintStart_toEndOf="@id/layoutEventImage"
app:layout_constraintTop_toTopOf="@id/txtExtra"
tools:src="@drawable/ic_store_cu" />

<TextView
android:id="@+id/txtStore"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
app:layout_constraintBottom_toBottomOf="@id/txtExtra"
app:layout_constraintStart_toEndOf="@id/imgStore"
app:layout_constraintTop_toTopOf="@id/txtExtra" />

<com.peonlee.core.ui.designsystem.chip.SmallChip
android:id="@+id/txtExtra"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginBottom="4dp"
app:layout_constraintBottom_toTopOf="@id/txtEvent"
app:layout_constraintStart_toEndOf="@id/txtStore"
app:layout_constraintTop_toTopOf="@id/layoutEventImage"
app:layout_constraintVertical_chainStyle="packed" />

<TextView
android:id="@+id/txtEvent"
style="@style/Text.Subtitle03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="4dp"
android:textColor="@color/bg80"
app:layout_constraintBottom_toTopOf="@id/txtDuration"
app:layout_constraintStart_toStartOf="@id/imgStore"
app:layout_constraintTop_toBottomOf="@id/txtExtra" />

<TextView
android:id="@+id/txtDuration"
style="@style/Text.Body06"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/bg40"
app:layout_constraintBottom_toBottomOf="@id/layoutEventImage"
app:layout_constraintStart_toStartOf="@id/imgStore"
app:layout_constraintTop_toBottomOf="@id/txtEvent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3 changes: 3 additions & 0 deletions feature/home/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
<string name="item_recent_review_user_and_date">%s · %s</string>
<string name="item_recent_review_recommended">또 먹을거에요</string>
<string name="item_recent_review_none_recommended">또 안사먹어요</string>
<!-- 이벤트 item -->
<string name="item_event_duration">%s ~ %s</string>
<string name="item_event_extra">D-%s</string>
</resources>

0 comments on commit 8a21093

Please sign in to comment.