Skip to content

Commit

Permalink
Merge pull request #513 from mash-up-kr/feature/schedule_daily
Browse files Browse the repository at this point in the history
전체 일정 탭 화면 만들기
  • Loading branch information
014967 authored Jul 3, 2024
2 parents e7d94ab + 38274cc commit 4574297
Show file tree
Hide file tree
Showing 7 changed files with 327 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/com/mashup/ui/schedule/ScheduleRoute.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.mashup.constant.log.LOG_SCHEDULE_EVENT_DETAIL
import com.mashup.constant.log.LOG_SCHEDULE_STATUS_CONFIRM
import com.mashup.core.common.extensions.fromHtml
import com.mashup.core.ui.colors.Brand500
import com.mashup.core.ui.colors.Gray50
import com.mashup.core.ui.colors.White
import com.mashup.core.ui.theme.MashUpTheme
import com.mashup.core.ui.widget.MashUpHtmlText
Expand Down Expand Up @@ -110,12 +111,17 @@ fun ScheduleRoute(
Box(
modifier = modifier
.pullRefresh(pullRefreshState)
.background(White)
.background(color = if (ScheduleType.values()[selectedTabIndex] == ScheduleType.WEEK) Color.White else Gray50)
) {
LazyColumn(modifier = modifier) {
item {
ScheduleTopbar(title)
Spacer(modifier = Modifier.height(26.dp))
Spacer(
modifier = Modifier
.height(26.dp)
.fillMaxWidth()
.background(Color.White)
)
}

stickyHeader {
Expand All @@ -134,9 +140,7 @@ fun ScheduleRoute(
is ScheduleState.Init -> {}
else -> {
ScheduleScreen(
modifier = Modifier
.fillMaxSize()
.background(color = Color.White),
modifier = Modifier.fillMaxSize(),
scheduleState = scheduleState,
onClickScheduleInformation = { context.moveToScheduleInformation(it) },
onClickAttendance = { context.moveToAttendance(it) },
Expand Down Expand Up @@ -197,6 +201,7 @@ fun Context.moveToAttendance(scheduleId: Int) {
fun ScheduleTopbar(title: String) {
Row(
modifier = Modifier
.background(White)
.padding(horizontal = 20.dp)
.padding(top = 24.dp)
.fillMaxWidth(),
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/mashup/ui/schedule/ScheduleScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.mashup.ui.schedule

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import com.mashup.ui.schedule.component.DailySchedule
import com.mashup.ui.schedule.component.WeeklySchedule
import com.mashup.ui.schedule.model.ScheduleType

Expand All @@ -26,6 +27,11 @@ fun ScheduleScreen(
}

ScheduleType.TOTAL -> {
DailySchedule(
scheduleState = scheduleState,
modifier = modifier,
onClickScheduleInformation = onClickScheduleInformation
)
}
}
}
13 changes: 13 additions & 0 deletions app/src/main/java/com/mashup/ui/schedule/ScheduleViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.mashup.ui.schedule

import com.mashup.core.common.base.BaseViewModel
import com.mashup.core.common.extensions.month
import com.mashup.core.common.extensions.year
import com.mashup.core.ui.widget.PlatformType
import com.mashup.data.dto.ScheduleResponse
import com.mashup.data.dto.SchedulesProgress
Expand Down Expand Up @@ -75,6 +77,7 @@ class ScheduleViewModel @Inject constructor(
} else {
response.scheduleList.map { mapperToScheduleCard(it) }
},
monthlyScheduleList = getMonthlyScheduleList(response.scheduleList),
schedulePosition = getSchedulePosition(response.scheduleList),
weeklySchedule = weeklySchedule.map { mapperToScheduleCard(it) },
weeklySchedulePosition = if (weeklySchedule.isEmpty()) {
Expand All @@ -93,6 +96,7 @@ class ScheduleViewModel @Inject constructor(
ScheduleState.Success(
scheduleTitleState = ScheduleTitleState.Empty,
scheduleList = listOf(ScheduleCard.EmptySchedule()),
monthlyScheduleList = emptyList(),
schedulePosition = 0,
weeklySchedule = listOf(ScheduleCard.EmptySchedule()),
weeklySchedulePosition = 0
Expand Down Expand Up @@ -155,6 +159,14 @@ class ScheduleViewModel @Inject constructor(
return ScheduleCard.EmptySchedule(scheduleResponse)
}

private fun getMonthlyScheduleList(scheduleList: List<ScheduleResponse>): List<Pair<String, List<ScheduleResponse>>> {
return scheduleList.groupBy {
val year = it.startedAt.year()
val month = it.startedAt.month()
"${year}${month}"
}.toList()
}

private fun getSchedulePosition(schedules: List<ScheduleResponse>): Int {
return schedules.size - schedules.filter { it.dateCount >= 0 }.size
}
Expand Down Expand Up @@ -185,6 +197,7 @@ sealed interface ScheduleState {
data class Success(
val scheduleTitleState: ScheduleTitleState,
val scheduleList: List<ScheduleCard>,
val monthlyScheduleList: List<Pair<String, List<ScheduleResponse>>>,
val weeklySchedule: List<ScheduleCard>,
val schedulePosition: Int,
val weeklySchedulePosition: Int
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.mashup.ui.schedule.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import com.mashup.core.ui.colors.Gray50
import com.mashup.core.ui.colors.Gray600
import com.mashup.core.ui.typography.Body5
import com.mashup.ui.schedule.ScheduleState
import com.mashup.ui.schedule.daily.DailyScheduleByMonth
import com.mashup.core.common.R as CR

@Composable
fun DailySchedule(
scheduleState: ScheduleState,
modifier: Modifier = Modifier,
onClickScheduleInformation: (Int) -> Unit = {}
) {
var cacheScheduleState by remember {
mutableStateOf(scheduleState)
}

LaunchedEffect(scheduleState) {
if (scheduleState is ScheduleState.Success) {
cacheScheduleState = scheduleState
}
}

(cacheScheduleState as? ScheduleState.Success)?.let { state ->
if (state.monthlyScheduleList.isEmpty()) {
Column(
modifier = Modifier
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally
) {
Spacer(modifier = Modifier.height(200.dp))
Image(
painter = painterResource(id = CR.drawable.img_placeholder_sleeping),
contentDescription = null,
modifier = Modifier.size(88.dp)
)
Spacer(modifier = Modifier.height(12.dp))
Text(
text = "열심히 일정을 준비하고 있어요\n조금만 기다려 주세요!",
style = Body5.copy(color = Gray600),
textAlign = TextAlign.Center
)
}
} else {
Spacer(modifier = Modifier.height(22.dp))
state.monthlyScheduleList.forEach { (title, scheduleList) ->
DailyScheduleByMonth(
title = title,
scheduleList = scheduleList,
modifier = Modifier
.background(Gray50)
.padding(horizontal = 20.dp),
isWeeklySchedule = { scheduleId ->
state.weeklySchedule.any { scheduleId == it.getScheduleId() }
},
onClickScheduleInformation = onClickScheduleInformation
)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package com.mashup.ui.schedule.daily

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mashup.core.common.extensions.day
import com.mashup.core.common.extensions.week
import com.mashup.core.ui.colors.Gray500
import com.mashup.core.ui.theme.MashUpTheme
import com.mashup.core.ui.typography.Body3
import com.mashup.core.ui.typography.Caption2
import com.mashup.core.ui.typography.Title3
import com.mashup.data.dto.ScheduleResponse

/**
* DailyScheduleByMonth.kt
*
* Created by Minji Jeong on 2024/06/29
* Copyright © 2024 MashUp All rights reserved.
*/

@Composable
fun DailyScheduleByMonth(
title: String,
scheduleList: List<ScheduleResponse>,
modifier: Modifier = Modifier,
isWeeklySchedule: (Int) -> Boolean = { false },
onClickScheduleInformation: (Int) -> Unit = {}
) {
Column(modifier = modifier) {
Text(title, style = Title3)
Spacer(modifier = Modifier.height(18.dp))
scheduleList
.groupBy { it.startedAt.day() }
.forEach { (_, dailySchedule) ->
DailyScheduleByDay(dailySchedule, isWeeklySchedule, onClickScheduleInformation)
}
}
}

@Composable
fun DailyScheduleByDay(
schedule: List<ScheduleResponse>,
isWeeklySchedule: (Int) -> Boolean,
onClickScheduleInformation: (Int) -> Unit
) {
Row(modifier = Modifier.padding(bottom = 32.dp)) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier.padding(top = 14.dp, end = 14.dp)
) {
Text(text = "${schedule[0].startedAt.day()}", style = Body3)
Text(text = schedule[0].startedAt.week(), style = Caption2.copy(color = Gray500))
}

Column {
schedule.forEach {
val highlight = isWeeklySchedule.invoke(it.scheduleId)
DailyScheduleItem(
title = it.name,
time = it.getTimeLine(),
place = it.location?.detailAddress ?: "-",
highlight = highlight,
modifier = Modifier.padding(bottom = 12.dp),
onClickScheduleInformation = { onClickScheduleInformation.invoke(it.scheduleId) }
)
}
}
}
}

@Preview
@Composable
fun PreviewDailySchedule() {
MashUpTheme {
DailyScheduleByMonth("2024년 8월", emptyList())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.mashup.ui.schedule.daily

import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import com.mashup.core.ui.colors.Brand500
import com.mashup.core.ui.colors.Gray100
import com.mashup.core.ui.colors.White
import com.mashup.core.ui.theme.MashUpTheme
import com.mashup.core.ui.typography.SubTitle1
import com.mashup.ui.schedule.detail.composable.ScheduleInfoText
import com.mashup.core.common.R as CR

/**
* TotalScheduleItem.kt
*
* Created by Minji Jeong on 2024/06/29
* Copyright © 2024 MashUp All rights reserved.
*/

@Composable
fun DailyScheduleItem(
title: String,
time: String,
place: String,
highlight: Boolean,
modifier: Modifier = Modifier,
onClickScheduleInformation: () -> Unit = {}
) {
val borderColor = if (highlight) {
listOf(Brand500, Color(0xFF31C1FF))
} else {
listOf(Gray100, Gray100)
}

Column(
modifier = modifier
.fillMaxWidth()
.clip(RoundedCornerShape(16.dp))
.clickable { onClickScheduleInformation() }
.background(White)
.border(
width = if (highlight) (1.5).dp else 1.dp,
brush = Brush.horizontalGradient(borderColor),
shape = RoundedCornerShape(16.dp)
)
.padding(horizontal = 20.dp, vertical = 16.dp)
) {
Text(text = title, style = SubTitle1)
Spacer(modifier = Modifier.height(4.dp))
ScheduleInfoText(iconRes = CR.drawable.ic_clock, info = time)
Spacer(modifier = Modifier.height(4.dp))
ScheduleInfoText(iconRes = CR.drawable.ic_mappin, info = place)
}
}

@Preview
@Composable
fun PreviewDailyScheduleItemHighlight() {
MashUpTheme {
DailyScheduleItem(
"안드로이드 팀 세미나",
"오후 3:00 - 오전 7:00",
"디스코드",
true
)
}
}

@Preview
@Composable
fun PreviewDailyScheduleItem() {
MashUpTheme {
DailyScheduleItem(
"안드로이드 팀 세미나",
"오후 3:00 - 오전 7:00",
"디스코드",
false
)
}
}
Loading

0 comments on commit 4574297

Please sign in to comment.