Skip to content

Commit

Permalink
KinectApplication, KinjectAppCompatActivity, KinjectComponentActivity…
Browse files Browse the repository at this point in the history
… etc
  • Loading branch information
ScottPierce committed Jul 3, 2024
1 parent 780d7c5 commit 927aceb
Show file tree
Hide file tree
Showing 10 changed files with 148 additions and 1 deletion.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ coreKtx = "1.13.1"
espressoCore = "3.6.1"
lifecycleRuntimeKtx = "2.8.2"
activityCompose = "1.9.0"
appcompat = "1.7.0"

[libraries]
androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
androidx-benchmark-junit4 = { group = "androidx.benchmark", name = "benchmark-junit4", version.ref = "benchmarkJunit4" }
androidx-junit = { group = "androidx.test.ext", name = "junit", version = "1.2.1" }
androidx-runner = { group = "androidx.test", name = "runner", version.ref = "runner" }
Expand Down
14 changes: 14 additions & 0 deletions kinject-android-appcompat/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradleMavenPublish)
}

android {
namespace = "kinject.android.appcompat"
}

dependencies {
api(project(":kinject-android"))
implementation(libs.androidx.appcompat)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kinject.android

import androidx.appcompat.app.AppCompatActivity
import kinject.HasObjectGraph
import kinject.ObjectGraph
import kinject.android.KinjectApplication.Companion.KINJECT_SERVICE

abstract class KinjectAppCompatActivity : AppCompatActivity(), HasObjectGraph {
override val objectGraph: ObjectGraph by lazy { createObjectGraph() }

protected abstract fun createObjectGraph(): ObjectGraph

override fun getSystemService(name: String): Any {
return when (name) {
KINJECT_SERVICE -> objectGraph
else -> super.getSystemService(name)
}
}

override fun getSystemServiceName(serviceClass: Class<*>): String? {
return if (serviceClass === ObjectGraph::class.java) {
KINJECT_SERVICE
} else {
super.getSystemServiceName(serviceClass)
}
}
}
14 changes: 14 additions & 0 deletions kinject-android-compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.gradleMavenPublish)
}

android {
namespace = "kinject.android.compose"
}

dependencies {
api(project(":kinject-android"))
implementation(libs.androidx.activity.compose)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kinject.android

import androidx.activity.ComponentActivity
import kinject.HasObjectGraph
import kinject.ObjectGraph
import kinject.android.KinjectApplication.Companion.KINJECT_SERVICE

abstract class KinjectComponentActivity : ComponentActivity(), HasObjectGraph {
override val objectGraph: ObjectGraph by lazy { createObjectGraph() }

protected abstract fun createObjectGraph(): ObjectGraph

override fun getSystemService(name: String): Any {
return when (name) {
KINJECT_SERVICE -> objectGraph
else -> super.getSystemService(name)
}
}

override fun getSystemServiceName(serviceClass: Class<*>): String? {
return if (serviceClass === ObjectGraph::class.java) {
KINJECT_SERVICE
} else {
super.getSystemServiceName(serviceClass)
}
}
}
1 change: 0 additions & 1 deletion kinject-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,4 @@ android {

dependencies {
api(project(":kinject-core"))
implementation(libs.androidx.lifecycle.viewmodel.android)
}
27 changes: 27 additions & 0 deletions kinject-android/src/main/kotlin/kinject/android/KinjectActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package kinject.android

import android.app.Activity
import kinject.HasObjectGraph
import kinject.ObjectGraph
import kinject.android.KinjectApplication.Companion.KINJECT_SERVICE

abstract class KinjectActivity : Activity(), HasObjectGraph {
override val objectGraph: ObjectGraph by lazy { createObjectGraph() }

protected abstract fun createObjectGraph(): ObjectGraph

override fun getSystemService(name: String): Any {
return when (name) {
KINJECT_SERVICE -> objectGraph
else -> super.getSystemService(name)
}
}

override fun getSystemServiceName(serviceClass: Class<*>): String? {
return if (serviceClass === ObjectGraph::class.java) {
KINJECT_SERVICE
} else {
super.getSystemServiceName(serviceClass)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package kinject.android

import android.app.Application
import kinject.HasObjectGraph
import kinject.ObjectGraph

abstract class KinjectApplication : Application(), HasObjectGraph {
companion object {
const val KINJECT_SERVICE = "kinject"
}

override val objectGraph: ObjectGraph by lazy { createObjectGraph() }

protected abstract fun createObjectGraph(): ObjectGraph

override fun getSystemService(name: String): Any {
return when (name) {
KINJECT_SERVICE -> objectGraph
else -> super.getSystemService(name)
}
}

override fun getSystemServiceName(serviceClass: Class<*>): String? {
return if (serviceClass === ObjectGraph::class.java) {
KINJECT_SERVICE
} else {
super.getSystemServiceName(serviceClass)
}
}
}
5 changes: 5 additions & 0 deletions kinject-core/src/commonMain/kotlin/kinject/HasObjectGraph.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kinject

interface HasObjectGraph {
val objectGraph: ObjectGraph
}
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ include(":benchmark:benchmark-android")
include(":benchmark:benchmark-kotlin")
include(":benchmark:benchmark-shared")
include(":kinject-android")
include(":kinject-android-appcompat")
include(":kinject-android-compose")
include(":kinject-bom")
include(":kinject-compose")
include(":kinject-compose-viewmodel")
Expand Down

0 comments on commit 927aceb

Please sign in to comment.