Change the create event button to an edit if event that day.

This commit is contained in:
Andres Gomez, Thomas (ITDV RL) 2025-10-01 16:15:52 +02:00
parent 4fdbaa66a5
commit 1a73795615
6 changed files with 59 additions and 12 deletions

View file

@ -26,7 +26,7 @@ android {
defaultConfig { defaultConfig {
namespace = "com.pixelized.headache" namespace = "com.pixelized.headache"
minSdk = 26 minSdk = 26
targetSdk = 35 targetSdk = 36
versionCode = 1 versionCode = 1
versionName = "1.0" versionName = "1.0"

View file

@ -16,6 +16,8 @@ import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Add 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.filled.Info
import androidx.compose.material.icons.outlined.Info import androidx.compose.material.icons.outlined.Info
import androidx.compose.material3.DropdownMenu 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.res.stringResource
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.pixelized.headache.R import com.pixelized.headache.R
import com.pixelized.headache.ui.common.toolbar.Toolbar import com.pixelized.headache.ui.common.toolbar.Toolbar
import com.pixelized.headache.ui.navigation.destination.MonthSummaryDestination import com.pixelized.headache.ui.navigation.destination.MonthSummaryDestination
@ -66,7 +69,9 @@ data class BottomBarItemUio(
fun HomePage( fun HomePage(
navigator: HomeNavigator, navigator: HomeNavigator,
editViewModel: EventEditBottomSheetViewModel = hiltViewModel(), editViewModel: EventEditBottomSheetViewModel = hiltViewModel(),
homeViewModel: HomeViewModel = hiltViewModel(),
) { ) {
val todayEventId = homeViewModel.todayEventId.collectAsStateWithLifecycle()
val bottomBarItems = rememberBottomBarItems( val bottomBarItems = rememberBottomBarItems(
onYearlyFollowUp = { onYearlyFollowUp = {
navigator.navigateToYearSummary() navigator.navigateToYearSummary()
@ -103,6 +108,7 @@ fun HomePage(
HomePageContent( HomePageContent(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
navigator = navigator, navigator = navigator,
todayEventId = todayEventId,
displayLegendAction = displayLegendAction, displayLegendAction = displayLegendAction,
displayLegendPopup = displayLegendPopup, displayLegendPopup = displayLegendPopup,
items = bottomBarItems, items = bottomBarItems,
@ -114,7 +120,7 @@ fun HomePage(
displayLegendPopup.value = false displayLegendPopup.value = false
}, },
onFabClick = { onFabClick = {
editViewModel.show() editViewModel.show(eventId = it)
}, },
) )
@ -156,11 +162,12 @@ private fun HomePageContent(
navigator: HomeNavigator, navigator: HomeNavigator,
displayLegendAction: State<Boolean>, displayLegendAction: State<Boolean>,
displayLegendPopup: State<Boolean>, displayLegendPopup: State<Boolean>,
todayEventId: State<Long?>,
items: List<BottomBarItemUio>, items: List<BottomBarItemUio>,
selectedItem: State<Int>, selectedItem: State<Int>,
onDisplayLegend: () -> Unit, onDisplayLegend: () -> Unit,
onDismissLegend: () -> Unit, onDismissLegend: () -> Unit,
onFabClick: () -> Unit, onFabClick: (Long?) -> Unit,
) { ) {
Scaffold( Scaffold(
modifier = modifier, modifier = modifier,
@ -230,15 +237,23 @@ private fun HomePageContent(
} }
}, },
floatingActionButton = { floatingActionButton = {
FloatingActionButton( AnimatedContent(
containerColor = MaterialTheme.colorScheme.primary, targetState = todayEventId.value,
shape = CircleShape, transitionSpec = { fadeIn() togetherWith fadeOut() },
onClick = onFabClick,
) { ) {
Icon( FloatingActionButton(
imageVector = Icons.Default.Add, containerColor = MaterialTheme.colorScheme.primary,
contentDescription = null, shape = CircleShape,
) onClick = { onFabClick(todayEventId.value) },
) {
Icon(
imageVector = when (it) {
null -> Icons.Default.Add
else -> Icons.Default.Edit
},
contentDescription = null,
)
}
} }
}, },
content = { paddingValues -> content = { paddingValues ->

View file

@ -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<Long?> = 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
)
}

View file

@ -13,7 +13,7 @@
# limitations under the License. # limitations under the License.
[versions] [versions]
agp = "8.12.2" agp = "8.13.0"
kotlin = "2.2.0" kotlin = "2.2.0"
kotlinSerialization = "2.2.0" kotlinSerialization = "2.2.0"
coreKtx = "1.16.0" coreKtx = "1.16.0"