Начат LocalStorage, выкинут мусор из UiState
This commit is contained in:
@@ -34,6 +34,9 @@ android {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// Timber
|
||||
implementation(libs.timber)
|
||||
|
||||
// Room
|
||||
implementation(libs.room.ktx)
|
||||
implementation(libs.room.runtime)
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.github.nullptroma.wallenc.data
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.models.IStorage
|
||||
import com.github.nullptroma.wallenc.domain.models.IStorageAccessor
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import java.util.UUID
|
||||
|
||||
class MockStorage(
|
||||
override val size: StateFlow<Int?> = MutableStateFlow(null),
|
||||
override val numberOfFiles: StateFlow<Int?> = MutableStateFlow(null),
|
||||
override val uuid: UUID,
|
||||
override val name: StateFlow<String> = MutableStateFlow(""),
|
||||
override val totalSpace: StateFlow<Int?> = MutableStateFlow(null),
|
||||
override val availableSpace: StateFlow<Int?> = MutableStateFlow(null),
|
||||
override val isAvailable: StateFlow<Boolean> = MutableStateFlow(false),
|
||||
override val accessor: IStorageAccessor
|
||||
) : IStorage {
|
||||
|
||||
override suspend fun rename(newName: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,16 @@
|
||||
package com.github.nullptroma.wallenc.data.vaults
|
||||
|
||||
class VaultsManager {
|
||||
import com.github.nullptroma.wallenc.data.vaults.local.LocalVault
|
||||
import com.github.nullptroma.wallenc.domain.models.IVault
|
||||
import com.github.nullptroma.wallenc.domain.models.IVaultsManager
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
class VaultsManager(override val localVault: LocalVault) : IVaultsManager {
|
||||
override val remoteVaults: StateFlow<List<IVault>>
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
override fun addYandexVault(email: String, token: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.github.nullptroma.wallenc.data.vaults.local
|
||||
|
||||
import com.github.nullptroma.wallenc.domain.datatypes.DataPackage
|
||||
import com.github.nullptroma.wallenc.domain.models.IDirectory
|
||||
import com.github.nullptroma.wallenc.domain.models.IFile
|
||||
import com.github.nullptroma.wallenc.domain.models.IStorageAccessor
|
||||
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
|
||||
|
||||
class LocalStorageAccessor : IStorageAccessor {
|
||||
override val isAvailable: StateFlow<Boolean>
|
||||
get() = TODO("Not yet implemented")
|
||||
override val filesUpdates: SharedFlow<DataPackage<IFile>>
|
||||
get() = TODO("Not yet implemented")
|
||||
override val dirsUpdates: SharedFlow<DataPackage<IDirectory>>
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
override suspend fun getAllFiles(): List<IFile> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getFiles(path: URI): List<IFile> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getFilesFlow(path: URI): Flow<DataPackage<IFile>> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getAllDirs(): List<IDirectory> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getDirs(path: URI): List<IDirectory> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getDirsFlow(path: URI): Flow<DataPackage<IDirectory>> {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun touchFile(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun touchDir(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun delete(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getFileInfo(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun getDirInfo(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun openWrite(path: URI): InputStream {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun openRead(path: URI): OutputStream {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override suspend fun moveToTrash(path: URI) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,37 @@
|
||||
package com.github.nullptroma.wallenc.data.vaults
|
||||
package com.github.nullptroma.wallenc.data.vaults.local
|
||||
|
||||
import android.content.Context
|
||||
import com.github.nullptroma.wallenc.data.MockStorage
|
||||
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.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.UUID
|
||||
import kotlin.io.path.Path
|
||||
import kotlin.io.path.createDirectory
|
||||
|
||||
class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context) : IVault {
|
||||
private val path = context.getExternalFilesDir("LocalVault")
|
||||
private val _storages = MutableStateFlow(listOf<IStorage>())
|
||||
|
||||
init {
|
||||
CoroutineScope(ioDispatcher).launch {
|
||||
if(path == null)
|
||||
return@launch
|
||||
|
||||
val dirs = path.listFiles()?.filter { it.isDirectory }
|
||||
if(dirs != null)
|
||||
_storages.value = dirs.map {
|
||||
MockStorage(uuid = UUID.fromString(it.name), accessor = LocalStorageAccessor())
|
||||
}
|
||||
val next = Path(path.path, UUID.randomUUID().toString())
|
||||
next.createDirectory()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +62,7 @@ class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context
|
||||
override val uuid: UUID
|
||||
get() = TODO("Not yet implemented")
|
||||
override val storages: StateFlow<List<IStorage>>
|
||||
get() = TODO("Not yet implemented")
|
||||
get() = _storages
|
||||
override val isAvailable: StateFlow<Boolean>
|
||||
get() = TODO("Not yet implemented")
|
||||
|
||||
Reference in New Issue
Block a user