Наведён порядок в DI
This commit is contained in:
@@ -11,12 +11,10 @@ import javax.inject.Singleton
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@Singleton
|
||||
annotation class MainDispatcher
|
||||
|
||||
@Qualifier
|
||||
@Retention(AnnotationRetention.BINARY)
|
||||
@Singleton
|
||||
annotation class IoDispatcher
|
||||
|
||||
@Module
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.nullptroma.wallenc.app.di
|
||||
package com.github.nullptroma.wallenc.app.di.modules.app
|
||||
|
||||
import com.github.nullptroma.wallenc.app.locale.AppLocaleControllerImpl
|
||||
import com.github.nullptroma.wallenc.ui.locale.AppLocaleController
|
||||
@@ -10,10 +10,8 @@ import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class SingletonModule {
|
||||
object LoggerModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLogger(): ILogger {
|
||||
return Logger()
|
||||
}
|
||||
fun provideLogger(): ILogger = Logger()
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.github.nullptroma.wallenc.app.di
|
||||
package com.github.nullptroma.wallenc.app.di.modules.app
|
||||
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.ui.resources.UiStringResolver
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskApiFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApi
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApiFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object NetworkModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexUserInfoApi(): YandexUserInfoApi = YandexUserInfoApiFactory.create()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexDiskApiFactory(
|
||||
yandexAccountStore: YandexAccountStore,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexDiskApiFactory = YandexDiskApiFactory(
|
||||
accountRepository = yandexAccountStore,
|
||||
ioDispatcher = ioDispatcher,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexDiskRepositoryFactory(
|
||||
apiFactory: YandexDiskApiFactory,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexDiskRepositoryFactory = YandexDiskRepositoryFactory(
|
||||
apiFactory = apiFactory,
|
||||
ioDispatcher = ioDispatcher,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexUserInfoRepository(
|
||||
api: YandexUserInfoApi,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexUserInfoRepository = YandexUserInfoRepository(api, ioDispatcher)
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageKeyMapDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageSyncGroupDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.YandexAccountDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageKeyMapRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageSyncGroupRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.YandexAccountRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Room DAO/repository types live in `:infrastructure-android` under `domain.vault` packages.
|
||||
*/
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object PersistenceModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageKeyMapRepository(
|
||||
dao: StorageKeyMapDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): StorageKeyMapRepository = StorageKeyMapRepository(dao, ioDispatcher)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageKeyMapStore(impl: StorageKeyMapRepository): StorageKeyMapStore = impl
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageSyncGroupStore(
|
||||
dao: StorageSyncGroupDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): IStorageSyncGroupStore = StorageSyncGroupRepository(dao, ioDispatcher)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexAccountRepository(
|
||||
dao: YandexAccountDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexAccountRepository = YandexAccountRepository(dao, ioDispatcher)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexAccountStore(impl: YandexAccountRepository): YandexAccountStore = impl
|
||||
}
|
||||
@@ -11,14 +11,16 @@ import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
/** Room types are implemented in `:infrastructure-android` with `domain.vault` packages. */
|
||||
@Module
|
||||
@InstallIn(dagger.hilt.components.SingletonComponent::class)
|
||||
class RoomModule {
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object RoomModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRoomFactory(@ApplicationContext appContext: Context) : RoomFactory {
|
||||
fun provideRoomFactory(@ApplicationContext appContext: Context): RoomFactory {
|
||||
return RoomFactory(appContext)
|
||||
}
|
||||
|
||||
@@ -48,9 +50,7 @@ class RoomModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideAppDb(
|
||||
factory: RoomFactory
|
||||
): IAppDb {
|
||||
fun provideAppDb(factory: RoomFactory): IAppDb {
|
||||
return factory.buildAppDb()
|
||||
}
|
||||
}
|
||||
@@ -1,169 +0,0 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageKeyMapDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageMetaInfoDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.StorageSyncGroupDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.dao.YandexAccountDao
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageKeyMapRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageMetaInfoRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.StorageSyncGroupRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.db.app.repository.YandexAccountRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.YandexDiskApiFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApi
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.YandexUserInfoApiFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
|
||||
import com.github.nullptroma.wallenc.task.runtime.TaskOrchestrator
|
||||
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
|
||||
import com.github.nullptroma.wallenc.domain.vault.vaults.local.LocalVault
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVault
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
|
||||
import com.github.nullptroma.wallenc.vault.contract.VaultRegistrar
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class SingletonModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideTaskOrchestrator(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): ITaskOrchestrator = TaskOrchestrator(ioDispatcher)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexUserInfoApi(): YandexUserInfoApi = YandexUserInfoApiFactory.create()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexDiskApiFactory(
|
||||
yandexAccountStore: YandexAccountStore,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexDiskApiFactory = YandexDiskApiFactory(
|
||||
accountRepository = yandexAccountStore,
|
||||
ioDispatcher = ioDispatcher,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexDiskRepositoryFactory(
|
||||
apiFactory: YandexDiskApiFactory,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): YandexDiskRepositoryFactory = YandexDiskRepositoryFactory(
|
||||
apiFactory = apiFactory,
|
||||
ioDispatcher = ioDispatcher,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideVaultsManager(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
localVault: IVault,
|
||||
keyRepo: StorageKeyMapStore,
|
||||
yandexAccountStore: YandexAccountStore,
|
||||
yandexUserInfoRepository: YandexUserInfoRepository,
|
||||
yandexDiskRepositoryFactory: YandexDiskRepositoryFactory,
|
||||
): VaultsManager {
|
||||
return VaultsManager(
|
||||
ioDispatcher = ioDispatcher,
|
||||
localVault = localVault,
|
||||
keyRepo = keyRepo,
|
||||
yandexAccountStore = yandexAccountStore,
|
||||
yandexUserInfoRepository = yandexUserInfoRepository,
|
||||
yandexDiskRepositoryFactory = yandexDiskRepositoryFactory,
|
||||
)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLocalVault(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context,
|
||||
): IVault = LocalVault(
|
||||
ioDispatcher = ioDispatcher,
|
||||
vaultRoot = context.getExternalFilesDir("LocalVault"),
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideIVaultsManager(impl: VaultsManager): IVaultsManager = impl
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideVaultRegistrar(impl: VaultsManager): VaultRegistrar = impl
|
||||
|
||||
@Provides
|
||||
fun provideUnlockManager(
|
||||
vaultsManager: IVaultsManager
|
||||
): IUnlockManager {
|
||||
return vaultsManager.unlockManager
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageKeyMapRepository(
|
||||
dao: StorageKeyMapDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher
|
||||
): StorageKeyMapRepository {
|
||||
return StorageKeyMapRepository(dao, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageKeyMapStore(
|
||||
impl: StorageKeyMapRepository,
|
||||
): StorageKeyMapStore = impl
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageMetaInfoRepository(
|
||||
dao: StorageMetaInfoDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher
|
||||
): StorageMetaInfoRepository {
|
||||
return StorageMetaInfoRepository(dao, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageSyncGroupStore(
|
||||
dao: StorageSyncGroupDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): IStorageSyncGroupStore = StorageSyncGroupRepository(dao, ioDispatcher)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexAccountRepository(
|
||||
dao: YandexAccountDao,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher
|
||||
): YandexAccountRepository {
|
||||
return YandexAccountRepository(dao, ioDispatcher)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexAccountStore(
|
||||
impl: YandexAccountRepository,
|
||||
): YandexAccountStore = impl
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideYandexUserInfoRepository(
|
||||
api: YandexUserInfoApi,
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher
|
||||
): YandexUserInfoRepository {
|
||||
return YandexUserInfoRepository(api, ioDispatcher)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
|
||||
import com.github.nullptroma.wallenc.task.runtime.TaskOrchestrator
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object TaskModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideTaskOrchestrator(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
): ITaskOrchestrator = TaskOrchestrator(ioDispatcher)
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
|
||||
import com.github.nullptroma.wallenc.vault.contract.VaultRegistrar
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class VaultBindingsModule {
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindVaultsManager(impl: VaultsManager): IVaultsManager
|
||||
|
||||
@Binds
|
||||
@Singleton
|
||||
abstract fun bindVaultRegistrar(impl: VaultsManager): VaultRegistrar
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.data
|
||||
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.app.di.modules.app.IoDispatcher
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVault
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexdisk.repository.YandexDiskRepositoryFactory
|
||||
import com.github.nullptroma.wallenc.domain.vault.network.yandexuserinfo.repository.YandexUserInfoRepository
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.StorageKeyMapStore
|
||||
import com.github.nullptroma.wallenc.domain.vault.ports.YandexAccountStore
|
||||
import com.github.nullptroma.wallenc.domain.vault.vaults.VaultsManager
|
||||
import com.github.nullptroma.wallenc.domain.vault.vaults.local.LocalVault
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import kotlinx.coroutines.CoroutineDispatcher
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
object VaultModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideLocalVault(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
@ApplicationContext context: Context,
|
||||
): IVault = LocalVault(
|
||||
ioDispatcher = ioDispatcher,
|
||||
// getExternalFilesDir may return null before storage is ready; LocalVault handles null root.
|
||||
vaultRoot = context.getExternalFilesDir("LocalVault"),
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideVaultsManager(
|
||||
@IoDispatcher ioDispatcher: CoroutineDispatcher,
|
||||
localVault: IVault,
|
||||
keyRepo: StorageKeyMapStore,
|
||||
yandexAccountStore: YandexAccountStore,
|
||||
yandexUserInfoRepository: YandexUserInfoRepository,
|
||||
yandexDiskRepositoryFactory: YandexDiskRepositoryFactory,
|
||||
): VaultsManager = VaultsManager(
|
||||
ioDispatcher = ioDispatcher,
|
||||
localVault = localVault,
|
||||
keyRepo = keyRepo,
|
||||
yandexAccountStore = yandexAccountStore,
|
||||
yandexUserInfoRepository = yandexUserInfoRepository,
|
||||
yandexDiskRepositoryFactory = yandexDiskRepositoryFactory,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideUnlockManager(vaultsManager: IVaultsManager): IUnlockManager =
|
||||
vaultsManager.unlockManager
|
||||
}
|
||||
@@ -1,131 +1,18 @@
|
||||
package com.github.nullptroma.wallenc.app.di.modules.domain
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncEngine
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
|
||||
import com.github.nullptroma.wallenc.domain.tasks.ITaskOrchestrator
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import com.github.nullptroma.wallenc.usecases.GetOpenedStoragesUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.FindStorageUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.ManageStoragesEncryptionUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.ManageTextSecretsUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.ManageTwoFaTokensUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.ManageVaultUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.RemoveStorageUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.RenameStorageUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.RunStorageSyncUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.ManageStorageSyncGroupsUseCase
|
||||
import com.github.nullptroma.wallenc.usecases.StorageSyncEngine
|
||||
import com.github.nullptroma.wallenc.usecases.StorageSyncReadiness
|
||||
import com.github.nullptroma.wallenc.usecases.StorageFileManagementUseCase
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
class UseCasesModule {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideGetOpenedStoragesUseCase(unlockManager: IUnlockManager): GetOpenedStoragesUseCase {
|
||||
return GetOpenedStoragesUseCase(unlockManager)
|
||||
}
|
||||
abstract class UseCasesModule {
|
||||
|
||||
@Provides
|
||||
@Binds
|
||||
@Singleton
|
||||
fun provideManageVaultUseCase(vaultsManager: IVaultsManager): ManageVaultUseCase {
|
||||
return ManageVaultUseCase(vaultsManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideFindStorageUseCase(vaultsManager: IVaultsManager): FindStorageUseCase {
|
||||
return FindStorageUseCase(vaultsManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageFileManagementUseCase(): StorageFileManagementUseCase {
|
||||
return StorageFileManagementUseCase()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRenameStorageUseCase(): RenameStorageUseCase {
|
||||
return RenameStorageUseCase()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideManageStoragesEncryptionUseCase(
|
||||
unlockManager: IUnlockManager,
|
||||
): ManageStoragesEncryptionUseCase {
|
||||
return ManageStoragesEncryptionUseCase(unlockManager)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRemoveStorageUseCase(
|
||||
vaultsManager: IVaultsManager,
|
||||
unlockManager: IUnlockManager,
|
||||
manageStoragesEncryptionUseCase: ManageStoragesEncryptionUseCase,
|
||||
): RemoveStorageUseCase {
|
||||
return RemoveStorageUseCase(vaultsManager, unlockManager, manageStoragesEncryptionUseCase)
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideManageTwoFaTokensUseCase(): ManageTwoFaTokensUseCase {
|
||||
return ManageTwoFaTokensUseCase()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideManageTextSecretsUseCase(): ManageTextSecretsUseCase {
|
||||
return ManageTextSecretsUseCase()
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageSyncEngine(
|
||||
vaultsManager: IVaultsManager,
|
||||
groupStore: IStorageSyncGroupStore,
|
||||
findStorageUseCase: FindStorageUseCase,
|
||||
): IStorageSyncEngine = StorageSyncEngine(
|
||||
vaultsManager = vaultsManager,
|
||||
groupStore = groupStore,
|
||||
findStorageUseCase = findStorageUseCase,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideManageStorageSyncGroupsUseCase(
|
||||
groupStore: IStorageSyncGroupStore,
|
||||
): ManageStorageSyncGroupsUseCase = ManageStorageSyncGroupsUseCase(groupStore)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorageSyncReadiness(
|
||||
vaultsManager: IVaultsManager,
|
||||
groupStore: IStorageSyncGroupStore,
|
||||
findStorageUseCase: FindStorageUseCase,
|
||||
): StorageSyncReadiness = StorageSyncReadiness(
|
||||
vaultsManager = vaultsManager,
|
||||
groupStore = groupStore,
|
||||
findStorageUseCase = findStorageUseCase,
|
||||
)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideRunStorageSyncUseCase(
|
||||
orchestrator: ITaskOrchestrator,
|
||||
syncEngine: IStorageSyncEngine,
|
||||
syncReadiness: StorageSyncReadiness,
|
||||
): RunStorageSyncUseCase = RunStorageSyncUseCase(
|
||||
orchestrator = orchestrator,
|
||||
syncEngine = syncEngine,
|
||||
syncReadiness = syncReadiness,
|
||||
)
|
||||
abstract fun bindStorageSyncEngine(impl: StorageSyncEngine): IStorageSyncEngine
|
||||
}
|
||||
@@ -14,6 +14,7 @@ kotlin {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compileOnly("javax.inject:javax.inject:1")
|
||||
implementation(project(":domain"))
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.kotlinx.serialization.json)
|
||||
|
||||
@@ -3,8 +3,11 @@ package com.github.nullptroma.wallenc.usecases
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class FindStorageUseCase(
|
||||
@Singleton
|
||||
class FindStorageUseCase @Inject constructor(
|
||||
private val vaultsManager: IVaultsManager,
|
||||
) {
|
||||
fun find(storageUuid: UUID): IStorage? {
|
||||
|
||||
@@ -4,8 +4,13 @@ import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class GetOpenedStoragesUseCase(private val unlockManager: IUnlockManager) {
|
||||
@Singleton
|
||||
class GetOpenedStoragesUseCase @Inject constructor(
|
||||
private val unlockManager: IUnlockManager,
|
||||
) {
|
||||
val openedStorages: StateFlow<Map<UUID, IStorageInfo>>
|
||||
get() = unlockManager.openedStorages
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.StorageSyncGroup
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.StorageSyncGroupEncryptionKind
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
data class StorageSyncCompatibilityInput(
|
||||
val isEncrypted: Boolean,
|
||||
@@ -19,7 +21,8 @@ sealed interface AddStorageToSyncGroupResult {
|
||||
data object MissingEncryptionSecret : AddStorageToSyncGroupResult
|
||||
}
|
||||
|
||||
class ManageStorageSyncGroupsUseCase(
|
||||
@Singleton
|
||||
class ManageStorageSyncGroupsUseCase @Inject constructor(
|
||||
private val groupStore: IStorageSyncGroupStore,
|
||||
) {
|
||||
suspend fun getGroups(): List<StorageSyncGroup> = groupStore.getGroups()
|
||||
|
||||
@@ -7,8 +7,11 @@ import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import com.github.nullptroma.wallenc.domain.tasks.TaskProgress
|
||||
import kotlinx.coroutines.flow.first
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class ManageStoragesEncryptionUseCase(
|
||||
@Singleton
|
||||
class ManageStoragesEncryptionUseCase @Inject constructor(
|
||||
private val unlockManager: IUnlockManager,
|
||||
) {
|
||||
sealed interface CanEncryptResult {
|
||||
|
||||
@@ -21,8 +21,11 @@ import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class ManageTextSecretsUseCase {
|
||||
@Singleton
|
||||
class ManageTextSecretsUseCase @Inject constructor() {
|
||||
private val mutex = Mutex()
|
||||
|
||||
fun observe(storageInfo: IStorageInfo): Flow<List<TextSecretRecord>> {
|
||||
|
||||
@@ -18,8 +18,11 @@ import kotlinx.serialization.json.buildJsonObject
|
||||
import kotlinx.serialization.json.contentOrNull
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class ManageTwoFaTokensUseCase {
|
||||
@Singleton
|
||||
class ManageTwoFaTokensUseCase @Inject constructor() {
|
||||
private val mutex = Mutex()
|
||||
|
||||
fun observe(storageInfo: IStorageInfo): Flow<List<TwoFaTokenRecord>> {
|
||||
|
||||
@@ -9,9 +9,14 @@ import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class ManageVaultUseCase(private val manager: IVaultsManager) {
|
||||
@Singleton
|
||||
class ManageVaultUseCase @Inject constructor(
|
||||
private val manager: IVaultsManager,
|
||||
) {
|
||||
|
||||
/** Найти vault по идентификатору в текущем состоянии. */
|
||||
fun find(vaultUuid: UUID): IVault? =
|
||||
|
||||
@@ -6,8 +6,11 @@ import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVault
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RemoveStorageUseCase(
|
||||
@Singleton
|
||||
class RemoveStorageUseCase @Inject constructor(
|
||||
private val vaultsManager: IVaultsManager,
|
||||
private val unlockManager: IUnlockManager,
|
||||
private val manageStoragesEncryptionUseCase: ManageStoragesEncryptionUseCase,
|
||||
|
||||
@@ -2,8 +2,11 @@ package com.github.nullptroma.wallenc.usecases
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RenameStorageUseCase {
|
||||
@Singleton
|
||||
class RenameStorageUseCase @Inject constructor() {
|
||||
suspend fun rename(storage: IStorageInfo, newName: String) {
|
||||
when (storage) {
|
||||
is IStorage -> storage.rename(newName)
|
||||
|
||||
@@ -12,8 +12,11 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class RunStorageSyncUseCase(
|
||||
@Singleton
|
||||
class RunStorageSyncUseCase @Inject constructor(
|
||||
private val orchestrator: ITaskOrchestrator,
|
||||
private val syncEngine: IStorageSyncEngine,
|
||||
private val syncReadiness: StorageSyncReadiness,
|
||||
|
||||
@@ -4,8 +4,11 @@ import com.github.nullptroma.wallenc.domain.interfaces.IDirectory
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IFile
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class StorageFileManagementUseCase {
|
||||
@Singleton
|
||||
class StorageFileManagementUseCase @Inject constructor() {
|
||||
private var _storage: IStorage? = null
|
||||
|
||||
fun setStorage(storage: IStorageInfo) {
|
||||
|
||||
@@ -16,8 +16,11 @@ import java.time.Instant
|
||||
import java.util.UUID
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.atomic.AtomicLong
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
class StorageSyncEngine(
|
||||
@Singleton
|
||||
class StorageSyncEngine @Inject constructor(
|
||||
private val vaultsManager: IVaultsManager,
|
||||
private val groupStore: IStorageSyncGroupStore,
|
||||
private val findStorageUseCase: FindStorageUseCase,
|
||||
|
||||
@@ -4,11 +4,14 @@ import com.github.nullptroma.wallenc.domain.interfaces.IStorageSyncGroupStore
|
||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||
import kotlinx.coroutines.delay
|
||||
import java.util.UUID
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
/**
|
||||
* Ожидание готовности хранилищ перед синхронизацией (холодный старт из WorkManager).
|
||||
*/
|
||||
class StorageSyncReadiness(
|
||||
@Singleton
|
||||
class StorageSyncReadiness @Inject constructor(
|
||||
private val vaultsManager: IVaultsManager,
|
||||
private val groupStore: IStorageSyncGroupStore,
|
||||
private val findStorageUseCase: FindStorageUseCase,
|
||||
|
||||
Reference in New Issue
Block a user