Merge pull request #7335 from vector-im/feature/bma/upgrade_arrow

Remove Arrow-kt dependency
This commit is contained in:
Benoit Marty 2022-10-12 16:26:02 +02:00 committed by GitHub
commit beb334babe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 48 additions and 73 deletions

1
changelog.d/7335.misc Normal file
View File

@ -0,0 +1 @@
Dependency to arrow has been removed. Please use `org.matrix.android.sdk.api.util.Optional` instead.

View File

@ -14,7 +14,6 @@ def kotlinCoroutines = "1.6.4"
def dagger = "2.44" def dagger = "2.44"
def appDistribution = "16.0.0-beta04" def appDistribution = "16.0.0-beta04"
def retrofit = "2.9.0" def retrofit = "2.9.0"
def arrow = "0.8.2"
def markwon = "4.6.2" def markwon = "4.6.2"
def moshi = "1.14.0" def moshi = "1.14.0"
def lifecycle = "2.5.1" def lifecycle = "2.5.1"
@ -115,10 +114,6 @@ ext.libs = [
rx : [ rx : [
'rxKotlin' : "io.reactivex.rxjava2:rxkotlin:2.4.0" 'rxKotlin' : "io.reactivex.rxjava2:rxkotlin:2.4.0"
], ],
arrow : [
'core' : "io.arrow-kt:arrow-core:$arrow",
'instances' : "io.arrow-kt:arrow-instances-core:$arrow"
],
markwon : [ markwon : [
'core' : "io.noties.markwon:core:$markwon", 'core' : "io.noties.markwon:core:$markwon",
'extLatex' : "io.noties.markwon:ext-latex:$markwon", 'extLatex' : "io.noties.markwon:ext-latex:$markwon",

View File

@ -134,7 +134,6 @@ ext.groups = [
'commons-io', 'commons-io',
'commons-logging', 'commons-logging',
'info.picocli', 'info.picocli',
'io.arrow-kt',
'io.element.android', 'io.element.android',
'io.github.davidburstrom.contester', 'io.github.davidburstrom.contester',
'io.github.detekt.sarif4k', 'io.github.detekt.sarif4k',

View File

@ -15,15 +15,13 @@
*/ */
package org.matrix.android.sdk.api.util package org.matrix.android.sdk.api.util
data class Optional<T : Any> constructor(private val value: T?) { data class Optional<T : Any>(private val value: T?) {
fun get(): T { fun get(): T = value!!
return value!!
}
fun getOrNull(): T? { fun orNull(): T? = value
return value
} fun getOrNull(): T? = value
fun <U : Any> map(fn: (T) -> U?): Optional<U> { fun <U : Any> map(fn: (T) -> U?): Optional<U> {
return if (value == null) { return if (value == null) {
@ -33,23 +31,19 @@ data class Optional<T : Any> constructor(private val value: T?) {
} }
} }
fun getOrElse(fn: () -> T): T { fun orElse(fn: () -> T): T {
return value ?: fn() return value ?: fn()
} }
fun hasValue(): Boolean { fun hasValue(): Boolean = value != null
return value != null
}
companion object { companion object {
fun <T : Any> from(value: T?): Optional<T> { fun <T : Any> from(value: T?): Optional<T> = Optional(value)
return Optional(value)
fun <T : Any> empty(): Optional<T> = Optional(null)
}
} }
fun <T : Any> empty(): Optional<T> { fun <T : Any> T?.toOption() = Optional(this)
return Optional(null)
}
}
}
fun <T : Any> T?.toOptional() = Optional(this) fun <T : Any> T?.toOptional() = Optional(this)

View File

@ -174,9 +174,6 @@ dependencies {
// Paging // Paging
implementation libs.androidx.pagingRuntimeKtx implementation libs.androidx.pagingRuntimeKtx
// Functional Programming
implementation libs.arrow.core
// Pref // Pref
api libs.androidx.preferenceKtx api libs.androidx.preferenceKtx

View File

@ -17,11 +17,11 @@
package im.vector.app package im.vector.app
import arrow.core.Option
import im.vector.app.core.utils.BehaviorDataSource import im.vector.app.core.utils.BehaviorDataSource
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Optional
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@Singleton @Singleton
class ActiveSessionDataSource @Inject constructor() : BehaviorDataSource<Option<Session>>() class ActiveSessionDataSource @Inject constructor() : BehaviorDataSource<Optional<Session>>()

View File

@ -17,10 +17,10 @@
package im.vector.app package im.vector.app
import androidx.lifecycle.DefaultLifecycleObserver import androidx.lifecycle.DefaultLifecycleObserver
import arrow.core.Option
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.util.Optional
/** /**
* Gets info about the current space the user has navigated to, any space backstack they may have * Gets info about the current space the user has navigated to, any space backstack they may have
@ -62,7 +62,7 @@ interface SpaceStateHandler : DefaultLifecycleObserver {
/** /**
* Gets a flow of the selected space for clients to react immediately to space changes. * Gets a flow of the selected space for clients to react immediately to space changes.
*/ */
fun getSelectedSpaceFlow(): Flow<Option<RoomSummary>> fun getSelectedSpaceFlow(): Flow<Optional<RoomSummary>>
/** /**
* Gets the id of the active space, or null if there is none. * Gets the id of the active space, or null if there is none.

View File

@ -17,7 +17,6 @@
package im.vector.app package im.vector.app
import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.LifecycleOwner
import arrow.core.Option
import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.BehaviorDataSource import im.vector.app.core.utils.BehaviorDataSource
import im.vector.app.features.analytics.AnalyticsTracker import im.vector.app.features.analytics.AnalyticsTracker
@ -42,6 +41,8 @@ import org.matrix.android.sdk.api.session.getRoom
import org.matrix.android.sdk.api.session.getRoomSummary import org.matrix.android.sdk.api.session.getRoomSummary
import org.matrix.android.sdk.api.session.room.model.RoomSummary import org.matrix.android.sdk.api.session.room.model.RoomSummary
import org.matrix.android.sdk.api.session.sync.SyncRequestState import org.matrix.android.sdk.api.session.sync.SyncRequestState
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOption
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
@ -59,7 +60,7 @@ class SpaceStateHandlerImpl @Inject constructor(
) : SpaceStateHandler { ) : SpaceStateHandler {
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main) private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
private val selectedSpaceDataSource = BehaviorDataSource<Option<RoomSummary>>(Option.empty()) private val selectedSpaceDataSource = BehaviorDataSource<Optional<RoomSummary>>(Optional.empty())
private val selectedSpaceFlow = selectedSpaceDataSource.stream() private val selectedSpaceFlow = selectedSpaceDataSource.stream()
override fun getCurrentSpace(): RoomSummary? { override fun getCurrentSpace(): RoomSummary? {
@ -98,11 +99,7 @@ class SpaceStateHandlerImpl @Inject constructor(
uiStateRepository.storeSelectedSpace(spaceToSet?.roomId, activeSession.sessionId) uiStateRepository.storeSelectedSpace(spaceToSet?.roomId, activeSession.sessionId)
} }
if (spaceToSet == null) { selectedSpaceDataSource.post(spaceToSet.toOption())
selectedSpaceDataSource.post(Option.empty())
} else {
selectedSpaceDataSource.post(Option.just(spaceToSet))
}
if (spaceId != null) { if (spaceId != null) {
activeSession.coroutineScope.launch(Dispatchers.IO) { activeSession.coroutineScope.launch(Dispatchers.IO) {

View File

@ -17,7 +17,6 @@
package im.vector.app.core.di package im.vector.app.core.di
import android.content.Context import android.content.Context
import arrow.core.Option
import im.vector.app.ActiveSessionDataSource import im.vector.app.ActiveSessionDataSource
import im.vector.app.core.extensions.startSyncing import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.pushers.UnifiedPushHelper import im.vector.app.core.pushers.UnifiedPushHelper
@ -31,6 +30,8 @@ import im.vector.app.features.session.SessionListener
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.auth.AuthenticationService import org.matrix.android.sdk.api.auth.AuthenticationService
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toOption
import timber.log.Timber import timber.log.Timber
import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject import javax.inject.Inject
@ -58,7 +59,7 @@ class ActiveSessionHolder @Inject constructor(
fun setActiveSession(session: Session) { fun setActiveSession(session: Session) {
Timber.w("setActiveSession of ${session.myUserId}") Timber.w("setActiveSession of ${session.myUserId}")
activeSessionReference.set(session) activeSessionReference.set(session)
activeSessionDataSource.post(Option.just(session)) activeSessionDataSource.post(session.toOption())
keyRequestHandler.start(session) keyRequestHandler.start(session)
incomingVerificationRequestHandler.start(session) incomingVerificationRequestHandler.start(session)
@ -78,7 +79,7 @@ class ActiveSessionHolder @Inject constructor(
} }
activeSessionReference.set(null) activeSessionReference.set(null)
activeSessionDataSource.post(Option.empty()) activeSessionDataSource.post(Optional.empty())
keyRequestHandler.stop() keyRequestHandler.stop()
incomingVerificationRequestHandler.stop() incomingVerificationRequestHandler.stop()

View File

@ -24,7 +24,6 @@ import android.os.Build
import android.provider.MediaStore import android.provider.MediaStore
import androidx.annotation.WorkerThread import androidx.annotation.WorkerThread
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import arrow.core.Try
import okio.buffer import okio.buffer
import okio.sink import okio.sink
import okio.source import okio.source
@ -35,25 +34,23 @@ import java.io.File
* Save a string to a file with Okio. * Save a string to a file with Okio.
*/ */
@WorkerThread @WorkerThread
fun writeToFile(str: String, file: File): Try<Unit> { @Throws
return Try<Unit> { fun writeToFile(str: String, file: File) {
file.sink().buffer().use { file.sink().buffer().use {
it.writeString(str, Charsets.UTF_8) it.writeString(str, Charsets.UTF_8)
} }
} }
}
/** /**
* Save a byte array to a file with Okio. * Save a byte array to a file with Okio.
*/ */
@WorkerThread @WorkerThread
fun writeToFile(data: ByteArray, file: File): Try<Unit> { @Throws
return Try<Unit> { fun writeToFile(data: ByteArray, file: File) {
file.sink().buffer().use { file.sink().buffer().use {
it.write(data) it.write(data)
} }
} }
}
fun addEntryToDownloadManager( fun addEntryToDownloadManager(
context: Context, context: Context,

View File

@ -25,7 +25,6 @@ import android.widget.TextView
import android.widget.Toast import android.widget.Toast
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope import androidx.lifecycle.lifecycleScope
import arrow.core.Try
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
@ -167,7 +166,7 @@ class KeysBackupSetupStep3Fragment :
private fun exportRecoveryKeyToFile(uri: Uri, data: String) { private fun exportRecoveryKeyToFile(uri: Uri, data: String) {
lifecycleScope.launch(Dispatchers.Main) { lifecycleScope.launch(Dispatchers.Main) {
Try { try {
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
requireContext().safeOpenOutputStream(uri) requireContext().safeOpenOutputStream(uri)
?.use { os -> ?.use { os ->
@ -176,24 +175,19 @@ class KeysBackupSetupStep3Fragment :
} }
} }
?: throw IOException("Unable to write the file") ?: throw IOException("Unable to write the file")
}
.fold(
{ throwable ->
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(throwable))
}
},
{
viewModel.copyHasBeenMade = true viewModel.copyHasBeenMade = true
activity?.let { activity?.let {
MaterialAlertDialogBuilder(it) MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_success) .setTitle(R.string.dialog_title_success)
.setMessage(R.string.recovery_key_export_saved) .setMessage(R.string.recovery_key_export_saved)
} }
} catch (throwable: Throwable) {
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(throwable))
}
} }
)
?.setCancelable(false) ?.setCancelable(false)
?.setPositiveButton(R.string.ok, null) ?.setPositiveButton(R.string.ok, null)
?.show() ?.show()

View File

@ -21,7 +21,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.paging.PagedList import androidx.paging.PagedList
import arrow.core.toOption
import com.airbnb.mvrx.MavericksViewModelFactory import com.airbnb.mvrx.MavericksViewModelFactory
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
@ -68,6 +67,7 @@ import org.matrix.android.sdk.api.session.room.roomSummaryQueryParams
import org.matrix.android.sdk.api.session.room.state.isPublic import org.matrix.android.sdk.api.session.room.state.isPublic
import org.matrix.android.sdk.api.util.Optional import org.matrix.android.sdk.api.util.Optional
import org.matrix.android.sdk.api.util.toMatrixItem import org.matrix.android.sdk.api.util.toMatrixItem
import org.matrix.android.sdk.api.util.toOption
import org.matrix.android.sdk.flow.flow import org.matrix.android.sdk.flow.flow
class HomeRoomListViewModel @AssistedInject constructor( class HomeRoomListViewModel @AssistedInject constructor(

View File

@ -16,15 +16,15 @@
package im.vector.app.test.fakes package im.vector.app.test.fakes
import arrow.core.Option
import im.vector.app.ActiveSessionDataSource import im.vector.app.ActiveSessionDataSource
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.toOptional
class FakeActiveSessionDataSource { class FakeActiveSessionDataSource {
val instance = ActiveSessionDataSource() val instance = ActiveSessionDataSource()
fun setActiveSession(session: Session) { fun setActiveSession(session: Session) {
instance.post(Option.just(session)) instance.post(session.toOptional())
} }
} }