mirror of
https://github.com/element-hq/element-android
synced 2024-11-28 21:48:50 +03:00
Identity: One class per file
This commit is contained in:
parent
ce42d2fb8a
commit
38fb7185b6
11 changed files with 213 additions and 63 deletions
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery
|
||||||
|
|
||||||
|
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||||
|
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||||
|
|
||||||
|
sealed class DiscoverySettingsAction : VectorViewModelAction {
|
||||||
|
object RetrieveBinding : DiscoverySettingsAction()
|
||||||
|
object Refresh : DiscoverySettingsAction()
|
||||||
|
|
||||||
|
data class ChangeIdentityServer(val url: String?) : DiscoverySettingsAction()
|
||||||
|
data class RevokeThreePid(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
|
data class ShareThreePid(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
|
data class FinalizeBind3pid(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
|
data class SubmitMsisdnToken(val threePid: ThreePid.Msisdn, val code: String) : DiscoverySettingsAction()
|
||||||
|
data class CancelBinding(val threePid: ThreePid) : DiscoverySettingsAction()
|
||||||
|
}
|
|
@ -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.discovery
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.Async
|
||||||
|
import com.airbnb.mvrx.MvRxState
|
||||||
|
import com.airbnb.mvrx.Uninitialized
|
||||||
|
|
||||||
|
data class DiscoverySettingsState(
|
||||||
|
val identityServer: Async<String?> = Uninitialized,
|
||||||
|
val emailList: Async<List<PidInfo>> = Uninitialized,
|
||||||
|
val phoneNumbersList: Async<List<PidInfo>> = Uninitialized,
|
||||||
|
// Can be true if terms are updated
|
||||||
|
val termsNotSigned: Boolean = false
|
||||||
|
) : MvRxState
|
|
@ -0,0 +1,23 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery
|
||||||
|
|
||||||
|
import im.vector.riotx.core.platform.VectorViewEvents
|
||||||
|
|
||||||
|
sealed class DiscoverySettingsViewEvents : VectorViewEvents {
|
||||||
|
data class Failure(val throwable: Throwable) : DiscoverySettingsViewEvents()
|
||||||
|
}
|
|
@ -19,7 +19,6 @@ import com.airbnb.mvrx.Async
|
||||||
import com.airbnb.mvrx.Fail
|
import com.airbnb.mvrx.Fail
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.Loading
|
import com.airbnb.mvrx.Loading
|
||||||
import com.airbnb.mvrx.MvRxState
|
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.Success
|
import com.airbnb.mvrx.Success
|
||||||
import com.airbnb.mvrx.Uninitialized
|
import com.airbnb.mvrx.Uninitialized
|
||||||
|
@ -34,43 +33,7 @@ import im.vector.matrix.android.api.session.identity.SharedState
|
||||||
import im.vector.matrix.android.api.session.identity.ThreePid
|
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||||
import im.vector.matrix.rx.rx
|
import im.vector.matrix.rx.rx
|
||||||
import im.vector.riotx.core.extensions.exhaustive
|
import im.vector.riotx.core.extensions.exhaustive
|
||||||
import im.vector.riotx.core.platform.VectorViewEvents
|
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
import im.vector.riotx.core.platform.VectorViewModelAction
|
|
||||||
|
|
||||||
data class PidInfo(
|
|
||||||
// Retrieved from the homeserver
|
|
||||||
val threePid: ThreePid,
|
|
||||||
// Retrieved from IdentityServer, or transient state
|
|
||||||
val isShared: Async<SharedState>,
|
|
||||||
// Contains information about a current request to submit the token (for instance SMS code received by SMS)
|
|
||||||
// Or a current binding finalization, for email
|
|
||||||
val finalRequest: Async<Unit> = Uninitialized
|
|
||||||
)
|
|
||||||
|
|
||||||
data class DiscoverySettingsState(
|
|
||||||
val identityServer: Async<String?> = Uninitialized,
|
|
||||||
val emailList: Async<List<PidInfo>> = Uninitialized,
|
|
||||||
val phoneNumbersList: Async<List<PidInfo>> = Uninitialized,
|
|
||||||
// Can be true if terms are updated
|
|
||||||
val termsNotSigned: Boolean = false
|
|
||||||
) : MvRxState
|
|
||||||
|
|
||||||
sealed class DiscoverySettingsAction : VectorViewModelAction {
|
|
||||||
object RetrieveBinding : DiscoverySettingsAction()
|
|
||||||
object Refresh : DiscoverySettingsAction()
|
|
||||||
|
|
||||||
data class ChangeIdentityServer(val url: String?) : DiscoverySettingsAction()
|
|
||||||
data class RevokeThreePid(val threePid: ThreePid) : DiscoverySettingsAction()
|
|
||||||
data class ShareThreePid(val threePid: ThreePid) : DiscoverySettingsAction()
|
|
||||||
data class FinalizeBind3pid(val threePid: ThreePid) : DiscoverySettingsAction()
|
|
||||||
data class SubmitMsisdnToken(val threePid: ThreePid.Msisdn, val code: String) : DiscoverySettingsAction()
|
|
||||||
data class CancelBinding(val threePid: ThreePid) : DiscoverySettingsAction()
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class DiscoverySettingsViewEvents : VectorViewEvents {
|
|
||||||
data class Failure(val throwable: Throwable) : DiscoverySettingsViewEvents()
|
|
||||||
}
|
|
||||||
|
|
||||||
class DiscoverySettingsViewModel @AssistedInject constructor(
|
class DiscoverySettingsViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: DiscoverySettingsState,
|
@Assisted initialState: DiscoverySettingsState,
|
||||||
|
|
|
@ -21,10 +21,6 @@ import im.vector.riotx.core.extensions.postLiveEvent
|
||||||
import im.vector.riotx.core.utils.LiveEvent
|
import im.vector.riotx.core.utils.LiveEvent
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
sealed class DiscoverySharedViewModelAction {
|
|
||||||
data class ChangeIdentityServer(val newUrl: String) : DiscoverySharedViewModelAction()
|
|
||||||
}
|
|
||||||
|
|
||||||
class DiscoverySharedViewModel @Inject constructor() : ViewModel() {
|
class DiscoverySharedViewModel @Inject constructor() : ViewModel() {
|
||||||
var navigateEvent = MutableLiveData<LiveEvent<DiscoverySharedViewModelAction>>()
|
var navigateEvent = MutableLiveData<LiveEvent<DiscoverySharedViewModelAction>>()
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery
|
||||||
|
|
||||||
|
sealed class DiscoverySharedViewModelAction {
|
||||||
|
data class ChangeIdentityServer(val newUrl: String) : DiscoverySharedViewModelAction()
|
||||||
|
}
|
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery
|
||||||
|
|
||||||
|
import com.airbnb.mvrx.Async
|
||||||
|
import com.airbnb.mvrx.Uninitialized
|
||||||
|
import im.vector.matrix.android.api.session.identity.SharedState
|
||||||
|
import im.vector.matrix.android.api.session.identity.ThreePid
|
||||||
|
|
||||||
|
data class PidInfo(
|
||||||
|
// Retrieved from the homeserver
|
||||||
|
val threePid: ThreePid,
|
||||||
|
// Retrieved from IdentityServer, or transient state
|
||||||
|
val isShared: Async<SharedState>,
|
||||||
|
// Contains information about a current request to submit the token (for instance SMS code received by SMS)
|
||||||
|
// Or a current binding finalization, for email
|
||||||
|
val finalRequest: Async<Unit> = Uninitialized
|
||||||
|
)
|
|
@ -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.discovery.change
|
||||||
|
|
||||||
|
import im.vector.riotx.core.platform.VectorViewModelAction
|
||||||
|
|
||||||
|
sealed class SetIdentityServerAction : VectorViewModelAction {
|
||||||
|
data class UpdateServerName(val url: String) : SetIdentityServerAction()
|
||||||
|
object DoChangeServerName : SetIdentityServerAction()
|
||||||
|
}
|
|
@ -0,0 +1,27 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery.change
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import com.airbnb.mvrx.MvRxState
|
||||||
|
|
||||||
|
data class SetIdentityServerState(
|
||||||
|
val existingIdentityServer: String? = null,
|
||||||
|
val newIdentityServer: String? = null,
|
||||||
|
@StringRes val errorMessageId: Int? = null,
|
||||||
|
val isVerifyingServer: Boolean = false
|
||||||
|
) : MvRxState
|
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* 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.discovery.change
|
||||||
|
|
||||||
|
import im.vector.riotx.core.platform.VectorViewEvents
|
||||||
|
|
||||||
|
sealed class SetIdentityServerViewEvents : VectorViewEvents {
|
||||||
|
data class ShowTerms(val newIdentityServer: String) : SetIdentityServerViewEvents()
|
||||||
|
object NoTerms : SetIdentityServerViewEvents()
|
||||||
|
object TermsAccepted : SetIdentityServerViewEvents()
|
||||||
|
}
|
|
@ -15,9 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package im.vector.riotx.features.discovery.change
|
package im.vector.riotx.features.discovery.change
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
|
||||||
import com.airbnb.mvrx.FragmentViewModelContext
|
import com.airbnb.mvrx.FragmentViewModelContext
|
||||||
import com.airbnb.mvrx.MvRxState
|
|
||||||
import com.airbnb.mvrx.MvRxViewModelFactory
|
import com.airbnb.mvrx.MvRxViewModelFactory
|
||||||
import com.airbnb.mvrx.ViewModelContext
|
import com.airbnb.mvrx.ViewModelContext
|
||||||
import com.squareup.inject.assisted.Assisted
|
import com.squareup.inject.assisted.Assisted
|
||||||
|
@ -29,29 +27,9 @@ import im.vector.matrix.android.api.session.terms.GetTermsResponse
|
||||||
import im.vector.matrix.android.api.session.terms.TermsService
|
import im.vector.matrix.android.api.session.terms.TermsService
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.extensions.exhaustive
|
import im.vector.riotx.core.extensions.exhaustive
|
||||||
import im.vector.riotx.core.platform.VectorViewEvents
|
|
||||||
import im.vector.riotx.core.platform.VectorViewModel
|
import im.vector.riotx.core.platform.VectorViewModel
|
||||||
import im.vector.riotx.core.platform.VectorViewModelAction
|
|
||||||
import im.vector.riotx.core.resources.StringProvider
|
import im.vector.riotx.core.resources.StringProvider
|
||||||
|
|
||||||
data class SetIdentityServerState(
|
|
||||||
val existingIdentityServer: String? = null,
|
|
||||||
val newIdentityServer: String? = null,
|
|
||||||
@StringRes val errorMessageId: Int? = null,
|
|
||||||
val isVerifyingServer: Boolean = false
|
|
||||||
) : MvRxState
|
|
||||||
|
|
||||||
sealed class SetIdentityServerAction : VectorViewModelAction {
|
|
||||||
data class UpdateServerName(val url: String) : SetIdentityServerAction()
|
|
||||||
object DoChangeServerName : SetIdentityServerAction()
|
|
||||||
}
|
|
||||||
|
|
||||||
sealed class SetIdentityServerViewEvents : VectorViewEvents {
|
|
||||||
data class ShowTerms(val newIdentityServer: String) : SetIdentityServerViewEvents()
|
|
||||||
object NoTerms : SetIdentityServerViewEvents()
|
|
||||||
object TermsAccepted : SetIdentityServerViewEvents()
|
|
||||||
}
|
|
||||||
|
|
||||||
class SetIdentityServerViewModel @AssistedInject constructor(
|
class SetIdentityServerViewModel @AssistedInject constructor(
|
||||||
@Assisted initialState: SetIdentityServerState,
|
@Assisted initialState: SetIdentityServerState,
|
||||||
private val mxSession: Session,
|
private val mxSession: Session,
|
||||||
|
|
Loading…
Reference in a new issue