Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Arrow-kt dependency #7335

Merged
merged 1 commit into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7335.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Dependency to arrow has been removed. Please use `org.matrix.android.sdk.api.util.Optional` instead.
5 changes: 0 additions & 5 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def kotlinCoroutines = "1.6.4"
def dagger = "2.44"
def appDistribution = "16.0.0-beta04"
def retrofit = "2.9.0"
def arrow = "0.8.2"
def markwon = "4.6.2"
def moshi = "1.14.0"
def lifecycle = "2.5.1"
Expand Down Expand Up @@ -114,10 +113,6 @@ ext.libs = [
rx : [
'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 : [
'core' : "io.noties.markwon:core:$markwon",
'extLatex' : "io.noties.markwon:ext-latex:$markwon",
Expand Down
1 change: 0 additions & 1 deletion dependencies_groups.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ ext.groups = [
'commons-io',
'commons-logging',
'info.picocli',
'io.arrow-kt',
'io.element.android',
'io.github.davidburstrom.contester',
'io.github.detekt.sarif4k',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@
*/
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 {
return value!!
}
fun get(): T = value!!

fun getOrNull(): T? {
return value
}
fun orNull(): T? = value
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a new alias to avoid to many changes.


fun getOrNull(): T? = value

fun <U : Any> map(fn: (T) -> U?): Optional<U> {
return if (value == null) {
Expand All @@ -33,23 +31,19 @@ data class Optional<T : Any> constructor(private val value: T?) {
}
}

fun getOrElse(fn: () -> T): T {
fun orElse(fn: () -> T): T {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not used at the moment)

return value ?: fn()
}

fun hasValue(): Boolean {
return value != null
}
fun hasValue(): Boolean = value != null

companion object {
fun <T : Any> from(value: T?): Optional<T> {
return Optional(value)
}
fun <T : Any> from(value: T?): Optional<T> = Optional(value)

fun <T : Any> empty(): Optional<T> {
return Optional(null)
}
fun <T : Any> empty(): Optional<T> = Optional(null)
}
}

fun <T : Any> T?.toOption() = Optional(this)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(another new alias)


fun <T : Any> T?.toOptional() = Optional(this)
3 changes: 0 additions & 3 deletions vector/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,6 @@ dependencies {
// Paging
implementation libs.androidx.pagingRuntimeKtx

// Functional Programming
implementation libs.arrow.core

// Pref
api libs.androidx.preferenceKtx

Expand Down
4 changes: 2 additions & 2 deletions vector/src/main/java/im/vector/app/ActiveSessionDataSource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@

package im.vector.app

import arrow.core.Option
import im.vector.app.core.utils.BehaviorDataSource
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.Optional
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class ActiveSessionDataSource @Inject constructor() : BehaviorDataSource<Option<Session>>()
class ActiveSessionDataSource @Inject constructor() : BehaviorDataSource<Optional<Session>>()
4 changes: 2 additions & 2 deletions vector/src/main/java/im/vector/app/SpaceStateHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
package im.vector.app

import androidx.lifecycle.DefaultLifecycleObserver
import arrow.core.Option
import kotlinx.coroutines.flow.Flow
import org.matrix.android.sdk.api.session.Session
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
Expand Down Expand Up @@ -62,7 +62,7 @@ interface SpaceStateHandler : DefaultLifecycleObserver {
/**
* 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.
Expand Down
11 changes: 4 additions & 7 deletions vector/src/main/java/im/vector/app/SpaceStateHandlerImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package im.vector.app

import androidx.lifecycle.LifecycleOwner
import arrow.core.Option
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.utils.BehaviorDataSource
import im.vector.app.features.analytics.AnalyticsTracker
Expand All @@ -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.room.model.RoomSummary
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.Singleton

Expand All @@ -59,7 +60,7 @@ class SpaceStateHandlerImpl @Inject constructor(
) : SpaceStateHandler {

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()

override fun getCurrentSpace(): RoomSummary? {
Expand Down Expand Up @@ -98,11 +99,7 @@ class SpaceStateHandlerImpl @Inject constructor(
uiStateRepository.storeSelectedSpace(spaceToSet?.roomId, activeSession.sessionId)
}

if (spaceToSet == null) {
selectedSpaceDataSource.post(Option.empty())
} else {
selectedSpaceDataSource.post(Option.just(spaceToSet))
}
selectedSpaceDataSource.post(spaceToSet.toOption())

if (spaceId != null) {
activeSession.coroutineScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package im.vector.app.core.di

import android.content.Context
import arrow.core.Option
import im.vector.app.ActiveSessionDataSource
import im.vector.app.core.extensions.configureAndStart
import im.vector.app.core.extensions.startSyncing
Expand All @@ -31,6 +30,8 @@ import im.vector.app.features.session.SessionListener
import kotlinx.coroutines.runBlocking
import org.matrix.android.sdk.api.auth.AuthenticationService
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 java.util.concurrent.atomic.AtomicReference
import javax.inject.Inject
Expand All @@ -57,7 +58,7 @@ class ActiveSessionHolder @Inject constructor(
fun setActiveSession(session: Session) {
Timber.w("setActiveSession of ${session.myUserId}")
activeSessionReference.set(session)
activeSessionDataSource.post(Option.just(session))
activeSessionDataSource.post(session.toOption())

keyRequestHandler.start(session)
incomingVerificationRequestHandler.start(session)
Expand All @@ -77,7 +78,7 @@ class ActiveSessionHolder @Inject constructor(
}

activeSessionReference.set(null)
activeSessionDataSource.post(Option.empty())
activeSessionDataSource.post(Optional.empty())

keyRequestHandler.stop()
incomingVerificationRequestHandler.stop()
Expand Down
19 changes: 8 additions & 11 deletions vector/src/main/java/im/vector/app/core/files/FileSaver.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.os.Build
import android.provider.MediaStore
import androidx.annotation.WorkerThread
import androidx.core.content.getSystemService
import arrow.core.Try
import okio.buffer
import okio.sink
import okio.source
Expand All @@ -35,23 +34,21 @@ import java.io.File
* Save a string to a file with Okio.
*/
@WorkerThread
fun writeToFile(str: String, file: File): Try<Unit> {
return Try<Unit> {
file.sink().buffer().use {
it.writeString(str, Charsets.UTF_8)
}
@Throws
fun writeToFile(str: String, file: File) {
file.sink().buffer().use {
it.writeString(str, Charsets.UTF_8)
}
}

/**
* Save a byte array to a file with Okio.
*/
@WorkerThread
fun writeToFile(data: ByteArray, file: File): Try<Unit> {
return Try<Unit> {
file.sink().buffer().use {
it.write(data)
}
@Throws
fun writeToFile(data: ByteArray, file: File) {
file.sink().buffer().use {
it.write(data)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those 2 fun are actually not used, but I do not want to delete this file.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import android.widget.TextView
import android.widget.Toast
import androidx.core.view.isVisible
import androidx.lifecycle.lifecycleScope
import arrow.core.Try
import com.google.android.material.bottomsheet.BottomSheetDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -167,7 +166,7 @@ class KeysBackupSetupStep3Fragment :

private fun exportRecoveryKeyToFile(uri: Uri, data: String) {
lifecycleScope.launch(Dispatchers.Main) {
Try {
try {
withContext(Dispatchers.IO) {
requireContext().safeOpenOutputStream(uri)
?.use { os ->
Expand All @@ -176,24 +175,19 @@ class KeysBackupSetupStep3Fragment :
}
}
?: throw IOException("Unable to write the file")
viewModel.copyHasBeenMade = true
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_success)
.setMessage(R.string.recovery_key_export_saved)
}
} catch (throwable: Throwable) {
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(throwable))
}
}
.fold(
{ throwable ->
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_error)
.setMessage(errorFormatter.toHumanReadable(throwable))
}
},
{
viewModel.copyHasBeenMade = true
activity?.let {
MaterialAlertDialogBuilder(it)
.setTitle(R.string.dialog_title_success)
.setMessage(R.string.recovery_key_export_saved)
}
}
)
?.setCancelable(false)
?.setPositiveButton(R.string.ok, null)
?.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.Observer
import androidx.paging.PagedList
import arrow.core.toOption
import com.airbnb.mvrx.MavericksViewModelFactory
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
Expand Down Expand Up @@ -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.util.Optional
import org.matrix.android.sdk.api.util.toMatrixItem
import org.matrix.android.sdk.api.util.toOption
import org.matrix.android.sdk.flow.flow

class HomeRoomListViewModel @AssistedInject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@

package im.vector.app.test.fakes

import arrow.core.Option
import im.vector.app.ActiveSessionDataSource
import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.util.toOptional

class FakeActiveSessionDataSource {

val instance = ActiveSessionDataSource()

fun setActiveSession(session: Session) {
instance.post(Option.just(session))
instance.post(session.toOptional())
}
}