diff --git a/app/build.gradle.kts b/app/build.gradle.kts index f13fc37..14c6853 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -7,6 +7,9 @@ plugins { alias(libs.plugins.android.application) alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.compose) + alias(libs.plugins.hilt) + alias(libs.plugins.kotlin.serialization) + } // Keystore @@ -88,6 +91,7 @@ dependencies { implementation(libs.hilt.android) ksp(libs.hilt.compiler) implementation(libs.hilt.navigation.compose) + implementation(libs.matomo) // Compose implementation(platform(libs.compose.bom)) @@ -96,9 +100,15 @@ dependencies { // Timber implementation(libs.timber) + implementation(libs.androidx.navigation.compose) + + // Tests testImplementation(libs.test.junit) androidTestImplementation(libs.test.junit) androidTestImplementation(libs.test.espresso) androidTestImplementation(libs.test.androidx.junit) + + implementation(libs.kotlin.serialization) + } \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 618d6b0..5dffbcc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -3,6 +3,7 @@ xmlns:tools="http://schemas.android.com/tools" > - Greeting( - name = "Android", - modifier = Modifier.padding(innerPadding) - ) + Scaffold( modifier = Modifier.fillMaxSize() ) { paddingValues -> + Box( + modifier = Modifier + .fillMaxSize() + .padding(paddingValues) + ) { + DemoNavGraph(navHostController = navHostController) + } } } } diff --git a/app/src/main/java/fr/openium/consentium/ui/navigation/DemoNavGraph.kt b/app/src/main/java/fr/openium/consentium/ui/navigation/DemoNavGraph.kt new file mode 100644 index 0000000..35e2772 --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/navigation/DemoNavGraph.kt @@ -0,0 +1,49 @@ +package fr.openium.afu.ui.navigation + +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 { + SplashScreen( + navigateToMain = { -> + navHostController.navigate(Destination.Main) { + popUpTo(navHostController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }) + } + + composable { + MainScreen() + } + + } +} diff --git a/app/src/main/java/fr/openium/consentium/ui/navigation/Destination.kt b/app/src/main/java/fr/openium/consentium/ui/navigation/Destination.kt new file mode 100644 index 0000000..2635d23 --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/navigation/Destination.kt @@ -0,0 +1,14 @@ +package fr.openium.afu.ui.navigation + +import kotlinx.serialization.Serializable + + +sealed interface Destination { + + @kotlinx.serialization.Serializable + data object Splash : Destination + + @Serializable + data object Main : Destination + +} diff --git a/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreen.kt b/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreen.kt new file mode 100644 index 0000000..d4fe0c5 --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreen.kt @@ -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") + +} \ No newline at end of file diff --git a/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreenViewModel.kt b/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreenViewModel.kt new file mode 100644 index 0000000..bdc0e21 --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/screens/main/MainScreenViewModel.kt @@ -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() { + +} \ No newline at end of file diff --git a/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreen.kt b/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreen.kt new file mode 100644 index 0000000..1a2f9b4 --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreen.kt @@ -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.fillMaxWidth +import androidx.compose.foundation.layout.padding +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.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") + + + 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() + } + + + + } + +} \ No newline at end of file diff --git a/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreenViewModel.kt b/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreenViewModel.kt new file mode 100644 index 0000000..1950abd --- /dev/null +++ b/app/src/main/java/fr/openium/consentium/ui/screens/splash/SplashScreenViewModel.kt @@ -0,0 +1,43 @@ +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.Loading) + val state: StateFlow = _state + + private fun loadMain() { + 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 + } + + init { + loadMain() + } + +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 0917e96..ad3cd5b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,4 +14,10 @@ plugins { // Agp alias(libs.plugins.android.library) apply false + + alias(libs.plugins.hilt) apply false + + alias(libs.plugins.kotlin.serialization) apply false + + } \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 448ed8f..2ae1caa 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -37,6 +37,18 @@ kotlin = "2.0.0" ksp = "2.0.0-1.0.23" junitVersion = "1.2.1" +# Matomo +matomo = "4.3" + +# Serialization +serialization = "1.7.1" + +navigationCommonKtx = "2.8.2" +navigationRuntimeKtx = "2.8.2" +navigationCompose = "2.8.2" + + + [libraries] # AndroidX @@ -67,6 +79,14 @@ compose-material3 = { group = "androidx.compose.material3", name = "material3" } # Material material = { group = "com.google.android.material", name = "material", version.ref = "material" } +# Matomo +matomo = { module = "com.github.matomo-org:matomo-sdk-android", version.ref = "matomo" } + +kotlin-serialization = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" } +androidx-navigation-common-ktx = { group = "androidx.navigation", name = "navigation-common-ktx", version.ref = "navigationCommonKtx" } +androidx-navigation-runtime-ktx = { group = "androidx.navigation", name = "navigation-runtime-ktx", version.ref = "navigationRuntimeKtx" } +androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" } + # Test test-junit = { group = "junit", name = "junit", version.ref = "junit" } test-androidx-junit = { group = "androidx.test.ext", name = "junit-ktx", version.ref = "junitExtVersion" } @@ -79,6 +99,10 @@ kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } android-library = { id = "com.android.library", version.ref = "agp" } +hilt = { id = "com.google.dagger.hilt.android", version.ref = "hilt" } +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } + + [bundles] androidx = ["androidx-core-ktx", "androidx-activity-compose"] diff --git a/settings.gradle.kts b/settings.gradle.kts index 58bbc13..b9f970c 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -16,6 +16,8 @@ dependencyResolutionManagement { repositories { google() mavenCentral() + maven { url = uri("https://jitpack.io/") } + } }