Created
September 17, 2020 16:38
-
-
Save hantrungkien/881b28144507a9a255238f9550e4d285 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FeatureActivity : AppCompatActivity(R.layout.feature_activity) { | |
@Inject | |
@UserModelSingletonQualifier | |
lateinit var singletonUserModel: UserModel | |
@Inject | |
lateinit var savedStateViewModelFactory: DFMSavedStateViewModelFactory | |
private val featureActivityViewModel by viewModels<FeatureActivityViewModel> { savedStateViewModelFactory } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
inject() | |
super.onCreate(savedInstanceState) | |
Timber.e("singleton userModel = $singletonUserModel") | |
singletonUserModel.value += " => FeatureActivity" | |
Timber.e("userModel = ${featureActivityViewModel.userModel}") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun FeatureActivity.inject() { | |
DaggerFeatureActivityComponent.factory() | |
.featureActivityComponent( | |
this, | |
EntryPointAccessors.fromApplication( | |
applicationContext, | |
CoreModuleDependencies::class.java | |
) | |
) | |
.inject(this) | |
} | |
@Component( | |
dependencies = [CoreModuleDependencies::class], | |
modules = [FeatureActivityModule::class] | |
) | |
interface FeatureActivityComponent { | |
fun inject(activity: FeatureActivity) | |
fun activity(): Activity | |
@Component.Factory | |
interface Factory { | |
fun featureActivityComponent( | |
@BindsInstance activity: Activity, | |
loginModuleDependencies: CoreModuleDependencies | |
): FeatureActivityComponent | |
} | |
} | |
@Module(includes = [FeatureActivityViewModel_HiltModule::class, ActivityViewModelModule::class]) | |
@InstallIn(ActivityComponent::class) | |
abstract class FeatureActivityModule { | |
companion object { | |
@Provides | |
@UserModelFeatureQualifier | |
fun provideUserModel() = UserModel(value = "FeatureActivity") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FeatureActivityViewModel @ViewModelInject constructor( | |
@UserModelFeatureQualifier val userModel: UserModel, | |
@Assisted private val savedStateHandle: SavedStateHandle | |
) : ViewModel() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mình update androidx.hilt:hilt-common:1.0.0-beta01
và com.google.dagger:hilt-android:2.33-beta thì bị lỗi, Nhờ bạn support