From d6bfba7fd8e8592925e3b9acf5c917993b1c5c14 Mon Sep 17 00:00:00 2001 From: Zyad Date: Fri, 27 Jun 2025 01:19:24 +0300 Subject: [PATCH 1/3] fix: navigation back after category edit --- .../com/moscow/tudee/presentation/navigation/MainNavGraph.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/moscow/tudee/presentation/navigation/MainNavGraph.kt b/app/src/main/java/com/moscow/tudee/presentation/navigation/MainNavGraph.kt index 5075972a..08fa09a4 100644 --- a/app/src/main/java/com/moscow/tudee/presentation/navigation/MainNavGraph.kt +++ b/app/src/main/java/com/moscow/tudee/presentation/navigation/MainNavGraph.kt @@ -60,6 +60,7 @@ fun MainNavGraph( navController.previousBackStackEntry ?.savedStateHandle ?.set("result_message", messageId) + navController.popBackStack() } , navigateBack ={ From b8b0adde46f217ccd64bd1b2e237822f42ae773e Mon Sep 17 00:00:00 2001 From: Zyad Date: Fri, 27 Jun 2025 01:27:19 +0300 Subject: [PATCH 2/3] fix: load category in home screen --- .../presentation/screen/home/HomeScreen.kt | 14 +++- .../presentation/screen/home/HomeViewModel.kt | 69 ++++++++++++------- 2 files changed, 57 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeScreen.kt b/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeScreen.kt index 1aecef42..da27c391 100644 --- a/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeScreen.kt +++ b/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeScreen.kt @@ -1,6 +1,5 @@ package com.moscow.tudee.presentation.screen.home import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize @@ -10,6 +9,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.material3.Scaffold import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource @@ -17,7 +17,10 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex +import androidx.lifecycle.Lifecycle +import androidx.lifecycle.compose.LocalLifecycleOwner import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.repeatOnLifecycle import com.moscow.tudee.R import com.moscow.tudee.domain.entity.Task import com.moscow.tudee.presentation.component.AddTaskBottomSheet @@ -48,6 +51,15 @@ fun HomeScreen( } } } + + val lifecycleOwner = LocalLifecycleOwner.current + LaunchedEffect(lifecycleOwner.lifecycle) { + lifecycleOwner.repeatOnLifecycle(Lifecycle.State.RESUMED) { + viewModel.loadTasks() + viewModel.getCategories() + } + } + HomeContent( uiState.value, viewModel diff --git a/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeViewModel.kt b/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeViewModel.kt index f2b39817..6670d4ff 100644 --- a/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeViewModel.kt +++ b/app/src/main/java/com/moscow/tudee/presentation/screen/home/HomeViewModel.kt @@ -1,4 +1,5 @@ package com.moscow.tudee.presentation.screen.home + import com.moscow.tudee.domain.entity.Task import com.moscow.tudee.domain.entity.Task.Status import com.moscow.tudee.domain.service.CategoryServices @@ -29,29 +30,44 @@ class HomeViewModel( } - private fun loadTasks() { + fun loadTasks() { launchWithResult( - action = { tasksServices.getTasksByDate(Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date).map { it.toTaskUi() } }, - onSuccess = ::onSuccessLoadingTasks , - onError = { handleHomeError(it) }, - onStart = { startLoading() }, + action = { + tasksServices.getTasksByDate( + Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date + ).map { it.toTaskUi() } + }, + onSuccess = ::onSuccessLoadingTasks, + onError = { handleHomeError(it) }, + onStart = { startLoading() }, onFinally = { endLoading() } ) updateSlider() } - private fun getTodayDate(){ - updateState { it.copy(formattedDate = Clock.System.now().toLocalDateTime(TimeZone.currentSystemDefault()).date.toJavaLocalDate().format(DateTimeFormatter.ofPattern("dd MMM yyyy")).toString()) } + private fun getTodayDate() { + updateState { + it.copy( + formattedDate = Clock.System.now() + .toLocalDateTime(TimeZone.currentSystemDefault()).date.toJavaLocalDate() + .format(DateTimeFormatter.ofPattern("dd MMM yyyy")).toString() + ) + } } - private fun onSuccessLoadingTasks(tasks:List){ - val groupedTasks = tasks.groupBy{ it.status } + + private fun onSuccessLoadingTasks(tasks: List) { + val groupedTasks = tasks.groupBy { it.status } updateState { it.copy( - todoTasks = groupedTasks[Status.TODO].orEmpty() , + todoTasks = groupedTasks[Status.TODO].orEmpty(), doneTasks = groupedTasks[Status.DONE].orEmpty(), inProgressTasks = groupedTasks[Status.IN_PROGRESS].orEmpty(), - sliderState = updateSliderState( uiState.value.doneTasks.size ,uiState.value.todoTasks.size ,uiState.value.inProgressTasks.size) + sliderState = updateSliderState( + uiState.value.doneTasks.size, + uiState.value.todoTasks.size, + uiState.value.inProgressTasks.size + ) ) } @@ -59,7 +75,11 @@ class HomeViewModel( updateSlider() } - private fun updateSliderState(doneTasks:Int, todoTasks:Int,inProgressTasks:Int): HomeState.SliderState { + private fun updateSliderState( + doneTasks: Int, + todoTasks: Int, + inProgressTasks: Int + ): HomeState.SliderState { val totalTasks = todoTasks + inProgressTasks + doneTasks return when { totalTasks == 0 -> HomeState.SliderState.NOTHING_ON_YOUR_LIST @@ -70,18 +90,17 @@ class HomeViewModel( } } - private fun getCategories() { - if(uiState.value.categories.isEmpty()) { - launchWithResult( - action = { categoryServices.getCategories() }, - onSuccess = { response -> - updateState { it.copy(categories = response.map { it.toCategoryUi() }) } - }, - onError = { handleHomeError(it) }, - onStart = { startLoading() }, - onFinally = { endLoading() } - ) - } + + fun getCategories() { + launchWithResult( + action = { categoryServices.getCategories() }, + onSuccess = { response -> + updateState { it.copy(categories = response.map { it.toCategoryUi() }) } + }, + onError = { handleHomeError(it) }, + onStart = { startLoading() }, + onFinally = { endLoading() } + ) } override fun onFloatingActionButtonClick() { @@ -197,7 +216,7 @@ class HomeViewModel( private fun getNextStatus(currentStatus: Task.Status): Task.Status { return when (currentStatus) { Status.TODO -> Status.IN_PROGRESS - Status.IN_PROGRESS ->Status.DONE + Status.IN_PROGRESS -> Status.DONE Status.DONE -> Status.DONE } } From 5aaaa0d74e37e3ac5550a8dc9f3d3de113aa7cca Mon Sep 17 00:00:00 2001 From: Zyad Date: Fri, 27 Jun 2025 01:45:20 +0300 Subject: [PATCH 3/3] fix: bottom navigation icon tint --- .../com/moscow/tudee/presentation/component/BottomNavBar.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/com/moscow/tudee/presentation/component/BottomNavBar.kt b/app/src/main/java/com/moscow/tudee/presentation/component/BottomNavBar.kt index 5fe12b0c..aade870e 100644 --- a/app/src/main/java/com/moscow/tudee/presentation/component/BottomNavBar.kt +++ b/app/src/main/java/com/moscow/tudee/presentation/component/BottomNavBar.kt @@ -94,7 +94,7 @@ private fun NavBarIcon( ) { val backgroundColor = if (isSelected) Theme.colors.primaryVariant else Theme.colors.surfaceHigh - val tintColor = if (isSelected) Theme.colors.primary else Theme.colors.hint + val tintColor = if (isSelected) Theme.colors.primary else Theme.colors.hint.copy(alpha = 1f) Icon(