diff --git a/app/build.gradle b/app/build.gradle index 6205372..da89103 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -57,6 +57,8 @@ dependencies { implementation "androidx.compose.ui:ui:$compose_version" implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" implementation "androidx.compose.material3:material3:$material3_version" + // Compose navigation + implementation("androidx.navigation:navigation-compose:$navigation_version") testImplementation "junit:junit:$junit_version" androidTestImplementation "androidx.test.ext:junit:$test_junit" diff --git a/app/src/main/java/com/rocqjones/mesdk/MainActivity.kt b/app/src/main/java/com/rocqjones/mesdk/MainActivity.kt index 2de46b7..2b1bd92 100644 --- a/app/src/main/java/com/rocqjones/mesdk/MainActivity.kt +++ b/app/src/main/java/com/rocqjones/mesdk/MainActivity.kt @@ -1,23 +1,23 @@ package com.rocqjones.mesdk -import android.content.Intent import android.content.res.Configuration import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.* -import androidx.compose.material3.Button +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface -import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import com.rocqjones.me_design.screens.ListActivity -import com.rocqjones.me_design.screens.bottomNavAdaptive.AdaptiveNavActivity +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.rememberNavController +import com.rocqjones.me_design.screens.BottomSheetDialogScreen +import com.rocqjones.me_design.screens.EndlessScreen import com.rocqjones.me_design.ui.theme.MeSDKTheme +import com.rocqjones.me_logic.models.Screen +import com.rocqjones.mesdk.screens.HomeScreen /** * This is the first launcher screen of the SDK. @@ -28,83 +28,34 @@ class MainActivity : ComponentActivity() { super.onCreate(savedInstanceState) setContent { MeSDKTheme { - // A surface container using the 'background' color from the theme Surface( modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background ) { - FirstScreen( - onMoveToListClicked = { navigateToList() }, - onMoveToNavClicked = { navigateToAdaptiveUI() } - ) + MyAppMain() } } } } - - private fun navigateToAdaptiveUI() { - try { - val b = Intent(this, AdaptiveNavActivity::class.java) - b.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(b) - } catch (e: Exception) { - e.printStackTrace() - } - } - - private fun navigateToList() { - try { - val a = Intent(this, ListActivity::class.java) - a.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) - startActivity(a) - } catch (e: Exception) { - e.printStackTrace() - } - } } @Composable -fun FirstScreen( - onMoveToListClicked: () -> Unit, - onMoveToNavClicked: () -> Unit, - modifier: Modifier = Modifier -) { - /** - * When the button is clicked, should navigate to the respective UI - */ - Column( - modifier = modifier.fillMaxSize(), - verticalArrangement = Arrangement.Center, - horizontalAlignment = Alignment.CenterHorizontally +fun MyAppMain() { + val navController = rememberNavController() + + NavHost( + navController, startDestination = Screen.HomeScreen.route ) { - val padding = 8.dp - Text( - "Welcome to the Me SDK!", - style = MaterialTheme.typography.headlineMedium, - color =MaterialTheme.colorScheme.secondary, - ) - // list - Button( - modifier = Modifier.padding(padding).fillMaxWidth(), - shape = MaterialTheme.shapes.medium, - onClick = onMoveToListClicked // sets the sate to true - ) { - Text( - "Endless List", - style = MaterialTheme.typography.bodyLarge - ) + composable(Screen.HomeScreen.route) { + HomeScreen(navController) + } + + composable(Screen.EndlessScreen.route) { + EndlessScreen(navController) } - // Adaptive Navigation - Button( - modifier = Modifier.padding(padding).fillMaxWidth(), - shape = MaterialTheme.shapes.medium, - onClick = onMoveToNavClicked // sets the sate to true - ) { - Text( - "Adaptive Navigation", - style = MaterialTheme.typography.bodyLarge - ) + composable(Screen.BottomSheetDialogScreen.route) { + BottomSheetDialogScreen(navController) } } } @@ -123,9 +74,6 @@ fun FirstScreen( @Composable fun DefaultPreview() { MeSDKTheme { - FirstScreen( - onMoveToListClicked = {}, - onMoveToNavClicked = {} - ) // empty lambda expression means "Do nothing" on click + MyAppMain() } } \ No newline at end of file diff --git a/app/src/main/java/com/rocqjones/mesdk/screens/HomeScreen.kt b/app/src/main/java/com/rocqjones/mesdk/screens/HomeScreen.kt new file mode 100644 index 0000000..3fa3389 --- /dev/null +++ b/app/src/main/java/com/rocqjones/mesdk/screens/HomeScreen.kt @@ -0,0 +1,67 @@ +package com.rocqjones.mesdk.screens + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Button +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavHostController +import com.rocqjones.me_logic.models.Screen + +@Composable +fun HomeScreen(navController: NavHostController) { + + Box { + /** + * When the button is clicked, should navigate to the respective UI + */ + Column( + modifier = Modifier.fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + val padding = 8.dp + Text( + "Welcome to the Me SDK!", + style = MaterialTheme.typography.headlineMedium, + color = MaterialTheme.colorScheme.secondary, + ) + + // list + Button( + modifier = Modifier + .padding(padding) + .fillMaxWidth(), + shape = MaterialTheme.shapes.medium, + onClick = { navController.navigate(Screen.EndlessScreen.route) } + ) { + Text( + "Vertical Endless List", + style = MaterialTheme.typography.bodyLarge + ) + } + + // Bottom Sheets + Button( + modifier = Modifier + .padding(padding) + .fillMaxWidth(), + shape = MaterialTheme.shapes.medium, + onClick = { navController.navigate(Screen.BottomSheetDialogScreen.route) } + ) { + Text( + "Bottom Sheets Dialog", + style = MaterialTheme.typography.bodyLarge + ) + } + } + } +} \ No newline at end of file diff --git a/build.gradle b/build.gradle index 124a80c..a801899 100644 --- a/build.gradle +++ b/build.gradle @@ -2,7 +2,7 @@ buildscript { ext.compose_version = '1.5.4' // compose.runtime ext.compose_compiler = '1.4.4' // Release: https://developer.android.com/jetpack/androidx/releases/compose-kotlin } -// Top-level build file where you can add configuration options common to all sub-projects/modules. + plugins { id 'com.android.application' version '8.1.4' apply false id 'com.android.library' version '8.1.4' apply false @@ -20,4 +20,5 @@ ext { test_espresso = '3.5.1' test_junit = '1.1.5' junit_version = '4.13.2' + navigation_version = '2.7.7' } \ No newline at end of file diff --git a/me-design/build.gradle b/me-design/build.gradle index bd885b9..16bdf78 100644 --- a/me-design/build.gradle +++ b/me-design/build.gradle @@ -72,4 +72,7 @@ dependencies { implementation "com.google.android.material:material:$material_version" implementation "androidx.compose.material3:material3:$material3_version" + + // Compose navigation + implementation("androidx.navigation:navigation-compose:$navigation_version") } \ No newline at end of file diff --git a/me-design/src/main/AndroidManifest.xml b/me-design/src/main/AndroidManifest.xml index 149f57d..7903fae 100644 --- a/me-design/src/main/AndroidManifest.xml +++ b/me-design/src/main/AndroidManifest.xml @@ -2,16 +2,6 @@ - -