-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
190 additions
and
2 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
core/common/src/main/java/com/peonlee/common/ext/LocalDateExtension.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
feature/home/src/main/java/com/peonlee/home/adapter/viewholder/event/EventViewHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
feature/home/src/main/java/com/peonlee/home/model/event/EventUiModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters