Skip to content

Commit

Permalink
configured feature modules in sample app
Browse files Browse the repository at this point in the history
  • Loading branch information
Morfly committed Oct 29, 2023
1 parent 8ea3c7b commit 3854785
Show file tree
Hide file tree
Showing 18 changed files with 195 additions and 25 deletions.
6 changes: 5 additions & 1 deletion gradle/sample-libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ compose-ui-tooling-preview = { module = "androidx.compose.ui:ui-tooling-preview"
compose-ui-test-manifest = { module = "androidx.compose.ui:ui-test-manifest" }
compose-material3 = { module = "androidx.compose.material3:material3" }
compose-activity = "androidx.activity:activity-compose:1.8.0"
compose-navigation = "androidx.navigation:navigation-compose:2.7.4"
compose-navigation-hilt = "androidx.hilt:hilt-navigation-compose:1.0.0"
androidx-core = "androidx.core:core-ktx:1.12.0"
androidx-lifecycle-runtime = "androidx.lifecycle:lifecycle-runtime-ktx:2.6.2"
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "dagger" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "dagger" }
junit = "junit:junit:4.13.2"
# ===== Gradle plugins =====
gradlePlugin-android-api = { module = "com.android.tools.build:gradle-api", version.ref = "agp" }
Expand All @@ -32,7 +36,7 @@ kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref =
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
android-application = { id = "com.android.application", version.ref = "agp" }
android-library = { id = "com.android.library", version.ref = "agp" }
dagger-hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "dagger" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "dagger" }
# ===== Convention Plugins =====
sample-android-common = { id = "sample.android.common", version.ref = "sampleConventionPlugin" }
sample-android-library = { id = "sample.android.library", version.ref = "sampleConventionPlugin" }
Expand Down
10 changes: 10 additions & 0 deletions samples/simple-android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
plugins {
alias(sampleLibs.plugins.sample.android.application)
alias(sampleLibs.plugins.sample.android.compose)
alias(sampleLibs.plugins.hilt.android)
alias(sampleLibs.plugins.ksp)
}

android {
Expand All @@ -12,9 +14,17 @@ android {
}

dependencies {
implementation(projects.featureA)
implementation(projects.featureB)
implementation(projects.libraryA)
implementation(projects.libraryB)

implementation(sampleLibs.androidx.core)
implementation(sampleLibs.androidx.lifecycle.runtime)
implementation(sampleLibs.compose.activity)
implementation(sampleLibs.compose.navigation)
implementation(sampleLibs.hilt.android)
ksp(sampleLibs.hilt.android.compiler)

testImplementation(sampleLibs.junit)
}
1 change: 1 addition & 0 deletions samples/simple-android/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=".AirinSampleApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.morfly.airin.sample

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class AirinSampleApplication : Application()
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.morfly.airin.sample

import androidx.compose.runtime.Composable
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import io.morfly.airin.sample.featureA.navigation.firstScreen
import io.morfly.airin.sample.featureA.navigation.firstScreenRoute
import io.morfly.airin.sample.featureB.navigation.navigateToSecondScreen
import io.morfly.airin.sample.featureB.navigation.secondScreen


@Composable
fun AirinSampleNavHost() {

val navController = rememberNavController()

NavHost(navController = navController, startDestination = firstScreenRoute) {
firstScreen(onNextClick = navController::navigateToSecondScreen)
secondScreen(onNextClick = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,25 @@ 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.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import io.morfly.airin.sample.ui.theme.AirinsampleTheme
import dagger.hilt.android.AndroidEntryPoint
import io.morfly.airin.sample.ui.theme.AirinSampleTheme

@AndroidEntryPoint
class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
AirinsampleTheme {
AirinSampleTheme {
// A surface container using the 'background' color from the theme
Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
Greeting("Android")
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
AirinSampleNavHost()
}
}
}
}
}

@Composable
fun Greeting(name: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $name!",
modifier = modifier
)
}

