diff --git a/vector/src/main/java/im/vector/app/core/di/HiltMavericksViewModelFactory.kt b/vector/src/main/java/im/vector/app/core/di/HiltMavericksViewModelFactory.kt index d0dd4fa002..10485b8189 100644 --- a/vector/src/main/java/im/vector/app/core/di/HiltMavericksViewModelFactory.kt +++ b/vector/src/main/java/im/vector/app/core/di/HiltMavericksViewModelFactory.kt @@ -59,6 +59,11 @@ class HiltMavericksViewModelFactory, S : MavericksSta val castedViewModelFactory = viewModelFactory as? MavericksAssistedViewModelFactory return castedViewModelFactory?.create(state) as VM } + + override fun initialState(viewModelContext: ViewModelContext): S? { + return super.initialState(viewModelContext) + } + } /** diff --git a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt index e8eb1d0fd0..430ecac83d 100644 --- a/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt +++ b/vector/src/main/java/im/vector/app/core/di/MavericksViewModelModule.kt @@ -20,7 +20,14 @@ import dagger.Binds import dagger.Module import dagger.hilt.InstallIn 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.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) @Module @@ -30,4 +37,42 @@ interface MavericksViewModelModule { @IntoMap @MavericksViewModelKey(RoomListViewModel::class) 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<*, *> + + + } diff --git a/vector/src/main/java/im/vector/app/features/auth/ReAuthActivity.kt b/vector/src/main/java/im/vector/app/features/auth/ReAuthActivity.kt index b7f570672b..13e788d3a0 100644 --- a/vector/src/main/java/im/vector/app/features/auth/ReAuthActivity.kt +++ b/vector/src/main/java/im/vector/app/features/auth/ReAuthActivity.kt @@ -42,7 +42,7 @@ import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage import timber.log.Timber import javax.inject.Inject -class ReAuthActivity : SimpleFragmentActivity(), ReAuthViewModel.Factory { +class ReAuthActivity : SimpleFragmentActivity(){ @Parcelize data class Args( @@ -59,9 +59,6 @@ class ReAuthActivity : SimpleFragmentActivity(), ReAuthViewModel.Factory { private var customTabsSession: CustomTabsSession? = null @Inject lateinit var authenticationService: AuthenticationService - @Inject lateinit var reAuthViewModelFactory: ReAuthViewModel.Factory - - override fun create(initialState: ReAuthState) = reAuthViewModelFactory.create(initialState) override fun injectWith(injector: ScreenComponent) { super.injectWith(injector) diff --git a/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt b/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt index 449270644e..a3d32ed13f 100644 --- a/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/auth/ReAuthViewModel.kt @@ -23,6 +23,8 @@ import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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 org.matrix.android.sdk.api.auth.data.LoginFlowTypes import org.matrix.android.sdk.api.session.Session @@ -35,20 +37,11 @@ class ReAuthViewModel @AssistedInject constructor( ) : VectorViewModel(initialState) { @AssistedFactory - interface Factory { - fun create(initialState: ReAuthState): ReAuthViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: ReAuthState): ReAuthViewModel } - companion object : MavericksViewModelFactory { - - 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") - } - } + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() override fun handle(action: ReAuthActions) = withState { state -> when (action) { diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index 0654942d4b..e54c04736b 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -41,6 +41,7 @@ import com.airbnb.mvrx.viewModel import com.airbnb.mvrx.withState import com.google.android.material.card.MaterialCardView import com.google.android.material.dialog.MaterialAlertDialogBuilder +import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.di.ScreenComponent import im.vector.app.core.extensions.setTextOrHide @@ -89,6 +90,7 @@ class VectorCallActivity : VectorBaseActivity(), CallContro override fun getBinding() = ActivityCallBinding.inflate(layoutInflater) + @Inject lateinit var callManager: WebRtcCallManager @Inject lateinit var avatarRenderer: AvatarRenderer override fun injectWith(injector: ScreenComponent) { @@ -97,8 +99,6 @@ class VectorCallActivity : VectorBaseActivity(), CallContro private val callViewModel: VectorCallViewModel by viewModel() - @Inject lateinit var callManager: WebRtcCallManager - @Inject lateinit var viewModelFactory: VectorCallViewModel.Factory private val dialPadCallback = object : DialPadFragment.Callback { override fun onDigitAppended(digit: String) { diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt index d8aaca9bd8..72b5f557dc 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallViewModel.kt @@ -25,6 +25,8 @@ import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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.platform.VectorViewModel import im.vector.app.features.call.audio.CallAudioManager @@ -341,16 +343,9 @@ class VectorCallViewModel @AssistedInject constructor( } @AssistedFactory - interface Factory { - fun create(initialState: VectorCallViewState): VectorCallViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: VectorCallViewState): VectorCallViewModel } - companion object : MavericksViewModelFactory { - - @JvmStatic - override fun create(viewModelContext: ViewModelContext, state: VectorCallViewState): VectorCallViewModel { - val callActivity: VectorCallActivity = viewModelContext.activity() - return callActivity.viewModelFactory.create(state) - } - } + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() } diff --git a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt index c46b4e459d..7a9a9099b5 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewModel.kt @@ -26,6 +26,8 @@ import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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.platform.VectorViewModel import kotlinx.coroutines.Job @@ -46,8 +48,8 @@ class JitsiCallViewModel @AssistedInject constructor( ) : VectorViewModel(initialState) { @AssistedFactory - interface Factory { - fun create(initialState: JitsiCallViewState): JitsiCallViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: JitsiCallViewState): JitsiCallViewModel } private var currentWidgetObserver: Job? = null @@ -143,24 +145,9 @@ class JitsiCallViewModel @AssistedInject constructor( } } - companion object : MavericksViewModelFactory { - + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() { 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 - ) - } } + + } diff --git a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewState.kt b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewState.kt index d4c70d7333..462e143fca 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewState.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/JitsiCallViewState.kt @@ -26,4 +26,12 @@ data class JitsiCallViewState( val widgetId: String = "", val enableVideo: Boolean = false, val widget: Async = Uninitialized -) : MavericksState +) : MavericksState { + + constructor(args: VectorJitsiActivity.Args): this( + roomId = args.roomId, + widgetId = args.widgetId, + enableVideo = args.enableVideo + ) + +} diff --git a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt index 62d017467f..a116d2ac34 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt @@ -61,8 +61,6 @@ class VectorJitsiActivity : VectorBaseActivity(), JitsiMee override fun getBinding() = ActivityJitsiBinding.inflate(layoutInflater) - @Inject lateinit var viewModelFactory: JitsiCallViewModel.Factory - private var jitsiMeetView: JitsiMeetView? = null private val jitsiViewModel: JitsiCallViewModel by viewModel() diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt index a2089e6cd5..7b002c9631 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/RoomDirectoryViewModel.kt @@ -26,6 +26,8 @@ import com.airbnb.mvrx.appendAt import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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.features.settings.VectorPreferences import kotlinx.coroutines.CancellationException @@ -49,18 +51,12 @@ class RoomDirectoryViewModel @AssistedInject constructor( ) : VectorViewModel(initialState) { @AssistedFactory - interface Factory { - fun create(initialState: PublicRoomsViewState): RoomDirectoryViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: PublicRoomsViewState): RoomDirectoryViewModel } - companion object : MavericksViewModelFactory { + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() { 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() diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt index 0a67977e6c..dff98722eb 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListFragment.kt @@ -39,12 +39,11 @@ import org.matrix.android.sdk.api.session.room.model.RoomSummary import javax.inject.Inject class SpaceListFragment @Inject constructor( - val spaceListViewModelFactory: SpacesListViewModel.Factory, private val spaceController: SpaceSummaryController ) : VectorBaseFragment(), SpaceSummaryController.Callback { 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 { return FragmentGroupListBinding.inflate(inflater, container, false) diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt similarity index 92% rename from vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt rename to vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt index fbbaeafe72..ed027702f2 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpacesListViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceListViewModel.kt @@ -17,16 +17,16 @@ package im.vector.app.features.spaces import androidx.lifecycle.asFlow -import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success -import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject import im.vector.app.AppStateHandler 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.features.invite.AutoAcceptInvites 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.flow.flow -class SpacesListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState, - private val appStateHandler: AppStateHandler, - private val session: Session, - private val vectorPreferences: VectorPreferences, - private val autoAcceptInvites: AutoAcceptInvites +class SpaceListViewModel @AssistedInject constructor(@Assisted initialState: SpaceListViewState, + private val appStateHandler: AppStateHandler, + private val session: Session, + private val vectorPreferences: VectorPreferences, + private val autoAcceptInvites: AutoAcceptInvites ) : VectorViewModel(initialState) { @AssistedFactory - interface Factory { - fun create(initialState: SpaceListViewState): SpacesListViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: SpaceListViewState): SpaceListViewModel } - companion object : MavericksViewModelFactory { - - @JvmStatic - override fun create(viewModelContext: ViewModelContext, state: SpaceListViewState): SpacesListViewModel { - val groupListFragment: SpaceListFragment = (viewModelContext as FragmentViewModelContext).fragment() - return groupListFragment.spaceListViewModelFactory.create(state) - } - } + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() // private var currentGroupingMethod : RoomGroupingMethod? = null diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt index f45f9099bb..9566e4bad3 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt @@ -51,10 +51,8 @@ data class SpaceManageArgs( ) : Parcelable class SpaceManageActivity : VectorBaseActivity(), - ToolbarConfigurable, - SpaceManageSharedViewModel.Factory { + ToolbarConfigurable { - @Inject lateinit var sharedViewModelFactory: SpaceManageSharedViewModel.Factory private lateinit var sharedDirectoryActionViewModel: RoomDirectorySharedActionViewModel override fun injectWith(injector: ScreenComponent) { @@ -194,8 +192,6 @@ class SpaceManageActivity : VectorBaseActivity(), } } - override fun create(initialState: SpaceManageViewState) = sharedViewModelFactory.create(initialState) - override fun configure(toolbar: MaterialToolbar) { configureToolbar(toolbar) } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt index 8e16784a6d..5fbac3bb6a 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsFragment.kt @@ -45,10 +45,8 @@ import java.util.concurrent.TimeUnit import javax.inject.Inject class SpaceManageRoomsFragment @Inject constructor( - private val viewModelFactory: SpaceManageRoomsViewModel.Factory, private val epoxyController: SpaceManageRoomsController ) : VectorBaseFragment(), - SpaceManageRoomsViewModel.Factory, OnBackPressed, SpaceManageRoomsController.Listener, Callback { @@ -107,8 +105,6 @@ class SpaceManageRoomsFragment @Inject constructor( super.onDestroyView() } - override fun create(initialState: SpaceManageRoomViewState) = viewModelFactory.create(initialState) - override fun invalidate() = withState(viewModel) { state -> epoxyController.setData(state) diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt index d36e62db13..a0cc4dea5c 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageRoomsViewModel.kt @@ -16,18 +16,16 @@ 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.FragmentViewModelContext import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.Success import com.airbnb.mvrx.Uninitialized -import com.airbnb.mvrx.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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.platform.VectorViewModel import im.vector.app.features.session.coroutineScope @@ -56,19 +54,11 @@ class SpaceManageRoomsViewModel @AssistedInject constructor( } @AssistedFactory - interface Factory { - fun create(initialState: SpaceManageRoomViewState): SpaceManageRoomsViewModel + interface Factory: MavericksAssistedViewModelFactory { + override fun create(state: SpaceManageRoomViewState): SpaceManageRoomsViewModel } - companion object : MavericksViewModelFactory { - 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") - } - } + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() override fun handle(action: SpaceManageRoomViewAction) { when (action) { diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageSharedViewModel.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageSharedViewModel.kt index 133054236e..925315b65c 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageSharedViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageSharedViewModel.kt @@ -16,13 +16,12 @@ 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.ViewModelContext import dagger.assisted.Assisted import dagger.assisted.AssistedFactory 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.platform.VectorViewModel import org.matrix.android.sdk.api.session.Session @@ -33,19 +32,11 @@ class SpaceManageSharedViewModel @AssistedInject constructor( ) : VectorViewModel(initialState) { @AssistedFactory - interface Factory { - fun create(initialState: SpaceManageViewState): SpaceManageSharedViewModel + interface Factory: MavericksAssistedViewModelFactory{ + override fun create(state: SpaceManageViewState): SpaceManageSharedViewModel } - companion object : MavericksViewModelFactory { - 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") - } - } + companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() override fun handle(action: SpaceManagedSharedAction) { when (action) {