Hilt: continue migration

This commit is contained in:
ganfra 2021-10-15 12:49:29 +02:00
parent f8d208fb4f
commit 9dd7017131
16 changed files with 106 additions and 117 deletions

View file

@ -59,6 +59,11 @@ class HiltMavericksViewModelFactory<VM : MavericksViewModel<S>, S : MavericksSta
val castedViewModelFactory = viewModelFactory as? MavericksAssistedViewModelFactory<VM, S> val castedViewModelFactory = viewModelFactory as? MavericksAssistedViewModelFactory<VM, S>
return castedViewModelFactory?.create(state) as VM return castedViewModelFactory?.create(state) as VM
} }
override fun initialState(viewModelContext: ViewModelContext): S? {
return super.initialState(viewModelContext)
}
} }
/** /**

View file

@ -20,7 +20,14 @@ import dagger.Binds
import dagger.Module import dagger.Module
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.multibindings.IntoMap import dagger.multibindings.IntoMap
import im.vector.app.features.auth.ReAuthViewModel
import im.vector.app.features.call.VectorCallViewModel
import im.vector.app.features.call.conference.JitsiCallViewModel
import im.vector.app.features.home.room.list.RoomListViewModel import im.vector.app.features.home.room.list.RoomListViewModel
import im.vector.app.features.roomdirectory.RoomDirectoryViewModel
import im.vector.app.features.spaces.SpaceListViewModel
import im.vector.app.features.spaces.manage.SpaceManageRoomsViewModel
import im.vector.app.features.spaces.manage.SpaceManageSharedViewModel
@InstallIn(MavericksViewModelComponent::class) @InstallIn(MavericksViewModelComponent::class)
@Module @Module
@ -30,4 +37,42 @@ interface MavericksViewModelModule {
@IntoMap @IntoMap
@MavericksViewModelKey(RoomListViewModel::class) @MavericksViewModelKey(RoomListViewModel::class)
fun roomListViewModelFactory(factory: RoomListViewModel.Factory): MavericksAssistedViewModelFactory<*, *> fun roomListViewModelFactory(factory: RoomListViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(SpaceManageRoomsViewModel::class)
fun spaceManageRoomsViewModelFactory(factory: SpaceManageRoomsViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(SpaceManageSharedViewModel::class)
fun spaceManageSharedViewModelFactory(factory: SpaceManageSharedViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(SpaceListViewModel::class)
fun spaceListViewModelFactory(factory: SpaceListViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(ReAuthViewModel::class)
fun reAuthViewModelFactory(factory: ReAuthViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(VectorCallViewModel::class)
fun vectorCallViewModelFactory(factory: VectorCallViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(JitsiCallViewModel::class)
fun jitsiCallViewModelFactory(factory: JitsiCallViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
@Binds
@IntoMap
@MavericksViewModelKey(RoomDirectoryViewModel::class)
fun roomDirectoryViewModelFactory(factory: RoomDirectoryViewModel.Factory): MavericksAssistedViewModelFactory<*, *>
} }

View file

@ -42,7 +42,7 @@ import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
import timber.log.Timber import timber.log.Timber
import javax.inject.Inject import javax.inject.Inject
class ReAuthActivity : SimpleFragmentActivity(), ReAuthViewModel.Factory { class ReAuthActivity : SimpleFragmentActivity(){
@Parcelize @Parcelize
data class Args( data class Args(
@ -59,9 +59,6 @@ class ReAuthActivity : SimpleFragmentActivity(), ReAuthViewModel.Factory {
private var customTabsSession: CustomTabsSession? = null private var customTabsSession: CustomTabsSession? = null
@Inject lateinit var authenticationService: AuthenticationService @Inject lateinit var authenticationService: AuthenticationService
@Inject lateinit var reAuthViewModelFactory: ReAuthViewModel.Factory
override fun create(initialState: ReAuthState) = reAuthViewModelFactory.create(initialState)
override fun injectWith(injector: ScreenComponent) { override fun injectWith(injector: ScreenComponent) {
super.injectWith(injector) super.injectWith(injector)

View file

@ -23,6 +23,8 @@ import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import org.matrix.android.sdk.api.auth.data.LoginFlowTypes import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
@ -35,20 +37,11 @@ class ReAuthViewModel @AssistedInject constructor(
) : VectorViewModel<ReAuthState, ReAuthActions, ReAuthEvents>(initialState) { ) : VectorViewModel<ReAuthState, ReAuthActions, ReAuthEvents>(initialState) {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<ReAuthViewModel,ReAuthState> {
fun create(initialState: ReAuthState): ReAuthViewModel override fun create(state: ReAuthState): ReAuthViewModel
} }
companion object : MavericksViewModelFactory<ReAuthViewModel, ReAuthState> { companion object : MavericksViewModelFactory<ReAuthViewModel, ReAuthState> by hiltMavericksViewModelFactory()
override fun create(viewModelContext: ViewModelContext, state: ReAuthState): ReAuthViewModel? {
val factory = when (viewModelContext) {
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
is ActivityViewModelContext -> viewModelContext.activity as? Factory
}
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
}
}
override fun handle(action: ReAuthActions) = withState { state -> override fun handle(action: ReAuthActions) = withState { state ->
when (action) { when (action) {

View file

@ -41,6 +41,7 @@ import com.airbnb.mvrx.viewModel
import com.airbnb.mvrx.withState import com.airbnb.mvrx.withState
import com.google.android.material.card.MaterialCardView import com.google.android.material.card.MaterialCardView
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
import im.vector.app.R import im.vector.app.R
import im.vector.app.core.di.ScreenComponent import im.vector.app.core.di.ScreenComponent
import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.extensions.setTextOrHide
@ -89,6 +90,7 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
override fun getBinding() = ActivityCallBinding.inflate(layoutInflater) override fun getBinding() = ActivityCallBinding.inflate(layoutInflater)
@Inject lateinit var callManager: WebRtcCallManager
@Inject lateinit var avatarRenderer: AvatarRenderer @Inject lateinit var avatarRenderer: AvatarRenderer
override fun injectWith(injector: ScreenComponent) { override fun injectWith(injector: ScreenComponent) {
@ -97,8 +99,6 @@ class VectorCallActivity : VectorBaseActivity<ActivityCallBinding>(), CallContro
private val callViewModel: VectorCallViewModel by viewModel() private val callViewModel: VectorCallViewModel by viewModel()
@Inject lateinit var callManager: WebRtcCallManager
@Inject lateinit var viewModelFactory: VectorCallViewModel.Factory
private val dialPadCallback = object : DialPadFragment.Callback { private val dialPadCallback = object : DialPadFragment.Callback {
override fun onDigitAppended(digit: String) { override fun onDigitAppended(digit: String) {

View file

@ -25,6 +25,8 @@ import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.call.audio.CallAudioManager import im.vector.app.features.call.audio.CallAudioManager
@ -341,16 +343,9 @@ class VectorCallViewModel @AssistedInject constructor(
} }
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<VectorCallViewModel,VectorCallViewState> {
fun create(initialState: VectorCallViewState): VectorCallViewModel override fun create(state: VectorCallViewState): VectorCallViewModel
} }
companion object : MavericksViewModelFactory<VectorCallViewModel, VectorCallViewState> { companion object : MavericksViewModelFactory<VectorCallViewModel, VectorCallViewState> by hiltMavericksViewModelFactory()
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: VectorCallViewState): VectorCallViewModel {
val callActivity: VectorCallActivity = viewModelContext.activity()
return callActivity.viewModelFactory.create(state)
}
}
} }

View file

@ -26,6 +26,8 @@ import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -46,8 +48,8 @@ class JitsiCallViewModel @AssistedInject constructor(
) : VectorViewModel<JitsiCallViewState, JitsiCallViewActions, JitsiCallViewEvents>(initialState) { ) : VectorViewModel<JitsiCallViewState, JitsiCallViewActions, JitsiCallViewEvents>(initialState) {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<JitsiCallViewModel,JitsiCallViewState> {
fun create(initialState: JitsiCallViewState): JitsiCallViewModel override fun create(state: JitsiCallViewState): JitsiCallViewModel
} }
private var currentWidgetObserver: Job? = null private var currentWidgetObserver: Job? = null
@ -143,24 +145,9 @@ class JitsiCallViewModel @AssistedInject constructor(
} }
} }
companion object : MavericksViewModelFactory<JitsiCallViewModel, JitsiCallViewState> { companion object : MavericksViewModelFactory<JitsiCallViewModel, JitsiCallViewState> by hiltMavericksViewModelFactory() {
const val ENABLE_VIDEO_OPTION = "ENABLE_VIDEO_OPTION" const val ENABLE_VIDEO_OPTION = "ENABLE_VIDEO_OPTION"
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: JitsiCallViewState): JitsiCallViewModel? {
val callActivity: VectorJitsiActivity = viewModelContext.activity()
return callActivity.viewModelFactory.create(state)
}
override fun initialState(viewModelContext: ViewModelContext): JitsiCallViewState? {
val args: VectorJitsiActivity.Args = viewModelContext.args()
return JitsiCallViewState(
roomId = args.roomId,
widgetId = args.widgetId,
enableVideo = args.enableVideo
)
}
} }
} }

View file

@ -26,4 +26,12 @@ data class JitsiCallViewState(
val widgetId: String = "", val widgetId: String = "",
val enableVideo: Boolean = false, val enableVideo: Boolean = false,
val widget: Async<Widget> = Uninitialized val widget: Async<Widget> = Uninitialized
) : MavericksState ) : MavericksState {
constructor(args: VectorJitsiActivity.Args): this(
roomId = args.roomId,
widgetId = args.widgetId,
enableVideo = args.enableVideo
)
}

View file

@ -61,8 +61,6 @@ class VectorJitsiActivity : VectorBaseActivity<ActivityJitsiBinding>(), JitsiMee
override fun getBinding() = ActivityJitsiBinding.inflate(layoutInflater) override fun getBinding() = ActivityJitsiBinding.inflate(layoutInflater)
@Inject lateinit var viewModelFactory: JitsiCallViewModel.Factory
private var jitsiMeetView: JitsiMeetView? = null private var jitsiMeetView: JitsiMeetView? = null
private val jitsiViewModel: JitsiCallViewModel by viewModel() private val jitsiViewModel: JitsiCallViewModel by viewModel()

View file

@ -26,6 +26,8 @@ import com.airbnb.mvrx.appendAt
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import kotlinx.coroutines.CancellationException import kotlinx.coroutines.CancellationException
@ -49,18 +51,12 @@ class RoomDirectoryViewModel @AssistedInject constructor(
) : VectorViewModel<PublicRoomsViewState, RoomDirectoryAction, RoomDirectoryViewEvents>(initialState) { ) : VectorViewModel<PublicRoomsViewState, RoomDirectoryAction, RoomDirectoryViewEvents>(initialState) {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<RoomDirectoryViewModel,PublicRoomsViewState> {
fun create(initialState: PublicRoomsViewState): RoomDirectoryViewModel override fun create(state: PublicRoomsViewState): RoomDirectoryViewModel
} }
companion object : MavericksViewModelFactory<RoomDirectoryViewModel, PublicRoomsViewState> { companion object : MavericksViewModelFactory<RoomDirectoryViewModel, PublicRoomsViewState> by hiltMavericksViewModelFactory() {
private const val PUBLIC_ROOMS_LIMIT = 20 private const val PUBLIC_ROOMS_LIMIT = 20
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: PublicRoomsViewState): RoomDirectoryViewModel? {
val activity: RoomDirectoryActivity = (viewModelContext as ActivityViewModelContext).activity()
return activity.roomDirectoryViewModelFactory.create(state)
}
} }
private val showAllRooms = vectorPreferences.showAllPublicRooms() private val showAllRooms = vectorPreferences.showAllPublicRooms()

View file

@ -39,12 +39,11 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary
import javax.inject.Inject import javax.inject.Inject
class SpaceListFragment @Inject constructor( class SpaceListFragment @Inject constructor(
val spaceListViewModelFactory: SpacesListViewModel.Factory,
private val spaceController: SpaceSummaryController private val spaceController: SpaceSummaryController
) : VectorBaseFragment<FragmentGroupListBinding>(), SpaceSummaryController.Callback { ) : VectorBaseFragment<FragmentGroupListBinding>(), SpaceSummaryController.Callback {
private lateinit var sharedActionViewModel: HomeSharedActionViewModel private lateinit var sharedActionViewModel: HomeSharedActionViewModel
private val viewModel: SpacesListViewModel by fragmentViewModel() private val viewModel: SpaceListViewModel by fragmentViewModel()
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentGroupListBinding { override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentGroupListBinding {
return FragmentGroupListBinding.inflate(inflater, container, false) return FragmentGroupListBinding.inflate(inflater, container, false)

View file

@ -17,16 +17,16 @@
package im.vector.app.features.spaces package im.vector.app.features.spaces
import androidx.lifecycle.asFlow import androidx.lifecycle.asFlow
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success import com.airbnb.mvrx.Success
import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.AppStateHandler import im.vector.app.AppStateHandler
import im.vector.app.RoomGroupingMethod import im.vector.app.RoomGroupingMethod
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.invite.AutoAcceptInvites import im.vector.app.features.invite.AutoAcceptInvites
import im.vector.app.features.session.coroutineScope import im.vector.app.features.session.coroutineScope
@ -59,26 +59,19 @@ import org.matrix.android.sdk.api.session.space.model.TopLevelSpaceComparator
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.flow
class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState, class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState,
private val appStateHandler: AppStateHandler, private val appStateHandler: AppStateHandler,
private val session: Session, private val session: Session,
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val autoAcceptInvites: AutoAcceptInvites private val autoAcceptInvites: AutoAcceptInvites
) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) { ) : VectorViewModel<SpaceListViewState, SpaceListAction, SpaceListViewEvents>(initialState) {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<SpaceListViewModel, SpaceListViewState> {
fun create(initialState: SpaceListViewState): SpacesListViewModel override fun create(state: SpaceListViewState): SpaceListViewModel
} }
companion object : MavericksViewModelFactory<SpacesListViewModel, SpaceListViewState> { companion object : MavericksViewModelFactory<SpaceListViewModel, SpaceListViewState> by hiltMavericksViewModelFactory()
@JvmStatic
override fun create(viewModelContext: ViewModelContext, state: SpaceListViewState): SpacesListViewModel {
val groupListFragment: SpaceListFragment = (viewModelContext as FragmentViewModelContext).fragment()
return groupListFragment.spaceListViewModelFactory.create(state)
}
}
// private var currentGroupingMethod : RoomGroupingMethod? = null // private var currentGroupingMethod : RoomGroupingMethod? = null

View file

@ -51,10 +51,8 @@ data class SpaceManageArgs(
) : Parcelable ) : Parcelable
class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(), class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(),
ToolbarConfigurable, ToolbarConfigurable {
SpaceManageSharedViewModel.Factory {
@Inject lateinit var sharedViewModelFactory: SpaceManageSharedViewModel.Factory
private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel
override fun injectWith(injector: ScreenComponent) { override fun injectWith(injector: ScreenComponent) {
@ -194,8 +192,6 @@ class SpaceManageActivity : VectorBaseActivity<ActivitySimpleLoadingBinding>(),
} }
} }
override fun create(initialState: SpaceManageViewState) = sharedViewModelFactory.create(initialState)
override fun configure(toolbar: MaterialToolbar) { override fun configure(toolbar: MaterialToolbar) {
configureToolbar(toolbar) configureToolbar(toolbar)
} }

View file

@ -45,10 +45,8 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject import javax.inject.Inject
class SpaceManageRoomsFragment @Inject constructor( class SpaceManageRoomsFragment @Inject constructor(
private val viewModelFactory: SpaceManageRoomsViewModel.Factory,
private val epoxyController: SpaceManageRoomsController private val epoxyController: SpaceManageRoomsController
) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(), ) : VectorBaseFragment<FragmentSpaceAddRoomsBinding>(),
SpaceManageRoomsViewModel.Factory,
OnBackPressed, OnBackPressed,
SpaceManageRoomsController.Listener, SpaceManageRoomsController.Listener,
Callback { Callback {
@ -107,8 +105,6 @@ class SpaceManageRoomsFragment @Inject constructor(
super.onDestroyView() super.onDestroyView()
} }
override fun create(initialState: SpaceManageRoomViewState) = viewModelFactory.create(initialState)
override fun invalidate() = withState(viewModel) { state -> override fun invalidate() = withState(viewModel) { state ->
epoxyController.setData(state) epoxyController.setData(state)

View file

@ -16,18 +16,16 @@
package im.vector.app.features.spaces.manage package im.vector.app.features.spaces.manage
import androidx.lifecycle.viewModelScope
import com.airbnb.mvrx.ActivityViewModelContext
import com.airbnb.mvrx.Fail import com.airbnb.mvrx.Fail
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.Loading import com.airbnb.mvrx.Loading
import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.Success import com.airbnb.mvrx.Success
import com.airbnb.mvrx.Uninitialized import com.airbnb.mvrx.Uninitialized
import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.mvrx.runCatchingToAsync import im.vector.app.core.mvrx.runCatchingToAsync
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import im.vector.app.features.session.coroutineScope import im.vector.app.features.session.coroutineScope
@ -56,19 +54,11 @@ class SpaceManageRoomsViewModel @AssistedInject constructor(
} }
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<SpaceManageRoomsViewModel, SpaceManageRoomViewState> {
fun create(initialState: SpaceManageRoomViewState): SpaceManageRoomsViewModel override fun create(state: SpaceManageRoomViewState): SpaceManageRoomsViewModel
} }
companion object : MavericksViewModelFactory<SpaceManageRoomsViewModel, SpaceManageRoomViewState> { companion object : MavericksViewModelFactory<SpaceManageRoomsViewModel, SpaceManageRoomViewState> by hiltMavericksViewModelFactory()
override fun create(viewModelContext: ViewModelContext, state: SpaceManageRoomViewState): SpaceManageRoomsViewModel? {
val factory = when (viewModelContext) {
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
is ActivityViewModelContext -> viewModelContext.activity as? Factory
}
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
}
}
override fun handle(action: SpaceManageRoomViewAction) { override fun handle(action: SpaceManageRoomViewAction) {
when (action) { when (action) {

View file

@ -16,13 +16,12 @@
package im.vector.app.features.spaces.manage package im.vector.app.features.spaces.manage
import com.airbnb.mvrx.ActivityViewModelContext
import com.airbnb.mvrx.FragmentViewModelContext
import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.MavericksViewModelFactory
import com.airbnb.mvrx.ViewModelContext
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.extensions.exhaustive import im.vector.app.core.extensions.exhaustive
import im.vector.app.core.platform.VectorViewModel import im.vector.app.core.platform.VectorViewModel
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
@ -33,19 +32,11 @@ class SpaceManageSharedViewModel @AssistedInject constructor(
) : VectorViewModel<SpaceManageViewState, SpaceManagedSharedAction, SpaceManagedSharedViewEvents>(initialState) { ) : VectorViewModel<SpaceManageViewState, SpaceManagedSharedAction, SpaceManagedSharedViewEvents>(initialState) {
@AssistedFactory @AssistedFactory
interface Factory { interface Factory: MavericksAssistedViewModelFactory<SpaceManageSharedViewModel,SpaceManageViewState>{
fun create(initialState: SpaceManageViewState): SpaceManageSharedViewModel override fun create(state: SpaceManageViewState): SpaceManageSharedViewModel
} }
companion object : MavericksViewModelFactory<SpaceManageSharedViewModel, SpaceManageViewState> { companion object : MavericksViewModelFactory<SpaceManageSharedViewModel, SpaceManageViewState> by hiltMavericksViewModelFactory()
override fun create(viewModelContext: ViewModelContext, state: SpaceManageViewState): SpaceManageSharedViewModel? {
val factory = when (viewModelContext) {
is FragmentViewModelContext -> viewModelContext.fragment as? Factory
is ActivityViewModelContext -> viewModelContext.activity as? Factory
}
return factory?.create(state) ?: error("You should let your activity/fragment implements Factory interface")
}
}
override fun handle(action: SpaceManagedSharedAction) { override fun handle(action: SpaceManagedSharedAction) {
when (action) { when (action) {