This commit is contained in:
Roman Pytkov
2024-12-17 21:13:41 +03:00
parent 7bfcd32d27
commit b5462dfd2f
19 changed files with 1088 additions and 924 deletions

View File

@@ -7,6 +7,7 @@ import androidx.activity.enableEdgeToEdge
import com.github.nullptroma.wallenc.presentation.WallencUi import com.github.nullptroma.wallenc.presentation.WallencUi
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
class Container<T>(val value: T)
@AndroidEntryPoint @AndroidEntryPoint
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
@@ -18,7 +19,8 @@ class MainActivity : ComponentActivity() {
// val launcher = // val launcher =
// registerForActivityResult(sdk.contract) { result -> handleResult(result) } // registerForActivityResult(sdk.contract) { result -> handleResult(result) }
// val loginOptions = YandexAuthLoginOptions(LoginType.CHROME_TAB) // val loginOptions = YandexAuthLoginOptions(LoginType.CHROME_TAB)
val cont1 = Container(true)
var cont2 = Container<Boolean>(true)
setContent { setContent {
WallencUi() WallencUi()
} }

View File

@@ -1,7 +1,6 @@
plugins { plugins {
alias(libs.plugins.android.library) alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.android) alias(libs.plugins.kotlin.android)
alias(libs.plugins.dagger.hilt)
alias(libs.plugins.ksp) alias(libs.plugins.ksp)
} }
@@ -35,10 +34,6 @@ android {
} }
dependencies { dependencies {
// Hilt
implementation(libs.dagger.hilt)
ksp(libs.dagger.hilt.compiler)
// Room // Room
implementation(libs.room.ktx) implementation(libs.room.ktx)
implementation(libs.room.runtime) implementation(libs.room.runtime)

View File

@@ -1,20 +0,0 @@
package com.github.nullptroma.wallenc.data
import com.github.nullptroma.wallenc.domain.models.IMetaInfo
import java.net.URI
import java.time.LocalDateTime
class TestImpl : IMetaInfo {
override val name: String
get() = "Hello225"
override val size: Int
get() = 10
override val isDeleted: Boolean
get() = true
override val isHidden: Boolean
get() = true
override val lastModified: LocalDateTime
get() = TODO("Not yet implemented")
override val path: URI
get() = URI("/Hello/path")
}

View File

@@ -1,18 +0,0 @@
package com.github.nullptroma.wallenc.data.di
import com.github.nullptroma.wallenc.data.TestImpl
import com.github.nullptroma.wallenc.domain.models.IMetaInfo
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
@Module
@InstallIn(SingletonComponent::class)
class SingletonModule {
@Provides
fun provideIMeta() : IMetaInfo {
return TestImpl()
}
}

View File

@@ -0,0 +1,53 @@
package com.github.nullptroma.wallenc.data.vaults
import android.content.Context
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
import com.github.nullptroma.wallenc.domain.enums.VaultType
import com.github.nullptroma.wallenc.domain.models.IStorage
import com.github.nullptroma.wallenc.domain.models.IVault
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.UUID
class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context) : IVault {
init {
CoroutineScope(ioDispatcher).launch {
}
}
override suspend fun createStorage(name: String): IStorage = withContext(ioDispatcher) {
TODO("Not yet implemented")
}
override suspend fun createStorage(
name: String,
key: EncryptKey
): IStorage = withContext(ioDispatcher) {
TODO("Not yet implemented")
}
override suspend fun createStorage(
name: String,
key: EncryptKey,
uuid: UUID
): IStorage = withContext(ioDispatcher) {
TODO("Not yet implemented")
}
override suspend fun remove(storage: IStorage) = withContext(ioDispatcher) {
TODO("Not yet implemented")
}
override val type: VaultType = VaultType.LOCAL
override val uuid: UUID
get() = TODO("Not yet implemented")
override val storages: StateFlow<List<IStorage>>
get() = TODO("Not yet implemented")
override val isAvailable: StateFlow<Boolean>
get() = TODO("Not yet implemented")
}

View File

@@ -0,0 +1,5 @@
package com.github.nullptroma.wallenc.data.vaults
class VaultsManager {
}

View File

@@ -1,8 +1,7 @@
package com.github.nullptroma.wallenc.domain.utils package com.github.nullptroma.wallenc.domain.datatypes
open class DataPackage<T>( open class DataPackage<T>(
val data: T, val data: T,
val hasNext: Boolean? = false,
val isLoading: Boolean? = false, val isLoading: Boolean? = false,
val isError: Boolean? = false val isError: Boolean? = false
) )

View File

@@ -1,7 +1,8 @@
package com.github.nullptroma.wallenc.domain.utils package com.github.nullptroma.wallenc.domain.datatypes
class DataPage<T>( class DataPage<T>(
list: List<T>, list: List<T>,
val hasNext: Boolean? = false,
val pageLength: Int, val pageLength: Int,
val pageNumber: Int val pageNumber: Int
) : DataPackage<List<T>>(list) ) : DataPackage<List<T>>(list)

View File

@@ -0,0 +1,9 @@
package com.github.nullptroma.wallenc.domain.datatypes
class EncryptKey {
val key: String
constructor(key: String) {
this@EncryptKey.key = key
}
}

View File

@@ -0,0 +1,6 @@
package com.github.nullptroma.wallenc.domain.enums
enum class VaultType {
LOCAL,
YANDEX
}

View File

@@ -1,11 +1,12 @@
package com.github.nullptroma.wallenc.domain.storage package com.github.nullptroma.wallenc.domain.models
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import java.util.UUID
interface IStorage { interface IStorage {
val size: StateFlow<Int> val size: StateFlow<Int?>
val numberOfFiles: StateFlow<Int> val numberOfFiles: StateFlow<Int?>
val uuid: String val uuid: UUID
val name: StateFlow<String> val name: StateFlow<String>
val totalSpace: StateFlow<Int?> val totalSpace: StateFlow<Int?>
val availableSpace: StateFlow<Int?> val availableSpace: StateFlow<Int?>

View File

@@ -0,0 +1,42 @@
package com.github.nullptroma.wallenc.domain.models
import com.github.nullptroma.wallenc.domain.datatypes.DataPackage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import java.io.InputStream
import java.io.OutputStream
import java.net.URI
interface IStorageAccessor {
val isAvailable: StateFlow<Boolean>
val filesUpdates: SharedFlow<DataPackage<IFile>>
val dirsUpdates: SharedFlow<DataPackage<IDirectory>>
suspend fun getAllFiles(): List<IFile>
suspend fun getFiles(path: URI): List<IFile>
/**
* Получение списка файлов в директории
* @param path Путь к директории
* @return Поток файлов
*/
fun getFilesFlow(path: URI): Flow<DataPackage<IFile>>
suspend fun getAllDirs(): List<IDirectory>
suspend fun getDirs(path: URI): List<IDirectory>
/**
* Получение списка директорий в директории
* @param path Путь к директории
* @return Поток директорий
*/
fun getDirsFlow(path: URI): Flow<DataPackage<IDirectory>>
suspend fun touchFile(path: URI)
suspend fun touchDir(path: URI)
suspend fun delete(path: URI)
suspend fun getFileInfo(path: URI)
suspend fun getDirInfo(path: URI)
suspend fun openWrite(path: URI): InputStream
suspend fun openRead(path: URI): OutputStream
suspend fun moveToTrash(path: URI)
}

View File

@@ -0,0 +1,11 @@
package com.github.nullptroma.wallenc.domain.models
import kotlinx.coroutines.flow.StateFlow
import java.net.URL
interface IStorageExplorer {
val currentPath: StateFlow<URL>
// TODO
// пока бесполезный интерфейс
}

View File

@@ -0,0 +1,11 @@
package com.github.nullptroma.wallenc.domain.models
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
import java.util.UUID
interface IVault : IVaultInfo {
suspend fun createStorage(name: String): IStorage
suspend fun createStorage(name: String, key: EncryptKey): IStorage
suspend fun createStorage(name: String, key: EncryptKey, uuid: UUID): IStorage
suspend fun remove(storage: IStorage)
}

View File

@@ -0,0 +1,12 @@
package com.github.nullptroma.wallenc.domain.models
import com.github.nullptroma.wallenc.domain.enums.VaultType
import kotlinx.coroutines.flow.StateFlow
import java.util.UUID
interface IVaultInfo {
val type: VaultType
val uuid: UUID
val storages: StateFlow<List<IStorage>>
val isAvailable: StateFlow<Boolean>
}

View File

@@ -0,0 +1,10 @@
package com.github.nullptroma.wallenc.domain.models
import kotlinx.coroutines.flow.StateFlow
interface IVaultsManager {
val localVault: StateFlow<IVault>
val remoteVaults: StateFlow<List<IVault>>
fun addYandexVault(email: String, token: String)
}

View File

@@ -1,32 +0,0 @@
package com.github.nullptroma.wallenc.domain.storage
import com.github.nullptroma.wallenc.domain.models.IDirectory
import com.github.nullptroma.wallenc.domain.models.IFile
import com.github.nullptroma.wallenc.domain.utils.DataPackage
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import java.net.URI
interface IStorageAccessor {
val isAvailable: StateFlow<Boolean>
val filesUpdates: SharedFlow<IFile>
val dirsUpdates: SharedFlow<IDirectory>
suspend fun getAllFiles(): List<IFile>
suspend fun getFiles(path: URI): List<IFile>
fun getFilesStream(path: URI): Flow<DataPackage<IFile>>
suspend fun getAllDirs(): List<IDirectory>
suspend fun getDirs(path: URI): List<IDirectory>
fun getDirsStream(path: URI): Flow<DataPackage<IDirectory>>
suspend fun touchFile(path: URI)
suspend fun touchDir(path: URI)
suspend fun delete(path: URI)
suspend fun getFileInfo(path: URI)
suspend fun getDirInfo(path: URI)
suspend fun openWrite(path: URI)
suspend fun openRead(path: URI)
suspend fun moveToTrash(path: URI)
}

View File

@@ -0,0 +1,14 @@
package com.github.nullptroma.wallenc.domain.usecases
import com.github.nullptroma.wallenc.domain.models.IVault
import com.github.nullptroma.wallenc.domain.models.IVaultsManager
import kotlinx.coroutines.flow.combine
class GetAllRawStoragesUseCase(val manager: IVaultsManager) {
fun getStoragesFlow() = manager.remoteVaults.combine(manager.localVault) { remote, local ->
mutableListOf<IVault>().apply {
addAll(remote)
add(local)
}
}
}

File diff suppressed because it is too large Load Diff