Skip to content

Commit

Permalink
Merge pull request #119 from pknu-wap/feature/tgyuu/#113
Browse files Browse the repository at this point in the history
Feature/tgyuu/#113
  • Loading branch information
tgyuuAn authored Feb 6, 2024
2 parents 20b026e + 00dcef5 commit dadd9ab
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 69 deletions.
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ android {
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro",
)
signingConfig = signingConfigs.getByName("debug")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
package com.wap.wapp.feature.notice

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
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.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Divider
import androidx.compose.material.Text
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.SheetState
import androidx.compose.material3.SheetValue
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -27,7 +34,6 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.wap.designsystem.WappTheme
import com.wap.designsystem.component.CircleLoader
import com.wap.wapp.core.commmon.util.DateUtil
import com.wap.wapp.core.commmon.util.DateUtil.HHmmFormatter
import com.wap.wapp.core.commmon.util.DateUtil.MONTH_DATE_START_INDEX
import com.wap.wapp.core.commmon.util.DateUtil.yyyyMMddFormatter
Expand All @@ -36,9 +42,11 @@ import java.time.LocalDate
import java.time.format.TextStyle
import java.util.Locale

@OptIn(ExperimentalMaterial3Api::class)
@Composable
internal fun BottomSheetContent(
expandableHeight: Dp,
bottomSheetState: SheetState,
events: NoticeViewModel.EventsState,
selectedDate: LocalDate,
) {
Expand All @@ -56,21 +64,29 @@ internal fun BottomSheetContent(
text = "$date $dayOfWeek",
style = WappTheme.typography.titleBold,
color = WappTheme.colors.white,
modifier = Modifier.padding(start = 15.dp, bottom = 15.dp),
modifier = Modifier.padding(start = 15.dp, bottom = 5.dp),
)
HandleEventsState(events = events)
}
}

