Удаление кошельков
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -31,3 +31,4 @@ google-services.json
|
|||||||
|
|
||||||
# Android Profiling
|
# Android Profiling
|
||||||
*.hprof
|
*.hprof
|
||||||
|
/app/release
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import java.util.UUID
|
|||||||
|
|
||||||
class LocalStorage(
|
class LocalStorage(
|
||||||
override val uuid: UUID,
|
override val uuid: UUID,
|
||||||
absolutePath: String,
|
val absolutePath: String,
|
||||||
private val ioDispatcher: CoroutineDispatcher,
|
private val ioDispatcher: CoroutineDispatcher,
|
||||||
) : IStorage {
|
) : IStorage {
|
||||||
override val size: StateFlow<Long?>
|
override val size: StateFlow<Long?>
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context
|
|||||||
override val uuid: UUID
|
override val uuid: UUID
|
||||||
get() = TODO("Not yet implemented")
|
get() = TODO("Not yet implemented")
|
||||||
|
|
||||||
private val _storages = MutableStateFlow(listOf<IStorage>())
|
private val _storages = MutableStateFlow(listOf<LocalStorage>())
|
||||||
override val storages: StateFlow<List<IStorage>> = _storages
|
override val storages: StateFlow<List<IStorage>> = _storages
|
||||||
|
|
||||||
private val _isAvailable = MutableStateFlow(false)
|
private val _isAvailable = MutableStateFlow(false)
|
||||||
@@ -48,7 +48,7 @@ class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context
|
|||||||
private suspend fun readStorages() {
|
private suspend fun readStorages() {
|
||||||
val path = path.value
|
val path = path.value
|
||||||
if (path == null || !_isAvailable.value)
|
if (path == null || !_isAvailable.value)
|
||||||
return
|
throw Exception("Not available")
|
||||||
|
|
||||||
val dirs = path.listFiles()?.filter { it.isDirectory }
|
val dirs = path.listFiles()?.filter { it.isDirectory }
|
||||||
if (dirs != null) {
|
if (dirs != null) {
|
||||||
@@ -84,6 +84,17 @@ class LocalVault(private val ioDispatcher: CoroutineDispatcher, context: Context
|
|||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun remove(storage: IStorage) = withContext(ioDispatcher) {
|
override suspend fun remove(storage: IStorage) = withContext(ioDispatcher) {
|
||||||
TODO("Not yet implemented")
|
val path = path.value
|
||||||
|
if (path == null || !_isAvailable.value)
|
||||||
|
throw Exception("Not available")
|
||||||
|
|
||||||
|
val curStorages = _storages.value.toMutableList()
|
||||||
|
val index = curStorages.indexOf(storage)
|
||||||
|
if(index != -1) {
|
||||||
|
val localStorage = curStorages[index]
|
||||||
|
curStorages.removeAt(index)
|
||||||
|
_storages.value = curStorages
|
||||||
|
File(localStorage.absolutePath).deleteRecursively()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.github.nullptroma.wallenc.domain.usecases
|
|||||||
|
|
||||||
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
|
import com.github.nullptroma.wallenc.domain.datatypes.EncryptKey
|
||||||
import com.github.nullptroma.wallenc.domain.encrypt.Encryptor
|
import com.github.nullptroma.wallenc.domain.encrypt.Encryptor
|
||||||
|
import com.github.nullptroma.wallenc.domain.interfaces.IStorage
|
||||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||||
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
import com.github.nullptroma.wallenc.domain.interfaces.IUnlockManager
|
||||||
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
import com.github.nullptroma.wallenc.domain.interfaces.IVaultsManager
|
||||||
@@ -21,4 +22,10 @@ class ManageLocalVaultUseCase(private val manager: IVaultsManager, private val u
|
|||||||
val storage = manager.localVault.createStorage(encInfo)
|
val storage = manager.localVault.createStorage(encInfo)
|
||||||
unlockManager.open(storage, key)
|
unlockManager.open(storage, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun remove(storage: IStorageInfo) {
|
||||||
|
when(storage) {
|
||||||
|
is IStorage -> manager.localVault.remove(storage)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,95 @@
|
|||||||
|
package com.github.nullptroma.wallenc.presentation.elements
|
||||||
|
|
||||||
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.Row
|
||||||
|
import androidx.compose.foundation.layout.Spacer
|
||||||
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
|
import androidx.compose.foundation.layout.padding
|
||||||
|
import androidx.compose.foundation.layout.width
|
||||||
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
|
import androidx.compose.material3.Button
|
||||||
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||||
|
import androidx.compose.material3.MaterialTheme
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.material3.TextField
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.focus.FocusRequester
|
||||||
|
import androidx.compose.ui.focus.focusRequester
|
||||||
|
import androidx.compose.ui.unit.dp
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun TextEditCancelOkDialog(onDismiss: () -> Unit, onConfirmation: (String) -> Unit, title: String, startString: String = "") {
|
||||||
|
var name by remember { mutableStateOf(startString) }
|
||||||
|
val focusRequester = remember { FocusRequester() }
|
||||||
|
BasicAlertDialog(
|
||||||
|
onDismissRequest = { onDismiss() }
|
||||||
|
) {
|
||||||
|
Card {
|
||||||
|
Column(modifier = Modifier.padding(12.dp)) {
|
||||||
|
Text(title, style = MaterialTheme.typography.titleLarge)
|
||||||
|
TextField(modifier = Modifier.focusRequester(focusRequester), value = name, onValueChange = {
|
||||||
|
name = it
|
||||||
|
})
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
|
) {
|
||||||
|
Button(modifier = Modifier.weight(1f), onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
|
Button(modifier = Modifier.weight(1f), onClick = {
|
||||||
|
onConfirmation(name)
|
||||||
|
}) {
|
||||||
|
Text("Ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
|
focusRequester.requestFocus()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@OptIn(ExperimentalMaterial3Api::class)
|
||||||
|
@Composable
|
||||||
|
fun ConfirmationCancelOkDialog(onDismiss: () -> Unit, onConfirmation: () -> Unit, title: String) {
|
||||||
|
BasicAlertDialog(
|
||||||
|
onDismissRequest = { onDismiss() }
|
||||||
|
) {
|
||||||
|
Card {
|
||||||
|
Column(modifier = Modifier.padding(12.dp)) {
|
||||||
|
Text(title, style = MaterialTheme.typography.titleLarge)
|
||||||
|
Spacer(modifier = Modifier.height(24.dp))
|
||||||
|
Row(
|
||||||
|
modifier = Modifier.fillMaxWidth(),
|
||||||
|
horizontalArrangement = Arrangement.SpaceEvenly,
|
||||||
|
) {
|
||||||
|
Button(modifier = Modifier.weight(1f), onClick = onDismiss) {
|
||||||
|
Text("Cancel")
|
||||||
|
}
|
||||||
|
Spacer(modifier = Modifier.width(12.dp))
|
||||||
|
Button(modifier = Modifier.weight(1f), onClick = {
|
||||||
|
onConfirmation()
|
||||||
|
}) {
|
||||||
|
Text("Ok")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,38 +1,26 @@
|
|||||||
package com.github.nullptroma.wallenc.presentation.elements
|
package com.github.nullptroma.wallenc.presentation.elements
|
||||||
|
|
||||||
import android.app.Dialog
|
|
||||||
import androidx.compose.foundation.Image
|
|
||||||
import androidx.compose.foundation.background
|
|
||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.IntrinsicSize
|
import androidx.compose.foundation.layout.IntrinsicSize
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.width
|
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.filled.MoreVert
|
import androidx.compose.material.icons.filled.MoreVert
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
|
||||||
import androidx.compose.material3.Button
|
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
import androidx.compose.material3.CardDefaults
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.Divider
|
|
||||||
import androidx.compose.material3.DropdownMenu
|
import androidx.compose.material3.DropdownMenu
|
||||||
import androidx.compose.material3.DropdownMenuItem
|
import androidx.compose.material3.DropdownMenuItem
|
||||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
import androidx.compose.material3.IconButton
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.LocalTextStyle
|
import androidx.compose.material3.LocalTextStyle
|
||||||
import androidx.compose.material3.MaterialTheme
|
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.TextField
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -41,15 +29,11 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.draw.clip
|
import androidx.compose.ui.draw.clip
|
||||||
import androidx.compose.ui.graphics.Color
|
|
||||||
import androidx.compose.ui.graphics.vector.ImageVector
|
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.text.PlatformTextStyle
|
import androidx.compose.ui.text.PlatformTextStyle
|
||||||
import androidx.compose.ui.text.style.TextAlign
|
import androidx.compose.ui.text.style.TextAlign
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
import androidx.compose.ui.window.Dialog
|
|
||||||
import androidx.compose.ui.window.DialogProperties
|
|
||||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||||
import com.github.nullptroma.wallenc.domain.datatypes.Tree
|
import com.github.nullptroma.wallenc.domain.datatypes.Tree
|
||||||
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
import com.github.nullptroma.wallenc.domain.interfaces.IStorageInfo
|
||||||
@@ -61,6 +45,7 @@ fun StorageTree(
|
|||||||
tree: Tree<IStorageInfo>,
|
tree: Tree<IStorageInfo>,
|
||||||
onClick: (Tree<IStorageInfo>) -> Unit,
|
onClick: (Tree<IStorageInfo>) -> Unit,
|
||||||
onRename: (Tree<IStorageInfo>, String) -> Unit,
|
onRename: (Tree<IStorageInfo>, String) -> Unit,
|
||||||
|
onRemove: (Tree<IStorageInfo>) -> Unit,
|
||||||
) {
|
) {
|
||||||
val cur = tree.value
|
val cur = tree.value
|
||||||
val cardShape = RoundedCornerShape(30.dp)
|
val cardShape = RoundedCornerShape(30.dp)
|
||||||
@@ -100,6 +85,7 @@ fun StorageTree(
|
|||||||
Box(modifier = Modifier.padding(0.dp, 8.dp, 8.dp, 0.dp)) {
|
Box(modifier = Modifier.padding(0.dp, 8.dp, 8.dp, 0.dp)) {
|
||||||
var expanded by remember { mutableStateOf(false) }
|
var expanded by remember { mutableStateOf(false) }
|
||||||
var showRenameDialog by remember { mutableStateOf(false) }
|
var showRenameDialog by remember { mutableStateOf(false) }
|
||||||
|
var showRemoveConfirmationDiaglog by remember { mutableStateOf(false) }
|
||||||
IconButton(onClick = { expanded = !expanded }) {
|
IconButton(onClick = { expanded = !expanded }) {
|
||||||
Icon(
|
Icon(
|
||||||
Icons.Default.MoreVert,
|
Icons.Default.MoreVert,
|
||||||
@@ -117,16 +103,38 @@ fun StorageTree(
|
|||||||
},
|
},
|
||||||
text = { Text(stringResource(R.string.rename)) }
|
text = { Text(stringResource(R.string.rename)) }
|
||||||
)
|
)
|
||||||
|
HorizontalDivider()
|
||||||
|
DropdownMenuItem(
|
||||||
|
onClick = {
|
||||||
|
expanded = false
|
||||||
|
showRemoveConfirmationDiaglog = true;
|
||||||
|
},
|
||||||
|
text = { Text(stringResource(R.string.remove)) }
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showRenameDialog) {
|
if (showRenameDialog) {
|
||||||
RenameDialog(
|
TextEditCancelOkDialog(
|
||||||
onDismiss = { showRenameDialog = false },
|
onDismiss = { showRenameDialog = false },
|
||||||
onConfirmation = { newName ->
|
onConfirmation = { newName ->
|
||||||
showRenameDialog = false
|
showRenameDialog = false
|
||||||
onRename(tree, newName)
|
onRename(tree, newName)
|
||||||
},
|
},
|
||||||
startName = tree.value.metaInfo.value.name ?: ""
|
title = stringResource(R.string.new_name_title),
|
||||||
|
startString = metaInfo.name ?: ""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showRemoveConfirmationDiaglog) {
|
||||||
|
ConfirmationCancelOkDialog(
|
||||||
|
onDismiss = {
|
||||||
|
showRemoveConfirmationDiaglog = false
|
||||||
|
},
|
||||||
|
onConfirmation = {
|
||||||
|
showRemoveConfirmationDiaglog = false
|
||||||
|
onRemove(tree)
|
||||||
|
},
|
||||||
|
title = stringResource(R.string.remove_confirmation_dialog, metaInfo.name ?: "<noname>")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,40 +157,8 @@ fun StorageTree(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (i in tree.children ?: listOf()) {
|
for (i in tree.children ?: listOf()) {
|
||||||
StorageTree(Modifier.padding(16.dp, 0.dp, 0.dp, 0.dp), i, onClick, onRename)
|
StorageTree(Modifier.padding(16.dp, 0.dp, 0.dp, 0.dp), i, onClick, onRename, onRemove)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterial3Api::class)
|
|
||||||
@Composable
|
|
||||||
fun RenameDialog(onDismiss: () -> Unit, onConfirmation: (String) -> Unit, startName: String = "") {
|
|
||||||
var name by remember { mutableStateOf(startName) }
|
|
||||||
BasicAlertDialog(
|
|
||||||
onDismissRequest = { onDismiss() }
|
|
||||||
) {
|
|
||||||
Card {
|
|
||||||
Column(modifier = Modifier.padding(12.dp)) {
|
|
||||||
Text("New name", style = MaterialTheme.typography.titleLarge)
|
|
||||||
TextField(name, {
|
|
||||||
name = it
|
|
||||||
})
|
|
||||||
Spacer(modifier = Modifier.height(24.dp))
|
|
||||||
Row(
|
|
||||||
modifier = Modifier.fillMaxWidth(),
|
|
||||||
horizontalArrangement = Arrangement.SpaceEvenly,
|
|
||||||
) {
|
|
||||||
Button(modifier = Modifier.weight(1f), onClick = onDismiss) {
|
|
||||||
Text("Cancel")
|
|
||||||
}
|
|
||||||
Spacer(modifier = Modifier.width(12.dp))
|
|
||||||
Button(modifier = Modifier.weight(1f), onClick = {
|
|
||||||
onConfirmation(name)
|
|
||||||
}) {
|
|
||||||
Text("Ok")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ fun LocalVaultScreen(
|
|||||||
},
|
},
|
||||||
onRename = { tree, newName ->
|
onRename = { tree, newName ->
|
||||||
viewModel.rename(tree.value, newName)
|
viewModel.rename(tree.value, newName)
|
||||||
|
},
|
||||||
|
onRemove = { tree ->
|
||||||
|
viewModel.remove(tree.value)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,4 +82,10 @@ class LocalVaultViewModel @Inject constructor(
|
|||||||
renameStorageUseCase.rename(storage, newName)
|
renameStorageUseCase.rename(storage, newName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun remove(storage: IStorageInfo) {
|
||||||
|
viewModelScope.launch {
|
||||||
|
manageLocalVaultUseCase.remove(storage)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,5 +9,8 @@
|
|||||||
<string name="no_name"><noname></string>
|
<string name="no_name"><noname></string>
|
||||||
<string name="show_storage_item_menu">Show storage item menu</string>
|
<string name="show_storage_item_menu">Show storage item menu</string>
|
||||||
<string name="rename">Rename</string>
|
<string name="rename">Rename</string>
|
||||||
|
<string name="remove">Remove</string>
|
||||||
|
<string name="new_name_title">New name</string>
|
||||||
|
<string name="remove_confirmation_dialog">Delete storage "%1$s"?</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user