From 211bbdc0a063c6f6d184fd9956030528b6cf3793 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sat, 13 Jul 2024 16:28:41 +0900 Subject: [PATCH 01/21] feat : icon --- .../src/main/res/drawable/email_icon.xml | 13 +++++++++++++ .../src/main/res/drawable/gihub_icon.xml | 9 +++++++++ .../src/main/res/drawable/instagram_icon.xml | 9 +++++++++ 3 files changed, 31 insertions(+) create mode 100644 core/designsystem/src/main/res/drawable/email_icon.xml create mode 100644 core/designsystem/src/main/res/drawable/gihub_icon.xml create mode 100644 core/designsystem/src/main/res/drawable/instagram_icon.xml diff --git a/core/designsystem/src/main/res/drawable/email_icon.xml b/core/designsystem/src/main/res/drawable/email_icon.xml new file mode 100644 index 00000000..dabb74b4 --- /dev/null +++ b/core/designsystem/src/main/res/drawable/email_icon.xml @@ -0,0 +1,13 @@ + + + + + + diff --git a/core/designsystem/src/main/res/drawable/gihub_icon.xml b/core/designsystem/src/main/res/drawable/gihub_icon.xml new file mode 100644 index 00000000..f0adaf3d --- /dev/null +++ b/core/designsystem/src/main/res/drawable/gihub_icon.xml @@ -0,0 +1,9 @@ + + + diff --git a/core/designsystem/src/main/res/drawable/instagram_icon.xml b/core/designsystem/src/main/res/drawable/instagram_icon.xml new file mode 100644 index 00000000..18cc0310 --- /dev/null +++ b/core/designsystem/src/main/res/drawable/instagram_icon.xml @@ -0,0 +1,9 @@ + + + From 14a253a5f4a148276bd5bcb59ff8d3a23feb8459 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sat, 13 Jul 2024 17:16:05 +0900 Subject: [PATCH 02/21] =?UTF-8?q?feat=20:=20external=20webview=20=EC=97=B0?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../feature/main/navigation/TiTiNavHost.kt | 8 ++ .../feature/setting/model/SettingActions.kt | 3 + .../setting/navigation/SettingNavigation.kt | 2 + .../app/feature/setting/ui/SettingScreen.kt | 79 +++++++++++++++++++ 4 files changed, 92 insertions(+) diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiNavHost.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiNavHost.kt index c30fa699..44340178 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiNavHost.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiNavHost.kt @@ -119,6 +119,14 @@ fun TiTiNavHost( onNavigateToDestination = { navController.navigateToTopLevelDestination(it) }, + onNavigateToExternalWeb = { + val intent = Intent( + Intent.ACTION_VIEW, + it.toUri(), + ) + + context.startActivity(intent) + }, ) webViewGraph(onNavigateUp = { navController.navigateUp() }) diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/SettingActions.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/SettingActions.kt index 9e4a8890..d665f7ba 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/SettingActions.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/SettingActions.kt @@ -6,6 +6,9 @@ sealed interface SettingActions { data object FeaturesList : Navigates data object PlayStore : Navigates data object UpdatesList : Navigates + + @JvmInline + value class ExternalWeb(val url: String) : Navigates } sealed interface Updates : SettingActions { diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/navigation/SettingNavigation.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/navigation/SettingNavigation.kt index cee22fd4..10f99d8e 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/navigation/SettingNavigation.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/navigation/SettingNavigation.kt @@ -38,6 +38,7 @@ fun NavGraphBuilder.settingGraph( onNavigateUp: () -> Unit, onNavigateToWebView: (title: String, url: String) -> Unit, onNavigateToDestination: (TopLevelDestination) -> Unit, + onNavigateToExternalWeb: (String) -> Unit, ) { composable(route = SETTING_ROUTE) { SettingScreen( @@ -46,6 +47,7 @@ fun NavGraphBuilder.settingGraph( SettingActions.Navigates.FeaturesList -> onNavigateToFeatures() SettingActions.Navigates.PlayStore -> onNavigateToPlayStore() SettingActions.Navigates.UpdatesList -> onNavigateToUpdates() + is SettingActions.Navigates.ExternalWeb -> onNavigateToExternalWeb(it.url) } }, onNavigateToDestination = onNavigateToDestination, diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt index 1091d968..ec551784 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt @@ -4,6 +4,7 @@ import android.util.Log import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.isSystemInDarkTheme +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer @@ -12,8 +13,10 @@ import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.safeDrawingPadding +import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.verticalScroll import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon @@ -26,6 +29,7 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource @@ -39,6 +43,7 @@ import com.google.firebase.database.DatabaseError import com.google.firebase.database.FirebaseDatabase import com.google.firebase.database.ValueEventListener import com.titi.app.core.designsystem.R +import com.titi.app.core.designsystem.component.TdsIconButton import com.titi.app.core.designsystem.component.TdsText import com.titi.app.core.designsystem.navigation.TdsBottomNavigationBar import com.titi.app.core.designsystem.navigation.TopLevelDestination @@ -176,6 +181,8 @@ private fun SettingScreen( ) Spacer(modifier = Modifier.height(35.dp)) + + DeveloperSection(onSettingActions = onSettingActions) } } @@ -384,6 +391,78 @@ internal fun ListContent( } } +@Composable +internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { + TdsText( + modifier = Modifier.padding(start = 16.dp), + text = "개발자", + textStyle = TdsTextStyle.SEMI_BOLD_TEXT_STYLE, + fontSize = 14.sp, + color = TdsColor.TEXT, + ) + + Spacer(modifier = Modifier.height(16.dp)) + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(start = 16.dp), + horizontalArrangement = Arrangement.spacedBy(16.dp), + ) { + TdsIconButton( + modifier = Modifier + .clip(CircleShape) + .background(TdsColor.SECONDARY_BACKGROUND.getColor()), + onClick = { + onSettingActions( + SettingActions.Navigates.ExternalWeb("https://github.com/TimerTiTi"), + ) + }, + size = 48.dp, + ) { + Icon( + modifier = Modifier.size(30.dp), + painter = painterResource(R.drawable.gihub_icon), + contentDescription = null, + ) + } + + TdsIconButton( + modifier = Modifier + .clip(CircleShape) + .background(TdsColor.SECONDARY_BACKGROUND.getColor()), + onClick = { + onSettingActions( + SettingActions.Navigates.ExternalWeb( + " https://www.instagram.com/study_withtiti/", + ), + ) + }, + size = 48.dp, + ) { + Icon( + modifier = Modifier.size(30.dp), + painter = painterResource(R.drawable.instagram_icon), + contentDescription = null, + ) + } + + TdsIconButton( + modifier = Modifier + .clip(CircleShape) + .background(TdsColor.SECONDARY_BACKGROUND.getColor()), + onClick = {}, + size = 48.dp, + ) { + Icon( + modifier = Modifier.size(30.dp), + painter = painterResource(R.drawable.email_icon), + contentDescription = null, + ) + } + } +} + @PreviewLightDark @Composable private fun SettingScreenPreview() { From 5c0d1b102c134e61531b5651e4ca1bfc8e647fb1 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 01:02:56 +0900 Subject: [PATCH 03/21] feat : send email --- app/src/main/AndroidManifest.xml | 6 +++++ .../app/feature/setting/ui/SettingScreen.kt | 27 +++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 257b2b88..b842340d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,4 +34,10 @@ + + + + + + \ No newline at end of file diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt index ec551784..bfc156ca 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt @@ -1,6 +1,9 @@ package com.titi.app.feature.setting.ui +import android.content.Intent +import android.net.Uri import android.util.Log +import android.widget.Toast import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.isSystemInDarkTheme @@ -393,6 +396,8 @@ internal fun ListContent( @Composable internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { + val context = LocalContext.current + TdsText( modifier = Modifier.padding(start = 16.dp), text = "개발자", @@ -434,7 +439,7 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { onClick = { onSettingActions( SettingActions.Navigates.ExternalWeb( - " https://www.instagram.com/study_withtiti/", + "https://www.instagram.com/study_withtiti/", ), ) }, @@ -451,7 +456,25 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { modifier = Modifier .clip(CircleShape) .background(TdsColor.SECONDARY_BACKGROUND.getColor()), - onClick = {}, + onClick = { + val uriText = "mailto:koreatlwls@gmail.com" + + "?subject=" + Uri.encode("TiTi 문의사항") + + val uri = Uri.parse(uriText) + + val sendIntent = Intent(Intent.ACTION_SENDTO) + sendIntent.data = uri + + if (sendIntent.resolveActivity(context.packageManager) != null) { + context.startActivity(Intent.createChooser(sendIntent, "Send email")) + } else { + Toast.makeText( + context, + "이메일 앱이 존재하지 않습니다.", + Toast.LENGTH_SHORT, + ).show() + } + }, size = 48.dp, ) { Icon( From 9f2f2be1e011ce69f1db391c475aa2c2c21bab17 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 01:09:02 +0900 Subject: [PATCH 04/21] update : icon --- .../src/main/res/drawable/email_icon.xml | 2 +- .../src/main/res/drawable/gihub_icon.xml | 9 --------- .../src/main/res/drawable/github_icon.xml | 20 +++++++++++++++++++ .../src/main/res/drawable/instagram_icon.xml | 2 +- .../app/feature/setting/ui/SettingScreen.kt | 5 ++++- 5 files changed, 26 insertions(+), 12 deletions(-) delete mode 100644 core/designsystem/src/main/res/drawable/gihub_icon.xml create mode 100644 core/designsystem/src/main/res/drawable/github_icon.xml diff --git a/core/designsystem/src/main/res/drawable/email_icon.xml b/core/designsystem/src/main/res/drawable/email_icon.xml index dabb74b4..801c2980 100644 --- a/core/designsystem/src/main/res/drawable/email_icon.xml +++ b/core/designsystem/src/main/res/drawable/email_icon.xml @@ -7,7 +7,7 @@ diff --git a/core/designsystem/src/main/res/drawable/gihub_icon.xml b/core/designsystem/src/main/res/drawable/gihub_icon.xml deleted file mode 100644 index f0adaf3d..00000000 --- a/core/designsystem/src/main/res/drawable/gihub_icon.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - diff --git a/core/designsystem/src/main/res/drawable/github_icon.xml b/core/designsystem/src/main/res/drawable/github_icon.xml new file mode 100644 index 00000000..69a22475 --- /dev/null +++ b/core/designsystem/src/main/res/drawable/github_icon.xml @@ -0,0 +1,20 @@ + + + + diff --git a/core/designsystem/src/main/res/drawable/instagram_icon.xml b/core/designsystem/src/main/res/drawable/instagram_icon.xml index 18cc0310..b0bf7819 100644 --- a/core/designsystem/src/main/res/drawable/instagram_icon.xml +++ b/core/designsystem/src/main/res/drawable/instagram_icon.xml @@ -4,6 +4,6 @@ android:viewportWidth="24" android:viewportHeight="24"> diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt index bfc156ca..adcfa5ef 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt @@ -427,8 +427,9 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { ) { Icon( modifier = Modifier.size(30.dp), - painter = painterResource(R.drawable.gihub_icon), + painter = painterResource(R.drawable.github_icon), contentDescription = null, + tint = TdsColor.TEXT.getColor(), ) } @@ -449,6 +450,7 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { modifier = Modifier.size(30.dp), painter = painterResource(R.drawable.instagram_icon), contentDescription = null, + tint = TdsColor.TEXT.getColor(), ) } @@ -481,6 +483,7 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { modifier = Modifier.size(30.dp), painter = painterResource(R.drawable.email_icon), contentDescription = null, + tint = TdsColor.TEXT.getColor(), ) } } From 212b9b54c08eb3c283003326764bc83a9884d774 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 14:15:52 +0900 Subject: [PATCH 05/21] update : padding && multiple --- .../titi/app/feature/main/navigation/TiTiApp.kt | 4 ++-- .../app/feature/setting/ui/SettingScreen.kt | 2 ++ .../com/titi/app/tds/component/TtdsSnackbar.kt | 17 +++++------------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiApp.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiApp.kt index 90f09bd5..edfdce47 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiApp.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/navigation/TiTiApp.kt @@ -71,8 +71,8 @@ fun TiTiApp(splashResultState: SplashResultState) { LottieAnimation( modifier = Modifier - .size(22.dp * multiple) - .padding(4.dp * multiple), + .size(22.dp) + .padding(4.dp), composition = composition, progress = { progress }, ) diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt index adcfa5ef..77e299c8 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt @@ -186,6 +186,8 @@ private fun SettingScreen( Spacer(modifier = Modifier.height(35.dp)) DeveloperSection(onSettingActions = onSettingActions) + + Spacer(modifier = Modifier.height(35.dp)) } } diff --git a/tds/src/main/kotlin/com/titi/app/tds/component/TtdsSnackbar.kt b/tds/src/main/kotlin/com/titi/app/tds/component/TtdsSnackbar.kt index 17c499e6..1fe2289a 100644 --- a/tds/src/main/kotlin/com/titi/app/tds/component/TtdsSnackbar.kt +++ b/tds/src/main/kotlin/com/titi/app/tds/component/TtdsSnackbar.kt @@ -9,14 +9,12 @@ import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.shadow import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.withStyle import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp -import com.titi.app.core.ui.isTablet import com.titi.app.tds.theme.TtdsColor import com.titi.app.tds.theme.TtdsTextStyle import com.titi.app.tds.theme.TtdsTheme @@ -37,23 +35,20 @@ fun TtdsSnackbar( message: String, ) { TtdsTheme { - val configuration = LocalConfiguration.current - val multiple = if (configuration.isTablet()) 2 else 1 - Row( modifier = Modifier .shadow( elevation = 3.dp, - shape = RoundedCornerShape(160.dp * multiple), + shape = RoundedCornerShape(160.dp), spotColor = Color.Black.copy(alpha = 0.12f), ) .background( color = Color.White, - shape = RoundedCornerShape(160.dp * multiple), + shape = RoundedCornerShape(160.dp), ) .padding( - vertical = 8.dp * multiple, - horizontal = 14.dp * multiple, + vertical = 8.dp, + horizontal = 14.dp, ), verticalAlignment = Alignment.CenterVertically, ) { @@ -62,7 +57,6 @@ fun TtdsSnackbar( } TtdsSnackbarMessage( - multiple = multiple, emphasizedMessage = emphasizedMessage, message = message, ) @@ -73,7 +67,6 @@ fun TtdsSnackbar( @Composable private fun TtdsSnackbarMessage( modifier: Modifier = Modifier, - multiple: Int = 1, emphasizedMessage: String?, message: String, ) { @@ -92,6 +85,6 @@ private fun TtdsSnackbarMessage( }, textStyle = TtdsTextStyle.MEDIUM_TEXT_STYLE, color = TtdsColor.TEXT, - fontSize = 14.sp * multiple, + fontSize = 14.sp, ) } From 0d6d20bf0a6f9c9e60059c2fd98a9a2dfdbe4102 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 15:40:14 +0900 Subject: [PATCH 06/21] #142 update : totaldata --- .../com/titi/app/core/util/JavaTimeUtil.kt | 29 +++ .../app/data/daily/api/DailyRepository.kt | 2 +- .../app/data/daily/impl/local/dao/DailyDao.kt | 2 +- .../impl/repository/DailyRepositoryImpl.kt | 6 +- .../daily/usecase/GetAllDailiesFlowUseCase.kt | 17 ++ .../usecase/GetAllDailiesTasksUseCase.kt | 24 -- .../daily/usecase/GetMonthDailyUseCase.kt | 29 --- .../log/mapper/DomainToFeatureMapper.kt | 219 ++++++++++-------- .../com/titi/app/feature/log/ui/LogScreen.kt | 1 - .../titi/app/feature/log/ui/LogViewModel.kt | 45 +--- 10 files changed, 181 insertions(+), 193 deletions(-) create mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesFlowUseCase.kt delete mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesTasksUseCase.kt delete mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetMonthDailyUseCase.kt diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt index 96866fb2..3456e5bc 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt @@ -7,6 +7,8 @@ import java.time.ZoneId import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter +import java.time.temporal.WeekFields +import java.util.Locale fun isCurrentWeek(checkDate: ZonedDateTime, currentDate: LocalDate): Boolean { val diffMonday = currentDate.dayOfWeek.value - DayOfWeek.MONDAY.value @@ -91,3 +93,30 @@ fun getDailyDayWithHour(hour: Int): Pair { startDateTime to endDateTime } } + +fun areDatesInSameMonth(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { + val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() + + return localDate.year == zonedDateTimeToLocalDate.year && + localDate.month == zonedDateTimeToLocalDate.month +} + +fun areDatesInSameWeek(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { + val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() + + val weekFields = WeekFields.of(Locale.getDefault()) + + val localDateWeek = localDate.get(weekFields.weekOfWeekBasedYear()) + val zonedDateTimeWeek = zonedDateTimeToLocalDate.get(weekFields.weekOfWeekBasedYear()) + + val localDateYear = localDate.get(weekFields.weekBasedYear()) + val zonedDateTimeYear = zonedDateTimeToLocalDate.get(weekFields.weekBasedYear()) + + return localDateWeek == zonedDateTimeWeek && localDateYear == zonedDateTimeYear +} + +fun areDatesInSameDay(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { + val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() + + return localDate == zonedDateTimeToLocalDate +} diff --git a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt index 70473af9..355beb12 100644 --- a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt +++ b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt @@ -39,7 +39,7 @@ interface DailyRepository { suspend fun getDailies(startDateTime: String, endDateTime: String): List? - suspend fun getAllDailies(): List? + fun getAllDailiesFlow(): Flow?> suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel) diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt index 06e4e1f9..f59ce95f 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt @@ -31,7 +31,7 @@ internal interface DailyDao { suspend fun getDailies(startDateTime: String, endDateTime: String): List? @Query("SELECT * FROM dailies") - suspend fun getAllDailies(): List? + fun getAllDailiesFlow(): Flow?> @Upsert suspend fun upsert(dailyEntity: DailyEntity) diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt index 29909a00..ef40d459 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt @@ -44,8 +44,10 @@ internal class DailyRepositoryImpl @Inject constructor( )?.map { it.toRepositoryModel() } } - override suspend fun getAllDailies(): List? { - return dailyDao.getAllDailies()?.map { it.toRepositoryModel() } + override fun getAllDailiesFlow(): Flow?> { + return dailyDao.getAllDailiesFlow().map { dailies -> + dailies?.map { it.toRepositoryModel() } + } } override suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel) { diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesFlowUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesFlowUseCase.kt new file mode 100644 index 00000000..c14b2a40 --- /dev/null +++ b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesFlowUseCase.kt @@ -0,0 +1,17 @@ +package com.titi.app.doamin.daily.usecase + +import com.titi.app.data.daily.api.DailyRepository +import com.titi.app.doamin.daily.mapper.toDomainModel +import com.titi.app.doamin.daily.model.Daily +import javax.inject.Inject +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +class GetAllDailiesFlowUseCase @Inject constructor( + private val dailyRepository: DailyRepository, +) { + operator fun invoke(): Flow?> = dailyRepository.getAllDailiesFlow() + .map { dailies -> + dailies?.map { it.toDomainModel() } + } +} diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesTasksUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesTasksUseCase.kt deleted file mode 100644 index 11391c56..00000000 --- a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetAllDailiesTasksUseCase.kt +++ /dev/null @@ -1,24 +0,0 @@ -package com.titi.app.doamin.daily.usecase - -import com.titi.app.data.daily.api.DailyRepository -import javax.inject.Inject - -class GetAllDailiesTasksUseCase @Inject constructor( - private val dailyRepository: DailyRepository, -) { - suspend operator fun invoke(): Map { - val taskMap = mutableMapOf() - - dailyRepository.getAllDailies()?.let { dailies -> - dailies.forEach { daily -> - daily.tasks?.let { task -> - task.forEach { (taskName, taskTime) -> - taskMap[taskName] = taskMap.getOrDefault(taskName, 0L) + taskTime - } - } - } - } - - return taskMap.toMap() - } -} diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetMonthDailyUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetMonthDailyUseCase.kt deleted file mode 100644 index 704caf63..00000000 --- a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetMonthDailyUseCase.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.titi.app.doamin.daily.usecase - -import com.titi.app.data.daily.api.DailyRepository -import com.titi.app.doamin.daily.mapper.toDomainModel -import com.titi.app.doamin.daily.model.Daily -import java.time.LocalDate -import java.time.ZoneId -import java.time.ZoneOffset -import javax.inject.Inject - -class GetMonthDailyUseCase @Inject constructor( - private val dailyRepository: DailyRepository, -) { - suspend operator fun invoke(currentDate: LocalDate): List { - return dailyRepository.getDailies( - startDateTime = currentDate - .withDayOfMonth(1) - .atStartOfDay(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - .toString(), - endDateTime = currentDate - .atTime(23, 59, 59) - .atZone(ZoneId.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - .toString(), - )?.map { it.toDomainModel() } - ?: emptyList() - } -} diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt index 66ba70f7..5f5e2cf2 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt @@ -7,8 +7,9 @@ import com.titi.app.core.designsystem.model.TdsTaskData import com.titi.app.core.designsystem.model.TdsTimeTableData import com.titi.app.core.designsystem.model.TdsWeekLineChartData import com.titi.app.core.designsystem.theme.TdsColor -import com.titi.app.core.util.isCurrentDaily -import com.titi.app.core.util.isCurrentWeek +import com.titi.app.core.util.areDatesInSameDay +import com.titi.app.core.util.areDatesInSameMonth +import com.titi.app.core.util.areDatesInSameWeek import com.titi.app.doamin.daily.model.Daily import com.titi.app.domain.color.model.GraphColor import com.titi.app.feature.log.model.DailyGraphData @@ -21,6 +22,121 @@ import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.temporal.ChronoUnit +internal fun List.toHomeFeatureModel(): HomeUiState { + val currentDate = LocalDate.now() + val totalTaskMap = mutableMapOf() + val monthTaskMap = mutableMapOf() + val weekLineChartData = currentDate.makeDefaultWeekLineChardData().toMutableList() + var dailyTimeLine = LongArray(24) { 0L }.toList() + var totalTime = 0L + var monthTime = 0L + var weekTime = 0L + var weekStudyCount = 0 + + this.forEach { daily -> + val dailyDateTime = ZonedDateTime + .parse(daily.day) + .withZoneSameInstant(ZoneId.systemDefault()) + + daily.tasks?.let { safeTask -> + safeTask.forEach { (taskName, taskTime) -> + totalTaskMap[taskName] = + totalTaskMap.getOrDefault(taskName, 0L) + taskTime + totalTime += taskTime + } + } + + if (areDatesInSameMonth(currentDate, dailyDateTime)) { + daily.tasks?.let { safeTask -> + safeTask.forEach { (taskName, taskTime) -> + monthTaskMap[taskName] = + monthTaskMap.getOrDefault(taskName, 0L) + taskTime + monthTime += taskTime + } + } + } + + if (areDatesInSameWeek(currentDate, dailyDateTime)) { + val sumTime = daily.tasks?.values?.sum() ?: 0L + val updateWeekLineChartData = TdsWeekLineChartData( + time = sumTime, + date = "${dailyDateTime.month.value}/${dailyDateTime.dayOfMonth}", + ) + + weekLineChartData[dailyDateTime.dayOfWeek.value - 1] = updateWeekLineChartData + weekTime += sumTime + + if (sumTime > 0) { + weekStudyCount++ + } + } + + if (areDatesInSameDay(currentDate, dailyDateTime)) { + dailyTimeLine = daily.timeLine.toSystemDefaultTimeLine() + } + } + + val totalTopLevelTask = totalTaskMap + .toList() + .sortedByDescending { it.second } + .take(5) + val totalTopLevelSum = totalTopLevelTask.sumOf { it.second } + + val monthTopLevelTask = monthTaskMap + .toList() + .sortedByDescending { it.second } + .take(5) + val monthTopLevelSum = monthTopLevelTask.sumOf { it.second } + + return HomeUiState( + totalData = HomeUiState.TotalData( + totalTimeSeconds = totalTime, + topTotalTdsTaskData = totalTopLevelTask + .map { + TdsTaskData( + key = it.first, + value = it.second.getTimeString(), + progress = if (totalTopLevelSum == 0L) { + 0f + } else { + it.second / totalTopLevelSum.toFloat() + }, + ) + }, + ), + homeGraphData = HomeUiState.HomeGraphData( + homeMonthGraphData = HomeUiState.HomeMonthGraphData( + totalTimeSeconds = monthTime, + taskData = monthTopLevelTask + .map { + TdsTaskData( + key = it.first, + value = it.second.getTimeString(), + progress = if (monthTopLevelSum == 0L) { + 0f + } else { + it.second / monthTopLevelSum.toFloat() + }, + ) + }, + ), + homeWeekGraphData = HomeUiState.HomeWeekGraphData( + totalTimeSeconds = weekTime, + totalWeekTime = weekTime.getTimeString(), + averageWeekTime = if (weekStudyCount > 0) { + (weekTime / weekStudyCount).getTimeString() + } else { + 0L.getTimeString() + }, + weekLineChartData = weekLineChartData, + ), + homeDailyGraphData = HomeUiState.HomeDailyGraphData( + timeLines = dailyTimeLine, + ), + ), + ) +} + internal fun GraphColor.toFeatureModel() = GraphColorUiState( selectedIndex = selectedIndex, direction = direction, @@ -155,105 +271,6 @@ internal fun List.toWeekFeatureModel(currentDate: LocalDate): WeekGraphDa ) } -internal fun Pair, List>.toHomeFeatureModel( - currentDate: LocalDate, -): HomeUiState { - val totalMap = this.first - val totalTaskSum = totalMap.values.sum() - val totalTopLevelTask = totalMap - .toList() - .sortedByDescending { it.second } - .take(5) - val totalTopLevelTaskSum = totalTopLevelTask.sumOf { it.second } - val totalTopLevelTdsTaskData = totalTopLevelTask.map { - TdsTaskData( - key = it.first, - value = it.second.getTimeString(), - progress = if (totalTopLevelTaskSum == 0L) { - 0f - } else { - it.second / totalTopLevelTaskSum.toFloat() - }, - ) - } - - val monthDailies = this.second - val weekDailies = - monthDailies.filter { isCurrentWeek(ZonedDateTime.parse(it.day), currentDate) } - val todayDaily = - weekDailies.firstOrNull { isCurrentDaily(ZonedDateTime.parse(it.day), currentDate) } - - val monthTaskMap = mutableMapOf() - var monthTotalTime = 0L - monthDailies.forEach { daily -> - daily.tasks?.let { task -> - task.forEach { (taskName, taskTime) -> - monthTaskMap[taskName] = monthTaskMap.getOrDefault(taskName, 0L) + taskTime - } - monthTotalTime += task.values.sum() - } - } - val monthTopTaskData = monthTaskMap - .toList() - .sortedByDescending { it.second } - .take(5) - val monthTopTaskSum = monthTopTaskData.sumOf { it.second } - val monthTopTdsTaskData = monthTopTaskData.map { - TdsTaskData( - key = it.first, - value = it.second.getTimeString(), - progress = if (monthTopTaskSum == 0L) 0f else it.second / monthTopTaskSum.toFloat(), - ) - } - - var weekTotalTime = 0L - var weekStudyCount = 0 - val weekLineChartData = currentDate.makeDefaultWeekLineChardData().toMutableList() - - weekDailies.forEach { daily -> - val dateTime = ZonedDateTime - .parse(daily.day) - .withZoneSameInstant(ZoneId.systemDefault()) - val sumTime = daily.tasks?.values?.sum() ?: 0L - - val updateWeekLineChartData = TdsWeekLineChartData( - time = sumTime, - date = "${dateTime.month.value}/${dateTime.dayOfMonth}", - ) - - weekLineChartData[dateTime.dayOfWeek.value - 1] = updateWeekLineChartData - weekTotalTime += sumTime - if (sumTime > 0) { - weekStudyCount++ - } - } - - return HomeUiState( - totalData = HomeUiState.TotalData( - totalTimeSeconds = totalTaskSum, - topTotalTdsTaskData = totalTopLevelTdsTaskData, - ), - homeGraphData = HomeUiState.HomeGraphData( - homeMonthGraphData = HomeUiState.HomeMonthGraphData( - totalTimeSeconds = monthTotalTime, - taskData = monthTopTdsTaskData, - ), - homeWeekGraphData = HomeUiState.HomeWeekGraphData( - weekInformation = currentDate.getWeekInformation(), - totalTimeSeconds = weekTotalTime, - totalWeekTime = weekTotalTime.getTimeString(), - averageWeekTime = (weekTotalTime / weekStudyCount).getTimeString(), - weekLineChartData = weekLineChartData, - ), - homeDailyGraphData = HomeUiState.HomeDailyGraphData( - currentDate = currentDate, - timeLines = todayDaily?.timeLine?.toSystemDefaultTimeLine() - ?: LongArray(24) { 0L }.toList(), - ), - ), - ) -} - fun List.toSystemDefaultTimeLine(): List { val diffTime = 24 - (ZonedDateTime.now().offset.totalSeconds / 3600 + 24 + 18) % 24 diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt index dee8de75..c972a279 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt @@ -84,7 +84,6 @@ fun LogScreen( LaunchedEffect(Unit) { val currentDate = LocalDate.now() - viewModel.updateCurrentDateHome(currentDate) viewModel.updateCurrentDateWeek(currentDate) val calendarCurrentDate = if (pagerState.currentPage == 1) { diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt index 58f33fc1..d452aa3a 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt @@ -7,9 +7,8 @@ import com.airbnb.mvrx.hilt.AssistedViewModelFactory import com.airbnb.mvrx.hilt.hiltMavericksViewModelFactory import com.titi.app.data.graph.api.GraphRepository import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel -import com.titi.app.doamin.daily.usecase.GetAllDailiesTasksUseCase +import com.titi.app.doamin.daily.usecase.GetAllDailiesFlowUseCase import com.titi.app.doamin.daily.usecase.GetCurrentDateDailyFlowUseCase -import com.titi.app.doamin.daily.usecase.GetMonthDailyUseCase import com.titi.app.doamin.daily.usecase.GetWeekDailyUseCase import com.titi.app.doamin.daily.usecase.HasDailyForCurrentMonthUseCase import com.titi.app.domain.color.usecase.GetGraphColorsFlowUseCase @@ -22,14 +21,12 @@ import com.titi.app.feature.log.mapper.toWeekFeatureModel import com.titi.app.feature.log.model.DailyGraphData import com.titi.app.feature.log.model.GraphColorUiState import com.titi.app.feature.log.model.GraphGoalTimeUiState -import com.titi.app.feature.log.model.HomeUiState import com.titi.app.feature.log.model.LogUiState import com.titi.app.feature.log.model.WeekGraphData import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import java.time.LocalDate -import kotlinx.coroutines.async import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.filterNotNull @@ -39,9 +36,8 @@ import kotlinx.coroutines.launch class LogViewModel @AssistedInject constructor( @Assisted initialState: LogUiState, getGraphColorsFlowUseCase: GetGraphColorsFlowUseCase, + getAllDailiesFlowUseCase: GetAllDailiesFlowUseCase, private val updateGraphColorsUseCase: UpdateGraphColorsUseCase, - private val getAllDailiesTasksUseCase: GetAllDailiesTasksUseCase, - private val getMonthDailyUseCase: GetMonthDailyUseCase, private val getCurrentDateDailyFlowUseCase: GetCurrentDateDailyFlowUseCase, private val getWeekDailyUseCase: GetWeekDailyUseCase, private val hasDailyForCurrentMonthUseCase: HasDailyForCurrentMonthUseCase, @@ -58,6 +54,15 @@ class LogViewModel @AssistedInject constructor( copy(graphColorUiState = it.toFeatureModel()) } + getAllDailiesFlowUseCase().catch { + Log.e("LogViewModel", it.message.toString()) + }.filterNotNull() + .setOnEach { dailies -> + copy( + homeUiState = dailies.toHomeFeatureModel(), + ) + } + graphRepository.getGraphCheckedFlow().catch { Log.e("LogViewModel", it.message.toString()) }.setOnEach { @@ -117,34 +122,6 @@ class LogViewModel @AssistedInject constructor( } } - fun updateCurrentDateHome(date: LocalDate) { - val totalAsync = viewModelScope.async { - getAllDailiesTasksUseCase() - } - - val graphData = viewModelScope.async { - getMonthDailyUseCase(date) - } - - viewModelScope.launch { - runCatching { - Pair(totalAsync.await(), graphData.await()).toHomeFeatureModel(date) - }.onSuccess { - setState { - copy( - homeUiState = it, - ) - } - }.onFailure { - setState { - copy( - homeUiState = HomeUiState(), - ) - } - } - } - } - fun updateCurrentDateWeek(date: LocalDate) { viewModelScope.launch { getWeekDailyUseCase(date) From f3bc5de69edc14fc3f539d3ade0473b103b74e77 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 15:40:50 +0900 Subject: [PATCH 07/21] #142 remove : unused func --- .../com/titi/app/core/util/JavaTimeUtil.kt | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt index 3456e5bc..910ebfbf 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt @@ -1,6 +1,5 @@ package com.titi.app.core.util -import java.time.DayOfWeek import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneId @@ -10,39 +9,6 @@ import java.time.format.DateTimeFormatter import java.time.temporal.WeekFields import java.util.Locale -fun isCurrentWeek(checkDate: ZonedDateTime, currentDate: LocalDate): Boolean { - val diffMonday = currentDate.dayOfWeek.value - DayOfWeek.MONDAY.value - val diffSunday = DayOfWeek.SUNDAY.value - currentDate.dayOfWeek.value - - val monday = currentDate - .minusDays(diffMonday.toLong()) - .atStartOfDay() - .atZone(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - - val sunday = currentDate - .plusDays(diffSunday.toLong()) - .atTime(23, 59, 59) - .atZone(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - - return checkDate.isAfter(monday) && checkDate.isBefore(sunday) -} - -fun isCurrentDaily(checkDate: ZonedDateTime, currentDate: LocalDate): Boolean { - val startCurrentDay = currentDate - .atStartOfDay() - .atZone(ZoneId.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - - val endCurrentDay = currentDate - .atTime(23, 59, 59) - .atZone(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - - return checkDate.isAfter(startCurrentDay) && checkDate.isBefore(endCurrentDay) -} - fun LocalDateTime.toOnlyTime(): String { val formatter = DateTimeFormatter.ofPattern("HH:mm:ss") return this.format(formatter) From 473ea7ac669069f4dc846c3b4b5bf0984c8a1d5b Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 16:51:15 +0900 Subject: [PATCH 08/21] #142 update : daily data --- .../component/TdsWeekLineChart.kt | 6 +- .../com/titi/app/core/util/JavaTimeUtil.kt | 24 ++-- .../log/mapper/DomainToFeatureMapper.kt | 78 ++++++------- .../com/titi/app/feature/log/ui/LogScreen.kt | 2 +- .../titi/app/feature/log/ui/LogViewModel.kt | 105 +++++++++--------- 5 files changed, 110 insertions(+), 105 deletions(-) diff --git a/core/designsystem/src/main/kotlin/com/titi/app/core/designsystem/component/TdsWeekLineChart.kt b/core/designsystem/src/main/kotlin/com/titi/app/core/designsystem/component/TdsWeekLineChart.kt index f2c276fe..678115f9 100644 --- a/core/designsystem/src/main/kotlin/com/titi/app/core/designsystem/component/TdsWeekLineChart.kt +++ b/core/designsystem/src/main/kotlin/com/titi/app/core/designsystem/component/TdsWeekLineChart.kt @@ -136,8 +136,8 @@ private fun TdsWeekLineBar( text = time, style = textStyle, topLeft = Offset( - x = center.x - dateTextLayoutResult.size.width / 2, - y = startY - dateTextLayoutResult.size.height - spacing, + x = center.x - timeTextLayoutResult.size.width / 2, + y = startY - timeTextLayoutResult.size.height - spacing, ), ) @@ -190,7 +190,7 @@ private fun TdsWeekLineChartPreview() { .background(Color.White), weekLineChartData = listOf( TdsWeekLineChartData( - time = 6200, + time = 36000, date = "1/12", ), TdsWeekLineChartData( diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt index 910ebfbf..3dac9d5a 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt @@ -1,13 +1,12 @@ package com.titi.app.core.util +import java.time.DayOfWeek import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneId import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.format.DateTimeFormatter -import java.time.temporal.WeekFields -import java.util.Locale fun LocalDateTime.toOnlyTime(): String { val formatter = DateTimeFormatter.ofPattern("HH:mm:ss") @@ -68,17 +67,22 @@ fun areDatesInSameMonth(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boo } fun areDatesInSameWeek(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { - val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() - - val weekFields = WeekFields.of(Locale.getDefault()) + val diffMonday = localDate.dayOfWeek.value - DayOfWeek.MONDAY.value + val diffSunday = DayOfWeek.SUNDAY.value - localDate.dayOfWeek.value - val localDateWeek = localDate.get(weekFields.weekOfWeekBasedYear()) - val zonedDateTimeWeek = zonedDateTimeToLocalDate.get(weekFields.weekOfWeekBasedYear()) + val monday = localDate + .minusDays(diffMonday.toLong()) + .atStartOfDay() + .atZone(ZoneOffset.systemDefault()) + .withZoneSameInstant(ZoneOffset.UTC) - val localDateYear = localDate.get(weekFields.weekBasedYear()) - val zonedDateTimeYear = zonedDateTimeToLocalDate.get(weekFields.weekBasedYear()) + val sunday = localDate + .plusDays(diffSunday.toLong()) + .atTime(23, 59, 59) + .atZone(ZoneOffset.systemDefault()) + .withZoneSameInstant(ZoneOffset.UTC) - return localDateWeek == zonedDateTimeWeek && localDateYear == zonedDateTimeYear + return zonedDateTime.isAfter(monday) && zonedDateTime.isBefore(sunday) } fun areDatesInSameDay(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt index 5f5e2cf2..54726806 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt @@ -22,6 +22,12 @@ import java.time.ZoneOffset import java.time.ZonedDateTime import java.time.temporal.ChronoUnit +internal fun GraphColor.toFeatureModel() = GraphColorUiState( + selectedIndex = selectedIndex, + direction = direction, + graphColors = graphColors.map { TdsColor.valueOf(it.name) }, +) + internal fun List.toHomeFeatureModel(): HomeUiState { val currentDate = LocalDate.now() val totalTaskMap = mutableMapOf() @@ -137,13 +143,7 @@ internal fun List.toHomeFeatureModel(): HomeUiState { ) } -internal fun GraphColor.toFeatureModel() = GraphColorUiState( - selectedIndex = selectedIndex, - direction = direction, - graphColors = graphColors.map { TdsColor.valueOf(it.name) }, -) - -internal fun Daily.toFeatureModel(colors: List): DailyGraphData { +internal fun Daily.toDailyFeatureModel(colors: List): DailyGraphData { val sumTime = tasks?.values?.sum() var colorIndex = 0 val taskColorMap = mutableMapOf() @@ -180,38 +180,6 @@ internal fun Daily.toFeatureModel(colors: List): DailyGraphData { ) } -internal fun makeTimeTableData( - color: TdsColor, - startDate: String, - endDate: String, -): List { - var startZonedDateTime = ZonedDateTime - .parse(startDate) - .withZoneSameInstant(ZoneOffset.systemDefault()) - val endZonedDateTime = ZonedDateTime - .parse(endDate) - .withZoneSameInstant(ZoneOffset.systemDefault()) - - val timeTableData = mutableListOf() - - while (startZonedDateTime.isBefore(endZonedDateTime)) { - var nextHour = startZonedDateTime.truncatedTo(ChronoUnit.HOURS).plusHours(1) - nextHour = if (nextHour.isBefore(endZonedDateTime)) nextHour else endZonedDateTime - - timeTableData.add( - TdsTimeTableData( - color = color, - hour = startZonedDateTime.hour, - start = startZonedDateTime.minute * 60 + startZonedDateTime.second, - end = if (nextHour.minute == 0) 3600 else nextHour.minute * 60 + nextHour.second, - ), - ) - startZonedDateTime = nextHour - } - - return timeTableData.toList() -} - internal fun List.toWeekFeatureModel(currentDate: LocalDate): WeekGraphData { val defaultWeekLineChartData = currentDate .makeDefaultWeekLineChardData() @@ -271,6 +239,38 @@ internal fun List.toWeekFeatureModel(currentDate: LocalDate): WeekGraphDa ) } +internal fun makeTimeTableData( + color: TdsColor, + startDate: String, + endDate: String, +): List { + var startZonedDateTime = ZonedDateTime + .parse(startDate) + .withZoneSameInstant(ZoneOffset.systemDefault()) + val endZonedDateTime = ZonedDateTime + .parse(endDate) + .withZoneSameInstant(ZoneOffset.systemDefault()) + + val timeTableData = mutableListOf() + + while (startZonedDateTime.isBefore(endZonedDateTime)) { + var nextHour = startZonedDateTime.truncatedTo(ChronoUnit.HOURS).plusHours(1) + nextHour = if (nextHour.isBefore(endZonedDateTime)) nextHour else endZonedDateTime + + timeTableData.add( + TdsTimeTableData( + color = color, + hour = startZonedDateTime.hour, + start = startZonedDateTime.minute * 60 + startZonedDateTime.second, + end = if (nextHour.minute == 0) 3600 else nextHour.minute * 60 + nextHour.second, + ), + ) + startZonedDateTime = nextHour + } + + return timeTableData.toList() +} + fun List.toSystemDefaultTimeLine(): List { val diffTime = 24 - (ZonedDateTime.now().offset.totalSeconds / 3600 + 24 + 18) % 24 diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt index c972a279..2f8f8f30 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt @@ -185,7 +185,7 @@ fun LogScreen( timeTableData = uiState.dailyUiState.dailyGraphData.tdsTimeTableData, checkedButtonStates = uiState.dailyUiState.checkedButtonStates, onClickDate = { clickDate -> - viewModel.updateCurrentDate(clickDate) + viewModel.updateCurrentDailyDate(clickDate) }, onClickGraphColor = { viewModel.updateGraphColors( diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt index d452aa3a..5c86105a 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt @@ -13,6 +13,7 @@ import com.titi.app.doamin.daily.usecase.GetWeekDailyUseCase import com.titi.app.doamin.daily.usecase.HasDailyForCurrentMonthUseCase import com.titi.app.domain.color.usecase.GetGraphColorsFlowUseCase import com.titi.app.domain.color.usecase.UpdateGraphColorsUseCase +import com.titi.app.feature.log.mapper.toDailyFeatureModel import com.titi.app.feature.log.mapper.toDomainModel import com.titi.app.feature.log.mapper.toFeatureModel import com.titi.app.feature.log.mapper.toHomeFeatureModel @@ -63,18 +64,6 @@ class LogViewModel @AssistedInject constructor( ) } - graphRepository.getGraphCheckedFlow().catch { - Log.e("LogViewModel", it.message.toString()) - }.setOnEach { - copy(dailyUiState = dailyUiState.copy(checkedButtonStates = it.checkedButtonStates)) - } - - graphRepository.getGraphGoalTimeFlow().catch { - Log.e("LogViewModel", it.message.toString()) - }.setOnEach { - copy(graphGoalTimeUiState = it.toFeatureModel()) - } - currentDailyDate.flatMapLatest { getCurrentDateDailyFlowUseCase(it) }.catch { @@ -84,11 +73,31 @@ class LogViewModel @AssistedInject constructor( dailyUiState = dailyUiState.copy( currentDate = currentDailyDate.value, dailyGraphData = daily - ?.toFeatureModel(graphColorUiState.graphColors) + ?.toDailyFeatureModel(graphColorUiState.graphColors) ?: DailyGraphData(), ), ) } + + graphRepository.getGraphGoalTimeFlow().catch { + Log.e("LogViewModel", it.message.toString()) + }.setOnEach { + copy(graphGoalTimeUiState = it.toFeatureModel()) + } + + graphRepository.getGraphCheckedFlow().catch { + Log.e("LogViewModel", it.message.toString()) + }.setOnEach { + copy(dailyUiState = dailyUiState.copy(checkedButtonStates = it.checkedButtonStates)) + } + } + + fun updateTabSelectedIndex(index: Int) { + setState { + copy( + tabSelectedIndex = index, + ) + } } fun updateGraphColors(selectedIndex: Int, graphColorUiState: GraphColorUiState) { @@ -122,6 +131,37 @@ class LogViewModel @AssistedInject constructor( } } + fun updateCurrentDailyDate(date: LocalDate) { + currentDailyDate.value = date + } + + fun updateCheckedState(page: Int, checked: Boolean, checkedButtonStates: List) { + viewModelScope.launch { + val updateCheckedButtonStates = checkedButtonStates.toMutableList().apply { + set(page, checked) + } + + graphRepository.setGraphChecked( + GraphCheckedRepositoryModel( + updateCheckedButtonStates, + ), + ) + } + } + + fun updateHasDailyAtDailyTab(date: LocalDate) { + viewModelScope.launch { + val hasDailies = hasDailyForCurrentMonthUseCase(date) + setState { + copy( + dailyUiState = dailyUiState.copy( + hasDailies = hasDailies, + ), + ) + } + } + } + fun updateCurrentDateWeek(date: LocalDate) { viewModelScope.launch { getWeekDailyUseCase(date) @@ -148,23 +188,6 @@ class LogViewModel @AssistedInject constructor( } } - fun updateHasDailyAtDailyTab(date: LocalDate) { - viewModelScope.launch { - val hasDailies = hasDailyForCurrentMonthUseCase(date) - setState { - copy( - dailyUiState = dailyUiState.copy( - hasDailies = hasDailies, - ), - ) - } - } - } - - fun updateCurrentDate(date: LocalDate) { - currentDailyDate.value = date - } - fun updateHasDailyAtWeekTab(date: LocalDate) { viewModelScope.launch { val state = awaitState() @@ -192,28 +215,6 @@ class LogViewModel @AssistedInject constructor( } } - fun updateCheckedState(page: Int, checked: Boolean, checkedButtonStates: List) { - viewModelScope.launch { - val updateCheckedButtonStates = checkedButtonStates.toMutableList().apply { - set(page, checked) - } - - graphRepository.setGraphChecked( - GraphCheckedRepositoryModel( - updateCheckedButtonStates, - ), - ) - } - } - - fun updateTabSelectedIndex(index: Int) { - setState { - copy( - tabSelectedIndex = index, - ) - } - } - @AssistedFactory interface Factory : AssistedViewModelFactory { override fun create(state: LogUiState): LogViewModel From 659e9ecb41c69c22d2beee1cfc438e29816181a0 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 17:23:44 +0900 Subject: [PATCH 09/21] #142 update : week data --- .../com/titi/app/core/util/JavaTimeUtil.kt | 31 +++++++----- .../app/data/daily/api/DailyRepository.kt | 5 ++ .../app/data/daily/impl/local/dao/DailyDao.kt | 7 +++ .../impl/repository/DailyRepositoryImpl.kt | 12 +++++ .../GetCurrentWeekDailiesFlowUseCase.kt | 25 ++++++++++ .../daily/usecase/GetWeekDailyUseCase.kt | 48 ------------------- .../log/mapper/DomainToFeatureMapper.kt | 16 ++++--- .../com/titi/app/feature/log/ui/LogScreen.kt | 5 +- .../titi/app/feature/log/ui/LogViewModel.kt | 48 ++++++++----------- 9 files changed, 99 insertions(+), 98 deletions(-) create mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetCurrentWeekDailiesFlowUseCase.kt delete mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetWeekDailyUseCase.kt diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt index 3dac9d5a..34ccd0d2 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt @@ -67,26 +67,31 @@ fun areDatesInSameMonth(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boo } fun areDatesInSameWeek(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { - val diffMonday = localDate.dayOfWeek.value - DayOfWeek.MONDAY.value - val diffSunday = DayOfWeek.SUNDAY.value - localDate.dayOfWeek.value + val (monday, sunday) = getMondaySunday(localDate) - val monday = localDate + return zonedDateTime.isAfter(monday) && zonedDateTime.isBefore(sunday) +} + +fun areDatesInSameDay(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { + val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() + + return localDate == zonedDateTimeToLocalDate +} + +fun getMondaySunday(currentDate: LocalDate): Pair { + val diffMonday = currentDate.dayOfWeek.value - DayOfWeek.MONDAY.value + val diffSunday = DayOfWeek.SUNDAY.value - currentDate.dayOfWeek.value + + val monday = currentDate .minusDays(diffMonday.toLong()) - .atStartOfDay() - .atZone(ZoneOffset.systemDefault()) + .atStartOfDay(ZoneOffset.systemDefault()) .withZoneSameInstant(ZoneOffset.UTC) - val sunday = localDate + val sunday = currentDate .plusDays(diffSunday.toLong()) .atTime(23, 59, 59) .atZone(ZoneOffset.systemDefault()) .withZoneSameInstant(ZoneOffset.UTC) - return zonedDateTime.isAfter(monday) && zonedDateTime.isBefore(sunday) -} - -fun areDatesInSameDay(localDate: LocalDate, zonedDateTime: ZonedDateTime): Boolean { - val zonedDateTimeToLocalDate = zonedDateTime.toLocalDate() - - return localDate == zonedDateTimeToLocalDate + return Pair(monday, sunday) } diff --git a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt index 355beb12..79e1076b 100644 --- a/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt +++ b/data/daily/api/src/main/kotlin/com/titi/app/data/daily/api/DailyRepository.kt @@ -39,6 +39,11 @@ interface DailyRepository { suspend fun getDailies(startDateTime: String, endDateTime: String): List? + fun getDailiesFlow( + startDateTime: String, + endDateTime: String, + ): Flow?> + fun getAllDailiesFlow(): Flow?> suspend fun upsert(dailyRepositoryModel: DailyRepositoryModel) diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt index f59ce95f..dcd6adfa 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/local/dao/DailyDao.kt @@ -30,6 +30,13 @@ internal interface DailyDao { ) suspend fun getDailies(startDateTime: String, endDateTime: String): List? + @Query( + "SELECT * FROM dailies " + + " WHERE datetime(day) " + + "BETWEEN datetime(:startDateTime) AND datetime(:endDateTime)", + ) + fun getDailiesFlow(startDateTime: String, endDateTime: String): Flow?> + @Query("SELECT * FROM dailies") fun getAllDailiesFlow(): Flow?> diff --git a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt index ef40d459..baea126f 100644 --- a/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt +++ b/data/daily/impl/src/main/kotlin/com/titi/app/data/daily/impl/repository/DailyRepositoryImpl.kt @@ -44,6 +44,18 @@ internal class DailyRepositoryImpl @Inject constructor( )?.map { it.toRepositoryModel() } } + override fun getDailiesFlow( + startDateTime: String, + endDateTime: String, + ): Flow?> { + return dailyDao.getDailiesFlow( + startDateTime = startDateTime, + endDateTime = endDateTime, + ).map { dailies -> + dailies?.map { it.toRepositoryModel() } + } + } + override fun getAllDailiesFlow(): Flow?> { return dailyDao.getAllDailiesFlow().map { dailies -> dailies?.map { it.toRepositoryModel() } diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetCurrentWeekDailiesFlowUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetCurrentWeekDailiesFlowUseCase.kt new file mode 100644 index 00000000..c323d53e --- /dev/null +++ b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetCurrentWeekDailiesFlowUseCase.kt @@ -0,0 +1,25 @@ +package com.titi.app.doamin.daily.usecase + +import com.titi.app.core.util.getMondaySunday +import com.titi.app.data.daily.api.DailyRepository +import com.titi.app.doamin.daily.mapper.toDomainModel +import com.titi.app.doamin.daily.model.Daily +import java.time.LocalDate +import javax.inject.Inject +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.map + +class GetCurrentWeekDailiesFlowUseCase @Inject constructor( + private val dailyRepository: DailyRepository, +) { + operator fun invoke(currentDate: LocalDate): Flow?> { + val (monday, sunday) = getMondaySunday(currentDate) + + return dailyRepository.getDailiesFlow( + startDateTime = monday.toString(), + endDateTime = sunday.toString(), + ).map { dailies -> + dailies?.map { it.toDomainModel() } + } + } +} diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetWeekDailyUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetWeekDailyUseCase.kt deleted file mode 100644 index 091c8f2b..00000000 --- a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetWeekDailyUseCase.kt +++ /dev/null @@ -1,48 +0,0 @@ -package com.titi.app.doamin.daily.usecase - -import com.titi.app.data.daily.api.DailyRepository -import com.titi.app.doamin.daily.mapper.toDomainModel -import com.titi.app.doamin.daily.model.Daily -import java.time.DayOfWeek -import java.time.LocalDate -import java.time.ZoneOffset -import javax.inject.Inject - -class GetWeekDailyUseCase @Inject constructor( - private val dailyRepository: DailyRepository, -) { - - suspend operator fun invoke(currentDate: LocalDate): Result?> { - val pairMonDaySunDay = getMondaySunday(currentDate) - - val startDateTime = pairMonDaySunDay.first - val endDateTime = pairMonDaySunDay.second - - return runCatching { - dailyRepository.getDailies( - startDateTime = startDateTime, - endDateTime = endDateTime, - )?.map { it.toDomainModel() } - } - } -} - -fun getMondaySunday(currentDate: LocalDate): Pair { - val diffMonday = currentDate.dayOfWeek.value - DayOfWeek.MONDAY.value - val diffSunday = DayOfWeek.SUNDAY.value - currentDate.dayOfWeek.value - - val monday = currentDate - .minusDays(diffMonday.toLong()) - .atStartOfDay(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - .toString() - - val sunday = currentDate - .plusDays(diffSunday.toLong()) - .atTime(23, 59, 59) - .atZone(ZoneOffset.systemDefault()) - .withZoneSameInstant(ZoneOffset.UTC) - .toString() - - return Pair(monday, sunday) -} diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt index 54726806..916b8915 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/DomainToFeatureMapper.kt @@ -193,7 +193,15 @@ internal fun List.toWeekFeatureModel(currentDate: LocalDate): WeekGraphDa val dateTime = ZonedDateTime .parse(daily.day) .withZoneSameInstant(ZoneId.systemDefault()) - val sumTime = daily.tasks?.values?.sum() ?: 0L + var sumTime = 0L + + daily.tasks?.let { taskMap -> + taskMap.forEach { (taskName, taskTime) -> + totalTaskMap[taskName] = totalTaskMap.getOrDefault(taskName, 0L) + taskTime + sumTime += taskTime + totalWeekTime += taskTime + } + } val updateWeekLineChartData = TdsWeekLineChartData( time = sumTime, @@ -202,14 +210,10 @@ internal fun List.toWeekFeatureModel(currentDate: LocalDate): WeekGraphDa defaultWeekLineChartData[dateTime.dayOfWeek.value - 1] = updateWeekLineChartData totalWeekTime += sumTime + if (sumTime > 0) { studyCount++ } - daily.tasks?.let { taskMap -> - taskMap.forEach { (taskName, taskTime) -> - totalTaskMap[taskName] = totalTaskMap.getOrDefault(taskName, 0L) + taskTime - } - } } val topLevelTask = totalTaskMap diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt index 2f8f8f30..aa5f07a8 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt @@ -83,9 +83,6 @@ fun LogScreen( } LaunchedEffect(Unit) { - val currentDate = LocalDate.now() - viewModel.updateCurrentDateWeek(currentDate) - val calendarCurrentDate = if (pagerState.currentPage == 1) { uiState.dailyUiState.currentDate } else { @@ -219,7 +216,7 @@ fun LogScreen( topLevelTaskData = uiState.weekUiState.weekGraphData.topLevelTdsTaskData, currentDate = uiState.weekUiState.currentDate, onClickDate = { - viewModel.updateCurrentDateWeek(it) + viewModel.updateCurrentWeekDate(it) }, onClickGraphColor = { viewModel.updateGraphColors( diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt index 5c86105a..567e2db7 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt @@ -9,7 +9,7 @@ import com.titi.app.data.graph.api.GraphRepository import com.titi.app.data.graph.api.model.GraphCheckedRepositoryModel import com.titi.app.doamin.daily.usecase.GetAllDailiesFlowUseCase import com.titi.app.doamin.daily.usecase.GetCurrentDateDailyFlowUseCase -import com.titi.app.doamin.daily.usecase.GetWeekDailyUseCase +import com.titi.app.doamin.daily.usecase.GetCurrentWeekDailiesFlowUseCase import com.titi.app.doamin.daily.usecase.HasDailyForCurrentMonthUseCase import com.titi.app.domain.color.usecase.GetGraphColorsFlowUseCase import com.titi.app.domain.color.usecase.UpdateGraphColorsUseCase @@ -38,14 +38,15 @@ class LogViewModel @AssistedInject constructor( @Assisted initialState: LogUiState, getGraphColorsFlowUseCase: GetGraphColorsFlowUseCase, getAllDailiesFlowUseCase: GetAllDailiesFlowUseCase, - private val updateGraphColorsUseCase: UpdateGraphColorsUseCase, private val getCurrentDateDailyFlowUseCase: GetCurrentDateDailyFlowUseCase, - private val getWeekDailyUseCase: GetWeekDailyUseCase, + private val getCurrentWeekDailiesFlowUseCase: GetCurrentWeekDailiesFlowUseCase, + private val updateGraphColorsUseCase: UpdateGraphColorsUseCase, private val hasDailyForCurrentMonthUseCase: HasDailyForCurrentMonthUseCase, private val graphRepository: GraphRepository, ) : MavericksViewModel(initialState) { private val currentDailyDate: MutableStateFlow = MutableStateFlow(LocalDate.now()) + private val currentWeekDate: MutableStateFlow = MutableStateFlow(LocalDate.now()) init { getGraphColorsFlowUseCase().catch { @@ -79,6 +80,21 @@ class LogViewModel @AssistedInject constructor( ) } + currentWeekDate.flatMapLatest { + getCurrentWeekDailiesFlowUseCase(it) + }.catch { + Log.e("LogViewModel", it.message.toString()) + }.setOnEach { daily -> + copy( + weekUiState = weekUiState.copy( + currentDate = currentWeekDate.value, + weekGraphData = daily + ?.toWeekFeatureModel(currentWeekDate.value) + ?: WeekGraphData(), + ), + ) + } + graphRepository.getGraphGoalTimeFlow().catch { Log.e("LogViewModel", it.message.toString()) }.setOnEach { @@ -162,30 +178,8 @@ class LogViewModel @AssistedInject constructor( } } - fun updateCurrentDateWeek(date: LocalDate) { - viewModelScope.launch { - getWeekDailyUseCase(date) - .onSuccess { - setState { - copy( - weekUiState = weekUiState.copy( - currentDate = date, - weekGraphData = it?.toWeekFeatureModel(date) ?: WeekGraphData(), - ), - ) - } - } - .onFailure { - setState { - copy( - weekUiState = weekUiState.copy( - currentDate = date, - weekGraphData = WeekGraphData(), - ), - ) - } - } - } + fun updateCurrentWeekDate(date: LocalDate) { + currentWeekDate.value = date } fun updateHasDailyAtWeekTab(date: LocalDate) { From 4ac75bac785244995ef47fd32ca0106f76156f9f Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 18:16:56 +0900 Subject: [PATCH 10/21] #142 update : graph goal time --- .../log/mapper/FeatureToRepositoryMapper.kt | 4 +- .../log/mapper/RepositoryToFeatureMapper.kt | 4 +- .../titi/app/feature/log/model/LogUiState.kt | 14 ++-- .../titi/app/feature/log/ui/DailyScreen.kt | 64 +++++++++---------- .../com/titi/app/feature/log/ui/HomeScreen.kt | 40 +++--------- .../com/titi/app/feature/log/ui/LogScreen.kt | 26 ++------ .../titi/app/feature/log/ui/LogViewModel.kt | 14 ++-- .../com/titi/app/feature/log/ui/WeekScreen.kt | 52 +++++++-------- .../log/ui/component/SettingBottomSheet.kt | 16 ++--- 9 files changed, 101 insertions(+), 133 deletions(-) diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/FeatureToRepositoryMapper.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/FeatureToRepositoryMapper.kt index 9565e8ec..f6ba946f 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/FeatureToRepositoryMapper.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/FeatureToRepositoryMapper.kt @@ -1,9 +1,9 @@ package com.titi.app.feature.log.mapper import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel -import com.titi.app.feature.log.model.GraphGoalTimeUiState +import com.titi.app.feature.log.model.HomeUiState -internal fun GraphGoalTimeUiState.toRepositoryModel() = GraphGoalTimeRepositoryModel( +internal fun HomeUiState.GraphGoalTime.toRepositoryModel() = GraphGoalTimeRepositoryModel( monthGoalTime = monthGoalTime, weekGoalTime = weekGoalTime, ) diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/RepositoryToFeatureMapper.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/RepositoryToFeatureMapper.kt index 6bde02e6..a23566fb 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/RepositoryToFeatureMapper.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/mapper/RepositoryToFeatureMapper.kt @@ -1,9 +1,9 @@ package com.titi.app.feature.log.mapper import com.titi.app.data.graph.api.model.GraphGoalTimeRepositoryModel -import com.titi.app.feature.log.model.GraphGoalTimeUiState +import com.titi.app.feature.log.model.HomeUiState -internal fun GraphGoalTimeRepositoryModel.toFeatureModel() = GraphGoalTimeUiState( +internal fun GraphGoalTimeRepositoryModel.toFeatureModel() = HomeUiState.GraphGoalTime( monthGoalTime = monthGoalTime, weekGoalTime = weekGoalTime, ) diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/model/LogUiState.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/model/LogUiState.kt index de0aaee8..19a3eb19 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/model/LogUiState.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/model/LogUiState.kt @@ -13,18 +13,12 @@ import java.time.LocalDate data class LogUiState( val tabSelectedIndex: Int = 0, - val graphGoalTimeUiState: GraphGoalTimeUiState = GraphGoalTimeUiState(), val graphColorUiState: GraphColorUiState = GraphColorUiState(), val homeUiState: HomeUiState = HomeUiState(), val dailyUiState: DailyUiState = DailyUiState(), val weekUiState: WeekUiState = WeekUiState(), ) : MavericksState -data class GraphGoalTimeUiState( - val monthGoalTime: Int = 100, - val weekGoalTime: Int = 30, -) - data class GraphColorUiState( val selectedIndex: Int = 0, val direction: GraphColor.GraphDirection = GraphColor.GraphDirection.Right, @@ -45,9 +39,15 @@ data class GraphColorUiState( ) data class HomeUiState( + val graphGoalTime: GraphGoalTime = GraphGoalTime(), val totalData: TotalData = TotalData(), val homeGraphData: HomeGraphData = HomeGraphData(), ) { + data class GraphGoalTime( + val monthGoalTime: Int = 100, + val weekGoalTime: Int = 30, + ) + data class TotalData( val totalTimeSeconds: Long = 0L, val topTotalTdsTaskData: List = emptyList(), @@ -84,6 +84,7 @@ data class HomeUiState( data class DailyUiState( val currentDate: LocalDate = LocalDate.now(), + val isCreate: Boolean = true, val hasDailies: List = emptyList(), val dailyGraphData: DailyGraphData = DailyGraphData(), val checkedButtonStates: List = List(4) { false }, @@ -99,6 +100,7 @@ data class DailyGraphData( data class WeekUiState( val currentDate: LocalDate = LocalDate.now(), + val isCreate: Boolean = true, val hasDailies: List = emptyList(), val weekGraphData: WeekGraphData = WeekGraphData(), ) diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/DailyScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/DailyScreen.kt index b343b22c..0c75c50a 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/DailyScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/DailyScreen.kt @@ -32,6 +32,8 @@ import com.titi.app.core.designsystem.model.TdsTaskData import com.titi.app.core.designsystem.model.TdsTimeTableData import com.titi.app.core.designsystem.theme.TdsColor import com.titi.app.core.designsystem.theme.TiTiTheme +import com.titi.app.feature.log.model.DailyGraphData +import com.titi.app.feature.log.model.DailyUiState import com.titi.app.feature.log.ui.component.ButtonRow import com.titi.app.feature.log.ui.component.CalendarContent import com.titi.app.feature.log.util.saveDailyGraph @@ -41,15 +43,8 @@ import java.time.LocalDate @Composable fun DailyScreen( - currentDate: LocalDate, - totalTime: String, - maxTime: String, - hasDailies: List, - taskData: List, + dailyUiState: DailyUiState, tdsColors: List, - timeLines: List, - timeTableData: List, - checkedButtonStates: List, onClickDate: (LocalDate) -> Unit, onClickGraphColor: (Int) -> Unit, onCalendarLocalDateChanged: (LocalDate) -> Unit, @@ -75,7 +70,7 @@ fun DailyScreen( coroutineScope = coroutineScope, context = context, pictureList = pictureList, - checkedButtonStates = checkedButtonStates, + checkedButtonStates = dailyUiState.checkedButtonStates, ) Toast.makeText(context, message, Toast.LENGTH_SHORT).show() } else { @@ -110,8 +105,8 @@ fun DailyScreen( CalendarContent( modifier = Modifier.fillMaxWidth(), themeColor = tdsColors.first(), - currentDate = currentDate, - hasDailies = hasDailies, + currentDate = dailyUiState.currentDate, + hasDailies = dailyUiState.hasDailies, onClickDate = onClickDate, onCalendarLocalDateChanged = onCalendarLocalDateChanged, ) @@ -127,14 +122,14 @@ fun DailyScreen( ButtonRow( modifier = Modifier.fillMaxWidth(), - isCreate = !hasDailies.contains(currentDate), + isCreate = dailyUiState.isCreate, onSaveClick = { - if (checkedButtonStates.any { it }) { + if (dailyUiState.checkedButtonStates.any { it }) { saveDailyGraphWithPermission( coroutineScope = coroutineScope, context = context, pictureList = pictureList, - checkedButtonStates = checkedButtonStates, + checkedButtonStates = dailyUiState.checkedButtonStates, permissionLauncher = requestWritePermissionLauncher, ) } else { @@ -142,11 +137,11 @@ fun DailyScreen( } }, onShareClick = { - if (checkedButtonStates.any { it }) { + if (dailyUiState.checkedButtonStates.any { it }) { shareDailyGraph( context = context, pictureList = pictureList, - checkedButtonStates = checkedButtonStates, + checkedButtonStates = dailyUiState.checkedButtonStates, ) } else { Toast.makeText(context, "선택된 그래프가 없습니다.", Toast.LENGTH_SHORT).show() @@ -159,15 +154,15 @@ fun DailyScreen( TdsGraphContent( modifier = Modifier.fillMaxWidth(), - todayDate = currentDate.toString().replace('-', '.'), - todayDayOfTheWeek = currentDate.dayOfWeek.value - 1, - totalTime = totalTime, - maxTime = maxTime, - taskData = taskData, + todayDate = dailyUiState.currentDate.toString().replace('-', '.'), + todayDayOfTheWeek = dailyUiState.currentDate.dayOfWeek.value - 1, + totalTime = dailyUiState.dailyGraphData.totalTime, + maxTime = dailyUiState.dailyGraphData.maxTime, + taskData = dailyUiState.dailyGraphData.taskData, tdsColors = tdsColors, - timeLines = timeLines, - timeTableData = timeTableData, - checkedButtonStates = checkedButtonStates, + timeLines = dailyUiState.dailyGraphData.timeLine, + timeTableData = dailyUiState.dailyGraphData.tdsTimeTableData, + checkedButtonStates = dailyUiState.checkedButtonStates, pictureList = pictureList, onCheckedChange = onCheckedChange, ) @@ -270,15 +265,20 @@ private fun DailyScreenPreview() { TiTiTheme { DailyScreen( - taskData = taskData, + dailyUiState = DailyUiState( + currentDate = LocalDate.now(), + isCreate = false, + hasDailies = listOf(), + dailyGraphData = DailyGraphData( + totalTime = "03:00:00", + maxTime = "03:00:00", + timeLine = timeLines, + taskData = taskData, + tdsTimeTableData = timeTableData, + ), + checkedButtonStates = listOf(), + ), tdsColors = tdsColors, - totalTime = "08:00:00", - maxTime = "03:00:00", - hasDailies = emptyList(), - timeLines = timeLines, - timeTableData = timeTableData, - currentDate = LocalDate.now(), - checkedButtonStates = List(4) { false }, onClickDate = {}, onClickGraphColor = {}, onCalendarLocalDateChanged = {}, diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/HomeScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/HomeScreen.kt index b5776317..aa31283c 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/HomeScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/HomeScreen.kt @@ -29,22 +29,13 @@ import com.titi.app.core.designsystem.component.TdsTaskResultList import com.titi.app.core.designsystem.component.TdsText import com.titi.app.core.designsystem.component.TdsTimeLineChart import com.titi.app.core.designsystem.component.TdsWeekLineChart -import com.titi.app.core.designsystem.model.TdsTaskData import com.titi.app.core.designsystem.theme.TdsColor import com.titi.app.core.designsystem.theme.TdsTextStyle import com.titi.app.core.designsystem.theme.TiTiTheme -import com.titi.app.feature.log.model.GraphGoalTimeUiState import com.titi.app.feature.log.model.HomeUiState @Composable -fun HomeScreen( - tdsColors: List, - totalData: HomeUiState.TotalData, - graphGoalTimeUiState: GraphGoalTimeUiState, - homeMonthGraphData: HomeUiState.HomeMonthGraphData, - homeWeekGraphData: HomeUiState.HomeWeekGraphData, - homeDailyGraphData: HomeUiState.HomeDailyGraphData, -) { +fun HomeScreen(homeUiState: HomeUiState, tdsColors: List) { val scrollState = rememberScrollState() Column( @@ -54,7 +45,7 @@ fun HomeScreen( horizontalAlignment = Alignment.CenterHorizontally, ) { TotalCard( - totalData = totalData, + totalData = homeUiState.totalData, tdsColors = tdsColors, ) @@ -74,20 +65,20 @@ fun HomeScreen( horizontalArrangement = Arrangement.SpaceBetween, ) { MonthSumCard( - totalTimeSeconds = homeMonthGraphData.totalTimeSeconds, - goalTimeSeconds = graphGoalTimeUiState.monthGoalTime * 3600L, + totalTimeSeconds = homeUiState.homeGraphData.homeMonthGraphData.totalTimeSeconds, + goalTimeSeconds = homeUiState.graphGoalTime.monthGoalTime * 3600L, themeColor = tdsColors.first(), ) WeekSumCard( - totalTimeSeconds = homeWeekGraphData.totalTimeSeconds, - goalTimeSeconds = graphGoalTimeUiState.weekGoalTime * 3600L, + totalTimeSeconds = homeUiState.homeGraphData.homeWeekGraphData.totalTimeSeconds, + goalTimeSeconds = homeUiState.graphGoalTime.weekGoalTime * 3600L, themeColor = tdsColors.first(), ) } MonthCard( - homeMonthGraphData = homeMonthGraphData, + homeMonthGraphData = homeUiState.homeGraphData.homeMonthGraphData, tdsColors = tdsColors, ) @@ -103,7 +94,7 @@ fun HomeScreen( Spacer(modifier = Modifier.height(16.dp)) WeekCard( - homeWeekGraphData = homeWeekGraphData, + homeWeekGraphData = homeUiState.homeGraphData.homeWeekGraphData, tdsColors = tdsColors, ) @@ -119,7 +110,7 @@ fun HomeScreen( Spacer(modifier = Modifier.height(16.dp)) TimeLineCard( - homeDailyGraphData = homeDailyGraphData, + homeDailyGraphData = homeUiState.homeGraphData.homeDailyGraphData, tdsColors = tdsColors, ) @@ -438,18 +429,7 @@ private fun HomeScreenPreview() { TiTiTheme { HomeScreen( tdsColors = tdsColors, - totalData = HomeUiState.TotalData( - totalTimeSeconds = 6368, - topTotalTdsTaskData = listOf( - TdsTaskData(key = "definitiones", value = "360H", progress = 0.3f), - TdsTaskData(key = "231445", value = "detraxit", progress = 0.2f), - TdsTaskData(key = "sadfsd", value = "detraxit", progress = 0.5f), - ), - ), - graphGoalTimeUiState = GraphGoalTimeUiState(), - homeMonthGraphData = HomeUiState.HomeMonthGraphData(), - homeWeekGraphData = HomeUiState.HomeWeekGraphData(), - homeDailyGraphData = HomeUiState.HomeDailyGraphData(), + homeUiState = HomeUiState(), ) } } diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt index aa5f07a8..53d98601 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogScreen.kt @@ -75,7 +75,7 @@ fun LogScreen( SettingBottomSheet( viewModel = viewModel, graphColorUiState = uiState.graphColorUiState, - graphGoalTimeUiState = uiState.graphGoalTimeUiState, + graphGoalTime = uiState.homeUiState.graphGoalTime, onDismissRequest = { showSettingBottomSheet = false }, @@ -163,24 +163,13 @@ fun LogScreen( ) { page -> when (page % 3) { 0 -> HomeScreen( + homeUiState = uiState.homeUiState, tdsColors = uiState.graphColorUiState.graphColors, - totalData = uiState.homeUiState.totalData, - graphGoalTimeUiState = uiState.graphGoalTimeUiState, - homeMonthGraphData = uiState.homeUiState.homeGraphData.homeMonthGraphData, - homeWeekGraphData = uiState.homeUiState.homeGraphData.homeWeekGraphData, - homeDailyGraphData = uiState.homeUiState.homeGraphData.homeDailyGraphData, ) 1 -> DailyScreen( - currentDate = uiState.dailyUiState.currentDate, - hasDailies = uiState.dailyUiState.hasDailies, - totalTime = uiState.dailyUiState.dailyGraphData.totalTime, - maxTime = uiState.dailyUiState.dailyGraphData.maxTime, - taskData = uiState.dailyUiState.dailyGraphData.taskData, + dailyUiState = uiState.dailyUiState, tdsColors = uiState.graphColorUiState.graphColors, - timeLines = uiState.dailyUiState.dailyGraphData.timeLine, - timeTableData = uiState.dailyUiState.dailyGraphData.tdsTimeTableData, - checkedButtonStates = uiState.dailyUiState.checkedButtonStates, onClickDate = { clickDate -> viewModel.updateCurrentDailyDate(clickDate) }, @@ -206,15 +195,8 @@ fun LogScreen( ) 2 -> WeekScreen( - weekInformation = uiState.weekUiState.weekGraphData.weekInformation, - hasDailies = uiState.weekUiState.hasDailies, - totalTime = uiState.weekUiState.weekGraphData.totalWeekTime, - averageTime = uiState.weekUiState.weekGraphData.averageWeekTime, - weekLineChartData = uiState.weekUiState.weekGraphData.weekLineChartData, + weekUiState = uiState.weekUiState, tdsColors = uiState.graphColorUiState.graphColors, - topLevelTaskTotal = uiState.weekUiState.weekGraphData.topLevelTaskTotal, - topLevelTaskData = uiState.weekUiState.weekGraphData.topLevelTdsTaskData, - currentDate = uiState.weekUiState.currentDate, onClickDate = { viewModel.updateCurrentWeekDate(it) }, diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt index 567e2db7..4f270cee 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/LogViewModel.kt @@ -21,7 +21,7 @@ import com.titi.app.feature.log.mapper.toRepositoryModel import com.titi.app.feature.log.mapper.toWeekFeatureModel import com.titi.app.feature.log.model.DailyGraphData import com.titi.app.feature.log.model.GraphColorUiState -import com.titi.app.feature.log.model.GraphGoalTimeUiState +import com.titi.app.feature.log.model.HomeUiState import com.titi.app.feature.log.model.LogUiState import com.titi.app.feature.log.model.WeekGraphData import dagger.assisted.Assisted @@ -73,6 +73,7 @@ class LogViewModel @AssistedInject constructor( copy( dailyUiState = dailyUiState.copy( currentDate = currentDailyDate.value, + isCreate = daily == null, dailyGraphData = daily ?.toDailyFeatureModel(graphColorUiState.graphColors) ?: DailyGraphData(), @@ -88,6 +89,7 @@ class LogViewModel @AssistedInject constructor( copy( weekUiState = weekUiState.copy( currentDate = currentWeekDate.value, + isCreate = daily == null, weekGraphData = daily ?.toWeekFeatureModel(currentWeekDate.value) ?: WeekGraphData(), @@ -98,7 +100,7 @@ class LogViewModel @AssistedInject constructor( graphRepository.getGraphGoalTimeFlow().catch { Log.e("LogViewModel", it.message.toString()) }.setOnEach { - copy(graphGoalTimeUiState = it.toFeatureModel()) + copy(homeUiState = homeUiState.copy(graphGoalTime = it.toFeatureModel())) } graphRepository.getGraphCheckedFlow().catch { @@ -128,19 +130,19 @@ class LogViewModel @AssistedInject constructor( fun updateGraphGoalTime( monthGoalTime: Int? = null, weekGoalTime: Int? = null, - graphGoalTimeUiState: GraphGoalTimeUiState, + graphGoalTime: HomeUiState.GraphGoalTime, ) { viewModelScope.launch { val updateGraphGoalTimeUiState = when { - monthGoalTime != null && monthGoalTime > 0 -> graphGoalTimeUiState.copy( + monthGoalTime != null && monthGoalTime > 0 -> graphGoalTime.copy( monthGoalTime = monthGoalTime, ) - weekGoalTime != null && weekGoalTime > 0 -> graphGoalTimeUiState.copy( + weekGoalTime != null && weekGoalTime > 0 -> graphGoalTime.copy( weekGoalTime = weekGoalTime, ) - else -> graphGoalTimeUiState + else -> graphGoalTime } graphRepository.setGraphGoalTime(updateGraphGoalTimeUiState.toRepositoryModel()) diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/WeekScreen.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/WeekScreen.kt index 9299502d..8d98987d 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/WeekScreen.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/WeekScreen.kt @@ -27,11 +27,14 @@ import com.titi.app.core.designsystem.R import com.titi.app.core.designsystem.component.TdsColorRow import com.titi.app.core.designsystem.component.TdsDialog import com.titi.app.core.designsystem.component.TdsStandardWeekGraph +import com.titi.app.core.designsystem.extension.getWeekInformation import com.titi.app.core.designsystem.model.TdsDialogInfo import com.titi.app.core.designsystem.model.TdsTaskData import com.titi.app.core.designsystem.model.TdsWeekLineChartData import com.titi.app.core.designsystem.theme.TdsColor import com.titi.app.core.designsystem.theme.TiTiTheme +import com.titi.app.feature.log.model.WeekGraphData +import com.titi.app.feature.log.model.WeekUiState import com.titi.app.feature.log.ui.component.ButtonRow import com.titi.app.feature.log.ui.component.CalendarContent import com.titi.app.feature.log.util.saveWeekGraph @@ -41,15 +44,8 @@ import java.time.LocalDate @Composable fun WeekScreen( - totalTime: String, - averageTime: String, - hasDailies: List, - weekLineChartData: List, - weekInformation: Triple, + weekUiState: WeekUiState, tdsColors: List, - topLevelTaskData: List, - topLevelTaskTotal: String, - currentDate: LocalDate, onClickDate: (LocalDate) -> Unit, onClickGraphColor: (Int) -> Unit, onCalendarLocalDateChanged: (LocalDate) -> Unit, @@ -108,8 +104,8 @@ fun WeekScreen( CalendarContent( modifier = Modifier.fillMaxWidth(), themeColor = tdsColors.first(), - currentDate = currentDate, - hasDailies = hasDailies, + currentDate = weekUiState.currentDate, + hasDailies = weekUiState.hasDailies, onClickDate = onClickDate, onCalendarLocalDateChanged = onCalendarLocalDateChanged, ) @@ -125,7 +121,7 @@ fun WeekScreen( ButtonRow( modifier = Modifier.fillMaxWidth(), - isCreate = !hasDailies.contains(currentDate), + isCreate = weekUiState.isCreate, onSaveClick = { saveWeekGraphWithPermission( coroutineScope = coroutineScope, @@ -147,13 +143,13 @@ fun WeekScreen( TdsStandardWeekGraph( modifier = Modifier.fillMaxWidth(), - totalTime = totalTime, - averageTime = averageTime, - weekInformation = weekInformation, - weekLineChartData = weekLineChartData, + totalTime = weekUiState.weekGraphData.totalWeekTime, + averageTime = weekUiState.weekGraphData.averageWeekTime, + weekInformation = weekUiState.weekGraphData.weekInformation, + weekLineChartData = weekUiState.weekGraphData.weekLineChartData, tdsColors = tdsColors, - topLevelTaskData = topLevelTaskData, - topLevelTaskTotal = topLevelTaskTotal, + topLevelTaskData = weekUiState.weekGraphData.topLevelTdsTaskData, + topLevelTaskTotal = weekUiState.weekGraphData.topLevelTaskTotal, picture = picture, ) } @@ -232,15 +228,21 @@ private fun WeekScreenPreview() { TiTiTheme { WeekScreen( - weekInformation = Triple("2024.02", "Week 2", "02.12~02.19"), - totalTime = "08:00:00", - averageTime = "03:00:00", - weekLineChartData = weekLineChartData, + weekUiState = WeekUiState( + currentDate = LocalDate.now(), + isCreate = false, + hasDailies = listOf(), + weekGraphData = WeekGraphData( + weekInformation = LocalDate.now().getWeekInformation(), + totalWeekTime = "03:00:00", + averageWeekTime = "03:00:00", + weekLineChartData = weekLineChartData, + topLevelTaskTotal = "03:00:00", + topLevelTdsTaskData = taskData, + ), + + ), tdsColors = tdsColors, - hasDailies = emptyList(), - topLevelTaskData = taskData, - topLevelTaskTotal = "08:00:00", - currentDate = LocalDate.now(), onClickDate = {}, onClickGraphColor = {}, onCalendarLocalDateChanged = {}, diff --git a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/component/SettingBottomSheet.kt b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/component/SettingBottomSheet.kt index cc7b9c70..e9e78e37 100644 --- a/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/component/SettingBottomSheet.kt +++ b/feature/log/src/main/kotlin/com/titi/app/feature/log/ui/component/SettingBottomSheet.kt @@ -52,7 +52,7 @@ import com.titi.app.core.designsystem.theme.TdsTextStyle import com.titi.app.core.designsystem.theme.TiTiTheme import com.titi.app.domain.color.model.GraphColor import com.titi.app.feature.log.model.GraphColorUiState -import com.titi.app.feature.log.model.GraphGoalTimeUiState +import com.titi.app.feature.log.model.HomeUiState import com.titi.app.feature.log.ui.LogViewModel import kotlinx.coroutines.android.awaitFrame @@ -61,7 +61,7 @@ import kotlinx.coroutines.android.awaitFrame fun SettingBottomSheet( viewModel: LogViewModel, graphColorUiState: GraphColorUiState, - graphGoalTimeUiState: GraphGoalTimeUiState, + graphGoalTime: HomeUiState.GraphGoalTime, onDismissRequest: () -> Unit, ) { val bottomSheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true) @@ -87,7 +87,7 @@ fun SettingBottomSheet( onPositive = { viewModel.updateGraphGoalTime( monthGoalTime = goalTime.toIntOrNull(), - graphGoalTimeUiState = graphGoalTimeUiState, + graphGoalTime = graphGoalTime, ) }, negativeText = stringResource(id = R.string.Cancel), @@ -120,7 +120,7 @@ fun SettingBottomSheet( showMonthGoalTimeDialog = false viewModel.updateGraphGoalTime( monthGoalTime = goalTime.toIntOrNull(), - graphGoalTimeUiState = graphGoalTimeUiState, + graphGoalTime = graphGoalTime, ) }, ), @@ -151,7 +151,7 @@ fun SettingBottomSheet( onPositive = { viewModel.updateGraphGoalTime( weekGoalTime = goalTime.toIntOrNull(), - graphGoalTimeUiState = graphGoalTimeUiState, + graphGoalTime = graphGoalTime, ) }, negativeText = stringResource(id = R.string.Cancel), @@ -184,7 +184,7 @@ fun SettingBottomSheet( showWeekGoalTimeDialog = false viewModel.updateGraphGoalTime( weekGoalTime = goalTime.toIntOrNull(), - graphGoalTimeUiState = graphGoalTimeUiState, + graphGoalTime = graphGoalTime, ) }, ), @@ -223,8 +223,8 @@ fun SettingBottomSheet( GraphColor.GraphDirection.Left -> 1 }, graphColors = graphColorUiState.graphColors, - monthGoalTime = "${graphGoalTimeUiState.monthGoalTime} H", - weekGoalTime = "${graphGoalTimeUiState.weekGoalTime} H", + monthGoalTime = "${graphGoalTime.monthGoalTime} H", + weekGoalTime = "${graphGoalTime.weekGoalTime} H", onClickColor = { viewModel.updateGraphColors( selectedIndex = it, From 605ee389cbc56dececa1f5b4bd0ada09e74a53ec Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 19:30:23 +0900 Subject: [PATCH 11/21] #138 update : title text --- .../kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt index 77e299c8..cc7936ea 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/ui/SettingScreen.kt @@ -470,7 +470,7 @@ internal fun DeveloperSection(onSettingActions: (SettingActions) -> Unit) { sendIntent.data = uri if (sendIntent.resolveActivity(context.packageManager) != null) { - context.startActivity(Intent.createChooser(sendIntent, "Send email")) + context.startActivity(Intent.createChooser(sendIntent, "Send Email")) } else { Toast.makeText( context, From d83b6812e0fea0c799401fab499bfbd8cb98e0a4 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 23:41:54 +0900 Subject: [PATCH 12/21] =?UTF-8?q?#138=20feat=20:=20add=20=EB=8D=B0?= =?UTF-8?q?=EC=9D=BC=EB=A6=AC=20=EC=88=98=EC=A0=95=20=EC=83=9D=EC=84=B1=20?= =?UTF-8?q?notion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/titi/app/feature/setting/model/FeaturesUiState.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/FeaturesUiState.kt b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/FeaturesUiState.kt index 6c6d2429..b9dc0b40 100644 --- a/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/FeaturesUiState.kt +++ b/feature/setting/src/main/kotlin/com/titi/app/feature/setting/model/FeaturesUiState.kt @@ -38,5 +38,9 @@ internal fun makeFeatures(): List { title = "Daily", url = "https://www.notion.so/timertiti/Daily-d60dc90f3c104744a74985ea221e5691?pvs=4", ), + FeaturesUiState.Feature( + title = "Daily 수정/생성", + url = "https://timertiti.notion.site/Daily-f3b7898bcda541dda3ac526ea6a56313?pvs=4", + ), ) } From 76a232db364f51d1a04394c75b9f8a52aae503b1 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Sun, 14 Jul 2024 23:59:29 +0900 Subject: [PATCH 13/21] =?UTF-8?q?#165=20fix=20:=20=EC=A2=85=EB=A3=8C=20?= =?UTF-8?q?=EC=9D=B4=ED=9B=84=20=ED=83=80=EC=9D=B4=EB=A8=B8=20=EC=8B=9C?= =?UTF-8?q?=EC=9E=91=20=EC=95=88=EB=90=98=EB=8A=94=20=ED=98=84=EC=83=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/feature/time/ui/timer/TimerViewModel.kt | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt index 3ca8078e..7cbb6b14 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt @@ -143,10 +143,18 @@ class TimerViewModel @AssistedInject constructor( savedGoalTime = it.recordTimes.setGoalTime, ) to Daily() } else { - it.recordTimes.copy( - recording = true, - recordStartAt = ZonedDateTime.now(ZoneOffset.UTC).toString(), - ) to it.daily + if (it.recordTimes.savedTimerTime > 0L) { + it.recordTimes.copy( + recording = true, + recordStartAt = ZonedDateTime.now(ZoneOffset.UTC).toString(), + ) + } else { + it.recordTimes.copy( + recording = true, + recordStartAt = ZonedDateTime.now(ZoneOffset.UTC).toString(), + savedTimerTime = it.recordTimes.setTimerTime, + ) + } to it.daily } setState { From 2e14c7336ddd7c481679bee81963754d00c74113 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 00:25:34 +0900 Subject: [PATCH 14/21] =?UTF-8?q?#165=20fix=20:=20updateRecordTimes=20?= =?UTF-8?q?=EB=88=84=EB=9D=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt | 4 ++++ .../com/titi/app/feature/time/ui/timer/TimerViewModel.kt | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt index 8748c365..7baabe59 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/stopwatch/StopWatchViewModel.kt @@ -148,6 +148,10 @@ class StopWatchViewModel @AssistedInject constructor( ) to it.daily } + viewModelScope.launch { + updateRecordTimesUseCase(updatePair.first) + } + setState { copy( splashResultStateString = SplashResultState( diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt index 7cbb6b14..ad1a519b 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/ui/timer/TimerViewModel.kt @@ -157,6 +157,10 @@ class TimerViewModel @AssistedInject constructor( } to it.daily } + viewModelScope.launch { + updateRecordTimesUseCase(updatePair.first) + } + setState { copy( recordTimes = updatePair.first, From 39b3114d2a8a0bd3a49ded73aa77ef1fa1671ba4 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 00:50:04 +0900 Subject: [PATCH 15/21] =?UTF-8?q?#165=20fix=20:=20measure=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/kotlin/com/titi/app/data/alarm/impl/AlarmReceiver.kt | 3 ++- feature/main/src/main/AndroidManifest.xml | 4 ++-- .../kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt | 3 +-- .../kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/data/alarm/impl/src/main/kotlin/com/titi/app/data/alarm/impl/AlarmReceiver.kt b/data/alarm/impl/src/main/kotlin/com/titi/app/data/alarm/impl/AlarmReceiver.kt index 62992479..2ecd2377 100644 --- a/data/alarm/impl/src/main/kotlin/com/titi/app/data/alarm/impl/AlarmReceiver.kt +++ b/data/alarm/impl/src/main/kotlin/com/titi/app/data/alarm/impl/AlarmReceiver.kt @@ -5,6 +5,7 @@ import android.app.PendingIntent import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP import android.net.Uri import androidx.core.app.NotificationCompat import com.titi.app.core.util.goAsync @@ -37,7 +38,7 @@ internal class AlarmReceiver : BroadcastReceiver() { val deepLink = "titi://" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(deepLink)).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + flags = FLAG_ACTIVITY_SINGLE_TOP } val pendingIntent: PendingIntent = PendingIntent.getActivity( context, diff --git a/feature/main/src/main/AndroidManifest.xml b/feature/main/src/main/AndroidManifest.xml index 3112b9f9..35af582b 100644 --- a/feature/main/src/main/AndroidManifest.xml +++ b/feature/main/src/main/AndroidManifest.xml @@ -5,6 +5,7 @@ @@ -16,8 +17,7 @@ - + diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt index cef85793..c33d6cf7 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt @@ -29,12 +29,11 @@ class MainActivity : ComponentActivity() { lateinit var getTimeColorFlowUseCase: GetTimeColorFlowUseCase private val viewModel: MainViewModel by viewModels() + private var splashResultState: SplashResultState? by mutableStateOf(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - var splashResultState: SplashResultState? by mutableStateOf(null) - val splashScreen = installSplashScreen() lifecycleScope.launch { diff --git a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt index 99f6a15a..0034c1db 100644 --- a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt +++ b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt @@ -4,6 +4,7 @@ import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent +import android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP import android.content.res.Configuration import android.net.Uri import android.os.Build @@ -330,7 +331,7 @@ private fun makeInProgressNotification(context: Context) { val deepLink = "titi://" val intent = Intent(Intent.ACTION_VIEW, Uri.parse(deepLink)).apply { - flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK + flags = FLAG_ACTIVITY_SINGLE_TOP } val pendingIntent: PendingIntent = PendingIntent.getActivity( context, From ded95847ed525b8c3973ee6c416339df2c84128c Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 22:47:56 +0900 Subject: [PATCH 16/21] =?UTF-8?q?#165=20fix=20:=20indexoutofbound=20?= =?UTF-8?q?=EB=B0=8F=20=EC=95=8C=EB=9E=8C=20=EC=9D=B4=EC=8A=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/titi/app/core/ui/ContextExtensions.kt | 10 ++ .../app/feature/main/ui/main/MainActivity.kt | 7 ++ .../app/feature/measure/ui/MeasuringScreen.kt | 98 ++++++++++--------- 3 files changed, 67 insertions(+), 48 deletions(-) diff --git a/core/ui/src/main/kotlin/com/titi/app/core/ui/ContextExtensions.kt b/core/ui/src/main/kotlin/com/titi/app/core/ui/ContextExtensions.kt index f18d79e5..dfbb187a 100644 --- a/core/ui/src/main/kotlin/com/titi/app/core/ui/ContextExtensions.kt +++ b/core/ui/src/main/kotlin/com/titi/app/core/ui/ContextExtensions.kt @@ -1,6 +1,7 @@ package com.titi.app.core.ui import android.app.Activity +import android.app.NotificationManager import android.content.Context import android.view.WindowManager @@ -11,3 +12,12 @@ fun Context.setBrightness(isDark: Boolean) { if (isDark) 5f / 255 else WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE activity.window.attributes = layoutParams } + +fun Context.removeNotification() { + val notificationManager = this.getSystemService( + Context.NOTIFICATION_SERVICE, + ) as NotificationManager + + notificationManager.cancel(0) + notificationManager.cancel(1) +} diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt index c33d6cf7..e5a8b330 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt @@ -14,6 +14,7 @@ import androidx.lifecycle.Lifecycle import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.titi.app.core.designsystem.theme.TiTiTheme +import com.titi.app.core.ui.removeNotification import com.titi.app.domain.color.usecase.GetTimeColorFlowUseCase import com.titi.app.feature.main.model.SplashResultState import com.titi.app.feature.main.navigation.TiTiApp @@ -65,4 +66,10 @@ class MainActivity : ComponentActivity() { } } } + + override fun onResume() { + super.onResume() + + this.removeNotification() + } } diff --git a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt index 0034c1db..d9b88d97 100644 --- a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt +++ b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringScreen.kt @@ -23,12 +23,12 @@ import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue -import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -41,8 +41,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.core.app.NotificationCompat import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle +import androidx.lifecycle.LifecycleEventObserver import com.airbnb.mvrx.asMavericksArgs import com.airbnb.mvrx.compose.collectAsState import com.airbnb.mvrx.compose.mavericksViewModel @@ -54,15 +53,11 @@ import com.titi.app.core.designsystem.component.TdsTimer import com.titi.app.core.designsystem.model.TdsDialogInfo import com.titi.app.core.designsystem.theme.TdsColor import com.titi.app.core.designsystem.theme.TdsTextStyle +import com.titi.app.core.ui.removeNotification import com.titi.app.core.ui.setBrightness import com.titi.app.core.util.fromJson import com.titi.app.feature.measure.model.MeasuringUiState import com.titi.app.feature.measure.model.SplashResultState -import kotlinx.coroutines.flow.collectLatest -import kotlinx.coroutines.flow.distinctUntilChanged -import kotlinx.coroutines.flow.filter -import kotlinx.coroutines.flow.map -import kotlinx.coroutines.launch import org.threeten.bp.ZoneOffset import org.threeten.bp.ZonedDateTime @@ -107,48 +102,63 @@ fun MeasuringScreen(splashResultState: String, onFinish: (isFinish: Boolean) -> measureTime = uiState.measureTime, endTime = ZonedDateTime.now(ZoneOffset.UTC).toString(), ) + + onFinish(uiState.measuringRecordTimes.savedTime <= 0L) + } + + val isFinish by remember { + derivedStateOf { + uiState.measuringRecordTimes.savedTime <= 0L + } } - LaunchedEffect(Unit) { - val timerTime = splashResultStateModel.recordTimes.savedTimerTime - val stopWatchTime = splashResultStateModel.recordTimes.savedStopWatchTime - val recordingMode = splashResultStateModel.recordTimes.recordingMode - - lifecycleOwner.lifecycleScope.launch { - lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { - snapshotFlow { - uiState.measuringRecordTimes.savedTime - }.map { it <= 0 && recordingMode == 1 } - .distinctUntilChanged() - .filter { it } - .collectLatest { - stopMeasuring() - removeNotification(context) - onFinish(uiState.measuringRecordTimes.savedTime <= 0L) + DisposableEffect(lifecycleOwner) { + val observer = LifecycleEventObserver { _, event -> + when (event) { + Lifecycle.Event.ON_CREATE, Lifecycle.Event.ON_START, + Lifecycle.Event.ON_ANY, Lifecycle.Event.ON_RESUME, + -> Unit + + Lifecycle.Event.ON_STOP, Lifecycle.Event.ON_PAUSE, Lifecycle.Event.ON_DESTROY -> { + if (!isFinish) { + makeInProgressNotification(context) } + } } } - makeInProgressNotification(context) + lifecycleOwner.lifecycle.addObserver(observer) + onDispose { + lifecycleOwner.lifecycle.removeObserver(observer) + } + } - viewModel.setAlarm( - title = alarmTitle, - finishMessage = alarmFinishMessage, - fiveMinutesBeforeFinish = alarmFiveMinutesBeforeFinish, - measureTime = if (recordingMode == 1) { - timerTime - uiState.measureTime - } else { - stopWatchTime + uiState.measureTime - }, - ) + LaunchedEffect(isFinish) { + if (isFinish) { + stopMeasuring() + } else { + val timerTime = splashResultStateModel.recordTimes.savedTimerTime + val stopWatchTime = splashResultStateModel.recordTimes.savedStopWatchTime + val recordingMode = splashResultStateModel.recordTimes.recordingMode + + viewModel.setAlarm( + title = alarmTitle, + finishMessage = alarmFinishMessage, + fiveMinutesBeforeFinish = alarmFiveMinutesBeforeFinish, + measureTime = if (recordingMode == 1) { + timerTime - uiState.measureTime + } else { + stopWatchTime + uiState.measureTime + }, + ) - showSetExactAlarmPermissionDialog = !viewModel.canSetAlarm() + showSetExactAlarmPermissionDialog = !viewModel.canSetAlarm() + } } BackHandler { stopMeasuring() - removeNotification(context) - onFinish(uiState.measuringRecordTimes.savedTime <= 0L) + context.removeNotification() } DisposableEffect(Unit) { @@ -192,8 +202,7 @@ fun MeasuringScreen(splashResultState: String, onFinish: (isFinish: Boolean) -> }, onFinishClick = { stopMeasuring() - removeNotification(context) - onFinish(uiState.measuringRecordTimes.savedTime <= 0L) + context.removeNotification() }, ) } @@ -347,15 +356,8 @@ private fun makeInProgressNotification(context: Context) { .setContentTitle(title) .setContentText(message) .setContentIntent(pendingIntent) + .setAutoCancel(true) .setPriority(NotificationCompat.PRIORITY_DEFAULT) notificationManager.notify(1, builder.build()) } - -private fun removeNotification(context: Context) { - val notificationManager = context.getSystemService( - Context.NOTIFICATION_SERVICE, - ) as NotificationManager - notificationManager.cancel(0) - notificationManager.cancel(1) -} From d801d065a9ad0ff8f9b99be90e8962af48732cfb Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 23:46:13 +0900 Subject: [PATCH 17/21] =?UTF-8?q?#165=20update=20:=20=EC=B8=A1=EC=A0=95=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=20=EC=9D=B4=EB=8F=99=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../daily/usecase/GetTodayDailyUseCase.kt | 20 ++++ feature/main/build.gradle.kts | 1 + .../feature/main/model/SplashResultState.kt | 2 + .../app/feature/main/ui/main/MainActivity.kt | 21 +--- .../app/feature/main/ui/main/MainViewModel.kt | 107 ++++++++++++++---- .../feature/measure/model/MeasuringUiState.kt | 35 +++--- .../feature/measure/ui/MeasuringViewModel.kt | 2 +- .../feature/time/model/SplashResultState.kt | 1 + .../feature/time/navigation/TimeNavigation.kt | 2 +- 9 files changed, 126 insertions(+), 65 deletions(-) create mode 100644 domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetTodayDailyUseCase.kt diff --git a/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetTodayDailyUseCase.kt b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetTodayDailyUseCase.kt new file mode 100644 index 00000000..d344bcc7 --- /dev/null +++ b/domain/daily/src/main/kotlin/com/titi/app/doamin/daily/usecase/GetTodayDailyUseCase.kt @@ -0,0 +1,20 @@ +package com.titi.app.doamin.daily.usecase + +import com.titi.app.core.util.getDailyDayWithHour +import com.titi.app.data.daily.api.DailyRepository +import com.titi.app.doamin.daily.mapper.toDomainModel +import com.titi.app.doamin.daily.model.Daily +import javax.inject.Inject + +class GetTodayDailyUseCase @Inject constructor( + private val dailyRepository: DailyRepository, +) { + suspend operator fun invoke(): Daily { + val timePair = getDailyDayWithHour(6) + + return dailyRepository.getDateDaily( + startDateTime = timePair.first, + endDateTime = timePair.second, + )?.toDomainModel() ?: Daily() + } +} diff --git a/feature/main/build.gradle.kts b/feature/main/build.gradle.kts index 4905560a..7476629d 100644 --- a/feature/main/build.gradle.kts +++ b/feature/main/build.gradle.kts @@ -10,6 +10,7 @@ dependencies { implementation(project(":domain:color")) implementation(project(":domain:time")) implementation(project(":domain:daily")) + implementation(project(":domain:task")) implementation(project(":feature:time")) implementation(project(":feature:measure")) diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/model/SplashResultState.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/model/SplashResultState.kt index ee198f02..71e9c524 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/model/SplashResultState.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/model/SplashResultState.kt @@ -8,10 +8,12 @@ data class SplashResultState( val recordTimes: RecordTimes = RecordTimes(), val timeColor: TimeColor = TimeColor(), val daily: Daily = Daily(), + val isMeasureFinish: Boolean = false, ) fun SplashResultState.toFeatureTimeModel() = com.titi.app.feature.time.model.SplashResultState( recordTimes = recordTimes, timeColor = timeColor, daily = daily, + isMeasureFinish = isMeasureFinish, ) diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt index e5a8b330..ea58e925 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainActivity.kt @@ -6,23 +6,13 @@ import androidx.activity.SystemBarStyle import androidx.activity.compose.setContent import androidx.activity.enableEdgeToEdge import androidx.activity.viewModels -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.setValue import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen -import androidx.lifecycle.Lifecycle -import androidx.lifecycle.lifecycleScope -import androidx.lifecycle.repeatOnLifecycle import com.titi.app.core.designsystem.theme.TiTiTheme import com.titi.app.core.ui.removeNotification import com.titi.app.domain.color.usecase.GetTimeColorFlowUseCase -import com.titi.app.feature.main.model.SplashResultState import com.titi.app.feature.main.navigation.TiTiApp import dagger.hilt.android.AndroidEntryPoint import javax.inject.Inject -import kotlinx.coroutines.flow.filterNotNull -import kotlinx.coroutines.flow.first -import kotlinx.coroutines.launch @AndroidEntryPoint class MainActivity : ComponentActivity() { @@ -30,21 +20,14 @@ class MainActivity : ComponentActivity() { lateinit var getTimeColorFlowUseCase: GetTimeColorFlowUseCase private val viewModel: MainViewModel by viewModels() - private var splashResultState: SplashResultState? by mutableStateOf(null) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) val splashScreen = installSplashScreen() - lifecycleScope.launch { - lifecycle.repeatOnLifecycle(Lifecycle.State.CREATED) { - splashResultState = viewModel.splashResultState.filterNotNull().first() - } - } - splashScreen.setKeepOnScreenCondition { - splashResultState == null + viewModel.splashResultState == null } enableEdgeToEdge( @@ -60,7 +43,7 @@ class MainActivity : ComponentActivity() { setContent { TiTiTheme { - splashResultState?.let { + viewModel.splashResultState?.let { TiTiApp(splashResultState = it) } } diff --git a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainViewModel.kt b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainViewModel.kt index 8b7099e8..869c7c5f 100644 --- a/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainViewModel.kt +++ b/feature/main/src/main/kotlin/com/titi/app/feature/main/ui/main/MainViewModel.kt @@ -1,38 +1,95 @@ package com.titi.app.feature.main.ui.main +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.titi.app.doamin.daily.usecase.GetTodayDailyFlowUseCase -import com.titi.app.domain.color.usecase.GetTimeColorFlowUseCase -import com.titi.app.domain.time.usecase.GetRecordTimesFlowUseCase +import com.titi.app.core.util.getMeasureTime +import com.titi.app.doamin.daily.usecase.AddMeasureTimeAtDailyUseCase +import com.titi.app.doamin.daily.usecase.GetTodayDailyUseCase +import com.titi.app.domain.color.usecase.GetTimeColorUseCase +import com.titi.app.domain.task.usecase.AddMeasureTimeAtTaskUseCase +import com.titi.app.domain.time.usecase.AddMeasureTimeAtRecordTimesUseCase +import com.titi.app.domain.time.usecase.GetRecordTimesUseCase import com.titi.app.feature.main.model.SplashResultState import dagger.hilt.android.lifecycle.HiltViewModel +import java.time.ZoneOffset +import java.time.ZonedDateTime import javax.inject.Inject -import kotlinx.coroutines.flow.SharedFlow -import kotlinx.coroutines.flow.SharingStarted -import kotlinx.coroutines.flow.combine -import kotlinx.coroutines.flow.shareIn +import kotlinx.coroutines.joinAll +import kotlinx.coroutines.launch @HiltViewModel class MainViewModel @Inject constructor( - getRecordTimesFlowUseCase: GetRecordTimesFlowUseCase, - getTimeColorFlowUseCase: GetTimeColorFlowUseCase, - getTodayDailyFlowUseCase: GetTodayDailyFlowUseCase, + getRecordTimesUseCase: GetRecordTimesUseCase, + getTimeColorUseCase: GetTimeColorUseCase, + getTodayDailyUseCase: GetTodayDailyUseCase, + private val addMeasureTimeAtDailyUseCase: AddMeasureTimeAtDailyUseCase, + private val addMeasureTimeAtRecordTimesUseCase: AddMeasureTimeAtRecordTimesUseCase, + private val addMeasureTimeAtTaskUseCase: AddMeasureTimeAtTaskUseCase, ) : ViewModel() { + var splashResultState: SplashResultState? by mutableStateOf(null) - val splashResultState: SharedFlow = combine( - getRecordTimesFlowUseCase(), - getTimeColorFlowUseCase(), - getTodayDailyFlowUseCase(), - ) { recordTimes, timeColor, daily -> - SplashResultState( - recordTimes = recordTimes, - timeColor = timeColor, - daily = daily, - ) - }.shareIn( - started = SharingStarted.WhileSubscribed(), - scope = viewModelScope, - replay = 0, - ) + init { + viewModelScope.launch { + val recordTimes = getRecordTimesUseCase() + val timeColor = getTimeColorUseCase() + val daily = getTodayDailyUseCase() + + val taskName = recordTimes.currentTask?.taskName + val startTime = recordTimes.recordStartAt + ?: ZonedDateTime.now(ZoneOffset.UTC).toString() + val endTime = ZonedDateTime.now(ZoneOffset.UTC).toString() + val measureTime = getMeasureTime(startTime) + + splashResultState = if ( + taskName != null && + recordTimes.recording && + recordTimes.recordingMode == 1 && + recordTimes.savedTimerTime - measureTime <= 0L + ) { + val dailyJob = launch { + addMeasureTimeAtDailyUseCase( + taskName = taskName, + startTime = startTime, + endTime = endTime, + ) + } + + val recordTimesJob = launch { + addMeasureTimeAtRecordTimesUseCase( + recordTimes = recordTimes, + measureTime = measureTime, + ) + } + + val taskJob = launch { + addMeasureTimeAtTaskUseCase( + taskName = taskName, + measureTime = measureTime, + ) + } + + joinAll(dailyJob, recordTimesJob, taskJob) + + val updateRecordTimes = getRecordTimesUseCase() + val updateTimeColor = getTimeColorUseCase() + val updateDaily = getTodayDailyUseCase() + + SplashResultState( + recordTimes = updateRecordTimes, + timeColor = updateTimeColor, + daily = updateDaily, + isMeasureFinish = true, + ) + } else { + SplashResultState( + recordTimes = recordTimes, + timeColor = timeColor, + daily = daily, + ) + } + } + } } diff --git a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/model/MeasuringUiState.kt b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/model/MeasuringUiState.kt index 0565ba20..bf276a25 100644 --- a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/model/MeasuringUiState.kt +++ b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/model/MeasuringUiState.kt @@ -80,29 +80,26 @@ fun RecordTimes.toMeasuringRecordTimes( daily: Daily, ): MeasuringRecordTimes { val calculateSumTime = savedSumTime + measureTime - val calculateSavedSumTime = - if (isSleepMode) { - calculateSumTime - calculateSumTime % 60 - } else { - calculateSumTime - } + val calculateSavedSumTime = if (isSleepMode) { + calculateSumTime - calculateSumTime % 60 + } else { + calculateSumTime + } - val calculateTime = + val calculateTime = if (recordingMode == 1) { + savedTimerTime - measureTime + } else { + savedStopWatchTime + measureTime + } + val calculateSavedTime = if (isSleepMode) { if (recordingMode == 1) { - savedTimerTime - measureTime - } else { - savedStopWatchTime + measureTime - } - val calculateSavedTime = - if (isSleepMode) { - if (recordingMode == 1) { - calculateTime - calculateTime % 60 + 60 - } else { - calculateTime - calculateTime % 60 - } + calculateTime - calculateTime % 60 + 60 } else { - calculateTime + calculateTime - calculateTime % 60 } + } else { + calculateTime + } val calculateGoalTime = currentTask?.let { if (it.isTaskTargetTimeOn) { diff --git a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringViewModel.kt b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringViewModel.kt index dd1a40c3..48e83a8b 100644 --- a/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringViewModel.kt +++ b/feature/measure/src/main/kotlin/com/titi/app/feature/measure/ui/MeasuringViewModel.kt @@ -32,12 +32,12 @@ class MeasuringViewModel @AssistedInject constructor( private val addMeasureTimeAtDailyUseCase: AddMeasureTimeAtDailyUseCase, private val addMeasureTimeAtRecordTimesUseCase: AddMeasureTimeAtRecordTimesUseCase, private val addMeasureTimeAtTaskUseCase: AddMeasureTimeAtTaskUseCase, - private val getSleepModeFlowUseCase: GetSleepModeFlowUseCase, private val setSleepModeUseCase: SetSleepModeUseCase, private val canSetAlarmUseCase: CanSetAlarmUseCase, private val setTimerAlarmUseCase: SetTimerAlarmUseCase, private val setStopWatchAlarmUseCase: SetStopWatchAlarmUseCase, private val cancelAlarmsUseCase: CancelAlarmsUseCase, + getSleepModeFlowUseCase: GetSleepModeFlowUseCase, ) : MavericksViewModel(initialState) { init { diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/model/SplashResultState.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/model/SplashResultState.kt index 26ed9ea1..5af208d5 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/model/SplashResultState.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/model/SplashResultState.kt @@ -11,4 +11,5 @@ data class SplashResultState( val recordTimes: RecordTimes = RecordTimes(), val timeColor: TimeColor = TimeColor(), val daily: Daily = Daily(), + val isMeasureFinish: Boolean = false, ) : Parcelable diff --git a/feature/time/src/main/kotlin/com/titi/app/feature/time/navigation/TimeNavigation.kt b/feature/time/src/main/kotlin/com/titi/app/feature/time/navigation/TimeNavigation.kt index 99f1ec2b..1526c16c 100644 --- a/feature/time/src/main/kotlin/com/titi/app/feature/time/navigation/TimeNavigation.kt +++ b/feature/time/src/main/kotlin/com/titi/app/feature/time/navigation/TimeNavigation.kt @@ -36,7 +36,7 @@ fun NavGraphBuilder.timeGraph( composable(route = TIMER_ROUTE) { backStackEntry -> val isFinish by backStackEntry .savedStateHandle - .getStateFlow(TIMER_FINISH_KEY, false) + .getStateFlow(TIMER_FINISH_KEY, splashResultState.isMeasureFinish) .collectAsStateWithLifecycle() TimerScreen( From ff62b13d88ba8788c959e1ed8a5d47766d7e3864 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 23:50:21 +0900 Subject: [PATCH 18/21] update : version --- build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt index b554fcbd..abca579f 100644 --- a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt +++ b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt @@ -9,7 +9,7 @@ object BuildType { object AppConfig { const val APP_ID = "com.titi.app" - const val APP_VERSION_NAME = "1.2.0" - const val APP_VERSION_CODE = 34 + const val APP_VERSION_NAME = "1.2.1" + const val APP_VERSION_CODE = 35 const val APP_NAME = "TiTi" } \ No newline at end of file From 804650f5671be362ab6b1ef79e8b77c07b90156a Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Mon, 15 Jul 2024 23:51:28 +0900 Subject: [PATCH 19/21] update : release-note --- release-note.txt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/release-note.txt b/release-note.txt index 856d21e1..a01fea2c 100644 --- a/release-note.txt +++ b/release-note.txt @@ -1,5 +1,4 @@ -TiTi android dev 1.2.0(34) -- 백그라운드에서 재진입 시 타이머 또는 스탑워치 화면으로 이동되는 이슈 #137 -- 데일리 6시 기준 자동화 및 토스트 띄우기 #147 -- TimeTable 같은 task는 같은 색상으로 수정 #148 -- version 상승 및 스낵바 태블릿 대응 #153 \ No newline at end of file +TiTi android dev 1.2.1(35) +- Setting Screen Ver.2 #138 +- Refactor Log Data #142 +- Fix measuring finish bug #164 \ No newline at end of file From 56dae94539cad315d9fc2cbdf859e04fea6f066b Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Tue, 16 Jul 2024 00:16:37 +0900 Subject: [PATCH 20/21] fix : zoneddatetime parse exception --- .../main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt | 8 ++++++++ .../src/main/kotlin/com/titi/app/core/util/TimeUtil.kt | 8 -------- .../app/domain/time/mapper/DomainToRepositoryMapper.kt | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt index 34ccd0d2..e7fb0312 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/JavaTimeUtil.kt @@ -1,6 +1,7 @@ package com.titi.app.core.util import java.time.DayOfWeek +import java.time.Duration import java.time.LocalDate import java.time.LocalDateTime import java.time.ZoneId @@ -95,3 +96,10 @@ fun getMondaySunday(currentDate: LocalDate): Pair return Pair(monday, sunday) } + +fun getMeasureTime(dateTime: String): Long { + val inputDateTime = ZonedDateTime.parse(dateTime) + val currentDateTime = ZonedDateTime.now(ZoneOffset.UTC) + + return Duration.between(inputDateTime, currentDateTime).seconds +} diff --git a/core/util/src/main/kotlin/com/titi/app/core/util/TimeUtil.kt b/core/util/src/main/kotlin/com/titi/app/core/util/TimeUtil.kt index 9c516749..8e909a4e 100644 --- a/core/util/src/main/kotlin/com/titi/app/core/util/TimeUtil.kt +++ b/core/util/src/main/kotlin/com/titi/app/core/util/TimeUtil.kt @@ -2,7 +2,6 @@ package com.titi.app.core.util import org.threeten.bp.Duration import org.threeten.bp.ZoneId -import org.threeten.bp.ZoneOffset import org.threeten.bp.ZonedDateTime import org.threeten.bp.format.DateTimeFormatter @@ -26,13 +25,6 @@ fun getTimeToLong(hour: String, minutes: String, seconds: String): Long { return hourLong * 3600 + minutesLong * 60 + secondsLong } -fun getMeasureTime(dateTime: String): Long { - val inputDateTime = ZonedDateTime.parse(dateTime) - val currentDateTime = ZonedDateTime.now(ZoneOffset.UTC) - - return Duration.between(inputDateTime, currentDateTime).seconds -} - fun addTimeLine( startTime: ZonedDateTime, endTime: ZonedDateTime, diff --git a/domain/time/src/main/kotlin/com/titi/app/domain/time/mapper/DomainToRepositoryMapper.kt b/domain/time/src/main/kotlin/com/titi/app/domain/time/mapper/DomainToRepositoryMapper.kt index 432eb06a..b162b343 100644 --- a/domain/time/src/main/kotlin/com/titi/app/domain/time/mapper/DomainToRepositoryMapper.kt +++ b/domain/time/src/main/kotlin/com/titi/app/domain/time/mapper/DomainToRepositoryMapper.kt @@ -8,7 +8,7 @@ import com.titi.app.domain.time.model.RecordTimes internal fun RecordTimes.toRepositoryModel() = RecordTimesRepositoryModel( recordingMode = recordingMode, recording = recording, - recordStartAt = recordStartAt ?: "", + recordStartAt = recordStartAt, setGoalTime = setGoalTime, setTimerTime = setTimerTime, savedSumTime = savedSumTime, From 5ded4fe573642c7d4e41194322bf51f25e33e712 Mon Sep 17 00:00:00 2001 From: koreatlwls Date: Tue, 16 Jul 2024 00:16:57 +0900 Subject: [PATCH 21/21] update : version --- build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt index abca579f..1e96a22a 100644 --- a/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt +++ b/build-logic/src/main/kotlin/com/titi/common/BuildInfo.kt @@ -10,6 +10,6 @@ object BuildType { object AppConfig { const val APP_ID = "com.titi.app" const val APP_VERSION_NAME = "1.2.1" - const val APP_VERSION_CODE = 35 + const val APP_VERSION_CODE = 36 const val APP_NAME = "TiTi" } \ No newline at end of file