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 {
|
||||
namespace = "com.pixelized.headache"
|
||||
minSdk = 26
|
||||
targetSdk = 35
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
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.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<Boolean>,
|
||||
displayLegendPopup: State<Boolean>,
|
||||
todayEventId: State<Long?>,
|
||||
items: List<BottomBarItemUio>,
|
||||
selectedItem: State<Int>,
|
||||
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 ->
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
||||
[versions]
|
||||
agp = "8.12.2"
|
||||
agp = "8.13.0"
|
||||
kotlin = "2.2.0"
|
||||
kotlinSerialization = "2.2.0"
|
||||
coreKtx = "1.16.0"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue