Skip to content

Commit

Permalink
Merge pull request #3 from azrael8576/chore/designsystem
Browse files Browse the repository at this point in the history
Implement functionality of the designsystem module
  • Loading branch information
azrael8576 authored Nov 30, 2023
2 parents f0a1c1d + 1e6746d commit 1706e1e
Show file tree
Hide file tree
Showing 34 changed files with 1,957 additions and 69 deletions.
13 changes: 2 additions & 11 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,6 @@ android {
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

buildTypes {
debug {
applicationIdSuffix = PqBuildType.DEBUG.applicationIdSuffix
Expand Down Expand Up @@ -76,9 +66,10 @@ android {
}

dependencies {
implementation(project(":feature:home"))

// TODO Wei
// implementation(project(":feature:login"))
// implementation(project(":feature:home"))
// implementation(project(":feature:contactme"))

implementation(project(":core:designsystem"))
Expand Down
112 changes: 86 additions & 26 deletions app/src/main/java/com/wei/picquest/MainActivity.kt
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 app/src/main/java/com/wei/picquest/navigation/PqNavHost.kt
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,
)
}
}
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,
),
}
Loading

0 comments on commit 1706e1e

Please sign in to comment.