feat(gift): 선물함 표시 정책을 추가한다
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift
|
||||
|
||||
import androidx.annotation.StringRes
|
||||
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||
|
||||
enum class GiftInboxViewMode { ALL, SENT, RECEIVED }
|
||||
enum class GiftInboxDirection { SENT, RECEIVED }
|
||||
enum class GiftInboxRowType { NOTICE, ADDRESS, SENT, RECEIVED, EMPTY_RECEIVED, INQUIRY, LOADING, RETRY }
|
||||
|
||||
data class GiftInboxCardUiModel(
|
||||
val applicationNo: String,
|
||||
val direction: GiftInboxDirection,
|
||||
val status: ToastMessage,
|
||||
@param:StringRes val subtitleRes: Int?,
|
||||
val createdDate: String,
|
||||
@param:StringRes val dateLabelRes: Int,
|
||||
val sizeName: String,
|
||||
val categoryName: String,
|
||||
val addressRequired: Boolean,
|
||||
val counterpartMemberId: Long,
|
||||
val counterpartNickname: String,
|
||||
val counterpartProfileImageUrl: String?
|
||||
)
|
||||
|
||||
sealed class GiftInboxRow(val type: GiftInboxRowType) {
|
||||
data class Notice(val received: Boolean) : GiftInboxRow(GiftInboxRowType.NOTICE)
|
||||
data class Address(val card: GiftInboxCardUiModel) : GiftInboxRow(GiftInboxRowType.ADDRESS)
|
||||
data class Card(val card: GiftInboxCardUiModel) : GiftInboxRow(
|
||||
if (card.direction == GiftInboxDirection.SENT) GiftInboxRowType.SENT else GiftInboxRowType.RECEIVED
|
||||
)
|
||||
data object EmptyReceived : GiftInboxRow(GiftInboxRowType.EMPTY_RECEIVED)
|
||||
data object Inquiry : GiftInboxRow(GiftInboxRowType.INQUIRY)
|
||||
data object Loading : GiftInboxRow(GiftInboxRowType.LOADING)
|
||||
data object Retry : GiftInboxRow(GiftInboxRowType.RETRY)
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package kr.co.vividnext.sodalive.v2.gift
|
||||
|
||||
import kr.co.vividnext.sodalive.R
|
||||
import kr.co.vividnext.sodalive.common.ToastMessage
|
||||
import kr.co.vividnext.sodalive.v2.gift.data.GiftInboxItemResponse
|
||||
|
||||
object GiftInboxPresenter {
|
||||
fun toCard(item: GiftInboxItemResponse): GiftInboxCardUiModel {
|
||||
val received = item.direction == "RECEIVED"
|
||||
val statusRes = if (received) {
|
||||
when (item.status) {
|
||||
"TRACKING_REGISTERED" -> R.string.gift_inbox_address_required
|
||||
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_inspecting
|
||||
"INSPECTION_COMPLETED" -> R.string.gift_inbox_inspected
|
||||
"DELIVERED" -> R.string.gift_inbox_delivered
|
||||
"UNDELIVERABLE" -> R.string.gift_inbox_undeliverable
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
when (item.status) {
|
||||
"RECEIVED" -> R.string.gift_inbox_tracking_required
|
||||
"TRACKING_REGISTERED" -> R.string.gift_inbox_sent_confirmed
|
||||
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_arrived
|
||||
"INSPECTION_COMPLETED" -> R.string.gift_inbox_inspected
|
||||
"DELIVERED" -> R.string.gift_inbox_delivered
|
||||
"UNDELIVERABLE" -> R.string.gift_inbox_undeliverable
|
||||
"CANCELED" -> R.string.gift_inbox_canceled
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
val subtitle = if (received) {
|
||||
when (item.status) {
|
||||
"TRACKING_REGISTERED" -> R.string.gift_inbox_expected
|
||||
"ARRIVED_AT_MAILBOX" -> R.string.gift_inbox_checking
|
||||
"INSPECTION_COMPLETED" -> R.string.gift_inbox_shipping
|
||||
else -> null
|
||||
}
|
||||
} else {
|
||||
null
|
||||
}
|
||||
return GiftInboxCardUiModel(
|
||||
applicationNo = item.applicationNo,
|
||||
direction = if (received) GiftInboxDirection.RECEIVED else GiftInboxDirection.SENT,
|
||||
status = if (statusRes != null) ToastMessage(resId = statusRes) else ToastMessage(message = item.statusName),
|
||||
subtitleRes = subtitle,
|
||||
createdDate = item.createdAt?.substringBefore('T')?.replace('-', '.').orEmpty(),
|
||||
dateLabelRes = R.string.gift_inbox_applied_date,
|
||||
sizeName = item.sizeName,
|
||||
categoryName = item.categoryName,
|
||||
addressRequired = received && item.status == "TRACKING_REGISTERED",
|
||||
counterpartMemberId = item.counterpartMemberId,
|
||||
counterpartNickname = item.counterpartNickname,
|
||||
counterpartProfileImageUrl = item.counterpartProfileImageUrl?.takeIf { it.isNotBlank() }
|
||||
)
|
||||
}
|
||||
|
||||
fun toUiModels(
|
||||
items: List<GiftInboxItemResponse>,
|
||||
viewMode: GiftInboxViewMode,
|
||||
isCreator: Boolean,
|
||||
isAppending: Boolean = false,
|
||||
canRetry: Boolean = false
|
||||
): List<GiftInboxRow> {
|
||||
val cards = items.filter { viewMode == GiftInboxViewMode.ALL || it.direction == viewMode.name }.map(::toCard)
|
||||
val rows = if (cards.isEmpty()) {
|
||||
val received = viewMode == GiftInboxViewMode.RECEIVED || (viewMode == GiftInboxViewMode.ALL && isCreator)
|
||||
listOf(if (received) GiftInboxRow.EmptyReceived else GiftInboxRow.Notice(false))
|
||||
} else {
|
||||
buildList {
|
||||
if (cards.any { it.direction == GiftInboxDirection.SENT }) add(GiftInboxRow.Notice(false))
|
||||
val hasReceived = cards.any { it.direction == GiftInboxDirection.RECEIVED }
|
||||
if (hasReceived) add(GiftInboxRow.Notice(true))
|
||||
cards.firstOrNull { it.addressRequired }?.let { add(GiftInboxRow.Address(it)) }
|
||||
addAll(cards.map(GiftInboxRow::Card))
|
||||
if (hasReceived) add(GiftInboxRow.Inquiry)
|
||||
}
|
||||
}
|
||||
return rows + when {
|
||||
isAppending -> listOf(GiftInboxRow.Loading)
|
||||
canRetry -> listOf(GiftInboxRow.Retry)
|
||||
else -> emptyList()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user