Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

년달력 격자 추가 #277

Merged
merged 6 commits into from
Nov 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import com.drunkenboys.ckscalendar.data.DayType
import com.drunkenboys.ckscalendar.utils.calendarSetToCalendarDatesList
import com.drunkenboys.ckscalendar.yearcalendar.YearCalendarViewModel
import com.drunkenboys.ckscalendar.yearcalendar.composeView.DayText
import com.drunkenboys.ckscalendar.yearcalendar.composeView.PaddingText
import com.drunkenboys.ckscalendar.yearcalendar.composeView.ScheduleText
import java.time.LocalDate

Expand Down Expand Up @@ -49,7 +48,7 @@ fun WeekCalendar(
week.forEach { day ->
when (day.dayType) {
// 빈 날짜
DayType.PADDING -> PaddingText(day = day, viewModel = viewModel)
DayType.PADDING -> { }

// 1일
else -> Column(modifier = dayModifier(day).layoutId(day.date.toString()), horizontalAlignment = Alignment.CenterHorizontally) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.drunkenboys.ckscalendar.yearcalendar.composeView

import android.view.Gravity
import android.view.RoundedCorner
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
Expand Down Expand Up @@ -38,46 +38,63 @@ fun CalendarLazyColumn(
) {
// RecyclerView의 상태를 관찰
val listState = rememberLazyListState()

val calendar by remember { viewModel.calendar }
val clickedDay by remember { viewModel.clickedDay }
val clickedEdge = { day: CalendarDate ->
BorderStroke(
width = 2.dp,
color = if (clickedDay == day.date) Color(viewModel.design.value.selectedFrameColor) else Color.Transparent
)
}

// viewModel의 recomposer를 LazyColumn으로 설정해서 setSchedule 호출 시 recompose
viewModel.setRecomposeScope(currentRecomposeScope)

// state hoisting
val dayColumnModifier = { day: CalendarDate ->
Modifier
.layoutId(day.date.toString())
.border(clickedEdge(day), shape = RoundedCornerShape(6.dp))
.clickable(onClick = {
if (clickedDay != day.date) onDayClickListener?.onDayClick(day.date, 0)
else onDaySecondClickListener?.onDayClick(day.date, 0)
viewModel.clickDay(day)
})

when (clickedDay) {

day.date -> {
Modifier
.layoutId(day.date.toString())
.border(
border = BorderStroke(width = 2.dp, color = Color(viewModel.design.value.selectedFrameColor)),
shape = RoundedCornerShape(6.dp)
)
.clickable(onClick = {
onDaySecondClickListener?.onDayClick(day.date, 0)
})
}

else -> {
Modifier
.layoutId(day.date.toString())
.border(
border = BorderStroke(width = 0.1f.dp, color = Color(viewModel.design.value.weekDayTextColor).copy(alpha = 0.1f))
)
.clickable(onClick = {
onDayClickListener?.onDayClick(day.date, 0)
viewModel.clickDay(day)
})
}
}
}

// setSchedule 호출 시 recompose할 Scope 전달
viewModel.setRecomposeScope(currentRecomposeScope)

// RecyclerView와 유사
LazyColumn(
state = listState,
modifier = Modifier.background(color = MaterialTheme.colors.background).fillMaxHeight()
modifier = Modifier
.background(color = MaterialTheme.colors.background)
.fillMaxHeight()
) {
items(calendar, key = { slice -> slice.startDate }) { slice ->

val firstOfYear = LocalDate.of(slice.endDate.year, 1, 1)

// 해가 갱신될 때마다 상단에 연표시
if (firstOfYear in slice.startDate..slice.endDate) {

Text(
text = "${firstOfYear.year}년",
color = MaterialTheme.colors.primary,
modifier = Modifier.fillMaxWidth(),
modifier = Modifier
.fillMaxWidth()
.padding(top = 16.dp, bottom = 16.dp),
textAlign = TextAlign.Center
)
}
Expand Down Expand Up @@ -123,7 +140,7 @@ fun PreviewCalendar() {
endDate = LocalDate.now().plusDays(30L)
))

viewModel.setCalendarSetList(newSlice)
// viewModel.setCalendarSetList(newSlice)

CustomTheme(design = viewModel.design.value) {
CalendarLazyColumn(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package com.drunkenboys.ckscalendar.yearcalendar.composeView

import android.view.Gravity
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import android.widget.Space
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.lazy.LazyListState
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.layoutId
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.ConstraintSet
import androidx.constraintlayout.compose.Dimension
Expand Down Expand Up @@ -46,7 +52,18 @@ fun MonthCalendar(
week.forEach { day ->
when (day.dayType) {
// 빈 날짜
DayType.PADDING -> PaddingText(day = day, viewModel = viewModel)
DayType.PADDING -> Column(
modifier = Modifier.layoutId(day.date.toString())
.border(border = BorderStroke(
width = 0.1f.dp,
color = Color(viewModel.design.value.weekDayTextColor).copy(alpha = 0.1f)
)
)
) {
repeat(viewModel.design.value.visibleScheduleCount + 1) {
Text(text = " ")
}
}

// 1일
else -> Column(
Expand Down

This file was deleted.