Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
Use toast and remember utils from medzik-android-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
M3DZIK committed Oct 14, 2023
1 parent f817ad5 commit 6b1bea0
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import dev.medzik.android.components.SwitcherPreference
import dev.medzik.android.components.rememberMutableString
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.utils.SecretStore.readKey
import dev.medzik.librepass.android.utils.SecretStore.writeKey
import dev.medzik.librepass.android.utils.StoreKey
import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.TopBarBackIcon
import dev.medzik.librepass.android.utils.rememberStringData
import java.util.Random

enum class PasswordType(val literals: String) {
Expand All @@ -55,7 +55,7 @@ fun PasswordGenerator(navController: NavController) {
val context = LocalContext.current
val clipboardManager = LocalClipboardManager.current

var generatedPassword by rememberStringData()
var generatedPassword by rememberMutableString()

// generator options
var passwordLength by remember { mutableIntStateOf(context.readKey(StoreKey.PasswordLength)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.android.components.rememberMutableString
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.utils.SecretStore.readKey
import dev.medzik.librepass.android.utils.SecretStore.writeKey
import dev.medzik.librepass.android.utils.StoreKey
import dev.medzik.librepass.android.utils.TextInputField
import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.TopBarBackIcon
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.android.utils.rememberStringData

@Composable
fun AddCustomServer(navController: NavController) {
val context = LocalContext.current

var loading by rememberLoadingState()
var server by rememberStringData()
var loading by rememberMutableBoolean()
var server by rememberMutableString()

fun submit(server: String) {
loading = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.PickerDialog
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberDialogState
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.android.components.rememberMutableString
import dev.medzik.android.utils.showToast
import dev.medzik.libcrypto.Hex
import dev.medzik.librepass.android.BuildConfig
import dev.medzik.librepass.android.R
Expand All @@ -37,9 +40,6 @@ import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.TopBarBackIcon
import dev.medzik.librepass.android.utils.UserSecrets
import dev.medzik.librepass.android.utils.exception.handle
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.android.utils.rememberStringData
import dev.medzik.librepass.android.utils.showToast
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.AuthClient
import kotlinx.coroutines.Dispatchers
Expand All @@ -51,10 +51,10 @@ fun LoginScreen(navController: NavController) {

val scope = rememberCoroutineScope()

var loading by rememberLoadingState()
var email by rememberStringData()
var password by rememberStringData()
var server by rememberStringData(Server.PRODUCTION)
var loading by rememberMutableBoolean()
var email by rememberMutableString()
var password by rememberMutableString()
var server by rememberMutableString(Server.PRODUCTION)

val credentialsRepository = context.getRepository().credentials

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.PickerDialog
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberDialogState
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.android.components.rememberMutableString
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.BuildConfig
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.ui.Screen
Expand All @@ -32,9 +35,6 @@ import dev.medzik.librepass.android.utils.TextInputField
import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.TopBarBackIcon
import dev.medzik.librepass.android.utils.exception.handle
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.android.utils.rememberStringData
import dev.medzik.librepass.android.utils.showToast
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.AuthClient
import kotlinx.coroutines.Dispatchers
Expand All @@ -46,12 +46,12 @@ fun RegisterScreen(navController: NavController) {

val scope = rememberCoroutineScope()

var loading by rememberLoadingState()
var email by rememberStringData()
var password by rememberStringData()
var configPassword by rememberStringData()
var passwordHint by rememberStringData()
var server by rememberStringData(Server.PRODUCTION)
var loading by rememberMutableBoolean()
var email by rememberMutableString()
var password by rememberMutableString()
var configPassword by rememberMutableString()
var passwordHint by rememberMutableString()
var server by rememberMutableString(Server.PRODUCTION)

// Register user with given credentials and navigate to log in screen.
fun submit(email: String, password: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ import androidx.fragment.app.FragmentActivity
import androidx.navigation.NavController
import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.android.components.rememberMutableString
import dev.medzik.android.crypto.KeyStore
import dev.medzik.android.utils.showToast
import dev.medzik.libcrypto.Argon2
import dev.medzik.libcrypto.Hex
import dev.medzik.libcrypto.X25519
Expand All @@ -35,9 +38,6 @@ import dev.medzik.librepass.android.utils.TextInputField
import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.UserSecrets
import dev.medzik.librepass.android.utils.exception.EncryptException
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.android.utils.rememberStringData
import dev.medzik.librepass.android.utils.showToast
import dev.medzik.librepass.client.utils.Cryptography
import dev.medzik.librepass.client.utils.Cryptography.computePasswordHash
import kotlinx.coroutines.Dispatchers
Expand All @@ -50,8 +50,8 @@ fun UnlockScreen(navController: NavController) {

val scope = rememberCoroutineScope()

var loading by rememberLoadingState()
var password by rememberStringData()
var loading by rememberMutableBoolean()
var password by rememberMutableString()

val credentials = context.getRepository().credentials.get()!!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
Expand All @@ -28,6 +26,8 @@ import com.google.gson.Gson
import dev.medzik.android.components.LoadingButton
import dev.medzik.android.components.SecondaryText
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberMutable
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.data.CipherTable
import dev.medzik.librepass.android.data.getRepository
Expand All @@ -38,7 +38,6 @@ import dev.medzik.librepass.android.utils.TextInputFieldBase
import dev.medzik.librepass.android.utils.TopBar
import dev.medzik.librepass.android.utils.TopBarBackIcon
import dev.medzik.librepass.android.utils.exception.handle
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.android.utils.shorten
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.CipherClient
Expand All @@ -63,10 +62,8 @@ fun CipherAddEditView(
?: return

val scope = rememberCoroutineScope()
var loading by rememberLoadingState()
var cipherData by remember {
mutableStateOf(baseCipher?.loginData ?: CipherLoginData(name = ""))
}
var loading by rememberMutableBoolean()
var cipherData by rememberMutable(baseCipher?.loginData ?: CipherLoginData(name = ""))

val repository = context.getRepository()
val credentials = repository.credentials.get()!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.navigation.NavController
import dev.medzik.android.components.navigate
import dev.medzik.android.components.rememberMutableBoolean
import dev.medzik.librepass.android.data.CipherTable
import dev.medzik.librepass.android.data.getRepository
import dev.medzik.librepass.android.ui.Argument
import dev.medzik.librepass.android.ui.Screen
import dev.medzik.librepass.android.ui.composables.CipherCard
import dev.medzik.librepass.android.utils.SecretStore.getUserSecrets
import dev.medzik.librepass.android.utils.exception.handle
import dev.medzik.librepass.android.utils.rememberLoadingState
import dev.medzik.librepass.client.Server
import dev.medzik.librepass.client.api.CipherClient
import dev.medzik.librepass.types.cipher.Cipher
Expand All @@ -40,7 +40,7 @@ fun DashboardScreen(navController: NavController) {
val scope = rememberCoroutineScope()

// states
var refreshing by rememberLoadingState()
var refreshing by rememberMutableBoolean()
var ciphers by remember { mutableStateOf(listOf<Cipher>()) }

// database repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ fun SettingsAppearance(navController: NavController) {
modifier = Modifier.padding(innerPadding)
) {
@Composable
fun getThemeTranslation(theme: Int): String {
val themeRes = when (theme) {
ThemeValues.SYSTEM.ordinal -> R.string.Settings_SystemDefault
ThemeValues.LIGHT.ordinal -> R.string.Settings_Light
ThemeValues.DARK.ordinal -> R.string.Settings_Dark
ThemeValues.BLACK.ordinal -> R.string.Settings_Black
// never happens
else -> throw UnsupportedOperationException()
}

return stringResource(themeRes)
fun getThemeTranslation(theme: ThemeValues): String {
return stringResource(
when (theme) {
ThemeValues.SYSTEM -> R.string.Settings_SystemDefault
ThemeValues.LIGHT -> R.string.Settings_Light
ThemeValues.DARK -> R.string.Settings_Dark
ThemeValues.BLACK -> R.string.Settings_Black
}
)
}

val theme = context.readKey(StoreKey.Theme)
Expand All @@ -69,7 +67,7 @@ fun SettingsAppearance(navController: NavController) {
PropertyPreference(
title = stringResource(R.string.Settings_Theme),
icon = { Icon(Icons.Default.DarkMode, contentDescription = null) },
currentValue = getThemeTranslation(theme),
currentValue = getThemeTranslation(ThemeValues.values()[theme]),
onClick = { themeDialogState.show() },
)

Expand Down Expand Up @@ -103,7 +101,7 @@ fun SettingsAppearance(navController: NavController) {
modifier = Modifier
.padding(start = 12.dp)
.fillMaxWidth(),
text = getThemeTranslation(it.ordinal)
text = getThemeTranslation(it)
)
}
}
Expand Down
17 changes: 0 additions & 17 deletions app/src/main/java/dev/medzik/librepass/android/utils/Remember.kt

This file was deleted.

23 changes: 0 additions & 23 deletions app/src/main/java/dev/medzik/librepass/android/utils/Toast.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.medzik.librepass.android.utils.exception

import android.content.Context
import dev.medzik.android.utils.showToast
import dev.medzik.librepass.android.BuildConfig
import dev.medzik.librepass.android.R
import dev.medzik.librepass.android.utils.showToast
import dev.medzik.librepass.client.errors.ApiException
import dev.medzik.librepass.client.errors.ClientException
import kotlinx.coroutines.DelicateCoroutinesApi
Expand Down

0 comments on commit 6b1bea0

Please sign in to comment.