@Composable
private fun HandleEventsState(events: NoticeViewModel.EventsState) = when (events) {
is NoticeViewModel.EventsState.Loading -> CircleLoader(modifier = Modifier.fillMaxWidth())
is NoticeViewModel.EventsState.Success -> EventsList(events.events)
is NoticeViewModel.EventsState.Failure -> Unit
when (events) {
is NoticeViewModel.EventsState.Loading ->
CircleLoader(modifier = Modifier.fillMaxWidth())

is NoticeViewModel.EventsState.Success -> EventsList(
bottomSheetState = bottomSheetState,
events = events.events,
)

is NoticeViewModel.EventsState.Failure -> Unit
}
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun EventsList(events: List<Event>) {
private fun EventsList(
bottomSheetState: SheetState,
events: List<Event>,
) {
if (events.isNotEmpty()) {
LazyColumn(
contentPadding = PaddingValues(horizontal = 15.dp),
Expand All @@ -81,7 +97,10 @@ private fun EventsList(events: List<Event>) {
items = events,
key = { event -> event.eventId },
) { event ->
EventItem(event = event)
EventItem(
bottomSheetState = bottomSheetState,
event = event,
)
}
}
} else {
Expand All @@ -107,49 +126,69 @@ private fun EventsList(events: List<Event>) {
}
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
private fun EventItem(event: Event) {
Column {
private fun EventItem(
bottomSheetState: SheetState,
event: Event,
) {
Column(modifier = Modifier.animateContentSize()) {
Row(
modifier = Modifier
.background(WappTheme.colors.black25)
.fillMaxWidth()
.padding(top = 5.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
.animateContentSize()
.padding(vertical = 10.dp)
.height(IntrinsicSize.Min)
.fillMaxWidth(),
) {
Text(
text = event.startDateTime.toLocalTime().format(DateUtil.HHmmFormatter),
text = event.startDateTime.toLocalTime().format(HHmmFormatter),
style = WappTheme.typography.contentBold,
color = WappTheme.colors.white,
)
Box(

Spacer(
modifier = Modifier
.padding(10.dp)
.size(width = 4.dp, height = 20.dp)
.width(4.dp)
.animateContentSize()
.fillMaxHeight()
.clip(RoundedCornerShape(10.dp))
.background(WappTheme.colors.yellow34),
)
Column(
horizontalAlignment = Alignment.Start,
modifier = Modifier.padding(start = 12.dp),
) {

Column(horizontalAlignment = Alignment.Start) {
Text(
text = event.title,
style = WappTheme.typography.contentRegular,
color = WappTheme.colors.white,
)

AnimatedVisibility(bottomSheetState.currentValue == SheetValue.Expanded) {
Column(horizontalAlignment = Alignment.Start) {
Text(
text = event.location,
style = WappTheme.typography.captionRegular,
color = WappTheme.colors.yellow34,
)

Text(
text = event.content,
style = WappTheme.typography.captionRegular,
color = WappTheme.colors.grayBD,
)
}
}

Text(
text = event.startDateTime.format(HHmmFormatter) + " ~ " +
event.endDateTime.format(HHmmFormatter),
style = WappTheme.typography.captionRegular,
color = WappTheme.colors.grayBD,
color = WappTheme.colors.yellow34,
)
}
}
Divider(
color = WappTheme.colors.gray82,
thickness = 1.dp,
modifier = Modifier.padding(top = 15.dp),
)

Divider(color = WappTheme.colors.gray82)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ internal fun Calendar(
measureDefaultModifier: Modifier,
measureExpandableModifier: Modifier,
onDateSelected: (LocalDate) -> Unit,
onCalendarMonthChanged: () -> Unit,
) {
Column(
modifier = measureDefaultModifier,
Expand All @@ -62,14 +63,27 @@ internal fun Calendar(
bottomSheetState = bottomSheetState,
selectedDate = selectedDate,
onDateSelected = onDateSelected,
onCalendarMonthChanged = onCalendarMonthChanged,
modifier = measureExpandableModifier,
)

handleMonthEventsState(
eventsState = monthEventsState,
selectedDate = selectedDate,
onDateSelected = onDateSelected,
)
when (monthEventsState) {
is NoticeViewModel.EventsState.Loading ->
CircleLoader(modifier = Modifier.fillMaxSize())

is NoticeViewModel.EventsState.Success -> {
val eventDates = monthEventsState.events.map {
it.startDateTime.toLocalDate()
}
CalendarBody(
selectedDate = selectedDate,
eventsDate = eventDates,
onDateSelected = onDateSelected,
)
}

is NoticeViewModel.EventsState.Failure -> {}
}
}
}

Expand All @@ -80,6 +94,7 @@ private fun CalendarHeader(
bottomSheetState: SheetState,
selectedDate: LocalDate,
onDateSelected: (LocalDate) -> Unit,
onCalendarMonthChanged: () -> Unit,
modifier: Modifier,
) = Box(
modifier = modifier,
Expand Down Expand Up @@ -110,7 +125,10 @@ private fun CalendarHeader(
contentDescription = stringResource(id = R.string.backMonthArrowContentDescription),
modifier = Modifier
.padding(end = 20.dp)
.clickable { onDateSelected(selectedDate.minusMonths(1)) },
.clickable {
onDateSelected(selectedDate.minusMonths(1))
onCalendarMonthChanged()
},
)

Text(
Expand All @@ -127,32 +145,14 @@ private fun CalendarHeader(
contentDescription = stringResource(id = R.string.forwardMonthArrowContentDescription),
modifier = Modifier
.padding(start = 20.dp)
.clickable { onDateSelected(selectedDate.plusMonths(1)) },
.clickable {
onDateSelected(selectedDate.plusMonths(1))
onCalendarMonthChanged()
},
)
}
}

@Composable
private fun handleMonthEventsState(
eventsState: NoticeViewModel.EventsState,
selectedDate: LocalDate,
onDateSelected: (LocalDate) -> Unit,
) = when (eventsState) {
is NoticeViewModel.EventsState.Loading -> CircleLoader(modifier = Modifier.fillMaxSize())
is NoticeViewModel.EventsState.Success -> {
val eventDates = eventsState.events.map {
it.startDateTime.toLocalDate()
}
CalendarBody(
selectedDate = selectedDate,
eventsDate = eventDates,
onDateSelected = onDateSelected,
)
}

is NoticeViewModel.EventsState.Failure -> {}
}

@Composable
private fun CalendarBody(
selectedDate: LocalDate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,15 @@ internal fun NoticeRoute(
val selectedDateEvents by viewModel.selectedDateEvents.collectAsStateWithLifecycle()
val selectedDate by viewModel.selectedDate.collectAsStateWithLifecycle()
val onDateSelected = viewModel::updateSelectedDate
val onCalendarMonthChanged = viewModel::getMonthEvents

NoticeScreen(MonthEvents, selectedDateEvents, selectedDate, onDateSelected)
NoticeScreen(
monthEvents = MonthEvents,
selectedDateEvents = selectedDateEvents,
selectedDate = selectedDate,
onDateSelected = onDateSelected,
onCalendarMonthChanged = onCalendarMonthChanged,
)
}

@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -45,6 +52,7 @@ internal fun NoticeScreen(
selectedDateEvents: EventsState,
selectedDate: LocalDate,
onDateSelected: (LocalDate) -> Unit,
onCalendarMonthChanged: () -> Unit,
) {
var defaultHeight: Dp by remember { mutableStateOf(0.dp) }
var expandableHeight: Dp by remember { mutableStateOf(0.dp) }
Expand All @@ -68,9 +76,10 @@ internal fun NoticeScreen(
sheetPeekHeight = defaultHeight,
sheetContent = {
BottomSheetContent(
expandableHeight,
selectedDateEvents,
selectedDate,
expandableHeight = expandableHeight,
bottomSheetState = scaffoldState.bottomSheetState,
events = selectedDateEvents,
selectedDate = selectedDate,
)
},
) {
Expand All @@ -80,6 +89,7 @@ internal fun NoticeScreen(
selectedDate = selectedDate,
monthEventsState = monthEvents,
onDateSelected = onDateSelected,
onCalendarMonthChanged = onCalendarMonthChanged,
measureDefaultModifier = Modifier
.fillMaxWidth()
.background(WappTheme.colors.black25)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class NoticeViewModel @Inject constructor(
getSelectedDateEvents()
}

private fun getMonthEvents() {
fun getMonthEvents() {
_monthEvents.value = EventsState.Loading
viewModelScope.launch {
getMonthEventListUseCase(_selectedDate.value)
Expand All @@ -42,7 +42,7 @@ class NoticeViewModel @Inject constructor(
}
}

fun getSelectedDateEvents() {
private fun getSelectedDateEvents() {
_selectedDateEvents.value = EventsState.Loading
viewModelScope.launch {
getDateEventListUseCase(_selectedDate.value).onSuccess { eventList ->
Expand Down

0 comments on commit dadd9ab

Please sign in to comment.