pull/5/head
avalin 10 months ago
parent b6c6f2c005
commit c362543581

@ -1,29 +1,29 @@
package fr.iut.alldev.allin.ui
import android.app.Activity
import android.os.Build
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.runtime.SideEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import dagger.hilt.android.AndroidEntryPoint
import fr.iut.alldev.allin.ui.navigation.AllInNavHost
import fr.iut.alldev.allin.theme.AllInTheme
import fr.iut.alldev.allin.ui.navigation.AllInNavHost
@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
enableEdgeToEdge(
navigationBarStyle = SystemBarStyle.light(
scrim = Color.Transparent.toArgb(),
darkScrim = Color.Transparent.toArgb()
)
)
super.onCreate(savedInstanceState)
setContent {
AllInTheme{
AllInTheme {
AllInNavHost()
}
}

@ -5,13 +5,12 @@ import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.items
@ -31,7 +30,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalHapticFeedback
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
@ -50,8 +48,6 @@ fun BetScreen(
viewModel: BetViewModel = hiltViewModel(),
selectBet: (Bet, Boolean) -> Unit,
) {
val haptic = LocalHapticFeedback.current
val bets by viewModel.bets.collectAsState()
val refreshing by viewModel.isRefreshing.collectAsState()
@ -96,11 +92,9 @@ fun BetScreen(
)
)
.padding(top = 5.dp, bottom = 19.dp),
horizontalArrangement = Arrangement.spacedBy(9.dp)
horizontalArrangement = Arrangement.spacedBy(9.dp),
contentPadding = PaddingValues(horizontal = 23.dp)
) {
item {
Spacer(modifier = Modifier.width(23.dp))
}
items(items) {
var isSelected by remember { mutableStateOf(false) }
AllInChip(
@ -110,9 +104,6 @@ fun BetScreen(
isSelected = !isSelected
})
}
item {
Spacer(modifier = Modifier.width(23.dp))
}
}
}
itemsIndexed(bets) { idx, it ->

@ -1,6 +1,5 @@
package fr.iut.alldev.allin.ui.betCreation
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
@ -26,6 +25,7 @@ import java.time.ZonedDateTime
fun BetCreationScreen(
viewModel: BetCreationViewModel = hiltViewModel(),
setLoading: (Boolean) -> Unit,
openDrawer: () -> Unit,
onCreation: () -> Unit
) {
val betTypes = remember { BetType.entries }
@ -93,6 +93,7 @@ fun BetCreationScreen(
selectedBetType = selectedBetType,
setSelectedBetTypeElement = { selectedBetTypeElement = it },
selectionBetType = selectionElements,
openDrawer = openDrawer,
onCreateBet = {
viewModel.createBet(
themeFieldName = themeFieldName,

@ -51,6 +51,7 @@ fun BetCreationScreenContent(
selectedBetType: BetType,
setSelectedBetTypeElement: (SelectionElement) -> Unit,
selectionBetType: List<SelectionElement>,
openDrawer: () -> Unit,
onCreateBet: () -> Unit
) {
val interactionSource = remember { MutableInteractionSource() }
@ -58,6 +59,7 @@ fun BetCreationScreenContent(
Box(Modifier.fillMaxSize()) {
AllInSections(
openDrawer = openDrawer,
onLoadSection = { focus.clearFocus() },
modifier = Modifier.align(Alignment.TopCenter),
sections = listOf(
@ -144,7 +146,8 @@ private fun BetCreationScreenContentPreview() {
selectedBetType = BetType.BINARY,
setSelectedBetTypeElement = { },
selectionBetType = listOf(),
onCreateBet = { }
onCreateBet = { },
openDrawer = { }
)
}
}

@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
@ -75,6 +76,7 @@ fun BetResultBottomSheetContent(
Box(
modifier = Modifier
.fillMaxSize()
.safeContentPadding()
.padding(16.dp)
) {
IconButton(

@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
@ -83,7 +82,7 @@ class BetStatusBottomSheetBetDisplayer(
val response1Answer = remember { betDetail.getAnswerOfResponse(response1) }
val response2Answer = remember { betDetail.getAnswerOfResponse(response2) }
Box(Modifier.navigationBarsPadding()) {
Box(Modifier) {
Column {
Column(Modifier.padding(horizontal = 20.dp)) {
BetTitleHeader(
@ -196,7 +195,7 @@ class BetStatusBottomSheetBetDisplayer(
item {
if (betDetail.bet.betStatus != BetStatus.FINISHED && betDetail.userParticipation == null) {
Spacer(modifier = Modifier.height(48.dp))
Spacer(modifier = Modifier.height(75.dp))
}
Spacer(modifier = Modifier.navigationBarsPadding())
}

@ -5,20 +5,11 @@ import androidx.compose.foundation.ExperimentalFoundationApi
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.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.safeContentPadding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyItemScope
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.LazyRow
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.pager.HorizontalPager
@ -48,54 +39,61 @@ fun AllInSections(
sections: List<SectionElement>,
modifier: Modifier = Modifier,
interSectionsPadding: Dp = 56.dp,
onLoadSection: ()->Unit = { }
openDrawer: () -> Unit,
onLoadSection: () -> Unit = { }
) {
val pagerState = rememberPagerState(pageCount = { sections.size })
val scope = rememberCoroutineScope()
LazyColumn(
modifier = modifier,
horizontalAlignment = Alignment.CenterHorizontally
){
stickyHeader {
Box(
modifier = Modifier
.fillMaxWidth()
.background(
Brush.verticalGradient(
0.75f to AllInTheme.themeColors.mainSurface,
1f to Color.Transparent
)
),
contentAlignment = Alignment.Center
LaunchedEffect(key1 = pagerState.isScrollInProgress) {
if (
pagerState.isScrollInProgress &&
!pagerState.canScrollBackward &&
pagerState.currentPage == pagerState.targetPage
) {
openDrawer()
}
}
Box(modifier = modifier) {
HorizontalPager(state = pagerState) { page ->
LaunchedEffect(key1 = page) { onLoadSection() }
LazyColumn(
modifier = Modifier.fillMaxSize(),
contentPadding = PaddingValues(top = 40.dp, start = 20.dp, end = 20.dp)
) {
LazyRow(
horizontalArrangement = Arrangement.spacedBy(interSectionsPadding),
modifier = Modifier.padding(vertical = 12.dp)
) {
itemsIndexed(sections) { index, section ->
AllInSectionButton(
text = section.text,
isSelected = index == pagerState.currentPage,
onClick = {
scope.launch {
pagerState.animateScrollToPage(index)
}
}
)
}
item {
sections[page].content()
}
}
}
item {
HorizontalPager(
state = pagerState
) { page ->
LaunchedEffect(key1 = page) { onLoadSection() }
Column(
modifier = Modifier.padding(horizontal = 20.dp)
) {
sections[page].content()
Box(
modifier = Modifier
.align(Alignment.TopCenter)
.fillMaxWidth()
.background(
Brush.verticalGradient(
0.75f to AllInTheme.themeColors.mainSurface,
1f to Color.Transparent
)
),
contentAlignment = Alignment.Center
) {
LazyRow(
horizontalArrangement = Arrangement.spacedBy(interSectionsPadding),
modifier = Modifier.padding(vertical = 12.dp)
) {
itemsIndexed(sections) { index, section ->
AllInSectionButton(
text = section.text,
isSelected = index == pagerState.currentPage,
onClick = {
scope.launch {
pagerState.animateScrollToPage(index)
}
}
)
}
}
}
@ -108,6 +106,7 @@ fun AllInSections(
private fun AllInSectionsPreview() {
AllInTheme {
AllInSections(
openDrawer = { },
sections = listOf(
SectionElement("Page 1") {
Text("This is page 1")

@ -108,6 +108,7 @@ fun MainScreen(
}
)
AllInDrawer(
drawerState = drawerState,
destinations = topLevelDestinations,
@ -153,6 +154,11 @@ fun MainScreen(
drawerState.close()
}
}
},
openDrawer = {
scope.launch {
drawerState.open()
}
}
)
}
@ -160,6 +166,7 @@ fun MainScreen(
}
events.firstOrNull()?.let {
it.Display(sheetState = eventBottomSheetState) {
mainViewModel.dismissedEvents += it

@ -43,14 +43,14 @@ class MainViewModel @Inject constructor(
val snackbarContent: MutableState<SnackbarContent?> by lazy { mutableStateOf(null) }
fun putSnackbarContent(content: SnackbarContent) {
snackbarContent.value = content
}
init {
fetchEvents()
}
fun putSnackbarContent(content: SnackbarContent) {
snackbarContent.value = content
}
fun fetchEvents() {
viewModelScope.launch {
val token = keystoreManager.getTokenOrEmpty()

@ -90,6 +90,7 @@ fun AllInNavHost(
@Composable
internal fun AllInDrawerNavHost(
modifier: Modifier = Modifier,
openDrawer: () -> Unit,
navController: NavHostController,
selectBet: (Bet, Boolean) -> Unit,
startDestination: String = Routes.PUBLIC_BETS,
@ -116,6 +117,7 @@ internal fun AllInDrawerNavHost(
val creationSuccessMessage = stringResource(id = R.string.bet_creation_success_message)
BetCreationScreen(
setLoading = setLoading,
openDrawer = openDrawer,
onCreation = {
putSnackbarContent(
MainViewModel.SnackbarContent(

Loading…
Cancel
Save