dagger-2

UninitializedPropertyAccessException: lateinit property has not been initialized

谁说我不能喝 提交于 2020-05-15 02:40:10
问题 I have a class which i inject into a ViewModel + ViewModel factory, when initialise the view model in the onCreate method in activity, its says the value being passed through is not initialised. Below is my code I am quite new to Kotlin so have tried debugging but am stuck on this issue. Here is MainActivity code: class MainActivity: AppCompatActivity(), RepoSelectedListener { @Inject lateinit var viewModel: MainActivityListViewModel lateinit var lifecycleOwner: LifecycleOwner lateinit var

UninitializedPropertyAccessException: lateinit property has not been initialized

谁说胖子不能爱 提交于 2020-05-15 02:40:06
问题 I have a class which i inject into a ViewModel + ViewModel factory, when initialise the view model in the onCreate method in activity, its says the value being passed through is not initialised. Below is my code I am quite new to Kotlin so have tried debugging but am stuck on this issue. Here is MainActivity code: class MainActivity: AppCompatActivity(), RepoSelectedListener { @Inject lateinit var viewModel: MainActivityListViewModel lateinit var lifecycleOwner: LifecycleOwner lateinit var

How to dynamically set the bundle from AbstractSavedStateViewModelFactory

丶灬走出姿态 提交于 2020-05-13 13:38:02
问题 My ViewModelFactory : class ViewModelFactory @Inject constructor( private val viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>, owner: SavedStateRegistryOwner, defaultArgs: Bundle? ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @Throws(IllegalStateException::class) @Suppress("UNCHECKED_CAST") override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T { return viewModelMap[modelClass]?.create(handle)

How to dynamically set the bundle from AbstractSavedStateViewModelFactory

余生长醉 提交于 2020-05-13 13:36:05
问题 My ViewModelFactory : class ViewModelFactory @Inject constructor( private val viewModelMap: MutableMap<Class<out ViewModel>, ViewModelAssistedFactory<out ViewModel>>, owner: SavedStateRegistryOwner, defaultArgs: Bundle? ) : AbstractSavedStateViewModelFactory(owner, defaultArgs) { @Throws(IllegalStateException::class) @Suppress("UNCHECKED_CAST") override fun <T : ViewModel?> create(key: String, modelClass: Class<T>, handle: SavedStateHandle): T { return viewModelMap[modelClass]?.create(handle)

@Binds methods must have only one parameter whose type is assignable to the return type

蹲街弑〆低调 提交于 2020-05-13 04:02:12
问题 I am migrating to the new dagger android 2.11 All set up based on the Google blueprint :MVP-Dagger.but I am having this error : Error:(22, 57) error: @Binds methods must have only one parameter whose type is assignable to the return type Here in this line : @ActivityScoped @Binds abstract PresenterFactory<MainContract.Presenter> providePresenterFactory(MainPresenter presenter); The presenter : @ActivityScoped public class MainPresenter extends BasePresenterImpl<MainContract.View> implements

@Binds methods must have only one parameter whose type is assignable to the return type

做~自己de王妃 提交于 2020-05-13 03:58:40
问题 I am migrating to the new dagger android 2.11 All set up based on the Google blueprint :MVP-Dagger.but I am having this error : Error:(22, 57) error: @Binds methods must have only one parameter whose type is assignable to the return type Here in this line : @ActivityScoped @Binds abstract PresenterFactory<MainContract.Presenter> providePresenterFactory(MainPresenter presenter); The presenter : @ActivityScoped public class MainPresenter extends BasePresenterImpl<MainContract.View> implements

Why should I use viewmodelproviders for viewmodels?

谁说我不能喝 提交于 2020-05-09 05:45:32
问题 Why should I use viewmodelproviders for viewmodels? Why I just can't add custom singleton annotation to my viewmodel, and then inject this viewmodel to fragment class? Like so: @MainScope class MainViewModel @Inject constructor(): ViewModel() And then: open class BaseFragment<T: ViewModel>: DaggerFragment() { @Inject protected lateinit var viewModel: T Both cases are independent of screen rotation. Is there any drawbacks of singleton annotation case? I see only advantages, with this approach

dagger2 and android: load module which injects viewmodel on a map

折月煮酒 提交于 2020-04-11 06:31:20
问题 I've started using Dagger2, so there's still a lot to learn. I'm wondering if someone could point me on the right direction. So, I've created a module for registering the view models used by my activities. It looks like this: @Module abstract class ViewModelModule { @Binds internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory @Binds @IntoMap @ViewModelKey(MainActivityViewModel::class) internal abstract fun bindMainActivityViewModel(viewModel:

dagger2 and android: load module which injects viewmodel on a map

99封情书 提交于 2020-04-11 06:31:07
问题 I've started using Dagger2, so there's still a lot to learn. I'm wondering if someone could point me on the right direction. So, I've created a module for registering the view models used by my activities. It looks like this: @Module abstract class ViewModelModule { @Binds internal abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory @Binds @IntoMap @ViewModelKey(MainActivityViewModel::class) internal abstract fun bindMainActivityViewModel(viewModel:

ViewModelProviders.get(…) in base class

核能气质少年 提交于 2020-04-09 17:57:18
问题 I'm trying to cut some of Dagger's boilerplate by moving some of my ViewModel instantiation in an abstract base class but can't find quite a good way to do this. My intent is to instantiate all my ViewModels from my base fragment for them to be ready to consume by all child fragments without having them do their own instantiation. My issue lies in retrieving the ViewModel using a generic (VM)- specifically here: .get(viewModel::class.java) . I also attempted .get(VM::class.java) that is not