diff --git a/app/build.gradle.kts b/app/build.gradle.kts index ebdf24d..f3ac78f 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -26,7 +26,7 @@ android { defaultConfig { namespace = "com.pixelized.headache" minSdk = 26 - targetSdk = 35 + targetSdk = 36 versionCode = 1 versionName = "1.0" diff --git a/app/release/baselineProfiles/0/app-release.dm b/app/release/baselineProfiles/0/app-release.dm index 58a4441..5c6fb5a 100644 Binary files a/app/release/baselineProfiles/0/app-release.dm and b/app/release/baselineProfiles/0/app-release.dm differ diff --git a/app/release/baselineProfiles/1/app-release.dm b/app/release/baselineProfiles/1/app-release.dm index 22aa0c6..5b90df9 100644 Binary files a/app/release/baselineProfiles/1/app-release.dm and b/app/release/baselineProfiles/1/app-release.dm differ diff --git a/app/src/main/java/com/pixelized/headache/ui/page/home/HomePage.kt b/app/src/main/java/com/pixelized/headache/ui/page/home/HomePage.kt index 74516c3..8bc72c7 100644 --- a/app/src/main/java/com/pixelized/headache/ui/page/home/HomePage.kt +++ b/app/src/main/java/com/pixelized/headache/ui/page/home/HomePage.kt @@ -16,6 +16,8 @@ import androidx.compose.foundation.layout.size import androidx.compose.foundation.shape.CircleShape import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.CalendarToday +import androidx.compose.material.icons.filled.Edit import androidx.compose.material.icons.filled.Info import androidx.compose.material.icons.outlined.Info import androidx.compose.material3.DropdownMenu @@ -40,6 +42,7 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel +import androidx.lifecycle.compose.collectAsStateWithLifecycle import com.pixelized.headache.R import com.pixelized.headache.ui.common.toolbar.Toolbar import com.pixelized.headache.ui.navigation.destination.MonthSummaryDestination @@ -66,7 +69,9 @@ data class BottomBarItemUio( fun HomePage( navigator: HomeNavigator, editViewModel: EventEditBottomSheetViewModel = hiltViewModel(), + homeViewModel: HomeViewModel = hiltViewModel(), ) { + val todayEventId = homeViewModel.todayEventId.collectAsStateWithLifecycle() val bottomBarItems = rememberBottomBarItems( onYearlyFollowUp = { navigator.navigateToYearSummary() @@ -103,6 +108,7 @@ fun HomePage( HomePageContent( modifier = Modifier.fillMaxSize(), navigator = navigator, + todayEventId = todayEventId, displayLegendAction = displayLegendAction, displayLegendPopup = displayLegendPopup, items = bottomBarItems, @@ -114,7 +120,7 @@ fun HomePage( displayLegendPopup.value = false }, onFabClick = { - editViewModel.show() + editViewModel.show(eventId = it) }, ) @@ -156,11 +162,12 @@ private fun HomePageContent( navigator: HomeNavigator, displayLegendAction: State, displayLegendPopup: State, + todayEventId: State, items: List, selectedItem: State, onDisplayLegend: () -> Unit, onDismissLegend: () -> Unit, - onFabClick: () -> Unit, + onFabClick: (Long?) -> Unit, ) { Scaffold( modifier = modifier, @@ -230,15 +237,23 @@ private fun HomePageContent( } }, floatingActionButton = { - FloatingActionButton( - containerColor = MaterialTheme.colorScheme.primary, - shape = CircleShape, - onClick = onFabClick, + AnimatedContent( + targetState = todayEventId.value, + transitionSpec = { fadeIn() togetherWith fadeOut() }, ) { - Icon( - imageVector = Icons.Default.Add, - contentDescription = null, - ) + FloatingActionButton( + containerColor = MaterialTheme.colorScheme.primary, + shape = CircleShape, + onClick = { onFabClick(todayEventId.value) }, + ) { + Icon( + imageVector = when (it) { + null -> Icons.Default.Add + else -> Icons.Default.Edit + }, + contentDescription = null, + ) + } } }, content = { paddingValues -> diff --git a/app/src/main/java/com/pixelized/headache/ui/page/home/HomeViewModel.kt b/app/src/main/java/com/pixelized/headache/ui/page/home/HomeViewModel.kt new file mode 100644 index 0000000..6984923 --- /dev/null +++ b/app/src/main/java/com/pixelized/headache/ui/page/home/HomeViewModel.kt @@ -0,0 +1,32 @@ +package com.pixelized.headache.ui.page.home + +import android.icu.util.Calendar +import androidx.lifecycle.ViewModel +import androidx.lifecycle.viewModelScope +import com.pixelized.headache.repository.event.EventRepository +import dagger.hilt.android.lifecycle.HiltViewModel +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn +import javax.inject.Inject + +@HiltViewModel +class HomeViewModel @Inject constructor( + eventRepository: EventRepository, +) : ViewModel() { + val todayEventId: StateFlow = eventRepository.eventsMapFlow() + .map { + val calendar = Calendar.getInstance() + val year = calendar.get(Calendar.YEAR) + val month = calendar.get(Calendar.MONTH) + val day = calendar.get(Calendar.DAY_OF_MONTH) + val event = it[year]?.get(month)?.get(day) + event?.firstOrNull()?.id + } + .stateIn( + scope = viewModelScope, + started = SharingStarted.Lazily, + initialValue = null + ) +} \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1447d6f..a333368 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -13,7 +13,7 @@ # limitations under the License. [versions] -agp = "8.12.2" +agp = "8.13.0" kotlin = "2.2.0" kotlinSerialization = "2.2.0" coreKtx = "1.16.0"