mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 05:31:21 +03:00
FIx / Crash when opening Invite User screen
This commit is contained in:
parent
7fddfa45e8
commit
2810923519
5 changed files with 71 additions and 15 deletions
|
@ -38,14 +38,6 @@ class CreateDirectRoomViewModel @AssistedInject constructor(@Assisted
|
||||||
fun create(initialState: CreateDirectRoomViewState): CreateDirectRoomViewModel
|
fun create(initialState: CreateDirectRoomViewState): CreateDirectRoomViewModel
|
||||||
}
|
}
|
||||||
|
|
||||||
init {
|
|
||||||
setState {
|
|
||||||
copy(
|
|
||||||
hsAdminHasDisabledE2E = !session.getHomeServerCapabilities().adminE2EByDefault
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object : MvRxViewModelFactory<CreateDirectRoomViewModel, CreateDirectRoomViewState> {
|
companion object : MvRxViewModelFactory<CreateDirectRoomViewModel, CreateDirectRoomViewState> {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
|
|
@ -21,6 +21,5 @@ import com.airbnb.mvrx.MvRxState
|
||||||
import com.airbnb.mvrx.Uninitialized
|
import com.airbnb.mvrx.Uninitialized
|
||||||
|
|
||||||
data class CreateDirectRoomViewState(
|
data class CreateDirectRoomViewState(
|
||||||
val createAndInviteState: Async<String> = Uninitialized,
|
val createAndInviteState: Async<String> = Uninitialized
|
||||||
val hsAdminHasDisabledE2E: Boolean = false
|
|
||||||
) : MvRxState
|
) : MvRxState
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
/*
|
||||||
|
* 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.homeserver
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
|
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities
|
||||||
|
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
|
||||||
|
|
||||||
|
class HomeServerCapabilitiesViewModel(initialState: HomeServerCapabilitiesViewState)
|
||||||
|
: VectorViewModel<HomeServerCapabilitiesViewState, EmptyAction, EmptyViewEvents>(initialState) {
|
||||||
|
|
||||||
|
companion object : MvRxViewModelFactory<HomeServerCapabilitiesViewModel, HomeServerCapabilitiesViewState> {
|
||||||
|
|
||||||
|
override fun initialState(viewModelContext: ViewModelContext): HomeServerCapabilitiesViewState? {
|
||||||
|
val session = (viewModelContext.activity as HasScreenInjector).injector().activeSessionHolder().getSafeActiveSession()
|
||||||
|
return HomeServerCapabilitiesViewState(
|
||||||
|
capabilities = session?.getHomeServerCapabilities() ?: HomeServerCapabilities()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun handle(action: EmptyAction) {}
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
/*
|
||||||
|
* 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.homeserver
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.MvRxState
|
||||||
|
import im.vector.matrix.android.api.session.homeserver.HomeServerCapabilities
|
||||||
|
|
||||||
|
data class HomeServerCapabilitiesViewState(
|
||||||
|
val capabilities: HomeServerCapabilities = HomeServerCapabilities()
|
||||||
|
) : MvRxState
|
|
@ -25,6 +25,7 @@ import androidx.core.view.forEach
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import com.airbnb.mvrx.activityViewModel
|
import com.airbnb.mvrx.activityViewModel
|
||||||
import com.airbnb.mvrx.args
|
import com.airbnb.mvrx.args
|
||||||
|
import com.airbnb.mvrx.fragmentViewModel
|
||||||
import com.airbnb.mvrx.withState
|
import com.airbnb.mvrx.withState
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.jakewharton.rxbinding3.widget.textChanges
|
import com.jakewharton.rxbinding3.widget.textChanges
|
||||||
|
@ -36,8 +37,7 @@ import im.vector.riotx.core.extensions.hideKeyboard
|
||||||
import im.vector.riotx.core.extensions.setupAsSearch
|
import im.vector.riotx.core.extensions.setupAsSearch
|
||||||
import im.vector.riotx.core.platform.VectorBaseFragment
|
import im.vector.riotx.core.platform.VectorBaseFragment
|
||||||
import im.vector.riotx.core.utils.DimensionConverter
|
import im.vector.riotx.core.utils.DimensionConverter
|
||||||
import im.vector.riotx.features.createdirect.CreateDirectRoomViewModel
|
import im.vector.riotx.features.homeserver.HomeServerCapabilitiesViewModel
|
||||||
import im.vector.riotx.features.createdirect.CreateDirectRoomViewState
|
|
||||||
import kotlinx.android.synthetic.main.fragment_known_users.*
|
import kotlinx.android.synthetic.main.fragment_known_users.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ class KnownUsersFragment @Inject constructor(
|
||||||
override fun getMenuRes() = args.menuResId
|
override fun getMenuRes() = args.menuResId
|
||||||
|
|
||||||
private val viewModel: UserDirectoryViewModel by activityViewModel()
|
private val viewModel: UserDirectoryViewModel by activityViewModel()
|
||||||
private val createDMViewModel: CreateDirectRoomViewModel by activityViewModel()
|
private val homeServerCapabilitiesViewModel: HomeServerCapabilitiesViewModel by fragmentViewModel()
|
||||||
|
|
||||||
private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel
|
private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel
|
||||||
|
|
||||||
|
@ -70,8 +70,8 @@ class KnownUsersFragment @Inject constructor(
|
||||||
setupAddFromPhoneBookView()
|
setupAddFromPhoneBookView()
|
||||||
setupCloseView()
|
setupCloseView()
|
||||||
|
|
||||||
createDMViewModel.selectSubscribe(this, CreateDirectRoomViewState::hsAdminHasDisabledE2E) {
|
homeServerCapabilitiesViewModel.subscribe {
|
||||||
knownUsersE2EbyDefaultDisabled.isVisible = it
|
knownUsersE2EbyDefaultDisabled.isVisible = !it.capabilities.adminE2EByDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.selectSubscribe(this, UserDirectoryViewState::pendingInvitees) {
|
viewModel.selectSubscribe(this, UserDirectoryViewState::pendingInvitees) {
|
||||||
|
|
Loading…
Reference in a new issue