-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(designsystem): Implement functionality of the designsystem module
feat(navigation): Implement top-level navigation in the app
- Loading branch information
1 parent
e846a94
commit 1e6746d
Showing
34 changed files
with
1,957 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,106 @@ | ||
package com.wei.picquest | ||
|
||
import android.graphics.Color | ||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.activity.SystemBarStyle | ||
import androidx.activity.compose.setContent | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Surface | ||
import androidx.compose.material3.Text | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.compose.foundation.isSystemInDarkTheme | ||
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi | ||
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.runtime.CompositionLocalProvider | ||
import androidx.compose.runtime.DisposableEffect | ||
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.accompanist.adaptive.calculateDisplayFeatures | ||
import com.wei.picquest.core.data.utils.NetworkMonitor | ||
import com.wei.picquest.core.designsystem.theme.PqTheme | ||
import com.wei.picquest.core.manager.SnackbarManager | ||
import com.wei.picquest.ui.PqApp | ||
import dagger.hilt.android.AndroidEntryPoint | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.launch | ||
import javax.inject.Inject | ||
|
||
@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) | ||
@AndroidEntryPoint | ||
class MainActivity : ComponentActivity() { | ||
|
||
@Inject | ||
lateinit var snackbarManager: SnackbarManager | ||
|
||
@Inject | ||
lateinit var networkMonitor: NetworkMonitor | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
val splashScreen = installSplashScreen() | ||
|
||
splashScreen.setKeepOnScreenCondition { true } | ||
|
||
// Turn off the decor fitting system windows, which allows us to handle insets, | ||
// including IME animations, and go edge-to-edge | ||
// This also sets up the initial system bar style based on the platform theme | ||
enableEdgeToEdge() | ||
|
||
setContent { | ||
PqTheme { | ||
// A surface container using the 'background' color from the theme | ||
Surface( | ||
modifier = Modifier.fillMaxSize(), | ||
color = MaterialTheme.colorScheme.background, | ||
) { | ||
Greeting("PicQuest") | ||
val darkTheme = shouldUseDarkTheme() | ||
|
||
// Update the edge to edge configuration to match the theme | ||
// This is the same parameters as the default enableEdgeToEdge call, but we manually | ||
// resolve whether or not to show dark theme using uiState, since it can be different | ||
// than the configuration's dark theme value based on the user preference. | ||
DisposableEffect(darkTheme) { | ||
enableEdgeToEdge( | ||
statusBarStyle = SystemBarStyle.auto( | ||
Color.TRANSPARENT, | ||
Color.TRANSPARENT, | ||
) { darkTheme }, | ||
navigationBarStyle = SystemBarStyle.auto( | ||
lightScrim, | ||
darkScrim, | ||
) { darkTheme }, | ||
) | ||
onDispose {} | ||
} | ||
|
||
CompositionLocalProvider() { | ||
PqTheme(darkTheme = darkTheme) { | ||
PqApp( | ||
networkMonitor = networkMonitor, | ||
windowSizeClass = calculateWindowSizeClass(this@MainActivity), | ||
displayFeatures = calculateDisplayFeatures(this@MainActivity), | ||
snackbarManager = snackbarManager, | ||
) | ||
} | ||
} | ||
} | ||
|
||
lifecycleScope.launch { | ||
// TODO Wei Loading user data | ||
delay(2_000) | ||
splashScreen.setKeepOnScreenCondition { false } | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Returns `true` if dark theme should be used, as a function of the [uiState] and the | ||
* current system context. | ||
*/ | ||
@Composable | ||
fun Greeting(name: String, modifier: Modifier = Modifier) { | ||
Text( | ||
text = "Hello $name!", | ||
modifier = modifier, | ||
) | ||
} | ||
private fun shouldUseDarkTheme(): Boolean = isSystemInDarkTheme() | ||
|
||
@Preview(showBackground = true) | ||
@Composable | ||
fun GreetingPreview() { | ||
PqTheme { | ||
Greeting("PicQuest") | ||
} | ||
} | ||
/** | ||
* The default light scrim, as defined by androidx and the platform: | ||
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=35-38;drc=27e7d52e8604a080133e8b842db10c89b4482598 | ||
*/ | ||
private val lightScrim = android.graphics.Color.argb(0xe6, 0xFF, 0xFF, 0xFF) | ||
|
||
/** | ||
* The default dark scrim, as defined by androidx and the platform: | ||
* https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:activity/activity/src/main/java/androidx/activity/EdgeToEdge.kt;l=40-44;drc=27e7d52e8604a080133e8b842db10c89b4482598 | ||
*/ | ||
private val darkScrim = android.graphics.Color.argb(0x80, 0x1b, 0x1b, 0x1b) |
40 changes: 40 additions & 0 deletions
40
app/src/main/java/com/wei/picquest/navigation/PqNavHost.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.wei.picquest.navigation | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.navigation.compose.NavHost | ||
import androidx.window.layout.DisplayFeature | ||
import com.wei.picquest.core.designsystem.ui.DeviceOrientation | ||
import com.wei.picquest.feature.home.home.navigation.homeGraph | ||
import com.wei.picquest.feature.home.home.navigation.homeRoute | ||
import com.wei.picquest.ui.PqAppState | ||
|
||
/** | ||
* Top-level navigation graph. Navigation is organized as explained at | ||
* https://d.android.com/jetpack/compose/nav-adaptive | ||
* | ||
* The navigation graph defined in this file defines the different top level routes. Navigation | ||
* within each route is handled using state and Back Handlers. | ||
*/ | ||
@Composable | ||
fun PqNavHost( | ||
modifier: Modifier = Modifier, | ||
appState: PqAppState, | ||
displayFeatures: List<DisplayFeature>, | ||
startDestination: String = homeRoute, | ||
) { | ||
val navController = appState.navController | ||
val navigationType = appState.navigationType | ||
val isPortrait = appState.currentDeviceOrientation == DeviceOrientation.PORTRAIT | ||
val contentType = appState.contentType | ||
|
||
NavHost( | ||
navController = navController, | ||
startDestination = startDestination, | ||
modifier = modifier, | ||
) { | ||
homeGraph( | ||
navController = navController, | ||
) | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
app/src/main/java/com/wei/picquest/navigation/TopLevelDestination.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.wei.picquest.navigation | ||
|
||
import androidx.compose.ui.graphics.vector.ImageVector | ||
import com.wei.picquest.R | ||
import com.wei.picquest.core.designsystem.icon.PqIcons | ||
|
||
/** | ||
* Type for the top level destinations in the application. Each of these destinations | ||
* can contain one or more screens (based on the window size). Navigation from one screen to the | ||
* next within a single destination will be handled directly in composables. | ||
*/ | ||
enum class TopLevelDestination( | ||
val selectedIcon: ImageVector, | ||
val unselectedIcon: ImageVector, | ||
val iconTextId: Int, | ||
val titleTextId: Int, | ||
) { | ||
HOME( | ||
selectedIcon = PqIcons.Home, | ||
unselectedIcon = PqIcons.HomeBorder, | ||
iconTextId = R.string.home, | ||
titleTextId = R.string.home, | ||
), | ||
PHOTO_LIBRARY( | ||
selectedIcon = PqIcons.PhotoLibrary, | ||
unselectedIcon = PqIcons.PhotoLibraryBorder, | ||
iconTextId = R.string.photo_library, | ||
titleTextId = R.string.photo_library, | ||
), | ||
CONTACT_ME( | ||
selectedIcon = PqIcons.ContactMe, | ||
unselectedIcon = PqIcons.ContactMeBorder, | ||
iconTextId = R.string.contact_me, | ||
titleTextId = R.string.contact_me, | ||
), | ||
} |
Oops, something went wrong.