Move `andThen` extension to app module

This commit is contained in:
Benoit Marty 2022-04-11 16:36:31 +02:00 committed by Benoit Marty
parent 1403557213
commit 814ba43867
3 changed files with 27 additions and 10 deletions

View File

@ -17,15 +17,7 @@ package org.matrix.android.sdk.internal.extensions
import org.matrix.android.sdk.api.MatrixCallback
fun <A> Result<A>.foldToCallback(callback: MatrixCallback<A>): Unit = fold(
internal fun <A> Result<A>.foldToCallback(callback: MatrixCallback<A>): Unit = fold(
{ callback.onSuccess(it) },
{ callback.onFailure(it) }
)
@Suppress("UNCHECKED_CAST") // We're casting null failure results to R
inline fun <T, R> Result<T>.andThen(block: (T) -> Result<R>): Result<R> {
return when (val result = getOrNull()) {
null -> this as Result<R>
else -> block(result)
}
}

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 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.app.core.extensions
@Suppress("UNCHECKED_CAST") // We're casting null failure results to R
inline fun <T, R> Result<T>.andThen(block: (T) -> Result<R>): Result<R> {
return when (val result = getOrNull()) {
null -> this as Result<R>
else -> block(result)
}
}

View File

@ -17,6 +17,7 @@
package im.vector.app.features.onboarding
import im.vector.app.R
import im.vector.app.core.extensions.andThen
import im.vector.app.core.resources.StringProvider
import im.vector.app.features.onboarding.OnboardingAction.LoginOrRegister
import org.matrix.android.sdk.api.MatrixPatterns.getDomain
@ -24,7 +25,6 @@ import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.auth.data.HomeServerConnectionConfig
import org.matrix.android.sdk.api.auth.wellknown.WellknownResult
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.internal.extensions.andThen
import javax.inject.Inject
class DirectLoginUseCase @Inject constructor(