update injectable

androidx
Ztiany 5 years ago
parent 24de572943
commit 601ea902c3
  1. 29
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectableEx.kt
  2. 13
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectableExtension.kt
  3. 2
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseDialogFragment.kt
  4. 16
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseFragment.kt
  5. 16
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseListFragment.kt
  6. 16
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseListV2Fragment.kt
  7. 16
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseStateDialogFragment.kt
  8. 16
      lib_base/src/main/java/com/android/base/app/fragment/injectable/InjectorBaseStateFragment.kt

@ -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
}

@ -11,7 +11,7 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseDialogFragment : BaseDialogFragment(), Injectable, InjectableEx { open class InjectorBaseDialogFragment : BaseDialogFragment(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory

@ -1,5 +1,7 @@
package com.android.base.app.fragment.injectable package com.android.base.app.fragment.injectable
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.android.base.app.dagger.Injectable import com.android.base.app.dagger.Injectable
import com.android.base.app.fragment.BaseFragment import com.android.base.app.fragment.BaseFragment
@ -11,10 +13,22 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseFragment : BaseFragment(), Injectable, InjectableEx { open class InjectorBaseFragment : BaseFragment(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject override lateinit var errorHandler: ErrorHandler @Inject override lateinit var errorHandler: ErrorHandler
inline fun <reified VM : ViewModel> injectViewModel(): Lazy<VM> {
return viewModels { viewModelFactory }
}
inline fun <reified VM : ViewModel> injectActivityViewModel(): Lazy<VM> {
return viewModels(
ownerProducer = {
requireActivity()
}
) { viewModelFactory }
}
} }

@ -1,5 +1,7 @@
package com.android.base.app.fragment.injectable package com.android.base.app.fragment.injectable
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.android.base.app.dagger.Injectable import com.android.base.app.dagger.Injectable
import com.android.base.app.fragment.BaseListFragment import com.android.base.app.fragment.BaseListFragment
@ -11,10 +13,22 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseListFragment<T> : BaseListFragment<T>(), Injectable, InjectableEx { open class InjectorBaseListFragment<T> : BaseListFragment<T>(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject override lateinit var errorHandler: ErrorHandler @Inject override lateinit var errorHandler: ErrorHandler
inline fun <reified VM : ViewModel> injectViewModel(): Lazy<VM> {
return viewModels { viewModelFactory }
}
inline fun <reified VM : ViewModel> injectActivityViewModel(): Lazy<VM> {
return viewModels(
ownerProducer = {
requireActivity()
}
) { viewModelFactory }
}
} }

@ -1,5 +1,7 @@
package com.android.base.app.fragment.injectable package com.android.base.app.fragment.injectable
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.android.base.app.dagger.Injectable import com.android.base.app.dagger.Injectable
import com.android.base.app.fragment.BaseListV2Fragment import com.android.base.app.fragment.BaseListV2Fragment
@ -11,10 +13,22 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseListV2Fragment<T> : BaseListV2Fragment<T>(), Injectable, InjectableEx { open class InjectorBaseListV2Fragment<T> : BaseListV2Fragment<T>(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject override lateinit var errorHandler: ErrorHandler @Inject override lateinit var errorHandler: ErrorHandler
inline fun <reified VM : ViewModel> injectViewModel(): Lazy<VM> {
return viewModels { viewModelFactory }
}
inline fun <reified VM : ViewModel> injectActivityViewModel(): Lazy<VM> {
return viewModels(
ownerProducer = {
requireActivity()
}
) { viewModelFactory }
}
} }

@ -1,5 +1,7 @@
package com.android.base.app.fragment.injectable package com.android.base.app.fragment.injectable
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.android.base.app.dagger.Injectable import com.android.base.app.dagger.Injectable
import com.android.base.app.fragment.BaseStateDialogFragment import com.android.base.app.fragment.BaseStateDialogFragment
@ -11,10 +13,22 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseStateDialogFragment : BaseStateDialogFragment(), Injectable, InjectableEx { open class InjectorBaseStateDialogFragment : BaseStateDialogFragment(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject override lateinit var errorHandler: ErrorHandler @Inject override lateinit var errorHandler: ErrorHandler
inline fun <reified VM : ViewModel> injectViewModel(): Lazy<VM> {
return viewModels { viewModelFactory }
}
inline fun <reified VM : ViewModel> injectActivityViewModel(): Lazy<VM> {
return viewModels(
ownerProducer = {
requireActivity()
}
) { viewModelFactory }
}
} }

@ -1,5 +1,7 @@
package com.android.base.app.fragment.injectable package com.android.base.app.fragment.injectable
import androidx.fragment.app.viewModels
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.android.base.app.dagger.Injectable import com.android.base.app.dagger.Injectable
import com.android.base.app.fragment.BaseStateFragment import com.android.base.app.fragment.BaseStateFragment
@ -11,10 +13,22 @@ import javax.inject.Inject
* Email: ztiany3@gmail.com * Email: ztiany3@gmail.com
* Date : 2019-01-15 12:57 * Date : 2019-01-15 12:57
*/ */
open class InjectorBaseStateFragment : BaseStateFragment(), Injectable, InjectableEx { open class InjectorBaseStateFragment : BaseStateFragment(), Injectable, InjectableExtension {
@Inject override lateinit var viewModelFactory: ViewModelProvider.Factory @Inject override lateinit var viewModelFactory: ViewModelProvider.Factory
@Inject override lateinit var errorHandler: ErrorHandler @Inject override lateinit var errorHandler: ErrorHandler
inline fun <reified VM : ViewModel> injectViewModel(): Lazy<VM> {
return viewModels { viewModelFactory }
}
inline fun <reified VM : ViewModel> injectActivityViewModel(): Lazy<VM> {
return viewModels(
ownerProducer = {
requireActivity()
}
) { viewModelFactory }
}
} }
Loading…
Cancel
Save