Skip to content

Commit

Permalink
Merge pull request #3 from AnteeOne/feature/add_new_modules
Browse files Browse the repository at this point in the history
feature: implement new core and common modules
  • Loading branch information
AnteeOne committed Oct 29, 2022
2 parents dfd833b + 0c5fee1 commit a7f0bfa
Show file tree
Hide file tree
Showing 65 changed files with 790 additions and 63 deletions.
11 changes: 9 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ android {
}

dependencies {
implementation(project(Modules.coreUi))
implementation(project(Modules.coreStrings))
projectImplementation(Modules.coreUi)
projectImplementation(Modules.coreStrings)
projectImplementation(Modules.coreUtils)

projectImplementation(Modules.commonDomain)
projectImplementation(Modules.commonData)
projectImplementation(Modules.commonDi)
projectImplementation(Modules.commonUi)
projectImplementation(Modules.commonMultiCompose)

implementation(Deps.Compose.ui)
implementation(Deps.Compose.foundation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,48 @@ package tech.antee.compose_multimodule_template
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.Modifier
import androidx.navigation.compose.rememberNavController
import tech.antee.compose_multimodule_template.di.LocalAppProvider
import tech.antee.compose_multimodule_template.ui.theme.MyApplicationTheme

// TODO("Implement your app")
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MyApplicationTheme {
// TODO("Implement your app")
GlobalDependenciesProvider {
Navigation()
}
}
}
}

@Composable
private fun Navigation(modifier: Modifier = Modifier) {
val navController = rememberNavController()
val destinations = LocalAppProvider.current.destinations
// val someFeature = destinations.find<SomeFeature>()
// val anotherFeature = destinations.find<AnotherFeature>()

// Box(modifier.fillMaxSize()) {
// NavHost(navController, someFeature.featureRoute) {
// with(someFeature) { composable(navController, destinations) }
// with(anotherFeature) { composable(navController, destinations) }
// }
// }
}

