All Projects → sczerwinski → android-hilt

sczerwinski / android-hilt

Licence: Apache-2.0 license
Extensions for Dagger Hilt

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to android-hilt

Newsster
Android App using Paging3, Hilt, Coroutines, Flow, Jetpack, MVVM architecture.
Stars: ✭ 147 (+345.45%)
Mutual labels:  hilt
Clother
Clother is an Android client-server app for swapping unused clothes.
Stars: ✭ 22 (-33.33%)
Mutual labels:  hilt
GitHubApplication
GitHubApplication 📱 is an Android application built to demonstrate the use of modern Android development tools - (Kotlin, Coroutines, Hilt, LiveData, View binding, Data Store, Architecture components, MVVM, Room, Retrofit, Navigation).
Stars: ✭ 11 (-66.67%)
Mutual labels:  hilt
Superhero-App
🦸🏻‍♂️🦹🏻‍♀️Superhero app built with Kotlin, ViewModel, LiveData, ViewBinding, Room, and Hilt
Stars: ✭ 27 (-18.18%)
Mutual labels:  hilt
SunnyBeach
阳光沙滩APP
Stars: ✭ 60 (+81.82%)
Mutual labels:  hilt
TheMovieDB
TheMovieDB is an android app based on TMDB api.
Stars: ✭ 16 (-51.52%)
Mutual labels:  hilt
android-pokemon-compose
A simple app demonstrates using Jetpack compose with other Jetpack libraries.
Stars: ✭ 56 (+69.7%)
Mutual labels:  hilt
Pokedex
🗡️ Android Pokedex using Hilt, Motion, Coroutines, Flow, Jetpack (Room, ViewModel) based on MVVM architecture.
Stars: ✭ 4,882 (+14693.94%)
Mutual labels:  hilt
Healthify
Healthify - An app to track your daily water intake and sleep and boost your work efficiency. Healthify is built using Kotlin and follows all modern android Development practices and hence is a good learning resource for beginners
Stars: ✭ 37 (+12.12%)
Mutual labels:  hilt
ApolloRickAndMorty
just a side project to try out GraphQL and Dagger Hilt with Clean architecture and MVVM
Stars: ✭ 28 (-15.15%)
Mutual labels:  hilt
Imomoe
樱花动漫第三方安卓Android客户端,不含广告,免费开源,目的是学习Android开发。Discord:https://discord.gg/MyaRtRGEzr
Stars: ✭ 996 (+2918.18%)
Mutual labels:  hilt
MVVMJetpack
JectpackDemo
Stars: ✭ 37 (+12.12%)
Mutual labels:  hilt
Updoot
A reddit client built for android
Stars: ✭ 51 (+54.55%)
Mutual labels:  hilt
Restaurant
❤️ A sample Restaurant application based on MVVM (ViewModel, Coroutines, Flow, Repository, Hilt) architecture
Stars: ✭ 24 (-27.27%)
Mutual labels:  hilt
RickAndMorty-AndroidMVVMSample
An android sample project using Jetpack libraries and MVVM design pattern
Stars: ✭ 17 (-48.48%)
Mutual labels:  hilt
ResDelivery-Hilt-Coroutines-Mvvm-Single-Activity
This is a Sample Single Activity App (Multi Fragments) that uses Dagger-Hilt, Coroutines Flows, Paging 3 & Mvvm Clean Architecture
Stars: ✭ 28 (-15.15%)
Mutual labels:  hilt
Jetpack-Compose-MVI-Demo
Demo / Sample Android Project created with Jetpack Compose and MVI Architecture Pattern
Stars: ✭ 114 (+245.45%)
Mutual labels:  hilt
Mvvm Architecture
The practice of MVVM + Jetpack architecture in Android.
Stars: ✭ 1,634 (+4851.52%)
Mutual labels:  hilt
MovieCompose
🎞 A demo movie app using Jetpack Compose and Hilt based on modern Android tech stacks.
Stars: ✭ 322 (+875.76%)
Mutual labels:  hilt
RickAndMorty
No description or website provided.
Stars: ✭ 63 (+90.91%)
Mutual labels:  hilt

Build

Extensions for Dagger Hilt

Hilt Extensions

Maven Central Sonatype Nexus (Snapshots)

Kotlin
dependencies {
    implementation("com.google.dagger:hilt-android:2.36")
    implementation("it.czerwinski.android.hilt:hilt-extensions:[VERSION]")
    kapt("it.czerwinski.android.hilt:hilt-processor:[VERSION]")
}
Groovy
dependencies {
    implementation 'com.google.dagger:hilt-android:2.36'
    implementation 'it.czerwinski.android.hilt:hilt-extensions:[VERSION]'
    kapt 'it.czerwinski.android.hilt:hilt-processor:[VERSION]'
}

