parent
24de572943
commit
601ea902c3
@ -1,29 +0,0 @@ |
||||
package com.android.base.app.fragment.injectable |
||||
|
||||
import androidx.fragment.app.Fragment |
||||
import androidx.fragment.app.viewModels |
||||
import androidx.lifecycle.ViewModel |
||||
import androidx.lifecycle.ViewModelProvider |
||||
import com.android.base.data.ErrorHandler |
||||
|
||||
|
||||
interface InjectableEx { |
||||
|
||||
val viewModelFactory: ViewModelProvider.Factory |
||||
|
||||
val errorHandler: ErrorHandler |
||||
|
||||
} |
||||
|
||||
inline fun <reified VM : ViewModel> InjectableEx.injectViewModel(fragment: Fragment): Lazy<VM> { |
||||
return fragment.viewModels { viewModelFactory } |
||||
} |
||||
|
||||
inline fun <reified VM : ViewModel> InjectableEx.injectActivityViewModel(fragment: Fragment): Lazy<VM> { |
||||
return fragment.viewModels( |
||||
ownerProducer = { |
||||
fragment.requireActivity() |
||||
} |
||||
) { viewModelFactory } |
||||
} |
||||
|
@ -0,0 +1,13 @@ |
||||
package com.android.base.app.fragment.injectable |
||||
|
||||
import androidx.lifecycle.ViewModelProvider |
||||
import com.android.base.data.ErrorHandler |
||||
|
||||
|
||||
interface InjectableExtension { |
||||
|
||||
val viewModelFactory: ViewModelProvider.Factory |
||||
|
||||
val errorHandler: ErrorHandler |
||||
|
||||
} |
Loading…
Reference in new issue