2024-06-22 04:25:20 +08:00
|
|
|
package com.aiosman.riderpro
|
|
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import androidx.activity.ComponentActivity
|
|
|
|
|
import androidx.activity.compose.setContent
|
|
|
|
|
import androidx.activity.enableEdgeToEdge
|
2024-07-12 01:36:59 +08:00
|
|
|
import androidx.compose.animation.core.tween
|
|
|
|
|
import androidx.compose.animation.fadeIn
|
|
|
|
|
import androidx.compose.animation.fadeOut
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.background
|
|
|
|
|
import androidx.compose.foundation.layout.Arrangement
|
2024-07-12 23:37:21 +08:00
|
|
|
import androidx.compose.foundation.layout.Box
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.foundation.layout.Column
|
|
|
|
|
import androidx.compose.foundation.layout.WindowInsets
|
|
|
|
|
import androidx.compose.foundation.layout.fillMaxSize
|
|
|
|
|
import androidx.compose.foundation.layout.height
|
|
|
|
|
import androidx.compose.foundation.layout.navigationBars
|
|
|
|
|
import androidx.compose.foundation.layout.padding
|
|
|
|
|
import androidx.compose.foundation.layout.size
|
|
|
|
|
import androidx.compose.foundation.layout.statusBarsPadding
|
|
|
|
|
import androidx.compose.material3.Icon
|
|
|
|
|
import androidx.compose.material3.NavigationBar
|
|
|
|
|
import androidx.compose.material3.NavigationBarItem
|
|
|
|
|
import androidx.compose.material3.NavigationBarItemColors
|
|
|
|
|
import androidx.compose.material3.Scaffold
|
|
|
|
|
import androidx.compose.material3.Surface
|
|
|
|
|
import androidx.compose.runtime.Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
import androidx.compose.runtime.CompositionLocalProvider
|
|
|
|
|
import androidx.compose.runtime.compositionLocalOf
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.compose.runtime.getValue
|
|
|
|
|
import androidx.compose.ui.Alignment
|
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
|
import androidx.compose.ui.graphics.Color
|
|
|
|
|
import androidx.compose.ui.platform.LocalDensity
|
|
|
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
import androidx.compose.ui.unit.dp
|
2024-07-13 17:41:51 +08:00
|
|
|
import androidx.core.view.WindowCompat
|
2024-06-22 04:25:20 +08:00
|
|
|
import androidx.navigation.NavHostController
|
|
|
|
|
import androidx.navigation.compose.NavHost
|
|
|
|
|
import androidx.navigation.compose.composable
|
|
|
|
|
import androidx.navigation.compose.currentBackStackEntryAsState
|
|
|
|
|
import androidx.navigation.compose.rememberNavController
|
|
|
|
|
import com.aiosman.riderpro.ui.theme.RiderProTheme
|
2024-07-12 01:36:59 +08:00
|
|
|
import com.google.accompanist.systemuicontroller.rememberSystemUiController
|
2024-06-22 04:25:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class MainActivity : ComponentActivity() {
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
2024-07-13 17:41:51 +08:00
|
|
|
WindowCompat.setDecorFitsSystemWindows(window, false)
|
|
|
|
|
|
2024-06-22 04:25:20 +08:00
|
|
|
enableEdgeToEdge()
|
|
|
|
|
setContent {
|
|
|
|
|
Navigation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 23:37:21 +08:00
|
|
|
val LocalNavController = compositionLocalOf<NavHostController> {
|
|
|
|
|
error("NavController not provided")
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-22 04:25:20 +08:00
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun NavigationController(navController: NavHostController) {
|
2024-06-22 04:25:20 +08:00
|
|
|
NavHost(
|
2024-07-12 01:36:59 +08:00
|
|
|
navController = navController,
|
|
|
|
|
startDestination = NavigationItem.Home.route,
|
|
|
|
|
enterTransition = {
|
2024-07-12 15:54:09 +08:00
|
|
|
fadeIn(animationSpec = tween(0))
|
2024-07-12 01:36:59 +08:00
|
|
|
},
|
|
|
|
|
exitTransition = {
|
2024-07-12 15:54:09 +08:00
|
|
|
fadeOut(animationSpec = tween(0))
|
2024-07-12 23:37:21 +08:00
|
|
|
}) {
|
|
|
|
|
composable(route = NavigationItem.Home.route) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Home()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
composable(route = NavigationItem.Street.route) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Street()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
composable(route = NavigationItem.Add.route) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Add()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
composable(route = NavigationItem.Message.route) {
|
2024-07-12 01:36:59 +08:00
|
|
|
Video()
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
composable(route = NavigationItem.Profile.route) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Profile()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
composable(route = "ProfileTimeline") {
|
|
|
|
|
GalleryPage()
|
|
|
|
|
}
|
2024-07-13 17:41:51 +08:00
|
|
|
composable(route="LocationDetail") {
|
|
|
|
|
LocationDetail()
|
|
|
|
|
}
|
2024-07-13 17:55:23 +08:00
|
|
|
composable(route="OfficialPhoto") {
|
|
|
|
|
OfficialGalleryPage()
|
|
|
|
|
}
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Navigation() {
|
2024-06-22 04:25:20 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
|
|
|
|
val navController = rememberNavController()
|
|
|
|
|
val item = listOf(
|
|
|
|
|
NavigationItem.Home,
|
|
|
|
|
NavigationItem.Street,
|
|
|
|
|
NavigationItem.Add,
|
|
|
|
|
NavigationItem.Message,
|
|
|
|
|
NavigationItem.Profile
|
|
|
|
|
)
|
2024-07-12 23:37:21 +08:00
|
|
|
CompositionLocalProvider(LocalNavController provides navController) {
|
|
|
|
|
Scaffold(
|
|
|
|
|
modifier = Modifier.statusBarsPadding(),
|
|
|
|
|
topBar = {},
|
2024-07-13 17:41:51 +08:00
|
|
|
|
2024-07-12 23:37:21 +08:00
|
|
|
bottomBar = {
|
|
|
|
|
NavigationBar(
|
|
|
|
|
modifier = Modifier.height(56.dp + navigationBarHeight),
|
|
|
|
|
containerColor = Color.Black
|
|
|
|
|
) {
|
|
|
|
|
val navBackStackEntry by navController.currentBackStackEntryAsState()
|
|
|
|
|
val currentRoute = navBackStackEntry?.destination?.route
|
|
|
|
|
val systemUiController = rememberSystemUiController()
|
|
|
|
|
item.forEach { it ->
|
|
|
|
|
NavigationBarItem(
|
|
|
|
|
selected = currentRoute == it.route,
|
|
|
|
|
onClick = {
|
|
|
|
|
if (currentRoute != it.route) {
|
|
|
|
|
navController.navigate(it.route)
|
2024-07-12 01:36:59 +08:00
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
when (it.route) {
|
|
|
|
|
NavigationItem.Add.route -> {
|
|
|
|
|
systemUiController.setSystemBarsColor(
|
|
|
|
|
color = Color.Black
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NavigationItem.Message.route -> {
|
|
|
|
|
systemUiController.setSystemBarsColor(
|
|
|
|
|
color = Color.Black
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else -> {
|
|
|
|
|
systemUiController.setSystemBarsColor(
|
|
|
|
|
color = Color.Transparent
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-07-12 01:36:59 +08:00
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
},
|
|
|
|
|
colors = NavigationBarItemColors(
|
|
|
|
|
selectedIconColor = Color.Red,
|
|
|
|
|
selectedTextColor = Color.Red,
|
|
|
|
|
selectedIndicatorColor = Color.Black,
|
|
|
|
|
unselectedIconColor = Color.Red,
|
|
|
|
|
unselectedTextColor = Color.Red,
|
|
|
|
|
disabledIconColor = Color.Red,
|
|
|
|
|
disabledTextColor = Color.Red,
|
2024-06-22 04:25:20 +08:00
|
|
|
|
2024-07-12 23:37:21 +08:00
|
|
|
),
|
|
|
|
|
icon = {
|
|
|
|
|
Icon(
|
|
|
|
|
modifier = Modifier.size(24.dp),
|
|
|
|
|
imageVector = it.icon(), contentDescription = null,
|
|
|
|
|
tint = if (currentRoute == it.route) Color.Red else Color.White
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
}
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-13 17:41:51 +08:00
|
|
|
) { it
|
2024-07-12 23:37:21 +08:00
|
|
|
Box(
|
2024-07-13 17:41:51 +08:00
|
|
|
modifier = Modifier.padding(it.calculateTopPadding())
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
|
|
|
|
NavigationController(navController = navController)
|
|
|
|
|
}
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Home() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
2024-07-13 00:02:45 +08:00
|
|
|
.fillMaxSize(),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
PagingBackendSample()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Street() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
2024-07-13 00:02:45 +08:00
|
|
|
.fillMaxSize(),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
|
|
|
|
) {
|
|
|
|
|
StreetPage()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Add() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
2024-06-27 11:47:05 +08:00
|
|
|
modifier = Modifier
|
2024-07-12 23:37:21 +08:00
|
|
|
.fillMaxSize()
|
2024-06-27 11:47:05 +08:00
|
|
|
.background(Color.Black),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
2024-06-27 11:47:05 +08:00
|
|
|
AddPage()
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-12 01:36:59 +08:00
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Video() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
2024-07-13 00:02:45 +08:00
|
|
|
.fillMaxSize(),
|
2024-07-12 01:36:59 +08:00
|
|
|
verticalArrangement = Arrangement.Top,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
2024-07-12 01:36:59 +08:00
|
|
|
ShortVideo()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-22 04:25:20 +08:00
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Message() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
2024-07-13 00:02:45 +08:00
|
|
|
.fillMaxSize(),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalArrangement = Arrangement.Top,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally,
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
2024-06-22 04:25:20 +08:00
|
|
|
MessagePage()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Composable
|
2024-07-12 23:37:21 +08:00
|
|
|
fun Profile() {
|
2024-07-12 04:36:03 +08:00
|
|
|
val navigationBarHeight = with(LocalDensity.current) {
|
|
|
|
|
WindowInsets.navigationBars.getBottom(this).toDp()
|
|
|
|
|
}
|
2024-07-12 23:37:21 +08:00
|
|
|
Column(
|
|
|
|
|
modifier = Modifier
|
2024-07-13 00:02:45 +08:00
|
|
|
.fillMaxSize(),
|
2024-06-22 04:25:20 +08:00
|
|
|
verticalArrangement = Arrangement.Center,
|
|
|
|
|
horizontalAlignment = Alignment.CenterHorizontally
|
2024-07-12 23:37:21 +08:00
|
|
|
) {
|
|
|
|
|
ProfilePage()
|
|
|
|
|
}
|
2024-06-22 04:25:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Preview(showBackground = true)
|
|
|
|
|
@Composable
|
|
|
|
|
fun GreetingPreview() {
|
|
|
|
|
RiderProTheme {
|
2024-07-12 23:37:21 +08:00
|
|
|
Surface(modifier = Modifier.fillMaxSize(), color = Color.White) {
|
2024-06-22 04:25:20 +08:00
|
|
|
Navigation()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|