@Composable
private fun GlobalDependenciesProvider(
content: @Composable () -> Unit
) {
CompositionLocalProvider(
LocalAppProvider provides application.appProvider,
content = content
)
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
package tech.antee.compose_multimodule_template

import android.app.Application
import tech.antee.compose_multimodule_template.di.AppProvider

class MyApplication : Application()
// TODO("Implement your app")
class MyApplication : Application() {

lateinit var appProvider: AppProvider

// override fun onCreate() {
// super.onCreate()
// appProvider = DaggerMyApplicationComponent.factory().create(this).apply {
// inject(this@App)
// }
// }
}

val Application.appProvider: AppProvider
get() = (this as MyApplication).appProvider
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package tech.antee.compose_multimodule_template.di

import android.content.Context
import dagger.BindsInstance
import dagger.Component
import tech.antee.compose_multimodule_template.MyApplication
import tech.antee.compose_multimodule_template.di.qualifiers.ApplicationContext
import javax.inject.Singleton

@Singleton
@Component(modules = [AppModule::class, FeaturesModule::class])
interface AppComponent : AppProvider {

fun inject(app: MyApplication)

@Component.Factory
interface Factory {
fun create(
@BindsInstance
@ApplicationContext
context: Context
): AppComponent
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package tech.antee.compose_multimodule_template.di

import dagger.Module
import tech.antee.compose_multimodule_template.data.di.DataModule

@Module(
includes = [DataModule::class]
)
interface AppModule
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package tech.antee.compose_multimodule_template.di

import androidx.compose.runtime.compositionLocalOf
import tech.antee.compose_multimodule_template.multi_compose.Destinations

interface AppProvider {
val destinations: Destinations
}

val LocalAppProvider = compositionLocalOf<AppProvider> { error("No app provider found!") }
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package tech.antee.compose_multimodule_template.di

import dagger.Module

@Module(
includes = []
)
interface FeaturesModule
22 changes: 21 additions & 1 deletion buildSrc/src/main/java/Accessors.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import org.gradle.api.artifacts.Dependency
import org.gradle.api.artifacts.ProjectDependency
import org.gradle.api.artifacts.dsl.DependencyHandler

/*
* Extensions that used to provide above dependency syntax that mimics Gradle Kotlin DSL syntax
* in module\build.gradle.kts.kts files. Mimics to extensions that are generated on the fly by Gradle.
* in module\build.gradle.kts files. Mimics to extensions that are generated on the fly by Gradle.
*/
fun DependencyHandler.implementation(dependencyNotation: Any): Dependency? =
add("implementation", dependencyNotation)
Expand All @@ -19,3 +20,22 @@ fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? =

fun DependencyHandler.androidTestImplementation(dependencyNotation: Any): Dependency? =
add("androidTestImplementation", dependencyNotation)

fun DependencyHandler.projectImplementation(dependencyNotation: String): Dependency? =
add("implementation", project(dependencyNotation))

fun DependencyHandler.projectApi(dependencyNotation: String): Dependency? =
add("api", project(dependencyNotation))

private fun DependencyHandler.project(
path: String,
configuration: String? = null
): ProjectDependency = uncheckedCast(
project(
if (configuration != null) mapOf("path" to path, "configuration" to configuration)
else mapOf("path" to path)
)
)

@Suppress("unchecked_cast", "nothing_to_inline")
private inline fun <T> uncheckedCast(obj: Any?): T = obj as T
65 changes: 51 additions & 14 deletions buildSrc/src/main/java/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,19 @@ object Versions {
const val androidxFragment = "1.2.5"
const val androidxCoreKtx = "1.7.0"
const val androidxConstraint = "2.1.1"
const val androidxConstraintCompose = "1.0.1"
const val androidxRecyclerView = "1.0.0"
const val androidxSwipeRefresh = "1.1.0"
const val androidxNavigation = "2.4.2"
const val androidxLifecycle = "2.4.0"
const val androidxViewpager = "1.1.0-alpha01"
const val androidxWorkManager = "2.4.0"
const val androidxWorkManager = "2.7.0"
const val androidxRoom = "2.4.0-beta01"
const val androidxPaging = "3.0.0-alpha06"
const val androidxViewPager2 = "1.0.0"
const val androidxHilt = "1.0.0-alpha03"
const val hilt = "2.36"
const val authApiPhone = "18.0.1"
const val splashScreen = "1.0.0"

const val material = "1.5.0-alpha04"
const val playServicesLocation = "17.0.0"
Expand Down Expand Up @@ -51,16 +53,23 @@ object Versions {
const val androidxEspresso = "3.4.0"
const val androidxCoreTesting = "1.1.3"

const val protobufPlugin = "0.8.18"
const val protoc = "3.21.2"
const val protobuf = "3.18.0"
const val dataStore = "1.0.0"
const val gradle = "7.0.3"
}

object Deps {

const val coreKtx = "androidx.core:core-ktx:${Versions.androidxCoreKtx}"
const val appCompat = "androidx.appcompat:appcompat:${Versions.androidxAppcompat}"
const val material = "com.google.android.material:material:${Versions.material}"
const val lifecycle = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.androidxLifecycle}"
const val lifecycleRuntimeKtx = "androidx.lifecycle:lifecycle-runtime-ktx:${Versions.androidxLifecycle}"
const val lifecycleService = "androidx.lifecycle:lifecycle-service:${Versions.androidxLifecycle}"
const val constraintLayout = "androidx.constraintlayout:constraintlayout:${Versions.androidxConstraint}"
const val inject = "javax.inject:javax.inject:${Versions.javaxInject}"
const val workManager = "androidx.work:work-runtime-ktx:${Versions.androidxWorkManager}"
const val splashScreen = "androidx.core:core-splashscreen:${Versions.splashScreen}"

object Test {
const val jUnit = "junit:junit:${Versions.junit}"
Expand All @@ -73,6 +82,35 @@ object Deps {
const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
}

object Coroutines {
const val kotlinCore = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Versions.coroutine}"
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutine}"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.androidxLifecycle}"
}

object Network {
const val retrofit = "com.squareup.retrofit2:retrofit:${Versions.retrofit}"
const val gsonConverter = "com.squareup.retrofit2:converter-gson:${Versions.retrofit}"
const val okHttpLogging = "com.squareup.okhttp3:logging-interceptor:${Versions.okHttp}"
}

object Local {
const val room = "androidx.room:room-runtime:${Versions.androidxRoom}"
const val roomKapt = "androidx.room:room-compiler:${Versions.androidxRoom}"
const val roomKtx = "androidx.room:room-ktx:${Versions.androidxRoom}"
}

object LocalStore {
const val dataStore = "androidx.datastore:datastore:${Versions.dataStore}"
const val protobuf = "com.google.protobuf:protobuf-javalite:${Versions.protobuf}"
const val protoc = "com.google.protobuf:protoc:${Versions.protoc}"
}

object Dagger {
const val core = "com.google.dagger:dagger:${Versions.dagger}"
const val compiler = "com.google.dagger:dagger-compiler:${Versions.dagger}"
}

object Compose {
const val ui = "androidx.compose.ui:ui:${Versions.compose}"
const val tools = "androidx.compose.ui:ui-tooling:${Versions.compose}"
Expand All @@ -87,20 +125,19 @@ object Deps {
const val navigation = "androidx.navigation:navigation-compose:${Versions.androidxNavigation}"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel-compose:${Versions.androidxLifecycle}"
const val jUnit = "androidx.compose.ui:ui-test-junit4:${Versions.compose}"
}

object Coroutines {
const val android = "org.jetbrains.kotlinx:kotlinx-coroutines-android:${Versions.coroutine}"
const val viewModel = "androidx.lifecycle:lifecycle-viewmodel-ktx:${Versions.androidxLifecycle}"
}

object Dagger {
const val core = "com.google.dagger:dagger:${Versions.dagger}"
const val compiler = "com.google.dagger:dagger-compiler:${Versions.dagger}"
const val constraintLayoutCompose =
"androidx.constraintlayout:constraintlayout-compose:${Versions.androidxConstraintCompose}"
}

object Accompanist {
const val permissions = "com.google.accompanist:accompanist-permissions:${Versions.accompanist}"
const val systemUiController = "com.google.accompanist:accompanist-systemuicontroller:${Versions.accompanist}"
const val pager = "com.google.accompanist:accompanist-pager:${Versions.accompanist}"
const val pagerIndicators = "com.google.accompanist:accompanist-pager-indicators:${Versions.accompanist}"
const val swipeRefresh = "com.google.accompanist:accompanist-swiperefresh:${Versions.accompanist}"
}

object GMS {
const val authApiPhone = "com.google.android.gms:play-services-auth-api-phone:${Versions.authApiPhone}"
}
}
12 changes: 10 additions & 2 deletions buildSrc/src/main/java/Modules.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
object Modules {
const val app = ":app"

const val commonMultiCompose = ":common:multi_compose"
const val commonUiComponents = ":common:ui-components"
const val coreUi = ":core:ui"
const val coreUtils = ":core:utils"
const val coreStrings = ":core:strings"

const val commonDomain = ":common:domain"
const val commonData = ":common:data"
const val commonDataRemote = ":common:data-remote"
const val commonDataLocal = ":common:data-local"
const val commonDi = ":common:di"
const val commonUi = ":common:ui"
const val commonUiComponents = ":common:ui-components"
const val commonMultiCompose = ":common:multi-compose"
}
1 change: 1 addition & 0 deletions common/data-local/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
22 changes: 22 additions & 0 deletions common/data-local/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id(Plugins.androidLibrary)
id(Plugins.androidBase)
id(Plugins.kotlinKapt)
}

dependencies {
projectImplementation(Modules.coreUtils)
projectApi(Modules.commonDomain)
projectImplementation(Modules.commonDi)

implementation(Deps.appCompat)
implementation(Deps.coreKtx)
implementation(Deps.Coroutines.kotlinCore)

implementation(Deps.Local.room)
implementation(Deps.Local.roomKtx)
kapt(Deps.Local.roomKapt)

implementation(Deps.Dagger.core)
kapt(Deps.Dagger.compiler)
}
Empty file.
21 changes: 21 additions & 0 deletions common/data-local/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
5 changes: 5 additions & 0 deletions common/data-local/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tech.antee.compose_multimodule_template.data.local">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package tech.antee.compose_multimodule_template.data.local.dao

import androidx.room.Dao

@Dao
interface AppDao
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package tech.antee.compose_multimodule_template.data.local.db

import androidx.room.Database
import androidx.room.RoomDatabase
import tech.antee.compose_multimodule_template.data.local.dao.AppDao

@Database(
entities = [],
version = 1
)
abstract class AppDatabase : RoomDatabase() {
abstract fun appDao(): AppDao


companion object {
const val NAME = "app-database"
}
}


Loading

0 comments on commit a7f0bfa

Please sign in to comment.