Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from Dagger2 to Hilt for GitHub Browser sample. #945

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions GithubBrowserSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ apply plugin: 'kotlin-kapt'

apply plugin: 'kotlin-allopen'
apply plugin: 'androidx.navigation.safeargs.kotlin'
apply plugin: 'dagger.hilt.android.plugin'

allOpen {
// allows mocking for classes w/o directly opening them for release builds
Expand Down Expand Up @@ -87,6 +88,11 @@ dependencies {
implementation deps.constraint_layout
implementation deps.kotlin.stdlib

implementation deps.hilt.runtime
implementation deps.hilt.lifecycle_viewmodel
kapt deps.hilt.compiler
kapt deps.hilt.androidx_compiler

implementation deps.timber

kapt deps.dagger.android_support_compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@ import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.fragment.app.FragmentContainerView
import com.android.example.github.R
import dagger.hilt.android.AndroidEntryPoint

/**
* Used for testing fragments inside a fake activity.
*/

@AndroidEntryPoint
class SingleFragmentActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val content = FragmentContainerView(this).apply {
layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
id = R.id.container
}
Expand All @@ -42,18 +45,18 @@ class SingleFragmentActivity : AppCompatActivity() {

fun setFragment(fragment: Fragment) {
supportFragmentManager.beginTransaction()
.add(R.id.container, fragment, "TEST")
.commit()
.add(R.id.container, fragment, "TEST")
.commit()
}

fun replaceFragment(fragment: Fragment, addToBackStack: Boolean = false) {
supportFragmentManager.beginTransaction()
.replace(R.id.container, fragment)
.apply {
if (addToBackStack) {
addToBackStack(null)
.replace(R.id.container, fragment)
.apply {
if (addToBackStack) {
addToBackStack(null)
}
}
}
.commit()
.commit()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,17 @@

package com.android.example.github

import android.app.Activity
import android.app.Application
import com.android.example.github.di.AppInjector
import dagger.android.DispatchingAndroidInjector
import dagger.android.HasActivityInjector
import dagger.hilt.android.HiltAndroidApp
import timber.log.Timber
import javax.inject.Inject


class GithubApp : Application(), HasActivityInjector {
@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Activity>
@HiltAndroidApp
class GithubApp : Application() {

override fun onCreate() {
super.onCreate()
if (BuildConfig.DEBUG) {
Timber.plant(Timber.DebugTree())
}
AppInjector.init(this)
}

override fun activityInjector() = dispatchingAndroidInjector
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@
package com.android.example.github

import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.appcompat.app.AppCompatActivity
import dagger.android.DispatchingAndroidInjector
import dagger.android.support.HasSupportFragmentInjector
import javax.inject.Inject
import dagger.hilt.android.AndroidEntryPoint

class MainActivity : AppCompatActivity(), HasSupportFragmentInjector {
@Inject
lateinit var dispatchingAndroidInjector: DispatchingAndroidInjector<Fragment>
@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
}

override fun supportFragmentInjector() = dispatchingAndroidInjector
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading