Начало LocalVault

This commit is contained in:
Roman Pytkov
2024-12-20 19:57:42 +03:00
parent 576fc4020c
commit a481868039
18 changed files with 246 additions and 92 deletions

View File

@@ -1,6 +1,9 @@
package com.github.nullptroma.wallenc.presentation.screens.main.screens.local.vault
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material3.Card
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -9,16 +12,22 @@ import androidx.compose.ui.Modifier
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun LocalVaultScreen(modifier: Modifier = Modifier,
viewModel: LocalVaultViewModel = hiltViewModel()) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
Column {
for(storage in uiState.storagesList) {
Text(storage.uuid.toString())
val uiState by viewModel.state.collectAsStateWithLifecycle()
LazyColumn(modifier = modifier) {
items(uiState.storagesList) {
Card {
Column {
Text(it.uuid.toString())
Text("IsAvailable: ${it.isAvailable.value}")
Text("Files: ${it.numberOfFiles.value}")
Text("Size: ${it.size.value}")
}
}
}
}
}

View File

@@ -13,9 +13,10 @@ class LocalVaultViewModel @Inject constructor(private val getAllRawStoragesUseCa
init {
viewModelScope.launch {
getAllRawStoragesUseCase.localStorage.storages.collect {
mutableUiState.value = mutableUiState.value.copy(
val newState = state.value.copy(
storagesList = it
)
updateState(newState)
}
}
}

View File

@@ -4,11 +4,19 @@ package com.github.nullptroma.wallenc.presentation.viewmodel
import androidx.lifecycle.ViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import timber.log.Timber
abstract class ViewModelBase<TState>(initState: TState) : ViewModel() {
protected val mutableUiState = MutableStateFlow<TState>(initState)
private val _state = MutableStateFlow<TState>(initState)
val uiState: StateFlow<TState>
get() = mutableUiState.asStateFlow()
init {
Timber.d("Init ViewModel ${this.javaClass.name}")
}
val state: StateFlow<TState>
get() = _state
protected fun updateState(newState: TState) {
_state.value = newState
}
}