diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheet.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheet.kt index dc8ed66fb8..3f21aa3168 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheet.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheet.kt @@ -21,15 +21,13 @@ import android.os.Bundle import android.view.KeyEvent import androidx.fragment.app.Fragment import com.airbnb.mvrx.MvRx -import com.airbnb.mvrx.Success import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import im.vector.riotx.R import im.vector.riotx.core.di.ScreenComponent import im.vector.riotx.core.extensions.commitTransaction -import im.vector.riotx.core.extensions.observeEvent +import im.vector.riotx.core.extensions.exhaustive import im.vector.riotx.core.platform.VectorBaseBottomSheetDialogFragment -import im.vector.riotx.features.crypto.verification.VerificationAction import im.vector.riotx.features.crypto.verification.VerificationBottomSheet import javax.inject.Inject import kotlin.reflect.KClass @@ -48,20 +46,16 @@ class DeviceListBottomSheet : VectorBaseBottomSheetDialogFragment() { override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) - viewModel.requestLiveData.observeEvent(this) { async -> - when (async) { - is Success -> { - when (val action = async.invoke()) { - is VerificationAction.StartSASVerification -> { - VerificationBottomSheet.withArgs( - roomId = null, - otherUserId = action.otherUserId, - transactionId = action.pendingRequestTransactionId - ).show(requireActivity().supportFragmentManager, "REQPOP") - } - } + viewModel.observeViewEvents { + when (it) { + is DeviceListBottomSheetViewEvents.Verify -> { + VerificationBottomSheet.withArgs( + roomId = null, + otherUserId = it.userId, + transactionId = it.txID + ).show(requireActivity().supportFragmentManager, "REQPOP") } - } + }.exhaustive } } diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt new file mode 100644 index 0000000000..6d7348577e --- /dev/null +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewEvents.kt @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.riotx.features.roommemberprofile.devices + +import im.vector.riotx.core.platform.VectorViewEvents + +/** + * Transient events for device list screen + */ +sealed class DeviceListBottomSheetViewEvents : VectorViewEvents { + // data class Loading(val message: CharSequence? = null) : RoomDirectoryViewEvents() + // data class Failure(val throwable: Throwable) : DeviceListBottomSheetViewEvents() + + data class Verify(val userId: String, val txID: String) : DeviceListBottomSheetViewEvents() +} diff --git a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt index 667c3b6cdc..6d37cbbd43 100644 --- a/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt +++ b/vector/src/main/java/im/vector/riotx/features/roommemberprofile/devices/DeviceListBottomSheetViewModel.kt @@ -16,14 +16,11 @@ */ package im.vector.riotx.features.roommemberprofile.devices -import androidx.lifecycle.LiveData -import androidx.lifecycle.MutableLiveData import com.airbnb.mvrx.Async import com.airbnb.mvrx.FragmentViewModelContext import com.airbnb.mvrx.Loading import com.airbnb.mvrx.MvRxState import com.airbnb.mvrx.MvRxViewModelFactory -import com.airbnb.mvrx.Success import com.airbnb.mvrx.ViewModelContext import com.squareup.inject.assisted.Assisted import com.squareup.inject.assisted.AssistedInject @@ -36,11 +33,7 @@ import im.vector.matrix.android.internal.crypto.model.CryptoDeviceInfo import im.vector.matrix.rx.rx import im.vector.riotx.core.di.HasScreenInjector import im.vector.riotx.core.platform.EmptyAction -import im.vector.riotx.core.platform.EmptyViewEvents import im.vector.riotx.core.platform.VectorViewModel -import im.vector.riotx.core.resources.StringProvider -import im.vector.riotx.core.utils.LiveEvent -import im.vector.riotx.features.crypto.verification.VerificationAction data class DeviceListViewState( val userItem: MatrixItem? = null, @@ -52,14 +45,8 @@ data class DeviceListViewState( class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted private val initialState: DeviceListViewState, @Assisted private val userId: String, - private val stringProvider: StringProvider, private val session: Session) - : VectorViewModel(initialState) { - - // Can be used for several actions, for a one shot result - private val _requestLiveData = MutableLiveData>>() - val requestLiveData: LiveData>> - get() = _requestLiveData + : VectorViewModel(initialState) { @AssistedInject.Factory interface Factory { @@ -67,7 +54,6 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted priva } init { - session.rx().liveUserCryptoDevices(userId) .execute { copy(cryptoDevices = it).also { @@ -93,15 +79,17 @@ class DeviceListBottomSheetViewModel @AssistedInject constructor(@Assisted priva } } + // TODO Use handle() fun selectDevice(device: CryptoDeviceInfo?) { setState { copy(selectedDevice = device) } } + // TODO Use handle() fun manuallyVerify(device: CryptoDeviceInfo) { session.getVerificationService().beginKeyVerification(VerificationMethod.SAS, userId, device.deviceId, null)?.let { txID -> - _requestLiveData.postValue(LiveEvent(Success(VerificationAction.StartSASVerification(userId, txID)))) + _viewEvents.post(DeviceListBottomSheetViewEvents.Verify(userId, txID)) } }