mise en place du squelette de l'application
ajout squelette application
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools" >
|
||||
|
||||
<application
|
||||
android:name=".DemoApplication"
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
|
13
app/src/main/java/fr/openium/consentium/DemoApplication.kt
Normal file
13
app/src/main/java/fr/openium/consentium/DemoApplication.kt
Normal file
@ -0,0 +1,13 @@
|
||||
package fr.openium.consentium
|
||||
|
||||
import android.app.Application
|
||||
import dagger.hilt.android.HiltAndroidApp
|
||||
|
||||
@HiltAndroidApp
|
||||
class DemoApplication : Application() {
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
}
|
||||
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
package fr.openium.consentium
|
||||
|
||||
import DemoNavGraph
|
||||
import android.os.Bundle
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.Scaffold
|
||||
@ -11,19 +13,28 @@ 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
|
||||
|
||||
@AndroidEntryPoint
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
enableEdgeToEdge()
|
||||
setContent {
|
||||
|
||||
val navHostController = rememberNavController()
|
||||
|
||||
ConsentiumTheme {
|
||||
Scaffold( modifier = Modifier.fillMaxSize() ) { innerPadding ->
|
||||
Greeting(
|
||||
name = "Android",
|
||||
modifier = Modifier.padding(innerPadding)
|
||||
)
|
||||
Scaffold( modifier = Modifier.fillMaxSize() ) { paddingValues ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
) {
|
||||
DemoNavGraph(navHostController = navHostController)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,48 @@
|
||||
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.runtime.Composable
|
||||
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
|
||||
|
||||
@Composable
|
||||
fun DemoNavGraph(navHostController: NavHostController) {
|
||||
|
||||
NavHost(
|
||||
navController = navHostController,
|
||||
startDestination = Destination.Splash,
|
||||
enterTransition = {
|
||||
fadeIn(animationSpec = tween(NAV_ANIMATION_TIME))
|
||||
},
|
||||
exitTransition = {
|
||||
fadeOut(animationSpec = tween(NAV_ANIMATION_TIME))
|
||||
},
|
||||
) {
|
||||
|
||||
composable<Destination.Splash> {
|
||||
SplashScreen(
|
||||
navigateToMain = { ->
|
||||
navHostController.navigate(Destination.Main) {
|
||||
popUpTo(navHostController.graph.findStartDestination().id) {
|
||||
saveState = true
|
||||
}
|
||||
launchSingleTop = true
|
||||
restoreState = true
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
composable<Destination.Main> {
|
||||
MainScreen()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
|
||||
sealed interface Destination {
|
||||
|
||||
@Serializable
|
||||
data object Splash : Destination
|
||||
|
||||
@Serializable
|
||||
data object Main : Destination
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package fr.openium.consentium.ui.screens.main
|
||||
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
|
||||
@Composable
|
||||
fun MainScreen(
|
||||
viewModel: MainScreenViewModel = hiltViewModel()
|
||||
) {
|
||||
|
||||
Text("Main")
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
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() {
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package fr.openium.consentium.ui.screens.splash
|
||||
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
|
||||
@Composable
|
||||
fun SplashScreen(
|
||||
viewModel: SplashScreenViewModel = hiltViewModel(),
|
||||
navigateToMain: () -> Unit,
|
||||
) {
|
||||
|
||||
val state by viewModel.state.collectAsState()
|
||||
|
||||
Text("Splash")
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
is SplashScreenViewModel.State.Loaded -> {
|
||||
navigateToMain()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package fr.openium.consentium.ui.screens.splash
|
||||
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class SplashScreenViewModel @Inject constructor(
|
||||
) : ViewModel() {
|
||||
|
||||
private val _state = MutableStateFlow<State>(State.Loading)
|
||||
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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface State {
|
||||
data object Loading : State
|
||||
data object Loaded : State
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user