diff options
Diffstat (limited to 'javatests/artifacts/dagger-android-ksp/app/src/main')
9 files changed, 300 insertions, 0 deletions
diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml new file mode 100644 index 000000000..89b0dbfd9 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/AndroidManifest.xml @@ -0,0 +1,30 @@ +<!-- + ~ Copyright (C) 2023 The Dagger Authors. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="dagger.android.ksp"> + + <application + android:name=".SimpleApplication" + android:label="@string/appName" + android:theme="@style/Theme.AppCompat.Light"> + <activity android:name=".SimpleActivity" android:exported="true"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> +</manifest>
\ No newline at end of file diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt new file mode 100644 index 000000000..8dd333dd5 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/Model .kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import javax.inject.Qualifier + +/** Qualifies bindings relating to [android.os.Build.MODEL]. */ +@Qualifier @Retention(AnnotationRetention.RUNTIME) internal annotation class Model diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt new file mode 100644 index 000000000..25c0f72ba --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/ModelModule.kt @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import android.os.Build.MODEL +import dagger.Module +import dagger.Provides + +@Module +object ModelModule { + @Provides @Model fun provideModel(): String = MODEL +} diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt new file mode 100644 index 000000000..5b9b84b03 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleActivity.kt @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import android.os.Bundle +import android.util.Log +import android.widget.TextView +import dagger.Binds +import dagger.Module +import dagger.Subcomponent +import dagger.android.AndroidInjector +import dagger.android.support.DaggerAppCompatActivity +import dagger.multibindings.ClassKey +import dagger.multibindings.IntoMap +import javax.inject.Inject + +/** + * The main activity of the application. + * + * <p>It can be injected with any binding from both {@link SimpleActivityComponent} and {@link + * SimpleApplication.SimpleComponent}. + */ +class SimpleActivity : DaggerAppCompatActivity() { + private val TAG: String = SimpleActivity::class.java.getSimpleName() + + @Inject @UserName lateinit var userName: String + @Inject @Model lateinit var model: String + + override protected fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + Log.i(TAG, "Injected with userName and model: " + userName + ", " + model) + + setContentView(R.layout.activity_main) + + val greeting = findViewById(R.id.greeting) as TextView + val text = getResources().getString(R.string.welcome, userName, model) + greeting.setText(text) + } +} + +@Subcomponent +interface SimpleActivityComponent : AndroidInjector<SimpleActivity> { + + @Subcomponent.Factory interface Factory : AndroidInjector.Factory<SimpleActivity> {} +} + +@Module(subcomponents = [SimpleActivityComponent::class], includes = [UserNameModule::class]) +interface InjectorModule { + @Binds + @IntoMap + @ClassKey(SimpleActivity::class) + fun bind(factory: SimpleActivityComponent.Factory): AndroidInjector.Factory<*> +} + diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt new file mode 100644 index 000000000..37dfd0500 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/SimpleApplication.kt @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import android.util.Log +import dagger.Component +import dagger.android.AndroidInjectionModule +import dagger.android.AndroidInjector +import dagger.android.DaggerApplication +import javax.inject.Inject +import javax.inject.Singleton + +/** + * A simple, skeletal application that demonstrates a dependency-injected application using the + * utilities in {@code dagger.android}. + */ +class SimpleApplication : DaggerApplication() { + private val TAG = SimpleApplication::class.java.getSimpleName() + + @Inject @Model lateinit var model: String + + override public fun onCreate() { + super.onCreate() + Log.i(TAG, "Injected with model: " + model) + } + + override protected fun applicationInjector(): AndroidInjector<SimpleApplication> { + return DaggerSimpleComponent.factory().create(this) + } +} + +@Singleton +@Component( + modules = + [AndroidInjectionModule::class, InjectorModule::class, ModelModule::class] +) +interface SimpleComponent : AndroidInjector<SimpleApplication> { + @Component.Factory interface Factory : AndroidInjector.Factory<SimpleApplication> {} +} diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt new file mode 100644 index 000000000..3388c09c0 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserName.kt @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import javax.inject.Qualifier + +/** Qualifies bindings relating to the user name. */ +@Qualifier @Retention(AnnotationRetention.RUNTIME) internal annotation class UserName diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt new file mode 100644 index 000000000..2628398d2 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/kotlin/dagger/android/ksp/UserNameModule.kt @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2023 The Dagger Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package dagger.android.ksp + +import dagger.Module +import dagger.Provides + +@Module +object UserNameModule { + @UserName @Provides fun provideUserName(): String = "ProdUser" +} diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml new file mode 100644 index 000000000..4693e5513 --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,30 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 The Dagger Authors. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:background="@android:color/background_light"> + + <TextView + android:id="@+id/greeting" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:layout_alignParentTop="true" + android:textColor="@android:color/primary_text_light" + /> +</RelativeLayout>
\ No newline at end of file diff --git a/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml b/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml new file mode 100644 index 000000000..4bf0e39bf --- /dev/null +++ b/javatests/artifacts/dagger-android-ksp/app/src/main/res/values/strings.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2023 The Dagger Authors. + ~ + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> + +<resources> + <!--The app name [CHAR_LIMIT=25]--> + <string name="appName">Simple Dagger Android</string> + + <!--The greeting message [CHAR_LIMIT=100]--> + <string name="welcome">Hello, %1$s! You are on build %2$s.</string> +</resources>
\ No newline at end of file |