mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-24 10:25:51 +03:00
Remove dependency to arrow. Please use org.matrix.android.sdk.api.util.Optional
instead.
This commit is contained in:
parent
34cc5e8bd7
commit
1669316682
13 changed files with 48 additions and 73 deletions
1
changelog.d/7335.misc
Normal file
1
changelog.d/7335.misc
Normal file
|
@ -0,0 +1 @@
|
|||
Dependency to arrow has been removed. Please use `org.matrix.android.sdk.api.util.Optional` instead.
|
|
@ -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"
|
||||
|
@ -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",
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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
|
||||
|
||||
fun getOrNull(): T? = value
|
||||
|
||||
fun <U : Any> map(fn: (T) -> U?): Optional<U> {
|
||||
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()
|
||||
}
|
||||
|
||||
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)
|
||||
|
||||
fun <T : Any> T?.toOptional() = Optional(this)
|
||||
|
|
|
@ -170,9 +170,6 @@ dependencies {
|
|||
// Paging
|
||||
implementation libs.androidx.pagingRuntimeKtx
|
||||
|
||||
// Functional Programming
|
||||
implementation libs.arrow.core
|
||||
|
||||
// Pref
|
||||
api libs.androidx.preferenceKtx
|
||||
|
||||
|
|
|
@ -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>>()
|
||||
|
|
|
@ -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
|
||||
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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? {
|
||||
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -77,7 +78,7 @@ class ActiveSessionHolder @Inject constructor(
|
|||
}
|
||||
|
||||
activeSessionReference.set(null)
|
||||
activeSessionDataSource.post(Option.empty())
|
||||
activeSessionDataSource.post(Optional.empty())
|
||||
|
||||
keyRequestHandler.stop()
|
||||
incomingVerificationRequestHandler.stop()
|
||||
|
|
|
@ -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
|
||||
|
@ -35,11 +34,10 @@ 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,11 +45,10 @@ fun writeToFile(str: String, file: File): Try<Unit> {
|
|||
* 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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -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 ->
|
||||
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
@ -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(
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue