|
@@ -1,16 +1,36 @@
|
|
|
package com.lostc.japp
|
|
package com.lostc.japp
|
|
|
|
|
|
|
|
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
|
|
|
import androidx.activity.enableEdgeToEdge
|
|
import androidx.activity.enableEdgeToEdge
|
|
|
|
|
+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.material3.Text
|
|
|
|
|
+import androidx.compose.material3.NavigationBar
|
|
|
|
|
+import androidx.compose.material3.NavigationBarDefaults
|
|
|
|
|
+import androidx.compose.material3.NavigationBarItem
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.Composable
|
|
|
import androidx.compose.ui.Modifier
|
|
import androidx.compose.ui.Modifier
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
|
|
+import androidx.navigation.compose.NavHost
|
|
|
|
|
+import androidx.navigation.compose.composable
|
|
|
|
|
+import androidx.compose.material3.Icon
|
|
|
|
|
+import androidx.compose.material.icons.Icons
|
|
|
|
|
+import androidx.compose.material.icons.filled.Home
|
|
|
|
|
+import androidx.compose.material.icons.filled.Notifications
|
|
|
|
|
+import androidx.compose.material.icons.filled.Place
|
|
|
|
|
+import androidx.navigation.compose.rememberNavController
|
|
|
|
|
+import androidx.compose.runtime.mutableIntStateOf
|
|
|
|
|
+import androidx.compose.runtime.saveable.rememberSaveable
|
|
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
|
|
+import androidx.compose.ui.graphics.vector.ImageVector
|
|
|
|
|
+import androidx.navigation.NavHostController
|
|
|
import com.lostc.japp.ui.theme.JAPPTheme
|
|
import com.lostc.japp.ui.theme.JAPPTheme
|
|
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
class MainActivity : ComponentActivity() {
|
|
@@ -20,8 +40,7 @@ class MainActivity : ComponentActivity() {
|
|
|
setContent {
|
|
setContent {
|
|
|
JAPPTheme {
|
|
JAPPTheme {
|
|
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
|
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
|
|
|
- Greeting(
|
|
|
|
|
- name = "Android",
|
|
|
|
|
|
|
+ NavigationBarExample(
|
|
|
modifier = Modifier.padding(innerPadding)
|
|
modifier = Modifier.padding(innerPadding)
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
@@ -38,6 +57,108 @@ fun Greeting(name: String, modifier: Modifier = Modifier) {
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+// ====
|
|
|
|
|
+
|
|
|
|
|
+enum class Destination(
|
|
|
|
|
+ val route: String,
|
|
|
|
|
+ val label: String,
|
|
|
|
|
+ val icon: ImageVector,
|
|
|
|
|
+ val contentDescription: String
|
|
|
|
|
+) {
|
|
|
|
|
+ SONGS("songs", "Songs", Icons.Default.Notifications, "Songs"),
|
|
|
|
|
+ ALBUM("album", "Album", Icons.Default.Home, "Album"),
|
|
|
|
|
+ PLAYLISTS("playlist", "Playlist", Icons.Default.Place, "Playlist")
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+fun AppNavHost(
|
|
|
|
|
+ navController: NavHostController,
|
|
|
|
|
+ startDestination: Destination,
|
|
|
|
|
+ modifier: Modifier = Modifier
|
|
|
|
|
+) {
|
|
|
|
|
+ NavHost(
|
|
|
|
|
+ navController,
|
|
|
|
|
+ startDestination = startDestination.route
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Destination.entries.forEach { destination ->
|
|
|
|
|
+ composable(destination.route) {
|
|
|
|
|
+ when (destination) {
|
|
|
|
|
+ Destination.SONGS -> SongsScreen()
|
|
|
|
|
+ Destination.ALBUM -> AlbumScreen()
|
|
|
|
|
+ Destination.PLAYLISTS -> PlaylistScreen()
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+fun SongsScreen(modifier: Modifier = Modifier) {
|
|
|
|
|
+ Box(
|
|
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Text("Songs Screen")
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+fun AlbumScreen(modifier: Modifier = Modifier) {
|
|
|
|
|
+ Box(
|
|
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Text("Album Screen")
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+fun PlaylistScreen(modifier: Modifier = Modifier) {
|
|
|
|
|
+ Box(
|
|
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
|
|
+ ) {
|
|
|
|
|
+ Text("Playlist Screen")
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+@Composable
|
|
|
|
|
+fun NavigationBarExample(modifier: Modifier = Modifier) {
|
|
|
|
|
+ val navController = rememberNavController()
|
|
|
|
|
+ val startDestination = Destination.SONGS
|
|
|
|
|
+ var selectedDestination by rememberSaveable { mutableIntStateOf(startDestination.ordinal) }
|
|
|
|
|
+
|
|
|
|
|
+ Scaffold(
|
|
|
|
|
+ modifier = modifier,
|
|
|
|
|
+ bottomBar = {
|
|
|
|
|
+ NavigationBar(windowInsets = NavigationBarDefaults.windowInsets) {
|
|
|
|
|
+ Destination.entries.forEachIndexed { index, destination ->
|
|
|
|
|
+ NavigationBarItem(
|
|
|
|
|
+ selected = selectedDestination == index,
|
|
|
|
|
+ onClick = {
|
|
|
|
|
+ navController.navigate(route = destination.route)
|
|
|
|
|
+ selectedDestination = index
|
|
|
|
|
+ },
|
|
|
|
|
+ icon = {
|
|
|
|
|
+ Icon(
|
|
|
|
|
+ destination.icon,
|
|
|
|
|
+ contentDescription = destination.contentDescription
|
|
|
|
|
+ )
|
|
|
|
|
+ },
|
|
|
|
|
+ label = { Text(destination.label) }
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ ) { contentPadding ->
|
|
|
|
|
+ AppNavHost(navController, startDestination, modifier = Modifier.padding(contentPadding))
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+// ===
|
|
|
|
|
+
|
|
|
@Preview(showBackground = true)
|
|
@Preview(showBackground = true)
|
|
|
@Composable
|
|
@Composable
|
|
|
fun GreetingPreview() {
|
|
fun GreetingPreview() {
|