@Preview(showBackground = true)
@Composable
fun GreetingPreview() {
AirinsampleTheme {
Greeting("Android")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private val LightColorScheme = lightColorScheme(
)

@Composable
fun AirinsampleTheme(
fun AirinSampleTheme(
darkTheme: Boolean = isSystemInDarkTheme(),
// Dynamic color is available on Android 12+
dynamicColor: Boolean = true,
Expand Down
2 changes: 2 additions & 0 deletions samples/simple-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ plugins {
alias(sampleLibs.plugins.kotlin.jvm) apply false
alias(sampleLibs.plugins.android.application) apply false
alias(sampleLibs.plugins.android.library) apply false
alias(sampleLibs.plugins.ksp) apply false
alias(sampleLibs.plugins.hilt.android) apply false
id("io.morfly.airin.android") version sampleLibs.versions.airin
}

Expand Down
17 changes: 17 additions & 0 deletions samples/simple-android/feature-A/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
alias(sampleLibs.plugins.sample.android.library)
alias(sampleLibs.plugins.sample.android.compose)
alias(sampleLibs.plugins.hilt.android)
alias(sampleLibs.plugins.ksp)
}

android {
namespace = "io.morfly.airin.sample.featureA"
}

dependencies {
implementation(sampleLibs.compose.navigation)
implementation(sampleLibs.compose.navigation.hilt)
implementation(sampleLibs.hilt.android)
ksp(sampleLibs.hilt.android.compiler)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.morfly.airin.sample.featureA.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import io.morfly.airin.sample.featureA.ui.FirstScreen

const val firstScreenRoute = "first_screen_route"

fun NavController.navigateToFirstScreen(navOptions: NavOptions? = null) {
navigate(firstScreenRoute, navOptions)
}

fun NavGraphBuilder.firstScreen(
onNextClick: () -> Unit
) {
composable(firstScreenRoute) {
FirstScreen(onNextClick = onNextClick)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.morfly.airin.sample.featureA.ui

import androidx.compose.foundation.clickable
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel

@Composable
fun FirstScreen(
modifier: Modifier = Modifier,
onNextClick: () -> Unit,
viewModel: FirstViewModel = hiltViewModel()
) {
Text(
text = "FirstScreen",
Modifier.clickable { onNextClick() }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.morfly.airin.sample.featureA.ui

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class FirstViewModel @Inject constructor(): ViewModel() {
}
17 changes: 17 additions & 0 deletions samples/simple-android/feature-B/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
alias(sampleLibs.plugins.sample.android.library)
alias(sampleLibs.plugins.sample.android.compose)
alias(sampleLibs.plugins.hilt.android)
alias(sampleLibs.plugins.ksp)
}

android {
namespace = "io.morfly.airin.sample.featureB"
}

dependencies {
implementation(sampleLibs.compose.navigation)
implementation(sampleLibs.compose.navigation.hilt)
implementation(sampleLibs.hilt.android)
ksp(sampleLibs.hilt.android.compiler)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.morfly.airin.sample.featureB.navigation

import androidx.navigation.NavController
import androidx.navigation.NavGraphBuilder
import androidx.navigation.NavOptions
import androidx.navigation.compose.composable
import io.morfly.airin.sample.featureB.ui.SecondScreen

const val secondScreenRoute = "second_screen_route"

fun NavController.navigateToSecondScreen(navOptions: NavOptions? = null) {
navigate(secondScreenRoute, navOptions)
}

fun NavGraphBuilder.secondScreen(
onNextClick: () -> Unit
) {
composable(secondScreenRoute) {
SecondScreen(onNextClick = onNextClick)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.morfly.airin.sample.featureB.ui

import androidx.compose.foundation.clickable
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel

@Composable
fun SecondScreen(
modifier: Modifier = Modifier,
onNextClick: () -> Unit,
viewModel: SecondViewModel = hiltViewModel()
) {
Text(
text = "FirstScreen",
Modifier.clickable { onNextClick() }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.morfly.airin.sample.featureB.ui

import androidx.lifecycle.ViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class SecondViewModel @Inject constructor(): ViewModel() {
}
3 changes: 3 additions & 0 deletions samples/simple-android/library-A/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm")
}
3 changes: 3 additions & 0 deletions samples/simple-android/library-B/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm")
}

0 comments on commit 3854785

Please sign in to comment.