diff --git a/CHANGES.md b/CHANGES.md index 4058dcda6b..4d6799ade4 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -16,7 +16,7 @@ Translations 🗣: - SDK API changes ⚠️: - - + - Rename `tryThis` to `tryOrNull` Build 🧱: - diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt index e5e71f3944..e9a1775ac3 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/UnwedgingTest.kt @@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.crypto import androidx.test.ext.junit.runners.AndroidJUnit4 import org.matrix.android.sdk.InstrumentedTest -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel @@ -212,7 +212,7 @@ class UnwedgingTest : InstrumentedTest { mTestHelper.waitWithLatch { mTestHelper.retryPeriodicallyWithLatch(it) { // we should get back the key and be able to decrypt - val result = tryThis { + val result = tryOrNull { bobSession.cryptoService().decryptEvent(messagesReceivedByBob[0].root, "") } Timber.i("## CRYPTO | testUnwedging: decrypt result ${result?.clearEvent}") diff --git a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt index 7154487219..03f9de2894 100644 --- a/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt +++ b/matrix-sdk-android/src/androidTest/java/org/matrix/android/sdk/internal/crypto/gossiping/WithHeldTests.kt @@ -20,7 +20,7 @@ import android.util.Log import androidx.test.ext.junit.runners.AndroidJUnit4 import org.matrix.android.sdk.InstrumentedTest import org.matrix.android.sdk.api.NoOpMatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.crypto.MXCryptoError import org.matrix.android.sdk.api.session.events.model.EventType import org.matrix.android.sdk.api.session.events.model.toModel @@ -227,7 +227,7 @@ class WithHeldTests : InstrumentedTest { mTestHelper.retryPeriodicallyWithLatch(latch) { val timeLineEvent = bobSecondSession.getRoom(testData.roomId)?.getTimeLineEvent(eventId)?.also { // try to decrypt and force key request - tryThis { bobSecondSession.cryptoService().decryptEvent(it.root, "") } + tryOrNull { bobSecondSession.cryptoService().decryptEvent(it.root, "") } } sessionId = timeLineEvent?.root?.content?.toModel()?.sessionId timeLineEvent != null diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/extensions/Try.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/extensions/Try.kt index baae9b70f5..555909aef9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/extensions/Try.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/extensions/Try.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.api.extensions import timber.log.Timber -inline fun tryThis(message: String? = null, operation: () -> A): A? { +inline fun tryOrNull(message: String? = null, operation: () -> A): A? { return try { operation() } catch (any: Throwable) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt index 8caed519b2..e27eaa2921 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/failure/Extensions.kt @@ -17,7 +17,7 @@ package org.matrix.android.sdk.api.failure -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.auth.registration.RegistrationFlowResponse import org.matrix.android.sdk.internal.di.MoshiProvider import java.io.IOException @@ -49,7 +49,7 @@ fun Throwable.isInvalidPassword(): Boolean { */ fun Throwable.toRegistrationFlowResponse(): RegistrationFlowResponse? { return if (this is Failure.OtherServerError && this.httpCode == 401) { - tryThis { + tryOrNull { MoshiProvider.providesMoshi() .adapter(RegistrationFlowResponse::class.java) .fromJson(this.errorBody) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 2725afdc21..c9d09ead5d 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -36,7 +36,7 @@ import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.NoOpMatrixCallback import org.matrix.android.sdk.api.crypto.MXCryptoConfig -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.listeners.ProgressListener import org.matrix.android.sdk.api.session.crypto.CryptoService @@ -345,13 +345,13 @@ internal class DefaultCryptoService @Inject constructor( // Open the store cryptoStore.open() // this can throw if no network - tryThis { + tryOrNull { uploadDeviceKeys() } oneTimeKeysUploader.maybeUploadOneTimeKeys() // this can throw if no backup - tryThis { + tryOrNull { keysBackupService.checkAndStartKeysBackup() } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt index fbc1eb6bb1..96125f5d81 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStoreMigration.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.internal.crypto.store.db import com.squareup.moshi.Moshi import com.squareup.moshi.Types -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.internal.crypto.model.MXDeviceInfo import org.matrix.android.sdk.internal.crypto.model.OlmInboundGroupSessionWrapper @@ -398,7 +398,7 @@ internal class RealmCryptoStoreMigration @Inject constructor(private val crossSi ?.addField(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, Long::class.java) ?.setNullable(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, true) ?.transform { deviceInfoEntity -> - tryThis { + tryOrNull { deviceInfoEntity.setLong(DeviceInfoEntityFields.FIRST_TIME_SEEN_LOCAL_TS, now) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/IncomingGossipingRequestEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/IncomingGossipingRequestEntity.kt index c15df27874..d7c1844d53 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/IncomingGossipingRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/IncomingGossipingRequestEntity.kt @@ -17,7 +17,7 @@ package org.matrix.android.sdk.internal.crypto.store.db.model -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.crypto.GossipRequestType import org.matrix.android.sdk.internal.crypto.GossipingRequestState import org.matrix.android.sdk.internal.crypto.IncomingRoomKeyRequest @@ -45,7 +45,7 @@ internal open class IncomingGossipingRequestEntity(@Index var requestId: String? var type: GossipRequestType get() { - return tryThis { typeStr?.let { GossipRequestType.valueOf(it) } } ?: GossipRequestType.KEY + return tryOrNull { typeStr?.let { GossipRequestType.valueOf(it) } } ?: GossipRequestType.KEY } set(value) { typeStr = value.name @@ -55,7 +55,7 @@ internal open class IncomingGossipingRequestEntity(@Index var requestId: String? var requestState: GossipingRequestState get() { - return tryThis { GossipingRequestState.valueOf(requestStateStr) } + return tryOrNull { GossipingRequestState.valueOf(requestStateStr) } ?: GossipingRequestState.NONE } set(value) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt index 2880735d6b..5b32e9077d 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/model/OutgoingGossipingRequestEntity.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.internal.crypto.store.db.model import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Types -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.crypto.GossipRequestType import org.matrix.android.sdk.internal.crypto.OutgoingGossipingRequest import org.matrix.android.sdk.internal.crypto.OutgoingGossipingRequestState @@ -47,7 +47,7 @@ internal open class OutgoingGossipingRequestEntity( var type: GossipRequestType get() { - return tryThis { typeStr?.let { GossipRequestType.valueOf(it) } } ?: GossipRequestType.KEY + return tryOrNull { typeStr?.let { GossipRequestType.valueOf(it) } } ?: GossipRequestType.KEY } set(value) { typeStr = value.name @@ -57,7 +57,7 @@ internal open class OutgoingGossipingRequestEntity( var requestState: OutgoingGossipingRequestState get() { - return tryThis { OutgoingGossipingRequestState.valueOf(requestStateStr) } + return tryOrNull { OutgoingGossipingRequestState.valueOf(requestStateStr) } ?: OutgoingGossipingRequestState.UNSENT } set(value) { diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ProgressRequestBody.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ProgressRequestBody.kt index 98dec301ee..83f2d13459 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ProgressRequestBody.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ProgressRequestBody.kt @@ -24,7 +24,7 @@ import okio.BufferedSink import okio.ForwardingSink import okio.Sink import okio.buffer -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import java.io.IOException internal class ProgressRequestBody(private val delegate: RequestBody, @@ -40,7 +40,7 @@ internal class ProgressRequestBody(private val delegate: RequestBody, override fun isDuplex() = delegate.isDuplex() - val length = tryThis { delegate.contentLength() } ?: -1 + val length = tryOrNull { delegate.contentLength() } ?: -1 override fun contentLength() = length diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt index a163cd4809..ff12030961 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/DefaultFileService.kt @@ -23,7 +23,7 @@ import android.webkit.MimeTypeMap import androidx.core.content.FileProvider import arrow.core.Try import org.matrix.android.sdk.api.MatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.api.session.file.FileService import org.matrix.android.sdk.api.util.Cancelable @@ -174,7 +174,7 @@ internal class DefaultFileService @Inject constructor( } } toNotify?.forEach { otherCallbacks -> - tryThis { otherCallbacks.onFailure(it) } + tryOrNull { otherCallbacks.onFailure(it) } } }, { file -> callback.onSuccess(file) @@ -186,7 +186,7 @@ internal class DefaultFileService @Inject constructor( } Timber.v("## FileService additional to notify ${toNotify?.size ?: 0} ") toNotify?.forEach { otherCallbacks -> - tryThis { otherCallbacks.onSuccess(file) } + tryOrNull { otherCallbacks.onSuccess(file) } } }) }.toCancelable() diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt index d9bc66eddf..a314b5fc3c 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/call/DefaultCallSignalingService.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.internal.session.call import android.os.SystemClock import org.matrix.android.sdk.api.MatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.call.CallSignalingService import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.session.call.CallsListener @@ -210,7 +210,7 @@ internal class DefaultCallSignalingService @Inject constructor( private fun onCallHangup(hangup: CallHangupContent) { callListeners.toList().forEach { - tryThis { + tryOrNull { it.onCallHangupReceived(hangup) } } @@ -218,7 +218,7 @@ internal class DefaultCallSignalingService @Inject constructor( private fun onCallAnswer(answer: CallAnswerContent) { callListeners.toList().forEach { - tryThis { + tryOrNull { it.onCallAnswerReceived(answer) } } @@ -226,7 +226,7 @@ internal class DefaultCallSignalingService @Inject constructor( private fun onCallManageByOtherSession(callId: String) { callListeners.toList().forEach { - tryThis { + tryOrNull { it.onCallManagedByOtherSession(callId) } } @@ -237,7 +237,7 @@ internal class DefaultCallSignalingService @Inject constructor( if (incomingCall.otherUserId == userId) return callListeners.toList().forEach { - tryThis { + tryOrNull { it.onCallInviteReceived(incomingCall, invite) } } @@ -245,7 +245,7 @@ internal class DefaultCallSignalingService @Inject constructor( private fun onCallIceCandidate(incomingCall: MxCall, candidates: CallCandidatesContent) { callListeners.toList().forEach { - tryThis { + tryOrNull { it.onCallIceCandidateReceived(incomingCall, candidates) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/FileUploader.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/FileUploader.kt index 4ddf394b00..bb62b02112 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/FileUploader.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/FileUploader.kt @@ -32,7 +32,7 @@ import okhttp3.RequestBody.Companion.toRequestBody import okio.BufferedSink import okio.source import org.greenrobot.eventbus.EventBus -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.internal.di.Authenticated import org.matrix.android.sdk.internal.network.ProgressRequestBody @@ -96,7 +96,7 @@ internal class FileUploader @Inject constructor(@Authenticated inputStream.copyTo(it) } return uploadFile(workingFile, filename, mimeType, progressListener).also { - tryThis { workingFile.delete() } + tryOrNull { workingFile.delete() } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt index 385e32ab15..44880de197 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/content/UploadContentWorker.kt @@ -22,7 +22,7 @@ import android.graphics.BitmapFactory import androidx.work.CoroutineWorker import androidx.work.WorkerParameters import com.squareup.moshi.JsonClass -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentAttachmentData import org.matrix.android.sdk.api.session.events.model.toContent import org.matrix.android.sdk.api.session.events.model.toModel @@ -229,7 +229,7 @@ internal class UploadContentWorker(val context: Context, params: WorkerParameter } finally { // Delete all temporary files filesToDelete.forEach { - tryThis { it.delete() } + tryOrNull { it.delete() } } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/download/DefaultContentDownloadStateTracker.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/download/DefaultContentDownloadStateTracker.kt index c4ba95af84..a1f305fb06 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/download/DefaultContentDownloadStateTracker.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/download/DefaultContentDownloadStateTracker.kt @@ -19,7 +19,7 @@ package org.matrix.android.sdk.internal.session.download import android.os.Handler import android.os.Looper -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.file.ContentDownloadStateTracker import org.matrix.android.sdk.internal.session.SessionScope import timber.log.Timber @@ -76,7 +76,7 @@ internal class DefaultContentDownloadStateTracker @Inject constructor() : Progre Timber.v("## DL Progress Error code:$errorCode") updateState(url, ContentDownloadStateTracker.State.Failure(errorCode)) listeners[url]?.forEach { - tryThis { it.onDownloadStateUpdate(ContentDownloadStateTracker.State.Failure(errorCode)) } + tryOrNull { it.onDownloadStateUpdate(ContentDownloadStateTracker.State.Failure(errorCode)) } } } } @@ -84,7 +84,7 @@ internal class DefaultContentDownloadStateTracker @Inject constructor() : Progre private fun updateState(url: String, state: ContentDownloadStateTracker.State) { states[url] = state listeners[url]?.forEach { - tryThis { it.onDownloadStateUpdate(state) } + tryOrNull { it.onDownloadStateUpdate(state) } } } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/DefaultIdentityService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/DefaultIdentityService.kt index d3a10764d3..fc841af2d9 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/DefaultIdentityService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/identity/DefaultIdentityService.kt @@ -23,7 +23,7 @@ import androidx.lifecycle.LifecycleRegistry import dagger.Lazy import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.auth.data.SessionParams -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.failure.Failure import org.matrix.android.sdk.api.failure.MatrixError import org.matrix.android.sdk.api.session.events.model.toModel @@ -113,7 +113,7 @@ internal class DefaultIdentityService @Inject constructor( // Url has changed, we have to reset our store, update internal configuration and notify listeners identityStore.setUrl(baseUrl) updateIdentityAPI(baseUrl) - listeners.toList().forEach { tryThis { it.onIdentityServerChange() } } + listeners.toList().forEach { tryOrNull { it.onIdentityServerChange() } } } } @@ -236,7 +236,7 @@ internal class DefaultIdentityService @Inject constructor( private suspend fun updateAccountData(url: String?) { // Also notify the listener withContext(coroutineDispatchers.main) { - listeners.toList().forEach { tryThis { it.onIdentityServerChange() } } + listeners.toList().forEach { tryOrNull { it.onIdentityServerChange() } } } updateUserAccountDataTask.execute(UpdateUserAccountDataTask.IdentityParams( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/WorkerParamsFactory.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/WorkerParamsFactory.kt index 84a42840f8..4c71597bc5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/WorkerParamsFactory.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/worker/WorkerParamsFactory.kt @@ -18,7 +18,7 @@ package org.matrix.android.sdk.internal.worker import androidx.work.Data -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.network.parsing.CheckNumberType @@ -42,7 +42,7 @@ internal object WorkerParamsFactory { return Data.Builder().putString(KEY, json).build() } - inline fun fromData(data: Data): T? = tryThis("Unable to parse work parameters") { + inline fun fromData(data: Data): T? = tryOrNull("Unable to parse work parameters") { val json = data.getString(KEY) return if (json == null) { null diff --git a/vector/src/main/java/im/vector/app/core/extensions/FragmentManager.kt b/vector/src/main/java/im/vector/app/core/extensions/FragmentManager.kt index 49b28fb190..7456719455 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/FragmentManager.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/FragmentManager.kt @@ -17,12 +17,12 @@ package im.vector.app.core.extensions import androidx.fragment.app.FragmentTransaction -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull inline fun androidx.fragment.app.FragmentManager.commitTransactionNow(func: FragmentTransaction.() -> FragmentTransaction) { // Could throw and make the app crash // e.g sharedActionViewModel.observe() - tryThis("Failed to commitTransactionNow") { + tryOrNull("Failed to commitTransactionNow") { beginTransaction().func().commitNow() } } diff --git a/vector/src/main/java/im/vector/app/core/extensions/ThreePid.kt b/vector/src/main/java/im/vector/app/core/extensions/ThreePid.kt index 5d91370963..2e451cfc1e 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ThreePid.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ThreePid.kt @@ -18,14 +18,14 @@ package im.vector.app.core.extensions import com.google.i18n.phonenumbers.PhoneNumberUtil import org.matrix.android.sdk.api.extensions.ensurePrefix -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.identity.ThreePid fun ThreePid.getFormattedValue(): String { return when (this) { is ThreePid.Email -> email is ThreePid.Msisdn -> { - tryThis(message = "Unable to parse the phone number") { + tryOrNull(message = "Unable to parse the phone number") { PhoneNumberUtil.getInstance().parse(msisdn.ensurePrefix("+"), null) } ?.let { diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 4835ce5af5..d39f42ff4f 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -84,7 +84,7 @@ import im.vector.app.receivers.DebugReceiver import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.Disposable -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.failure.GlobalError import timber.log.Timber import kotlin.system.measureTimeMillis @@ -362,7 +362,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), HasScreenInjector { super.onPostResume() synchronized(postResumeScheduledActions) { postResumeScheduledActions.forEach { - tryThis { it.invoke() } + tryOrNull { it.invoke() } } postResumeScheduledActions.clear() } diff --git a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt index b1c63a406a..d28f6749a6 100644 --- a/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt +++ b/vector/src/main/java/im/vector/app/core/utils/ExternalApplicationsUtil.kt @@ -40,7 +40,7 @@ import androidx.fragment.app.Fragment import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.features.notifications.NotificationUtils -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch @@ -530,7 +530,7 @@ fun saveFileIntoLegacy(sourceFile: File, dstDirPath: File, outputFilename: Strin return null } finally { // Close resources - tryThis { inputStream?.close() } - tryThis { outputStream?.close() } + tryOrNull { inputStream?.close() } + tryOrNull { outputStream?.close() } } } diff --git a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt index 3230e97809..6d3f8b5885 100644 --- a/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt +++ b/vector/src/main/java/im/vector/app/features/call/WebRtcPeerConnectionManager.kt @@ -27,7 +27,7 @@ import io.reactivex.disposables.Disposable import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.ReplaySubject import org.matrix.android.sdk.api.MatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.call.CallState import org.matrix.android.sdk.api.session.call.CallsListener @@ -95,7 +95,7 @@ class WebRtcPeerConnectionManager @Inject constructor( val callAudioManager = CallAudioManager(context.applicationContext) { currentCallsListeners.forEach { - tryThis { it.onAudioDevicesChange() } + tryOrNull { it.onAudioDevicesChange() } } } @@ -174,7 +174,7 @@ class WebRtcPeerConnectionManager @Inject constructor( set(value) { field = value currentCallsListeners.forEach { - tryThis { it.onCaptureStateChanged() } + tryOrNull { it.onCaptureStateChanged() } } } @@ -205,7 +205,7 @@ class WebRtcPeerConnectionManager @Inject constructor( set(value) { field = value currentCallsListeners.forEach { - tryThis { it.onCurrentCallChange(value?.mxCall) } + tryOrNull { it.onCurrentCallChange(value?.mxCall) } } } @@ -745,7 +745,7 @@ class WebRtcPeerConnectionManager @Inject constructor( } currentCallsListeners.forEach { - tryThis { it.onCameraChange() } + tryOrNull { it.onCameraChange() } } } @@ -771,7 +771,7 @@ class WebRtcPeerConnectionManager @Inject constructor( // videoCapturer?.stopCapture() videoCapturer?.changeCaptureFormat(format.width, format.height, format.fps) currentCaptureMode = format - currentCallsListeners.forEach { tryThis { it.onCaptureStateChanged() } } + currentCallsListeners.forEach { tryOrNull { it.onCaptureStateChanged() } } } } diff --git a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt index e26cb23ac7..5a4c25a8ad 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt @@ -38,7 +38,7 @@ import org.jitsi.meet.sdk.JitsiMeetActivityInterface import org.jitsi.meet.sdk.JitsiMeetConferenceOptions import org.jitsi.meet.sdk.JitsiMeetView import org.jitsi.meet.sdk.JitsiMeetViewListener -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import java.net.URL import javax.inject.Inject @@ -100,7 +100,7 @@ class VectorJitsiActivity : VectorBaseActivity(), JitsiMeetActivityInterface, Ji .setVideoMuted(!viewState.enableVideo) .setUserInfo(viewState.userInfo) .apply { - tryThis { URL(viewState.jitsiUrl) }?.let { + tryOrNull { URL(viewState.jitsiUrl) }?.let { setServerURL(it) } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageKeyFragment.kt b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageKeyFragment.kt index f8b3f4d6a4..ee47a4d8e9 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageKeyFragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/quads/SharedSecuredStorageKeyFragment.kt @@ -27,7 +27,7 @@ import com.jakewharton.rxbinding3.widget.textChanges import im.vector.app.R import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.startImportTextFromFileIntent -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import io.reactivex.android.schedulers.AndroidSchedulers import kotlinx.android.synthetic.main.fragment_ssss_access_from_key.* import java.util.concurrent.TimeUnit @@ -84,7 +84,7 @@ class SharedSecuredStorageKeyFragment @Inject constructor() : VectorBaseFragment override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == IMPORT_FILE_REQ && resultCode == Activity.RESULT_OK) { data?.data?.let { dataURI -> - tryThis { + tryOrNull { activity?.contentResolver?.openInputStream(dataURI) ?.bufferedReader() ?.use { it.readText() } diff --git a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapMigrateBackupFragment.kt b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapMigrateBackupFragment.kt index e43e2f2493..a89e08988c 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapMigrateBackupFragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/recover/BootstrapMigrateBackupFragment.kt @@ -37,7 +37,7 @@ import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.resources.ColorProvider import im.vector.app.core.utils.colorizeMatchingText import im.vector.app.core.utils.startImportTextFromFileIntent -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.internal.crypto.keysbackup.util.isValidRecoveryKey import io.reactivex.android.schedulers.AndroidSchedulers import kotlinx.android.synthetic.main.fragment_bootstrap_enter_passphrase.bootstrapDescriptionText @@ -150,7 +150,7 @@ class BootstrapMigrateBackupFragment @Inject constructor( override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { if (requestCode == IMPORT_FILE_REQ && resultCode == Activity.RESULT_OK) { data?.data?.let { dataURI -> - tryThis { + tryOrNull { activity?.contentResolver?.openInputStream(dataURI) ?.bufferedReader() ?.use { it.readText() } diff --git a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt index e15f1e90cb..7787054240 100644 --- a/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/home/AvatarRenderer.kt @@ -34,7 +34,7 @@ import im.vector.app.core.glide.GlideApp import im.vector.app.core.glide.GlideRequest import im.vector.app.core.glide.GlideRequests import im.vector.app.core.utils.getColorFromUserId -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.api.util.MatrixItem import javax.inject.Inject @@ -59,7 +59,7 @@ class AvatarRenderer @Inject constructor(private val activeSessionHolder: Active fun clear(imageView: ImageView) { // It can be called after recycler view is destroyed, just silently catch - tryThis { GlideApp.with(imageView).clear(imageView) } + tryOrNull { GlideApp.with(imageView).clear(imageView) } } @UiThread diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt index 9b2239bd4b..0f205e3379 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailViewModel.kt @@ -57,7 +57,7 @@ import org.commonmark.renderer.html.HtmlRenderer import org.matrix.android.sdk.api.MatrixCallback import org.matrix.android.sdk.api.MatrixPatterns import org.matrix.android.sdk.api.NoOpMatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.query.QueryStringValue import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session @@ -334,7 +334,7 @@ class RoomDetailViewModel @AssistedInject constructor( val roomId: String = room.roomId val confId = roomId.substring(1, roomId.indexOf(":") - 1) + widgetSessionId.toLowerCase(VectorLocale.applicationLocale) - val preferredJitsiDomain = tryThis { + val preferredJitsiDomain = tryOrNull { rawService.getElementWellknown(session.myUserId) ?.jitsiServer ?.preferredDomain @@ -988,7 +988,7 @@ class RoomDetailViewModel @AssistedInject constructor( && mxcUrl?.startsWith("content://") ?: false val isDownloaded = mxcUrl?.let { session.fileService().isFileInCache(it, action.messageFileContent.mimeType) } ?: false if (isLocalSendingFile) { - tryThis { Uri.parse(mxcUrl) }?.let { + tryOrNull { Uri.parse(mxcUrl) }?.let { _viewEvents.post(RoomDetailViewEvents.OpenFile( action.messageFileContent.mimeType, it, diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/widget/RoomWidgetItem.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/widget/RoomWidgetItem.kt index a58b8291c7..691b6ec4ee 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/widget/RoomWidgetItem.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/widget/RoomWidgetItem.kt @@ -27,7 +27,7 @@ import im.vector.app.R import im.vector.app.core.epoxy.ClickListener import im.vector.app.core.epoxy.VectorEpoxyHolder import im.vector.app.core.epoxy.onClick -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.session.widgets.model.Widget import java.net.URL @@ -42,7 +42,7 @@ abstract class RoomWidgetItem : EpoxyModelWithHolder() { override fun bind(holder: Holder) { super.bind(holder) holder.widgetName.text = widget.name - holder.widgetUrl.text = tryThis { URL(widget.computedUrl) }?.host ?: widget.computedUrl + holder.widgetUrl.text = tryOrNull { URL(widget.computedUrl) }?.host ?: widget.computedUrl if (iconRes != null) { holder.iconImage.isVisible = true holder.iconImage.setImageResource(iconRes!!) diff --git a/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt b/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt index 0252f20425..f6c60f6a6d 100644 --- a/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/homeserver/HomeServerCapabilitiesViewModel.kt @@ -31,7 +31,7 @@ import im.vector.app.features.raw.wellknown.isE2EByDefault import im.vector.app.features.userdirectory.KnownUsersFragment import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.homeserver.HomeServerCapabilities @@ -68,7 +68,7 @@ class HomeServerCapabilitiesViewModel @AssistedInject constructor( private fun initAdminE2eByDefault() { viewModelScope.launch(Dispatchers.IO) { - val adminE2EByDefault = tryThis { + val adminE2EByDefault = tryOrNull { rawService.getElementWellknown(session.myUserId) ?.isE2EByDefault() ?: true diff --git a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt index 74aca87bd1..da63ca529d 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt @@ -44,7 +44,7 @@ import im.vector.app.features.login.terms.toLocalizedLoginTerms import im.vector.app.features.pin.UnlockedActivity import org.matrix.android.sdk.api.auth.registration.FlowResult import org.matrix.android.sdk.api.auth.registration.Stage -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import kotlinx.android.synthetic.main.activity_login.* import javax.inject.Inject @@ -262,7 +262,7 @@ open class LoginActivity : VectorBaseActivity(), ToolbarConfigurable, UnlockedAc super.onNewIntent(intent) intent?.data - ?.let { tryThis { it.getQueryParameter("loginToken") } } + ?.let { tryOrNull { it.getQueryParameter("loginToken") } } ?.let { loginViewModel.handle(LoginAction.LoginWithToken(it)) } } diff --git a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt index cf1381a1cf..0336e2d03c 100644 --- a/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt +++ b/vector/src/main/java/im/vector/app/features/media/ImageContentRenderer.kt @@ -39,7 +39,7 @@ import im.vector.app.core.utils.isLocalFile import kotlinx.android.parcel.Parcelize import org.matrix.android.sdk.api.session.content.ContentUrlResolver import org.matrix.android.sdk.internal.crypto.attachments.ElementToDecrypt -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import timber.log.Timber import java.io.File import javax.inject.Inject @@ -109,7 +109,7 @@ class ImageContentRenderer @Inject constructor(private val activeSessionHolder: fun clear(imageView: ImageView) { // It can be called after recycler view is destroyed, just silently catch // We'd better keep ref to requestManager, but we don't have it - tryThis { + tryOrNull { GlideApp .with(imageView).clear(imageView) } diff --git a/vector/src/main/java/im/vector/app/features/raw/wellknown/ElementWellKnownExt.kt b/vector/src/main/java/im/vector/app/features/raw/wellknown/ElementWellKnownExt.kt index 636a7098e3..119be66f94 100644 --- a/vector/src/main/java/im/vector/app/features/raw/wellknown/ElementWellKnownExt.kt +++ b/vector/src/main/java/im/vector/app/features/raw/wellknown/ElementWellKnownExt.kt @@ -16,12 +16,12 @@ package im.vector.app.features.raw.wellknown -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.internal.util.awaitCallback suspend fun RawService.getElementWellknown(userId: String): ElementWellKnown? { - return tryThis { awaitCallback { getWellknown(userId, it) } } + return tryOrNull { awaitCallback { getWellknown(userId, it) } } ?.let { ElementWellKnownMapper.from(it) } } diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt index be4bbed15b..c213992258 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomViewModel.kt @@ -34,7 +34,7 @@ import im.vector.app.features.roomdirectory.RoomDirectoryActivity import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import org.matrix.android.sdk.api.MatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.raw.RawService import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.room.model.RoomDirectoryVisibility @@ -59,7 +59,7 @@ class CreateRoomViewModel @AssistedInject constructor(@Assisted initialState: Cr private fun initAdminE2eByDefault() { viewModelScope.launch(Dispatchers.IO) { - adminE2EByDefault = tryThis { + adminE2EByDefault = tryOrNull { rawService.getElementWellknown(session.myUserId) ?.isE2EByDefault() ?: true diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 9fc566aac4..52c3a5ec5e 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -28,7 +28,7 @@ import im.vector.app.R import im.vector.app.core.di.DefaultSharedPreferences import im.vector.app.features.homeserver.ServerUrlsRepository import im.vector.app.features.themes.ThemeUtils -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import timber.log.Timber import javax.inject.Inject @@ -424,7 +424,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { } fun getUnknownDeviceDismissedList(): List { - return tryThis { + return tryOrNull { defaultPrefs.getStringSet(SETTINGS_UNKNOWN_DEVICE_DISMISSED_LIST, null)?.toList() }.orEmpty() } @@ -846,7 +846,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { } fun backgroundSyncTimeOut(): Int { - return tryThis { + return tryOrNull { // The xml pref is saved as a string so use getString and parse defaultPrefs.getString(SETTINGS_SET_SYNC_TIMEOUT_PREFERENCE_KEY, null)?.toInt() } ?: BackgroundSyncMode.DEFAULT_SYNC_TIMEOUT_SECONDS @@ -860,7 +860,7 @@ class VectorPreferences @Inject constructor(private val context: Context) { } fun backgroundSyncDelay(): Int { - return tryThis { + return tryOrNull { // The xml pref is saved as a string so use getString and parse defaultPrefs.getString(SETTINGS_SET_SYNC_DELAY_PREFERENCE_KEY, null)?.toInt() } ?: BackgroundSyncMode.DEFAULT_SYNC_DELAY_SECONDS diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsNotificationPreferenceFragment.kt index 3f74c4db75..d6d9cf6e31 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsNotificationPreferenceFragment.kt @@ -37,7 +37,7 @@ import im.vector.app.core.utils.requestDisablingBatteryOptimization import im.vector.app.features.notifications.NotificationUtils import im.vector.app.push.fcm.FcmHelper import org.matrix.android.sdk.api.MatrixCallback -import org.matrix.android.sdk.api.extensions.tryThis +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.pushrules.RuleIds import org.matrix.android.sdk.api.pushrules.RuleKind import javax.inject.Inject @@ -88,7 +88,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( it.summary = secondsToText(vectorPreferences.backgroundSyncTimeOut()) it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> if (newValue is String) { - val syncTimeout = tryThis { Integer.parseInt(newValue) } ?: BackgroundSyncMode.DEFAULT_SYNC_TIMEOUT_SECONDS + val syncTimeout = tryOrNull { Integer.parseInt(newValue) } ?: BackgroundSyncMode.DEFAULT_SYNC_TIMEOUT_SECONDS vectorPreferences.setBackgroundSyncTimeout(maxOf(0, syncTimeout)) refreshBackgroundSyncPrefs() } @@ -101,7 +101,7 @@ class VectorSettingsNotificationPreferenceFragment @Inject constructor( it.summary = secondsToText(vectorPreferences.backgroundSyncDelay()) it.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> if (newValue is String) { - val syncDelay = tryThis { Integer.parseInt(newValue) } ?: BackgroundSyncMode.DEFAULT_SYNC_DELAY_SECONDS + val syncDelay = tryOrNull { Integer.parseInt(newValue) } ?: BackgroundSyncMode.DEFAULT_SYNC_DELAY_SECONDS vectorPreferences.setBackgroundSyncDelay(maxOf(0, syncDelay)) refreshBackgroundSyncPrefs() }