Skip to content

Instantly share code, notes, and snippets.

Avatar
👩‍💻
I learn how to be better everyday...

Damilola Omoyiwola princessdharmy

👩‍💻
I learn how to be better everyday...
View GitHub Profile
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()
}
View view_pager_nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/view_pager_nav_graph"
app:startDestination="@id/viewPager">
<fragment
android:id="@+id/viewPager"
android:name="com.example.competitiondetails.ui.ViewPagerFragment">
View bottom_nav_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/bottom_nav_graph"
app:startDestination="@id/todayFixtureFragment">
<fragment
android:id="@+id/todayFixtureFragment"
android:name="com.example.competitions.ui.today.TodayFixturesFragment"
android:label="Today's Fixture" />
You can’t perform that action at this time.