feat(CON-176) : Update app demo
This commit is contained in:
parent
60361a5e2a
commit
d406cc703f
@ -4,10 +4,4 @@ import android.app.Application
|
|||||||
import dagger.hilt.android.HiltAndroidApp
|
import dagger.hilt.android.HiltAndroidApp
|
||||||
|
|
||||||
@HiltAndroidApp
|
@HiltAndroidApp
|
||||||
class DemoApplication : Application() {
|
class DemoApplication : Application()
|
||||||
|
|
||||||
override fun onCreate() {
|
|
||||||
super.onCreate()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,6 +1,6 @@
|
|||||||
package fr.openium.consentium
|
package fr.openium.consentium
|
||||||
|
|
||||||
import DemoNavGraph
|
import fr.openium.consentium.ui.navigation.DemoNavGraph
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.activity.ComponentActivity
|
import androidx.activity.ComponentActivity
|
||||||
import androidx.activity.compose.setContent
|
import androidx.activity.compose.setContent
|
||||||
@ -9,10 +9,7 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.material3.Scaffold
|
import androidx.compose.material3.Scaffold
|
||||||
import androidx.compose.material3.Text
|
|
||||||
import androidx.compose.runtime.Composable
|
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
|
||||||
import androidx.navigation.compose.rememberNavController
|
import androidx.navigation.compose.rememberNavController
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import fr.openium.consentium.ui.theme.ConsentiumTheme
|
import fr.openium.consentium.ui.theme.ConsentiumTheme
|
||||||
@ -40,19 +37,3 @@ class MainActivity : ComponentActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
|
||||||
Text(
|
|
||||||
text = "Hello $name!",
|
|
||||||
modifier = modifier
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Preview(showBackground = true)
|
|
||||||
@Composable
|
|
||||||
fun GreetingPreview() {
|
|
||||||
ConsentiumTheme {
|
|
||||||
Greeting("Android")
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +1,19 @@
|
|||||||
|
package fr.openium.consentium.ui.navigation
|
||||||
|
|
||||||
|
import Destination
|
||||||
import androidx.compose.animation.core.tween
|
import androidx.compose.animation.core.tween
|
||||||
import androidx.compose.animation.fadeIn
|
import androidx.compose.animation.slideIn
|
||||||
import androidx.compose.animation.fadeOut
|
import androidx.compose.animation.slideOut
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.unit.IntOffset
|
||||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||||
import androidx.navigation.NavHostController
|
import androidx.navigation.NavHostController
|
||||||
import androidx.navigation.compose.NavHost
|
import androidx.navigation.compose.NavHost
|
||||||
import androidx.navigation.compose.composable
|
import androidx.navigation.compose.composable
|
||||||
import androidx.navigation.compose.navigation
|
|
||||||
import fr.openium.consentium.ui.screens.main.MainScreen
|
import fr.openium.consentium.ui.screens.main.MainScreen
|
||||||
import fr.openium.consentium.ui.screens.splash.SplashScreen
|
import fr.openium.consentium.ui.screens.splash.SplashScreen
|
||||||
|
|
||||||
private const val NAV_ANIMATION_TIME = 100
|
private const val NAV_ANIMATION_TIME = 500
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun DemoNavGraph(navHostController: NavHostController) {
|
fun DemoNavGraph(navHostController: NavHostController) {
|
||||||
@ -20,29 +22,44 @@ fun DemoNavGraph(navHostController: NavHostController) {
|
|||||||
navController = navHostController,
|
navController = navHostController,
|
||||||
startDestination = Destination.Splash,
|
startDestination = Destination.Splash,
|
||||||
enterTransition = {
|
enterTransition = {
|
||||||
fadeIn(animationSpec = tween(NAV_ANIMATION_TIME))
|
slideIn(
|
||||||
|
animationSpec = tween(NAV_ANIMATION_TIME),
|
||||||
|
initialOffset = { fullSize -> IntOffset(x = fullSize.height, y = 0) }
|
||||||
|
)
|
||||||
},
|
},
|
||||||
exitTransition = {
|
exitTransition = {
|
||||||
fadeOut(animationSpec = tween(NAV_ANIMATION_TIME))
|
slideOut(
|
||||||
|
animationSpec = tween(NAV_ANIMATION_TIME),
|
||||||
|
targetOffset = { fullSize -> IntOffset(x = -fullSize.height, y = 0) }
|
||||||
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
|
|
||||||
composable<Destination.Splash> {
|
composable<Destination.Splash> {
|
||||||
SplashScreen(
|
SplashScreen(
|
||||||
navigateToMain = { ->
|
navigateToMain = {
|
||||||
navHostController.navigate(Destination.Main) {
|
navHostController.navigate(Destination.Main) {
|
||||||
popUpTo(navHostController.graph.findStartDestination().id) {
|
popUpTo(navHostController.graph.findStartDestination().id) {
|
||||||
saveState = true
|
saveState = true
|
||||||
}
|
}
|
||||||
launchSingleTop = true
|
|
||||||
restoreState = true
|
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
composable<Destination.Main> {
|
composable<Destination.Main> {
|
||||||
MainScreen()
|
MainScreen(
|
||||||
|
onGoToConsentDetail = {
|
||||||
|
navHostController.navigate(Destination.Consent)
|
||||||
|
},
|
||||||
|
onGoToConsentMaster = {
|
||||||
|
navHostController.navigate(Destination.Consent)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
composable<Destination.Consent> {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
|
|
||||||
|
|
||||||
@ -10,4 +9,7 @@ sealed interface Destination {
|
|||||||
@Serializable
|
@Serializable
|
||||||
data object Main : Destination
|
data object Main : Destination
|
||||||
|
|
||||||
|
@Serializable
|
||||||
|
data object Consent : Destination
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package fr.openium.consentium.ui.screens.consent
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun ConsentScreen() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -1,14 +1,49 @@
|
|||||||
package fr.openium.consentium.ui.screens.main
|
package fr.openium.consentium.ui.screens.main
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.material3.Button
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.compose.ui.Alignment
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun MainScreen(
|
fun MainScreen(
|
||||||
viewModel: MainScreenViewModel = hiltViewModel()
|
onGoToConsentMaster: () -> Unit,
|
||||||
|
onGoToConsentDetail: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
Text("Main")
|
// View
|
||||||
|
Column(
|
||||||
|
modifier = modifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = onGoToConsentMaster,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Go to Consent Master"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(14.dp))
|
||||||
|
|
||||||
|
Button(
|
||||||
|
onClick = onGoToConsentDetail,
|
||||||
|
) {
|
||||||
|
Text(
|
||||||
|
text = "Go to Consent Detail"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,11 +0,0 @@
|
|||||||
package fr.openium.consentium.ui.screens.main
|
|
||||||
|
|
||||||
import androidx.lifecycle.ViewModel
|
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
|
||||||
import javax.inject.Inject
|
|
||||||
|
|
||||||
@HiltViewModel
|
|
||||||
class MainScreenViewModel @Inject constructor(
|
|
||||||
) : ViewModel() {
|
|
||||||
|
|
||||||
}
|
|
@ -1,7 +1,10 @@
|
|||||||
package fr.openium.consentium.ui.screens.splash
|
package fr.openium.consentium.ui.screens.splash
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
@ -16,34 +19,41 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
|||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun SplashScreen(
|
fun SplashScreen(
|
||||||
viewModel: SplashScreenViewModel = hiltViewModel(),
|
|
||||||
navigateToMain: () -> Unit,
|
navigateToMain: () -> Unit,
|
||||||
|
viewModel: SplashScreenViewModel = hiltViewModel(),
|
||||||
) {
|
) {
|
||||||
|
// State
|
||||||
|
val currentState by viewModel.state.collectAsState()
|
||||||
|
|
||||||
val state by viewModel.state.collectAsState()
|
// Effect
|
||||||
|
|
||||||
Text("Splash")
|
|
||||||
|
|
||||||
LaunchedEffect(Unit) {
|
LaunchedEffect(Unit) {
|
||||||
viewModel.initMain()
|
viewModel.initMain()
|
||||||
}
|
}
|
||||||
|
|
||||||
when (val _state = state) {
|
LaunchedEffect(currentState) {
|
||||||
|
when (val state = currentState) {
|
||||||
is SplashScreenViewModel.State.Loading -> Box(
|
is SplashScreenViewModel.State.Loaded -> {
|
||||||
modifier = Modifier.fillMaxSize()
|
if (state.isSplashEnded) {
|
||||||
) {
|
navigateToMain()
|
||||||
CircularProgressIndicator(
|
}
|
||||||
modifier = Modifier
|
}
|
||||||
.size(200.dp)
|
|
||||||
.align(Alignment.Center)
|
|
||||||
)
|
|
||||||
//tracking matomo
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
is SplashScreenViewModel.State.Loaded -> {
|
// View
|
||||||
navigateToMain()
|
Column(
|
||||||
}
|
modifier = Modifier.fillMaxSize(),
|
||||||
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
|
verticalArrangement = Arrangement.Center
|
||||||
|
) {
|
||||||
|
|
||||||
|
Text("Splash Screen")
|
||||||
|
|
||||||
|
Spacer(modifier = Modifier.height(14.dp))
|
||||||
|
|
||||||
|
CircularProgressIndicator(
|
||||||
|
modifier = Modifier.size(40.dp)
|
||||||
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,27 +13,18 @@ import javax.inject.Inject
|
|||||||
class SplashScreenViewModel @Inject constructor(
|
class SplashScreenViewModel @Inject constructor(
|
||||||
) : ViewModel() {
|
) : ViewModel() {
|
||||||
|
|
||||||
private val _state = MutableStateFlow<State>(State.Loading)
|
private val _state = MutableStateFlow<State>(State.Loaded(false))
|
||||||
val state: StateFlow<State> = _state
|
val state: StateFlow<State> = _state
|
||||||
|
|
||||||
fun initMain() {
|
fun initMain() {
|
||||||
val delay = viewModelScope.launch {
|
|
||||||
delay(1500L)
|
|
||||||
}
|
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
_state.value = State.Loading
|
delay(1500L)
|
||||||
try {
|
_state.value = State.Loaded(true)
|
||||||
delay.join()
|
|
||||||
_state.value = State.Loaded
|
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed interface State {
|
sealed interface State {
|
||||||
data object Loading : State
|
data class Loaded(val isSplashEnded: Boolean) : State
|
||||||
data object Loaded : State
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,6 +1,5 @@
|
|||||||
package fr.openium.consentium.ui.theme
|
package fr.openium.consentium.ui.theme
|
||||||
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.compose.foundation.isSystemInDarkTheme
|
import androidx.compose.foundation.isSystemInDarkTheme
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
@ -21,37 +20,27 @@ private val LightColorScheme = lightColorScheme(
|
|||||||
primary = Purple40,
|
primary = Purple40,
|
||||||
secondary = PurpleGrey40,
|
secondary = PurpleGrey40,
|
||||||
tertiary = Pink40
|
tertiary = Pink40
|
||||||
|
|
||||||
/* Other default colors to override
|
|
||||||
background = Color(0xFFFFFBFE),
|
|
||||||
surface = Color(0xFFFFFBFE),
|
|
||||||
onPrimary = Color.White,
|
|
||||||
onSecondary = Color.White,
|
|
||||||
onTertiary = Color.White,
|
|
||||||
onBackground = Color(0xFF1C1B1F),
|
|
||||||
onSurface = Color(0xFF1C1B1F),
|
|
||||||
*/
|
|
||||||
)
|
)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ConsentiumTheme(
|
fun ConsentiumTheme(
|
||||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||||
// Dynamic color is available on Android 12+
|
|
||||||
dynamicColor: Boolean = true,
|
dynamicColor: Boolean = true,
|
||||||
content: @Composable () -> Unit
|
content: @Composable () -> Unit,
|
||||||
) {
|
) {
|
||||||
val colorScheme = when {
|
val colorScheme = when {
|
||||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||||
}
|
}
|
||||||
darkTheme -> DarkColorScheme
|
|
||||||
else -> LightColorScheme
|
darkTheme -> DarkColorScheme
|
||||||
|
else -> LightColorScheme
|
||||||
}
|
}
|
||||||
|
|
||||||
MaterialTheme(
|
MaterialTheme(
|
||||||
colorScheme = colorScheme,
|
colorScheme = colorScheme,
|
||||||
typography = Typography,
|
typography = Typography,
|
||||||
content = content
|
content = content
|
||||||
)
|
)
|
||||||
}
|
}
|
@ -15,20 +15,4 @@ val Typography = Typography(
|
|||||||
lineHeight = 24.sp,
|
lineHeight = 24.sp,
|
||||||
letterSpacing = 0.5.sp
|
letterSpacing = 0.5.sp
|
||||||
)
|
)
|
||||||
/* Other default text styles to override
|
|
||||||
titleLarge = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Normal,
|
|
||||||
fontSize = 22.sp,
|
|
||||||
lineHeight = 28.sp,
|
|
||||||
letterSpacing = 0.sp
|
|
||||||
),
|
|
||||||
labelSmall = TextStyle(
|
|
||||||
fontFamily = FontFamily.Default,
|
|
||||||
fontWeight = FontWeight.Medium,
|
|
||||||
fontSize = 11.sp,
|
|
||||||
lineHeight = 16.sp,
|
|
||||||
letterSpacing = 0.5.sp
|
|
||||||
)
|
|
||||||
*/
|
|
||||||
)
|
)
|
Loading…
x
Reference in New Issue
Block a user