Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI] #119 홈 화면에 이벤트 탭 추가 UI작업 #120

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
4 changes: 3 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,7 @@ enum class MainHomeViewType {
DIVIDER, // 구분선
CONDITIONAL_PRODUCTS, // 조건별 상품 리스트
RECENT_REVIEW, // 최신 리뷰
EVENT_BY_STORE
EVENT_BY_STORE,
EVENT, // 이벤트
BUTTON
}
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
14 changes: 14 additions & 0 deletions feature/home/src/main/java/com/peonlee/home/HomeViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import com.peonlee.data.handle
import com.peonlee.data.model.Product
import com.peonlee.data.model.home.HomeComment
import com.peonlee.domain.login.GetHomeProductUseCase
import com.peonlee.home.model.button.ButtonUiModel
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 @@ -37,6 +40,7 @@ class HomeViewModel @Inject constructor(
onSuccess = { allInfo ->
_products.value = getConditionalProductsItem(1, SortType.RECENT, "주목할 신상", allInfo.newProductList) +
getConditionalProductsItem(3, SortType.POPULAR, "꾸준한 인기상품이에요", allInfo.popularProductList) +
getEventListItem() +
getEventProductsItem(allInfo.promotionProductMap) +
getRecentComment(allInfo.recentProductCommentList)
}
Expand Down Expand Up @@ -85,4 +89,14 @@ class HomeViewModel @Inject constructor(
TitleUiModel(id = 9, title = "최근 리뷰")
) + comment.map { it.toUiModel() }
}

private fun getEventListItem(): List<MainHomeListItem> {
return listOf(
HomeDividerUiModel(id = 10),
TitleUiModel(id = 11, title = "진행중인 이벤트")
) + EVENT_DUMMY +
ButtonUiModel(
id = 12, text = "더 많은 이벤트 보기"
)
}
}
13 changes: 13 additions & 0 deletions feature/home/src/main/java/com/peonlee/home/adapter/HomeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import android.view.ViewGroup
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.button.ButtonViewHolder
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.ListItemButtonBinding
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 +49,15 @@ class HomeAdapter(
navigator,
moveToStoreExplore
)
MainHomeViewType.BUTTON -> ButtonViewHolder(
ListItemButtonBinding.inflate(inflater, parent, false),
navigator
)

MainHomeViewType.EVENT -> EventViewHolder(
ListItemHomeEventBinding.inflate(inflater, parent, false),
navigator
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.peonlee.home.adapter.viewholder.button

import com.peonlee.core.ui.Navigator
import com.peonlee.core.ui.viewholder.CommonViewHolder
import com.peonlee.home.databinding.ListItemButtonBinding
import com.peonlee.home.model.button.ButtonUiModel

class ButtonViewHolder(
private val binding: ListItemButtonBinding,
private val navigator: Navigator
) : CommonViewHolder<ButtonUiModel>(binding) {
override fun onBindView(item: ButtonUiModel) {
binding.btnButton.text = item.text
}
}
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,10 @@
package com.peonlee.home.model.button

import com.peonlee.model.MainHomeListItem
import com.peonlee.model.MainHomeViewType

data class ButtonUiModel(
override val id: Long,
override val viewType: MainHomeViewType = MainHomeViewType.BUTTON,
val text: String
) : MainHomeListItem
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())
)
}
11 changes: 11 additions & 0 deletions feature/home/src/main/res/layout/list_item_button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<com.peonlee.core.ui.designsystem.button.LargeButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btnButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/item_button_horizontal_margin"
android:layout_marginTop="@dimen/item_button_top_margin"
android:layout_marginBottom="@dimen/item_button_bottom_margin"
android:background="@drawable/bg_white_outline_radius_10dp"
android:backgroundTint="@color/bg10"/>
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>
Loading