Property Delegation

With this library, it is possible to delegate properties to additional objects.

dagger.Lazy

val lazy: dagger.Lazy<String>

val property: String by lazy

javax.inject.Provider

val intProvider: Provider<Int>

val property: Int by intProvider

Generating Hilt Modules

@Bound and @BoundTo

Marks implementation bound to the given supertype in the given component.

@Bound annotation (added in v1.1.0) works exactly like @BoundTo annotation, but it implicitly uses the direct supertype of the annotated class. It may only annotate classes having exactly one direct supertype, excluding java.lang.Object.

For example:

interface Repository

@BoundTo(supertype = Repository::class, component = SingletonComponent::class)
class RepositoryA @Inject constructor() : Repository

@BoundTo(supertype = Repository::class, component = SingletonComponent::class)
@Singleton
class RepositoryB @Inject constructor() : Repository

@Bound(component = SingletonComponent::class)
@Named("offline")
class RepositoryC @Inject constructor() : Repository

will generate module:

@Module
@InstallIn(SingletonComponent.class)
public interface Repository_SingletonComponent_BindingsModule {

    @Binds
    Repository bindRepositoryA(RepositoryA implementation);

    @Binds
    @Singleton
    Repository bindRepositoryB(RepositoryB implementation);

    @Binds
    @Named("offline")
    Repository bindRepositoryC(RepositoryC implementation);
}

Since release 1.1.0, component property is optional, and set to SingletonComponent by default.

@FactoryMethod

Marks factory method for the class returned by the annotated function.

For example, for a Room database:

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

    @FactoryMethod(component = SingletonComponent::class)
    @Singleton
    abstract fun usersDao(): UsersDao
}

and a database factory:

interface DatabaseFactory {

    @FactoryMethod(component = SingletonComponent::class)
    @Singleton
    fun createDatabase(): AppDatabase
}

and a database factory provider:

object DatabaseFactoryProvider {

    @FactoryMethod(component = SingletonComponent::class)
    fun createDatabaseFactory(
        @ApplicationContext context: Context
    ): DatabaseFactory =
        if (BuildConfig.DEBUG) TestDatabaseFactory(context)
        else ProductionDatabaseFactory(context)
}

annotation processor will generate modules:

@Module
@InstallIn(SingletonComponent.class)
public class UsersDao_SingletonComponent_FactoryMethodsModule {
    @Provides
    @Singleton
    public UsersDao appDatabase_usersDao(AppDatabase factory) {
        return factory.usersDao();
    }
}
@Module
@InstallIn(SingletonComponent.class)
public class AppDatabase_SingletonComponent_FactoryMethodsModule {
    @Provides
    @Singleton
    public AppDatabase databaseFactory_createDatabase(DatabaseFactory factory) {
        return factory.createDatabase();
    }
}
@Module
@InstallIn(SingletonComponent.class)
public class DatabaseFactory_SingletonComponent_FactoryMethodsModule {
    @Provides
    public DatabaseFactory databaseFactoryProvider_createDatabaseFactory(
            @ApplicationContext Context context_0) {
        return DatabaseFactoryProvider.INSTANCE.createDatabaseFactory(context_0);
    }
}

Since release 1.1.0, component property is optional, and set to SingletonComponent by default.

@TestBound, @TestBoundTo and @TestFactoryMethod

Version 1.1.0 introduces additional test annotations that can be used to generate modules annotated with @TestInstallIn, instead of @InstallIn:

  • @TestBound (instead of @Bound)
  • @TestBoundTo (instead of @BoundTo)
  • @TestFactoryMethod (instead of @FactoryMethod)

Test module generated using @TestBound and/or @TestBoundTo will replace the module generated using @Bound and/or @BoundTo.

Test module generated using @TestFactoryMethod will replace the module generated with @FactoryMethod.

Hilt Testing Extensions

Maven Central Sonatype Nexus (Snapshots)

Must be used as debugImplementation dependency to properly register EmptyFragmentActivity in manifest.

Kotlin
dependencies {
    implementation("com.google.dagger:hilt-android:2.36")

    androidTestImplementation("androidx.test:runner:1.3.0")
    debugImplementation("it.czerwinski.android.hilt:hilt-fragment-testing:[VERSION]")
}
Groovy
dependencies {
    implementation 'com.google.dagger:hilt-android:2.36'

    androidTestImplementation 'androidx.test:runner:1.3.0'
    debugImplementation 'it.czerwinski.android.hilt:hilt-fragment-testing:[VERSION]'
}

Testing Fragments With Hilt

HiltFragmentScenario

Works exactly like FragmentScenario, but supports Hilt dependency injection in fragments.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].