Change the create event button to an edit if event that day.
This commit is contained in:
parent
4fdbaa66a5
commit
1a73795615
6 changed files with 59 additions and 12 deletions
|
|
@ -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"
|
||||||
|
|
||||||
|
|
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -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,16 +237,24 @@ private fun HomePageContent(
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
floatingActionButton = {
|
floatingActionButton = {
|
||||||
|
AnimatedContent(
|
||||||
|
targetState = todayEventId.value,
|
||||||
|
transitionSpec = { fadeIn() togetherWith fadeOut() },
|
||||||
|
) {
|
||||||
FloatingActionButton(
|
FloatingActionButton(
|
||||||
containerColor = MaterialTheme.colorScheme.primary,
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
shape = CircleShape,
|
shape = CircleShape,
|
||||||
onClick = onFabClick,
|
onClick = { onFabClick(todayEventId.value) },
|
||||||
) {
|
) {
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.Default.Add,
|
imageVector = when (it) {
|
||||||
|
null -> Icons.Default.Add
|
||||||
|
else -> Icons.Default.Edit
|
||||||
|
},
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
content = { paddingValues ->
|
content = { paddingValues ->
|
||||||
HomeNavDisplay(
|
HomeNavDisplay(
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue