Skip to content

Commit

Permalink
init first screen
Browse files Browse the repository at this point in the history
  • Loading branch information
stslex committed Jul 23, 2023
1 parent c7f7721 commit a82d031
Show file tree
Hide file tree
Showing 18 changed files with 364 additions and 49 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/android_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Android Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
timeout-minutes: 60

steps:

- name: Checkout branch
uses: actions/checkout@v2

- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
cache: gradle

- name: set up LOCAL_PROPERTIES
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > ./local.properties

- name: Grant execute permission for gradlew
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Junit tests with Gradle
run: ./gradlew testDebugUnitTest
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
xmlns:tools="http://schemas.android.com/tools">

<application
android:name=".SelectApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -13,7 +14,7 @@
android:theme="@style/Theme.AProSelection"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:name=".ui.MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.AProSelection">
Expand Down
46 changes: 0 additions & 46 deletions app/src/main/java/com/stslex/aproselection/MainActivity.kt

This file was deleted.

17 changes: 17 additions & 0 deletions app/src/main/java/com/stslex/aproselection/SelectApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.stslex.aproselection

import android.app.Application
import com.stslex.aproselection.feature.auth.di.FeatureAuthModule.featureAuthModule
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin

class SelectApplication : Application() {

override fun onCreate() {
super.onCreate()
startKoin {
androidContext(applicationContext)
modules(featureAuthModule)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.stslex.aproselection.navigation

import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import com.stslex.aproselection.core.network.AppDestination
import com.stslex.aproselection.core.network.NavigationScreen
import com.stslex.aproselection.feature.auth.ui.navigation.authRouter

@Composable
fun NavigationHost(
navController: NavHostController,
modifier: Modifier = Modifier,
startDestination: AppDestination = AppDestination.AUTH
) {
val navigator: (NavigationScreen) -> Unit = { screen ->
when (screen) {
is NavigationScreen.PopBackStack -> navController.popBackStack()
else -> navController.navigateScreen(screen)
}
}
NavHost(
navController = navController,
startDestination = startDestination.route
) {
authRouter(modifier, navigator)
}
}

fun NavHostController.navigateScreen(screen: NavigationScreen) {
navigate(screen.screenRoute) {
if (screen.isSingleTop.not()) return@navigate
graph.startDestinationRoute?.let { route ->
popUpTo(route) {
inclusive = true
saveState = true
}
}
launchSingleTop = true
restoreState = false
}
}
23 changes: 23 additions & 0 deletions app/src/main/java/com/stslex/aproselection/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.stslex.aproselection.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.core.view.WindowCompat
import com.stslex.aproselection.ui.components.InitialApp
import com.stslex.aproselection.ui.theme.AppTheme

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

WindowCompat.setDecorFitsSystemWindows(window, false)

setContent {
AppTheme {
InitialApp()
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.stslex.aproselection.ui.components

import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.compose.rememberNavController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.stslex.aproselection.navigation.NavigationHost
import com.stslex.aproselection.ui.theme.AppTheme

@Composable
fun InitialApp() {
val navController = rememberNavController()
val systemUiController = rememberSystemUiController()
val isDarkTheme = isSystemInDarkTheme()

DisposableEffect(systemUiController, isDarkTheme) {
systemUiController.setSystemBarsColor(
color = Color.Transparent,
darkIcons = isDarkTheme.not(),
)
onDispose {}
}

NavigationHost(navController = navController)
}

@Preview(showBackground = true)
@Composable
fun InitialAppPreview() {
AppTheme {
InitialApp()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private val LightColorScheme = lightColorScheme(
)

@Composable
fun AProSelectionTheme(
fun AppTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.stslex.aproselection.core.network

sealed class AppArguments {

abstract val arguments: List<String>

open val argumentsForRoute: String
get() = arguments.joinToString(separator = "/", prefix = "/")

object Empty : AppArguments() {
override val arguments: List<String>
get() = emptyList()
override val argumentsForRoute: String
get() = String()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.stslex.aproselection.core.network

enum class AppDestination(
vararg val argsNames: String
) {
AUTH;

val route: String
get() = StringBuilder()
.append(name, SEPARATOR_ROUTE, TAG_ROUTE)
.toString()
.lowercase()

val navigationRoute: String
get() = "$route${argsNames.argumentsRoute}"

private val Array<out String>.argumentsRoute: String
get() = if (isEmpty()) {
String()
} else {
joinToString(separator = "}/{", prefix = "/{", postfix = "}")
}

companion object {
private const val SEPARATOR_ROUTE = "_"
private const val TAG_ROUTE = "route"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.stslex.aproselection.core.network

import androidx.navigation.NamedNavArgument
import androidx.navigation.NavBackStackEntry
import androidx.navigation.NavType
import androidx.navigation.navArgument

object NavExt {

val AppDestination.composableArguments: List<NamedNavArgument>
get() = argsNames.map { name ->
navArgument(name) { NavType.StringType }
}

val AppDestination.parseArguments: NavBackStackEntry.() -> List<String>
get() = {
argsNames.map { name ->
arguments?.getString(name).orEmpty()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.stslex.aproselection.core.network

sealed class NavigationScreen {

abstract val screen: AppDestination

val screenRoute: String
get() = "${screen.route}${appArgs.argumentsForRoute}"

open val isSingleTop: Boolean
get() = false

open val appArgs: AppArguments
get() = AppArguments.Empty

object Auth : NavigationScreen() {

override val screen: AppDestination = AppDestination.AUTH
override val isSingleTop: Boolean = true
}

object PopBackStack : NavigationScreen() {
override val screen: AppDestination = throw Exception("PopBackStack")
override val appArgs: AppArguments = throw Exception("PopBackStack")
}
}
7 changes: 7 additions & 0 deletions feature/auth/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ android {
kotlinOptions {
jvmTarget = "1.8"
}

buildFeatures {
compose = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.3"
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.stslex.aproselection.feature.auth.di

import com.stslex.aproselection.feature.auth.ui.AuthViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

object FeatureAuthModule {

val featureAuthModule = module {
viewModelOf(::AuthViewModel)
}
}
Loading

0 comments on commit a82d031

Please sign in to comment.