mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +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
|
||||
}
|
||||
|
||||
init {
|
||||
setState {
|
||||
copy(
|
||||
hsAdminHasDisabledE2E = !session.getHomeServerCapabilities().adminE2EByDefault
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
companion object : MvRxViewModelFactory<CreateDirectRoomViewModel, CreateDirectRoomViewState> {
|
||||
|
||||
@JvmStatic
|
||||
|
|
|
@ -21,6 +21,5 @@ import com.airbnb.mvrx.MvRxState
|
|||
import com.airbnb.mvrx.Uninitialized
|
||||
|
||||
data class CreateDirectRoomViewState(
|
||||
val createAndInviteState: Async<String> = Uninitialized,
|
||||
val hsAdminHasDisabledE2E: Boolean = false
|
||||
val createAndInviteState: Async<String> = Uninitialized
|
||||
) : 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 com.airbnb.mvrx.activityViewModel
|
||||
import com.airbnb.mvrx.args
|
||||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.airbnb.mvrx.withState
|
||||
import com.google.android.material.chip.Chip
|
||||
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.platform.VectorBaseFragment
|
||||
import im.vector.riotx.core.utils.DimensionConverter
|
||||
import im.vector.riotx.features.createdirect.CreateDirectRoomViewModel
|
||||
import im.vector.riotx.features.createdirect.CreateDirectRoomViewState
|
||||
import im.vector.riotx.features.homeserver.HomeServerCapabilitiesViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_known_users.*
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -54,7 +54,7 @@ class KnownUsersFragment @Inject constructor(
|
|||
override fun getMenuRes() = args.menuResId
|
||||
|
||||
private val viewModel: UserDirectoryViewModel by activityViewModel()
|
||||
private val createDMViewModel: CreateDirectRoomViewModel by activityViewModel()
|
||||
private val homeServerCapabilitiesViewModel: HomeServerCapabilitiesViewModel by fragmentViewModel()
|
||||
|
||||
private lateinit var sharedActionViewModel: UserDirectorySharedActionViewModel
|
||||
|
||||
|
@ -70,8 +70,8 @@ class KnownUsersFragment @Inject constructor(
|
|||
setupAddFromPhoneBookView()
|
||||
setupCloseView()
|
||||
|
||||
createDMViewModel.selectSubscribe(this, CreateDirectRoomViewState::hsAdminHasDisabledE2E) {
|
||||
knownUsersE2EbyDefaultDisabled.isVisible = it
|
||||
homeServerCapabilitiesViewModel.subscribe {
|
||||
knownUsersE2EbyDefaultDisabled.isVisible = !it.capabilities.adminE2EByDefault
|
||||
}
|
||||
|
||||
viewModel.selectSubscribe(this, UserDirectoryViewState::pendingInvitees) {
|
||||
|
|
Loading…
Reference in a new issue