Skip to content

Commit

Permalink
템플릿탭 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
leesa-l committed Dec 19, 2023
1 parent 6a9e1b9 commit 399f3c2
Show file tree
Hide file tree
Showing 10 changed files with 351 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal object CategoryMapper : Mapper<CategoryResponse, Category> {
id = id,
icon = CategoryIconTypeMapper.mapDomain(icon),
subject = subject,
createdTime = FormattedTimeMapper.mapDomain(createdTime),
createdTime = FormattedTimeMapper.mapCreatedTime(createdTime),
checkedCount = checkedCount,
checkList = checkList.map(CheckItemMapper::mapDomain)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ internal object CheckItemMapper : Mapper<CheckItemResponse, CheckItem> {
content = content,
memo = memo,
quantity = quantity,
createdTime = FormattedTimeMapper.mapDomain(createdTime),
createdTime = FormattedTimeMapper.mapCreatedTime(createdTime),
checked = checked
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ internal object FormattedTimeMapper {
return FormattedTime(unixMillis = unixMillis, formatted = formatted)
}

fun mapCreatedTime(unixMillis: Long, format: String = "yyyy.MM.dd"): FormattedTime {
val formatted = SimpleDateFormat(format, Locale.getDefault()).format(unixMillis)
return FormattedTime(unixMillis = unixMillis, formatted = formatted)
}

fun mapLocalDate(unixMillis: Long): LocalDateTime? {
return LocalDateTime.ofInstant(
Instant.ofEpochMilli(unixMillis),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal object PlanMapper : Mapper<PlanResponse, Plan> {
planType = PlanTypeMapper.mapDomain(planTypeResponse),
owner = OwnerMapper.mapDomain(owner),
isPublic = isPublic,
createdTime = FormattedTimeMapper.mapDomain(createdTime),
createdTime = FormattedTimeMapper.mapCreatedTime(createdTime),
categoryList = categories.map(CategoryMapper::mapDomain),
schedule = schedule?.let { ScheduleMapper.mapDomain(it) } ?: Schedule(
backgroundImageUrl = "",
Expand All @@ -34,7 +34,7 @@ internal object PlanMapper : Mapper<PlanResponse, Plan> {
planType = PlanTypeMapper.mapDomain(planTypeResponse),
owner = OwnerMapper.mapDomain(owner),
isPublic = isPublic,
createdTime = FormattedTimeMapper.mapDomain(createdTime),
createdTime = FormattedTimeMapper.mapCreatedTime(createdTime),
categoryList = categories.map(CategoryMapper::mapDomain),
template = template?.let { TemplateMapper.mapDomain(it) } ?: TemplateDetail(
colorType = ColorType.DAWN, subject = ""
Expand Down
1 change: 1 addition & 0 deletions presentation/home/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dependencies {
implementation(project(":presentation:common"))
implementation(libs.compose.navigation)
implementation(libs.coil.compose)
implementation(libs.lottie.compose)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.statusBarsPadding
Expand Down Expand Up @@ -97,6 +98,20 @@ class Home : MVIComposeFragment<HomeIntent, HomeState, HomeEffect>() {
is TemplateEffect.NavigateToTemplate -> {
deepLink(DeepLink.TemplateDetail(effect.id)) { popUpTo(R.id.home) }
}

is TemplateEffect.NavigateToAddCategory -> {
deepLink(DeepLink.AddCategory(planId = effect.planId)) { popUpTo(R.id.home) }
}

TemplateEffect.DeleteTemplateFail -> {
Toast.makeText(requireContext(), "템플릿 삭제에 실패하였습니다.", Toast.LENGTH_LONG).show()
}
TemplateEffect.GetTemplateListFail -> {
Toast.makeText(requireContext(), "템플릿 불러오기에 실패하였습니다.", Toast.LENGTH_LONG).show()
}
TemplateEffect.SaveTemplateFail -> {
Toast.makeText(requireContext(), "템플릿 저장에 실패하였습니다.", Toast.LENGTH_LONG).show()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@ import androidx.compose.runtime.Stable
import com.dkin.chevit.core.mvi.ViewEffect
import com.dkin.chevit.core.mvi.ViewIntent
import com.dkin.chevit.core.mvi.ViewState
import com.dkin.chevit.presentation.common.model.SortType
import com.dkin.chevit.presentation.home.contents.template.model.Template
import com.dkin.chevit.presentation.resource.TemplateColor

sealed interface TemplateIntent : ViewIntent
sealed interface TemplateIntent : ViewIntent {
object GetTemplateList : TemplateIntent
data class ClickTemplate(val id: String) : TemplateIntent
data class SortTemplate(val type: SortType) : TemplateIntent
data class RemoveTemplate(val planId: String) : TemplateIntent
data class SaveTemplate(val title: String, val color: TemplateColor) : TemplateIntent
data class UpdateTemplate(val id: String, val title: String, val color: TemplateColor) : TemplateIntent
}

@Stable
sealed interface TemplateState : ViewState {
object EMPTY : TemplateState
object Loading : TemplateState
data class Available(
val templateList: List<Template>
) : TemplateState

companion object {
fun empty(): TemplateState = Available(
templateList = listOf()
)

fun dummy(): TemplateState = Available(
listOf(
Template(
Expand Down Expand Up @@ -68,4 +80,8 @@ sealed interface TemplateState : ViewState {

sealed interface TemplateEffect : ViewEffect {
data class NavigateToTemplate(val id: String) : TemplateEffect
data class NavigateToAddCategory(val planId: String) : TemplateEffect
object GetTemplateListFail : TemplateEffect
object DeleteTemplateFail : TemplateEffect
object SaveTemplateFail : TemplateEffect
}
Loading

0 comments on commit 399f3c2

Please sign in to comment.