mirror of
https://github.com/anyproto/anytype-kotlin.git
synced 2025-06-08 05:47:05 +09:00
DROID-1386 App | Tech | Release stabilisation fixes 1 (#66)
This commit is contained in:
parent
a99fd4ed82
commit
ad25ecfcaf
3 changed files with 25 additions and 7 deletions
|
@ -72,6 +72,7 @@ abstract class ResultatInteractor<in P, out R> {
|
|||
abstract class ResultInteractor<in P, R>(
|
||||
private val context: CoroutineContext
|
||||
) {
|
||||
@Throws(Exception::class)
|
||||
fun asFlow(params: P): Flow<R> = flow { emit(doWork(params)) }.flowOn(context)
|
||||
|
||||
fun stream(params: P): Flow<Resultat<R>> {
|
||||
|
|
|
@ -19,17 +19,18 @@ import com.anytypeio.anytype.device.BuildProvider
|
|||
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
|
||||
import com.anytypeio.anytype.domain.base.BaseUseCase
|
||||
import com.anytypeio.anytype.domain.base.Interactor
|
||||
import com.anytypeio.anytype.domain.base.fold
|
||||
import com.anytypeio.anytype.domain.config.ConfigStorage
|
||||
import com.anytypeio.anytype.domain.device.ClearFileCache
|
||||
import com.anytypeio.anytype.domain.library.StoreSearchByIdsParams
|
||||
import com.anytypeio.anytype.domain.library.StorelessSubscriptionContainer
|
||||
import com.anytypeio.anytype.domain.misc.UrlBuilder
|
||||
import com.anytypeio.anytype.domain.workspace.FileSpaceUsage
|
||||
import com.anytypeio.anytype.domain.workspace.InterceptFileLimitEvents
|
||||
import com.anytypeio.anytype.presentation.extension.sendSettingsOffloadEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendSettingsStorageEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendSettingsStorageManageEvent
|
||||
import com.anytypeio.anytype.presentation.extension.sendSettingsStorageOffloadEvent
|
||||
import com.anytypeio.anytype.domain.workspace.FileSpaceUsage
|
||||
import com.anytypeio.anytype.domain.workspace.InterceptFileLimitEvents
|
||||
import com.anytypeio.anytype.presentation.spaces.SpaceGradientProvider
|
||||
import com.anytypeio.anytype.presentation.spaces.SpaceIconView
|
||||
import com.anytypeio.anytype.presentation.spaces.spaceIcon
|
||||
|
@ -91,9 +92,18 @@ class FilesStorageViewModel(
|
|||
|
||||
private fun subscribeToFileLimits() {
|
||||
jobs += viewModelScope.launch {
|
||||
fileSpaceUsage.asFlow(Unit).collect { fileLimits ->
|
||||
_fileLimitsState.value = fileLimits
|
||||
}
|
||||
fileSpaceUsage
|
||||
.stream(Unit)
|
||||
.collect { result ->
|
||||
result.fold(
|
||||
onSuccess = {
|
||||
_fileLimitsState.value = it
|
||||
},
|
||||
onFailure = {
|
||||
Timber.e(it, "Error while getting file space usage")
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -58,6 +58,7 @@ import kotlinx.coroutines.flow.MutableSharedFlow
|
|||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.catch
|
||||
import kotlinx.coroutines.flow.combine
|
||||
import kotlinx.coroutines.flow.debounce
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
|
@ -208,7 +209,7 @@ class CollectionViewModel(
|
|||
launch {
|
||||
when (subscription) {
|
||||
Subscription.Favorites -> {
|
||||
favoritesSubsciptionFlow().map { it.map { it as CollectionView } }
|
||||
favoritesSubscriptionFlow().map { it.map { it as CollectionView } }
|
||||
}
|
||||
|
||||
Subscription.Files -> {
|
||||
|
@ -256,6 +257,8 @@ class CollectionViewModel(
|
|||
listOf(CollectionView.EmptySearch(query))
|
||||
else
|
||||
result
|
||||
}.catch {
|
||||
Timber.e(it, "Error in subscription flow")
|
||||
}
|
||||
|
||||
private fun List<ObjectView>.tryAddSections() =
|
||||
|
@ -288,7 +291,7 @@ class CollectionViewModel(
|
|||
}
|
||||
|
||||
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
|
||||
private suspend fun favoritesSubsciptionFlow() =
|
||||
private suspend fun favoritesSubscriptionFlow() =
|
||||
combine(
|
||||
container.subscribe(buildSearchParams()),
|
||||
queryFlow(),
|
||||
|
@ -301,6 +304,8 @@ class CollectionViewModel(
|
|||
listOf(CollectionView.EmptySearch(query))
|
||||
else
|
||||
result
|
||||
}.catch {
|
||||
Timber.e(it, "Error in favorites subscription flow")
|
||||
}
|
||||
|
||||
private fun prepareFavorites(
|
||||
|
@ -768,6 +773,8 @@ class CollectionViewModel(
|
|||
} else {
|
||||
result
|
||||
}
|
||||
}.catch {
|
||||
Timber.e(it, "Error in file subscription flow")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue