View DatabaseModule.kt
@InstallIn(ApplicationComponent::class) | |
@Module | |
object DatabaseModule { | |
/* | |
* The method returns the Database object | |
**/ | |
@Singleton | |
@Provides | |
fun provideAppDatabase(@ApplicationContext context: Context): FootballDatabase = Room.databaseBuilder( |
View CompetitionsViewModel.kt
class CompetitionsViewModel @ViewModelInject constructor( | |
private val getTodayFixturesUseCase: GetTodayFixturesUseCase, | |
private val getCompetitionsUseCase: GetCompetitionsUseCase | |
) : ViewModel() { | |
... | |
} |
View data_layer_modules.kt
// DataModule | |
@InstallIn(ApplicationComponent::class) | |
@Module | |
object DataModule { | |
... | |
} | |
// DatabaseModule | |
@InstallIn(ApplicationComponent::class) | |
@Module |
View HiltCompetitionsFragment.kt
@AndroidEntryPoint | |
class CompetitionsFragment : BaseFragment() { | |
... | |
/** | |
* This should be deleted as it's no longer needed | |
*/ | |
override fun onAttach(context: Context) { | |
super.onAttach(context) | |
// Inject dagger here |
View HiltMainApplication.kt
@HiltAndroidApp | |
class MainApplication: Application() |
View app_build.gradle
... | |
apply plugin: 'kotlin-kapt' | |
apply plugin: 'dagger.hilt.android.plugin' | |
android { | |
... | |
} | |
dependencies { | |
implementation "com.google.dagger:hilt-android:${Versions.hiltVersion}" |
View project_build.gradle
buildscript { | |
... | |
dependencies { | |
... | |
classpath "com.google.dagger:hilt-android-gradle-plugin:${Versions.hiltGradlePluginVersion}" | |
} | |
} |
View HomeActivity.kt
class HomeActivity : BaseActivity() { | |
private lateinit var navController: NavController | |
private lateinit var appBarConfiguration: AppBarConfiguration | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setSupportActionBar(binding.toolbar) | |
initBinding() | |
} |
NewerOlder