From 9165b80429cf2a4f5a04df558661d5da2e5e4278 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Sat, 2 Apr 2022 23:28:00 +0900 Subject: [PATCH 1/8] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20calendar=20animation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../halill2/features/calendar/Calendar.kt | 48 ++++++++++--------- .../halill2/features/write/WriteTodoState.kt | 3 +- 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt index 3a8088c..83a9f4c 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt @@ -21,6 +21,7 @@ import androidx.hilt.navigation.compose.hiltViewModel import androidx.navigation.NavController import com.halill.halill2.features.list.TodoList import com.halill.halill2.util.isToday +import com.halill.halill2.util.toMontDayList import java.time.LocalDate @Composable @@ -91,8 +92,8 @@ fun CalendarContent( SizeTransform(clip = false) ) } - ) { - CalendarView(state, doOnDateSelect) + ) { showingDate -> + CalendarView(showingDate = showingDate, doOnDateSelect = doOnDateSelect) } Divider(color = MaterialTheme.colors.onSurface) @@ -172,23 +173,24 @@ fun CalendarMonthLayout( } @Composable -fun CalendarView(state: CalendarState, doOnDateSelect: (LocalDate) -> Unit) { +fun CalendarView( + doOnDateSelect: (LocalDate) -> Unit, + showingDate: LocalDate +) { Column(modifier = Modifier.padding(0.dp, 7.dp, 0.dp, 0.dp)) { - val monthDayList = state.showingMonthDayList + val monthDayList = showingDate.toMontDayList() val firstDayOfWeek = monthDayList[0].dayOfWeek.value val alreadyShowDateCount = if (firstDayOfWeek == 7) 7 else (7 - firstDayOfWeek) CalendarFirstWeekLayout( - state = state, - firstDayOfWeek = firstDayOfWeek, - doOnDateSelect = doOnDateSelect + monthDayList = monthDayList, + doOnDateSelect = doOnDateSelect, + showingMonthDayList = monthDayList ) CalendarWeekLayout( - state = state, showingMonthDayList = monthDayList, alreadyShowDateCount = alreadyShowDateCount, doOnDateSelect = doOnDateSelect ) - } } @@ -197,17 +199,17 @@ val calendarItemHeight = 55.dp @Composable fun CalendarFirstWeekLayout( - state: CalendarState, - firstDayOfWeek: Int, + monthDayList: List, + showingMonthDayList: List, doOnDateSelect: (LocalDate) -> Unit ) { + val firstDayOfWeek = monthDayList[0].dayOfWeek.value WeekLineLayout { CalendarFrontSpacer(dayOfWeek = firstDayOfWeek) FirstWeekLayout( - state = state, - showingMonthDayList = state.showingMonthDayList, - doOnDateSelect = doOnDateSelect + doOnDateSelect = doOnDateSelect, + showingMonthDayList = showingMonthDayList ) } } @@ -227,12 +229,11 @@ fun CalendarFrontSpacer(dayOfWeek: Int) { @Composable fun FirstWeekLayout( - state: CalendarState, - showingMonthDayList: List, - doOnDateSelect: (LocalDate) -> Unit + doOnDateSelect: (LocalDate) -> Unit, + showingMonthDayList: List ) { for (day in showingMonthDayList) { - CalendarDayItem(day, doOnDateSelect = doOnDateSelect, state = state) + CalendarDayItem(day, doOnDateSelect = doOnDateSelect) if (day.dayOfWeek.value == 6) { break } @@ -241,7 +242,6 @@ fun FirstWeekLayout( @Composable fun CalendarWeekLayout( - state: CalendarState, showingMonthDayList: List, alreadyShowDateCount: Int, doOnDateSelect: (LocalDate) -> Unit @@ -268,8 +268,7 @@ fun CalendarWeekLayout( } else { CalendarDayItem( showingMonthDayList[showedDateCount], - doOnDateSelect = doOnDateSelect, - state = state + doOnDateSelect = doOnDateSelect ) dayList.removeAt(0) showedDateCount += 1 @@ -293,7 +292,12 @@ fun WeekLineLayout(content: @Composable () -> Unit) { } @Composable -fun CalendarDayItem(day: LocalDate, state: CalendarState, doOnDateSelect: (LocalDate) -> Unit) { +fun CalendarDayItem( + day: LocalDate, + doOnDateSelect: (LocalDate) -> Unit, + viewModel: CalendarViewModel = hiltViewModel() +) { + val state = viewModel.state.collectAsState().value val borderColor = if (day.isToday()) MaterialTheme.colors.primary else MaterialTheme.colors.background val textColor = if (day.isToday()) Color.White else Color.Unspecified diff --git a/app/src/main/java/com/halill/halill2/features/write/WriteTodoState.kt b/app/src/main/java/com/halill/halill2/features/write/WriteTodoState.kt index cdc2a78..64adf7f 100644 --- a/app/src/main/java/com/halill/halill2/features/write/WriteTodoState.kt +++ b/app/src/main/java/com/halill/halill2/features/write/WriteTodoState.kt @@ -3,7 +3,6 @@ package com.halill.halill2.features.write import com.halill.halill2.base.MviState import java.time.LocalDateTime - data class WriteTodoState( val title: String, val content: String, @@ -14,6 +13,7 @@ data class WriteTodoState( val showDateSelectDialog: Boolean, val showHourSelectDialog: Boolean ): MviState { + companion object { fun initial() = WriteTodoState( @@ -26,6 +26,5 @@ data class WriteTodoState( showDateSelectDialog = false, showHourSelectDialog = false ) - } } \ No newline at end of file From af43aeda49c38866fc20c4c26ba4fbbb264e7748 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Sun, 3 Apr 2022 17:03:11 +0900 Subject: [PATCH 2/8] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20compose=20version=20?= =?UTF-8?q?1.1.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 9340c03..3ccee4d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { - compose_version = '1.0.1' - kotlin_version = "1.5.21" + compose_version = '1.1.1' + kotlin_version = "1.6.10" hilt_version = "2.39" room_version = "2.4.2" } From 9f4b5d9b26686851c3474bfa16ed5144bf62eb48 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Sun, 3 Apr 2022 21:56:47 +0900 Subject: [PATCH 3/8] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20calendar=20scroll?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../halill2/features/calendar/Calendar.kt | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt index 83a9f4c..344a21a 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt @@ -4,6 +4,9 @@ import androidx.compose.animation.* import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable +import androidx.compose.foundation.gestures.Orientation +import androidx.compose.foundation.gestures.rememberScrollableState +import androidx.compose.foundation.gestures.scrollable import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material.* @@ -38,7 +41,7 @@ fun Calendar(navController: NavController, viewModel: CalendarViewModel = hiltVi CalendarContent( state = state, - doOnNextClick = { + doOnNextMonthClick = { viewModel.showNextMonth() }, doOnBeforeMonthClick = { @@ -64,7 +67,7 @@ fun Calendar(navController: NavController, viewModel: CalendarViewModel = hiltVi fun CalendarContent( state: CalendarState, doOnBeforeMonthClick: () -> Unit, - doOnNextClick: () -> Unit, + doOnNextMonthClick: () -> Unit, doOnDateSelect: (LocalDate) -> Unit, doOnTodoClick: (Long) -> Unit, doOnDoneClick: (Long) -> Unit, @@ -74,7 +77,7 @@ fun CalendarContent( CalendarMonthLayout( state.showingMonthDate, doOnBeforeMonthClick = doOnBeforeMonthClick, - doOnNextClick = doOnNextClick + doOnNextMonthClick = doOnNextMonthClick ) WeekTextLinearLayout() Divider(color = MaterialTheme.colors.onSurface) @@ -93,7 +96,12 @@ fun CalendarContent( ) } ) { showingDate -> - CalendarView(showingDate = showingDate, doOnDateSelect = doOnDateSelect) + CalendarView( + showingDate = showingDate, + doOnDateSelect = doOnDateSelect, + showBeforeMonth = doOnBeforeMonthClick, + showNextMonth = doOnNextMonthClick + ) } Divider(color = MaterialTheme.colors.onSurface) @@ -134,7 +142,7 @@ fun WeekText(weekText: String, textColor: Color) { fun CalendarMonthLayout( showingDate: LocalDate, doOnBeforeMonthClick: () -> Unit, - doOnNextClick: () -> Unit + doOnNextMonthClick: () -> Unit ) { Row( horizontalArrangement = Arrangement.SpaceBetween, @@ -158,7 +166,7 @@ fun CalendarMonthLayout( Text(text = monthText, fontSize = 22.sp) IconButton( - onClick = doOnNextClick, modifier = Modifier + onClick = doOnNextMonthClick, modifier = Modifier .padding(10.dp) .size(60.dp) ) { @@ -175,9 +183,32 @@ fun CalendarMonthLayout( @Composable fun CalendarView( doOnDateSelect: (LocalDate) -> Unit, + showNextMonth: () -> Unit, + showBeforeMonth: () -> Unit, showingDate: LocalDate ) { - Column(modifier = Modifier.padding(0.dp, 7.dp, 0.dp, 0.dp)) { + var currentDelta by remember { + mutableStateOf(0f) + } + Column( + modifier = Modifier + .padding(0.dp, 7.dp, 0.dp, 0.dp) + .scrollable( + orientation = Orientation.Vertical, state = rememberScrollableState { delta -> + when { + delta + 5 > currentDelta -> { + showNextMonth() + currentDelta = delta + } + delta - 5 < currentDelta -> { + showBeforeMonth() + currentDelta = delta + } + } + delta + } + ) + ) { val monthDayList = showingDate.toMontDayList() val firstDayOfWeek = monthDayList[0].dayOfWeek.value val alreadyShowDateCount = if (firstDayOfWeek == 7) 7 else (7 - firstDayOfWeek) From 1e053c263884c01c64f69768030c952a7730f732 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Mon, 4 Apr 2022 09:58:46 +0900 Subject: [PATCH 4/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F::=20compose=20version=20?= =?UTF-8?q?down?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem with compose navigation --- build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 3ccee4d..9340c03 100644 --- a/build.gradle +++ b/build.gradle @@ -1,8 +1,8 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { - compose_version = '1.1.1' - kotlin_version = "1.6.10" + compose_version = '1.0.1' + kotlin_version = "1.5.21" hilt_version = "2.39" room_version = "2.4.2" } From 25f5be53cf4f9b3592679a5f4b273d09e675aeb8 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Mon, 4 Apr 2022 09:59:25 +0900 Subject: [PATCH 5/8] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20surface=20color?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/halill/halill2/ui/theme/Theme.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/halill/halill2/ui/theme/Theme.kt b/app/src/main/java/com/halill/halill2/ui/theme/Theme.kt index ed3fa88..3d67e29 100644 --- a/app/src/main/java/com/halill/halill2/ui/theme/Theme.kt +++ b/app/src/main/java/com/halill/halill2/ui/theme/Theme.kt @@ -21,7 +21,7 @@ private val LightColorPalette = lightColors( primaryVariant = Teal900, secondary = Purple500, background = Color.White, - surface = Color.White, + surface = Gray100, onSurface = Gray900 ) From 65ce3592ad9eb79247658b3f9c3abcecb6f2bfab Mon Sep 17 00:00:00 2001 From: Jaewon Date: Tue, 5 Apr 2022 21:50:40 +0900 Subject: [PATCH 6/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F::=20challenge=20viewmode?= =?UTF-8?q?l=20on=20failure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../halill2/features/calendar/Calendar.kt | 24 +++++++++---------- .../features/calendar/CalendarViewModel.kt | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt index 344a21a..5ca460c 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt @@ -4,9 +4,7 @@ import androidx.compose.animation.* import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.gestures.rememberScrollableState -import androidx.compose.foundation.gestures.scrollable +import androidx.compose.foundation.gestures.* import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material.* @@ -187,26 +185,28 @@ fun CalendarView( showBeforeMonth: () -> Unit, showingDate: LocalDate ) { - var currentDelta by remember { + var changedDelta by remember { mutableStateOf(0f) } Column( modifier = Modifier .padding(0.dp, 7.dp, 0.dp, 0.dp) - .scrollable( - orientation = Orientation.Vertical, state = rememberScrollableState { delta -> + .draggable( + orientation = Orientation.Horizontal, + state = rememberDraggableState { delta -> + changedDelta += delta when { - delta + 5 > currentDelta -> { + changedDelta > 300 -> { showNextMonth() - currentDelta = delta + changedDelta = 0f } - delta - 5 < currentDelta -> { + changedDelta < -300 -> { showBeforeMonth() - currentDelta = delta + changedDelta = 0f } } - delta - } + }, + reverseDirection = true ) ) { val monthDayList = showingDate.toMontDayList() diff --git a/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt b/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt index 04cc79c..88d7b9e 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt @@ -8,6 +8,7 @@ import com.halill.domain.features.todo.usecase.FetchTodoListWithDateUseCase import com.halill.halill2.base.BaseViewModel import com.halill.halill2.util.toMontDayList import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.launch import java.time.LocalDate import javax.inject.Inject From 75f0bf77a48b68d3cbe9bfb56b26e2221592e4bf Mon Sep 17 00:00:00 2001 From: Jaewon Date: Tue, 5 Apr 2022 21:50:40 +0900 Subject: [PATCH 7/8] =?UTF-8?q?=E2=99=BB=EF=B8=8F::=20calendar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../halill2/features/calendar/Calendar.kt | 24 +++++++++---------- .../features/calendar/CalendarViewModel.kt | 1 + 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt index 344a21a..5ca460c 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt @@ -4,9 +4,7 @@ import androidx.compose.animation.* import androidx.compose.foundation.background import androidx.compose.foundation.border import androidx.compose.foundation.clickable -import androidx.compose.foundation.gestures.Orientation -import androidx.compose.foundation.gestures.rememberScrollableState -import androidx.compose.foundation.gestures.scrollable +import androidx.compose.foundation.gestures.* import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.layout.* import androidx.compose.material.* @@ -187,26 +185,28 @@ fun CalendarView( showBeforeMonth: () -> Unit, showingDate: LocalDate ) { - var currentDelta by remember { + var changedDelta by remember { mutableStateOf(0f) } Column( modifier = Modifier .padding(0.dp, 7.dp, 0.dp, 0.dp) - .scrollable( - orientation = Orientation.Vertical, state = rememberScrollableState { delta -> + .draggable( + orientation = Orientation.Horizontal, + state = rememberDraggableState { delta -> + changedDelta += delta when { - delta + 5 > currentDelta -> { + changedDelta > 300 -> { showNextMonth() - currentDelta = delta + changedDelta = 0f } - delta - 5 < currentDelta -> { + changedDelta < -300 -> { showBeforeMonth() - currentDelta = delta + changedDelta = 0f } } - delta - } + }, + reverseDirection = true ) ) { val monthDayList = showingDate.toMontDayList() diff --git a/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt b/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt index 04cc79c..88d7b9e 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/CalendarViewModel.kt @@ -8,6 +8,7 @@ import com.halill.domain.features.todo.usecase.FetchTodoListWithDateUseCase import com.halill.halill2.base.BaseViewModel import com.halill.halill2.util.toMontDayList import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.flow import kotlinx.coroutines.launch import java.time.LocalDate import javax.inject.Inject From 15a06905be380d59a3d42de3cf6782ada12c6470 Mon Sep 17 00:00:00 2001 From: Jaewon Date: Wed, 6 Apr 2022 21:57:19 +0900 Subject: [PATCH 8/8] =?UTF-8?q?=E2=9A=A1=EF=B8=8F::=20drag=20calendar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/halill/halill2/features/calendar/Calendar.kt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt index 5ca460c..f220a24 100644 --- a/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt +++ b/app/src/main/java/com/halill/halill2/features/calendar/Calendar.kt @@ -24,6 +24,7 @@ import com.halill.halill2.features.list.TodoList import com.halill.halill2.util.isToday import com.halill.halill2.util.toMontDayList import java.time.LocalDate +import kotlin.math.abs @Composable fun Calendar(navController: NavController, viewModel: CalendarViewModel = hiltViewModel()) { @@ -194,7 +195,9 @@ fun CalendarView( .draggable( orientation = Orientation.Horizontal, state = rememberDraggableState { delta -> - changedDelta += delta + if (abs(delta) < 250) { + changedDelta += delta + } when { changedDelta > 300 -> { showNextMonth()