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
|
||||
|
||||
@HiltAndroidApp
|
||||
class DemoApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
}
|
||||
|
||||
}
|
||||
class DemoApplication : Application()
|
@ -1,6 +1,6 @@
|
||||
package fr.openium.consentium
|
||||
|
||||
import DemoNavGraph
|
||||
import fr.openium.consentium.ui.navigation.DemoNavGraph
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
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.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
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.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.slideIn
|
||||
import androidx.compose.animation.slideOut
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.unit.IntOffset
|
||||
import androidx.navigation.NavGraph.Companion.findStartDestination
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import androidx.navigation.compose.navigation
|
||||
import fr.openium.consentium.ui.screens.main.MainScreen
|
||||
import fr.openium.consentium.ui.screens.splash.SplashScreen
|
||||
|
||||
private const val NAV_ANIMATION_TIME = 100
|
||||
private const val NAV_ANIMATION_TIME = 500
|
||||
|
||||
@Composable
|
||||
fun DemoNavGraph(navHostController: NavHostController) {
|
||||
@ -20,29 +22,44 @@ fun DemoNavGraph(navHostController: NavHostController) {
|
||||
navController = navHostController,
|
||||
startDestination = Destination.Splash,
|
||||
enterTransition = {
|
||||
fadeIn(animationSpec = tween(NAV_ANIMATION_TIME))
|
||||
slideIn(
|
||||
animationSpec = tween(NAV_ANIMATION_TIME),
|
||||
initialOffset = { fullSize -> IntOffset(x = fullSize.height, y = 0) }
|
||||
)
|
||||
},
|
||||
exitTransition = {
|
||||
fadeOut(animationSpec = tween(NAV_ANIMATION_TIME))
|
||||
slideOut(
|
||||
animationSpec = tween(NAV_ANIMATION_TIME),
|
||||
targetOffset = { fullSize -> IntOffset(x = -fullSize.height, y = 0) }
|
||||
)
|
||||
},
|
||||
) {
|
||||
|
||||
composable<Destination.Splash> {
|
||||
SplashScreen(
|
||||
navigateToMain = { ->
|
||||
navigateToMain = {
|
||||
navHostController.navigate(Destination.Main) {
|
||||
popUpTo(navHostController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
|
||||
@ -10,4 +9,7 @@ sealed interface Destination {
|
||||
@Serializable
|
||||
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
|
||||
|
||||
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.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
|
||||
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
|
||||
|
||||
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.height
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Text
|
||||
@ -16,34 +19,41 @@ import androidx.hilt.navigation.compose.hiltViewModel
|
||||
|
||||
@Composable
|
||||
fun SplashScreen(
|
||||
viewModel: SplashScreenViewModel = hiltViewModel(),
|
||||
navigateToMain: () -> Unit,
|
||||
viewModel: SplashScreenViewModel = hiltViewModel(),
|
||||
) {
|
||||
// State
|
||||
val currentState by viewModel.state.collectAsState()
|
||||
|
||||
val state by viewModel.state.collectAsState()
|
||||
|
||||
Text("Splash")
|
||||
|
||||
// Effect
|
||||
LaunchedEffect(Unit) {
|
||||
viewModel.initMain()
|
||||
}
|
||||
|
||||
when (val _state = state) {
|
||||
|
||||
is SplashScreenViewModel.State.Loading -> Box(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier
|
||||
.size(200.dp)
|
||||
.align(Alignment.Center)
|
||||
)
|
||||
//tracking matomo
|
||||
}
|
||||
|
||||
LaunchedEffect(currentState) {
|
||||
when (val state = currentState) {
|
||||
is SplashScreenViewModel.State.Loaded -> {
|
||||
if (state.isSplashEnded) {
|
||||
navigateToMain()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// View
|
||||
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(
|
||||
) : ViewModel() {
|
||||
|
||||
private val _state = MutableStateFlow<State>(State.Loading)
|
||||
private val _state = MutableStateFlow<State>(State.Loaded(false))
|
||||
val state: StateFlow<State> = _state
|
||||
|
||||
fun initMain() {
|
||||
val delay = viewModelScope.launch {
|
||||
delay(1500L)
|
||||
}
|
||||
viewModelScope.launch {
|
||||
_state.value = State.Loading
|
||||
try {
|
||||
delay.join()
|
||||
_state.value = State.Loaded
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
delay(1500L)
|
||||
_state.value = State.Loaded(true)
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface State {
|
||||
data object Loading : State
|
||||
data object Loaded : State
|
||||
data class Loaded(val isSplashEnded: Boolean) : State
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
package fr.openium.consentium.ui.theme
|
||||
|
||||
import android.app.Activity
|
||||
import android.os.Build
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@ -21,30 +20,20 @@ private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
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
|
||||
fun ConsentiumTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
// Dynamic color is available on Android 12+
|
||||
dynamicColor: Boolean = true,
|
||||
content: @Composable () -> Unit
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val colorScheme = when {
|
||||
dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> {
|
||||
val context = LocalContext.current
|
||||
if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
|
||||
}
|
||||
|
||||
darkTheme -> DarkColorScheme
|
||||
else -> LightColorScheme
|
||||
}
|
||||
|
@ -15,20 +15,4 @@ val Typography = Typography(
|
||||
lineHeight = 24.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