1
0
Fork 0
mirror of https://github.com/anyproto/anytype-kotlin.git synced 2025-06-08 05:47:05 +09:00

DROID-1388 Auth | Enhancement | Added usecase setup

DROID-1388 Auth | Enhancement | Added usecase setup
This commit is contained in:
Allan Quatermain 2023-06-13 22:32:14 +03:00 committed by uburoiubu
parent ccc3b955b0
commit 225ff6128a
No known key found for this signature in database
GPG key ID: C8FB80E0A595FBB6
13 changed files with 94 additions and 6 deletions

View file

@ -17,6 +17,9 @@ import com.anytypeio.anytype.domain.config.ConfigStorage
import com.anytypeio.anytype.domain.config.FeaturesConfigProvider
import com.anytypeio.anytype.domain.device.PathProvider
import com.anytypeio.anytype.CrashReporter
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.block.repo.BlockRepository
import com.anytypeio.anytype.domain.`object`.SetupMobileUseCaseSkip
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
import com.anytypeio.anytype.domain.workspace.WorkspaceManager
@ -213,7 +216,8 @@ object SetupNewAccountModule {
objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
spaceGradientProvider: SpaceGradientProvider,
configStorage: ConfigStorage,
crashReporter: CrashReporter
crashReporter: CrashReporter,
setupMobileUseCaseSkip: SetupMobileUseCaseSkip
): SetupNewAccountViewModelFactory {
return SetupNewAccountViewModelFactory(
createAccount = createAccount,
@ -223,7 +227,8 @@ object SetupNewAccountModule {
objectTypesSubscriptionManager = objectTypesSubscriptionManager,
spaceGradientProvider = spaceGradientProvider,
configStorage = configStorage,
crashReporter = crashReporter
crashReporter = crashReporter,
setupMobileUseCaseSkip = setupMobileUseCaseSkip
)
}
@ -244,6 +249,18 @@ object SetupNewAccountModule {
configStorage = configStorage,
workspaceManager = workspaceManager
)
@JvmStatic
@Provides
@PerScreen
fun provideImportUseCase(
dispatchers: AppCoroutineDispatchers,
blockRepository: BlockRepository
) = SetupMobileUseCaseSkip(
repo = blockRepository,
dispatchers = dispatchers
)
}
@Module

View file

@ -220,6 +220,8 @@ class BlockDataRepository(
Undo.Result.Exhausted
}
override suspend fun importUseCaseSkip() = remote.importUseCaseSkip()
override suspend fun redo(
command: Command.Redo
): Redo.Result = try {

View file

@ -72,6 +72,7 @@ interface BlockDataStore {
suspend fun createBookmarkObject(url: Url): Id
suspend fun fetchBookmarkObject(ctx: Id, url: Url)
suspend fun undo(command: Command.Undo): Payload
suspend fun importUseCaseSkip()
suspend fun redo(command: Command.Redo): Payload
suspend fun turnIntoDocument(command: Command.TurnIntoDocument): List<Id>
suspend fun paste(command: Command.Paste): Response.Clipboard.Paste

View file

@ -72,6 +72,7 @@ interface BlockRemote {
suspend fun createBookmarkObject(url: Url): Id
suspend fun fetchBookmarkObject(ctx: Id, url: Url)
suspend fun undo(command: Command.Undo): Payload
suspend fun importUseCaseSkip()
suspend fun redo(command: Command.Redo): Payload
suspend fun turnIntoDocument(command: Command.TurnIntoDocument): List<Id>
suspend fun paste(command: Command.Paste): Response.Clipboard.Paste

View file

@ -166,6 +166,8 @@ class BlockRemoteDataStore(private val remote: BlockRemote) : BlockDataStore {
override suspend fun undo(command: Command.Undo) = remote.undo(command)
override suspend fun importUseCaseSkip() = remote.importUseCaseSkip()
override suspend fun redo(command: Command.Redo) = remote.redo(command)
override suspend fun turnIntoDocument(

View file

@ -129,6 +129,9 @@ interface BlockRepository {
suspend fun fetchBookmarkObject(ctx: Id, url: Url)
suspend fun undo(command: Command.Undo): Undo.Result
suspend fun importUseCaseSkip()
suspend fun redo(command: Command.Redo): Redo.Result
suspend fun copy(command: Command.Copy): Response.Clipboard.Copy

View file

@ -0,0 +1,16 @@
package com.anytypeio.anytype.domain.`object`
import com.anytypeio.anytype.domain.base.AppCoroutineDispatchers
import com.anytypeio.anytype.domain.base.ResultInteractor
import com.anytypeio.anytype.domain.block.repo.BlockRepository
class SetupMobileUseCaseSkip(
private val repo: BlockRepository,
dispatchers: AppCoroutineDispatchers
): ResultInteractor<Unit, Unit>(dispatchers.io) {
override suspend fun doWork(params: Unit) {
repo.importUseCaseSkip()
}
}

View file

@ -186,6 +186,8 @@ class BlockMiddleware(
command: Command.Undo
): Payload = middleware.objectUndo(command)
override suspend fun importUseCaseSkip() = middleware.objectImportUseCaseSkip()
override suspend fun redo(
command: Command.Redo
): Payload = middleware.objectRedo(command)

View file

@ -1552,6 +1552,16 @@ class Middleware(
return response.event.toPayload()
}
@Throws(Exception::class)
fun objectImportUseCaseSkip() {
val request = Rpc.Object.ImportUseCase.Request(
useCase = Rpc.Object.ImportUseCase.Request.UseCase.SKIP
)
if (BuildConfig.DEBUG) logRequest(request)
val response = service.objectImportUseCase(request)
if (BuildConfig.DEBUG) logResponse(response)
}
@Throws(Exception::class)
fun versionGet(): Rpc.App.GetVersion.Response {
val request = Rpc.App.GetVersion.Request()

View file

@ -122,6 +122,9 @@ interface MiddlewareService {
@Throws(Exception::class)
fun objectUndo(request: Rpc.Object.Undo.Request): Rpc.Object.Undo.Response
@Throws(Exception::class)
fun objectImportUseCase(request: Rpc.Object.ImportUseCase.Request): Rpc.Object.ImportUseCase.Response
@Throws(Exception::class)
fun objectRedo(request: Rpc.Object.Redo.Request): Rpc.Object.Redo.Response

View file

@ -1103,6 +1103,17 @@ class MiddlewareServiceImplementation @Inject constructor(
}
}
override fun objectImportUseCase(request: Rpc.Object.ImportUseCase.Request): Rpc.Object.ImportUseCase.Response {
val encoded = Service.objectImportUseCase(Rpc.Object.ImportUseCase.Request.ADAPTER.encode(request))
val response = Rpc.Object.ImportUseCase.Response.ADAPTER.decode(encoded)
val error = response.error
if (error != null && error.code != Rpc.Object.ImportUseCase.Response.Error.Code.NULL) {
throw Exception(error.description)
} else {
return response
}
}
override fun unsplashDownload(request: Rpc.Unsplash.Download.Request): Rpc.Unsplash.Download.Response {
val encoded = Service.unsplashDownload(
Rpc.Unsplash.Download.Request.ADAPTER.encode(request)

View file

@ -10,7 +10,9 @@ import com.anytypeio.anytype.analytics.base.EventsDictionary
import com.anytypeio.anytype.core_models.exceptions.CreateAccountException
import com.anytypeio.anytype.core_utils.common.EventWrapper
import com.anytypeio.anytype.domain.auth.interactor.CreateAccount
import com.anytypeio.anytype.domain.base.fold
import com.anytypeio.anytype.domain.config.ConfigStorage
import com.anytypeio.anytype.domain.`object`.SetupMobileUseCaseSkip
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
import com.anytypeio.anytype.presentation.auth.model.Session
@ -38,7 +40,8 @@ class SetupNewAccountViewModel(
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
private val spaceGradientProvider: SpaceGradientProvider,
private val configStorage: ConfigStorage,
private val crashReporter: CrashReporter
private val crashReporter: CrashReporter,
private val setupMobileUseCaseSkip: SetupMobileUseCaseSkip
) : ViewModel(), SupportNavigation<EventWrapper<AppNavigation.Command>> {
override val navigation: MutableLiveData<EventWrapper<AppNavigation.Command>> =
@ -96,7 +99,7 @@ class SetupNewAccountViewModel(
else -> {
_state.postValue(
SetupNewAccountViewState.Error(
"Error while creating an account: ${error.message ?:"Unknown error"}"
"Error while creating an account: ${error.message ?: "Unknown error"}"
)
)
}
@ -109,6 +112,20 @@ class SetupNewAccountViewModel(
_state.postValue(SetupNewAccountViewState.Success)
relationsSubscriptionManager.onStart()
objectTypesSubscriptionManager.onStart()
setupUseCase()
}
)
}
}
private fun setupUseCase() {
viewModelScope.launch {
setupMobileUseCaseSkip.execute(Unit).fold(
onFailure = {
Timber.e(it, "Error while importing use case")
navigateToDashboard()
},
onSuccess = {
navigateToDashboard()
}
)

View file

@ -6,6 +6,7 @@ import com.anytypeio.anytype.CrashReporter
import com.anytypeio.anytype.analytics.base.Analytics
import com.anytypeio.anytype.domain.auth.interactor.CreateAccount
import com.anytypeio.anytype.domain.config.ConfigStorage
import com.anytypeio.anytype.domain.`object`.SetupMobileUseCaseSkip
import com.anytypeio.anytype.domain.search.ObjectTypesSubscriptionManager
import com.anytypeio.anytype.domain.search.RelationsSubscriptionManager
import com.anytypeio.anytype.presentation.auth.model.Session
@ -19,7 +20,8 @@ class SetupNewAccountViewModelFactory(
private val objectTypesSubscriptionManager: ObjectTypesSubscriptionManager,
private val spaceGradientProvider: SpaceGradientProvider,
private val configStorage: ConfigStorage,
private val crashReporter: CrashReporter
private val crashReporter: CrashReporter,
private val setupMobileUseCaseSkip: SetupMobileUseCaseSkip
) : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
@ -32,7 +34,8 @@ class SetupNewAccountViewModelFactory(
objectTypesSubscriptionManager = objectTypesSubscriptionManager,
spaceGradientProvider = spaceGradientProvider,
configStorage = configStorage,
crashReporter = crashReporter
crashReporter = crashReporter,
setupMobileUseCaseSkip = setupMobileUseCaseSkip
) as T
}
}