split serveur config and login
CI / lint-backend (push) Successful in 1m42s
CI / lint-mobile (push) Canceled after 5m5s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
CI / lint-backend (push) Successful in 1m42s
CI / lint-mobile (push) Canceled after 5m5s
CI / test-backend (push) Canceled after 0s
CI / test-mobile (push) Canceled after 0s
CI / build-backend (push) Canceled after 0s
CI / docker (push) Canceled after 0s
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.kazier.mobile.ui.settings
|
||||
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.horizontalScroll
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
@@ -17,21 +16,24 @@ import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.DarkMode
|
||||
import androidx.compose.material.icons.filled.Dns
|
||||
import androidx.compose.material.icons.filled.Folder
|
||||
import androidx.compose.material.icons.filled.Person
|
||||
import androidx.compose.material3.AlertDialog
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.FilterChip
|
||||
import androidx.compose.material3.HorizontalDivider
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedButton
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.RadioButton
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.material3.TopAppBar
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
@@ -48,7 +50,6 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import com.kazier.mobile.R
|
||||
import com.kazier.mobile.domain.ThemePreference
|
||||
import com.kazier.mobile.features.connection.ConnectionStatusViewModel
|
||||
import com.kazier.mobile.features.connection.ServerConnectionStatus
|
||||
import com.kazier.mobile.features.sync.SyncViewModel
|
||||
import com.kazier.mobile.ui.auth.AuthState
|
||||
import com.kazier.mobile.ui.auth.AuthViewModel
|
||||
@@ -80,6 +81,17 @@ fun SettingsScreen(
|
||||
|
||||
var username by rememberSaveable { mutableStateOf("") }
|
||||
var password by rememberSaveable { mutableStateOf("") }
|
||||
var showThemeDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showServerDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showAuthDialog by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
// Login réussi → refermer le dialogue et purger le mot de passe.
|
||||
LaunchedEffect(authState) {
|
||||
if (authState is AuthState.SignedIn) {
|
||||
showAuthDialog = false
|
||||
password = ""
|
||||
}
|
||||
}
|
||||
|
||||
Scaffold(
|
||||
topBar = {
|
||||
@@ -106,8 +118,8 @@ fun SettingsScreen(
|
||||
.verticalScroll(rememberScrollState()),
|
||||
) {
|
||||
HorizontalDivider()
|
||||
// M36 : 3 états (Système/Clair/Sombre) — le Switch DARK/LIGHT
|
||||
// rendait SYSTEM inatteignable alors que le store le supporte.
|
||||
// Une ligne par section — le détail vit dans un dialogue,
|
||||
// comme les dossiers système surveillés.
|
||||
SettingsRow(
|
||||
icon = { Icon(Icons.Filled.DarkMode, contentDescription = null) },
|
||||
title = stringResource(R.string.settings_theme),
|
||||
@@ -118,12 +130,7 @@ fun SettingsScreen(
|
||||
ThemePreference.SYSTEM -> R.string.settings_theme_system
|
||||
},
|
||||
),
|
||||
trailing = {
|
||||
ThemeSelector(
|
||||
selected = theme,
|
||||
onSelect = viewModel::setTheme,
|
||||
)
|
||||
},
|
||||
onClick = { showThemeDialog = true },
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
@@ -138,72 +145,89 @@ fun SettingsScreen(
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
SettingsSectionTitle(stringResource(R.string.settings_server))
|
||||
|
||||
OutlinedTextField(
|
||||
value = serverUrl,
|
||||
onValueChange = viewModel::onServerUrlChange,
|
||||
label = { Text(stringResource(R.string.settings_server_url)) },
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Uri,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
)
|
||||
Row(
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = viewModel::testConnection,
|
||||
enabled = !testUiState.isTesting,
|
||||
) {
|
||||
if (testUiState.isTesting) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(18.dp),
|
||||
strokeWidth = 2.dp,
|
||||
)
|
||||
} else {
|
||||
Text(stringResource(R.string.settings_test_connection))
|
||||
}
|
||||
}
|
||||
testUiState.success?.let { success ->
|
||||
Spacer(Modifier.size(16.dp))
|
||||
Text(
|
||||
text = stringResource(
|
||||
if (success) R.string.settings_test_success
|
||||
else R.string.settings_test_failure,
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (success) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.error
|
||||
SettingsRow(
|
||||
icon = { Icon(Icons.Filled.Dns, contentDescription = null) },
|
||||
title = stringResource(R.string.settings_server),
|
||||
subtitle = serverUrl.ifBlank {
|
||||
stringResource(R.string.settings_server_hint)
|
||||
},
|
||||
onClick = { showServerDialog = true },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
when (val state = authState) {
|
||||
is AuthState.SignedIn -> {
|
||||
val signedIn = authState as? AuthState.SignedIn
|
||||
SettingsRow(
|
||||
icon = { Icon(Icons.Filled.Person, contentDescription = null) },
|
||||
title = stringResource(R.string.settings_connected_as, state.user.username),
|
||||
subtitle = serverStatusLabel(connectionStatus),
|
||||
trailing = {
|
||||
TextButton(onClick = authViewModel::signOutToLocal) {
|
||||
title = stringResource(
|
||||
if (signedIn != null) R.string.settings_disconnect
|
||||
else R.string.settings_connect,
|
||||
),
|
||||
subtitle = when (val state = authState) {
|
||||
is AuthState.SignedIn ->
|
||||
stringResource(R.string.settings_connected_as, state.user.username)
|
||||
AuthState.Local -> stringResource(R.string.status_local)
|
||||
AuthState.Loading -> stringResource(R.string.status_checking)
|
||||
else -> stringResource(R.string.settings_sign_in_hint)
|
||||
},
|
||||
onClick = { showAuthDialog = true },
|
||||
)
|
||||
|
||||
HorizontalDivider()
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
|
||||
if (showThemeDialog) {
|
||||
ThemeDialog(
|
||||
selected = theme,
|
||||
onSelect = viewModel::setTheme,
|
||||
onDismiss = { showThemeDialog = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (showServerDialog) {
|
||||
ServerDialog(
|
||||
serverUrl = serverUrl,
|
||||
onServerUrlChange = viewModel::onServerUrlChange,
|
||||
isTesting = testUiState.isTesting,
|
||||
success = testUiState.success,
|
||||
onTest = viewModel::testConnection,
|
||||
onDismiss = { showServerDialog = false },
|
||||
)
|
||||
}
|
||||
|
||||
if (showAuthDialog) {
|
||||
when (val state = authState) {
|
||||
is AuthState.SignedIn -> {
|
||||
AlertDialog(
|
||||
onDismissRequest = { showAuthDialog = false },
|
||||
title = { Text(stringResource(R.string.settings_disconnect)) },
|
||||
text = {
|
||||
Text(stringResource(R.string.settings_disconnect_confirm, state.user.username))
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(
|
||||
onClick = {
|
||||
authViewModel.signOutToLocal()
|
||||
showAuthDialog = false
|
||||
},
|
||||
) {
|
||||
Text(stringResource(R.string.settings_disconnect))
|
||||
}
|
||||
},
|
||||
dismissButton = {
|
||||
TextButton(onClick = { showAuthDialog = false }) {
|
||||
Text(stringResource(R.string.settings_cancel))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
AuthState.Loading -> Unit
|
||||
else -> {
|
||||
SettingsSectionTitle(stringResource(R.string.settings_connect))
|
||||
AlertDialog(
|
||||
onDismissRequest = { showAuthDialog = false },
|
||||
title = { Text(stringResource(R.string.settings_connect)) },
|
||||
text = {
|
||||
LoginForm(
|
||||
username = username,
|
||||
onUsernameChange = { username = it },
|
||||
@@ -213,58 +237,132 @@ fun SettingsScreen(
|
||||
errorRes = loginUi.error?.let(::authErrorResFor),
|
||||
submitLabel = stringResource(R.string.settings_connect),
|
||||
onSubmit = { authViewModel.signIn(username, password) },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 16.dp),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
},
|
||||
confirmButton = {},
|
||||
)
|
||||
Spacer(Modifier.height(12.dp))
|
||||
}
|
||||
}
|
||||
|
||||
HorizontalDivider()
|
||||
Spacer(Modifier.height(16.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ThemeSelector(
|
||||
private fun ThemeDialog(
|
||||
selected: ThemePreference,
|
||||
onSelect: (ThemePreference) -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
val options = listOf(
|
||||
ThemePreference.SYSTEM to R.string.settings_theme_system,
|
||||
ThemePreference.LIGHT to R.string.settings_theme_light,
|
||||
ThemePreference.DARK to R.string.settings_theme_dark,
|
||||
)
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.settings_theme_choose)) },
|
||||
text = {
|
||||
Column {
|
||||
options.forEach { (preference, labelRes) ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clickable {
|
||||
onSelect(preference)
|
||||
onDismiss()
|
||||
}
|
||||
.padding(vertical = 4.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = Modifier.horizontalScroll(rememberScrollState()),
|
||||
) {
|
||||
ThemeChip(
|
||||
label = stringResource(R.string.settings_theme_system),
|
||||
selected = selected == ThemePreference.SYSTEM,
|
||||
onClick = { onSelect(ThemePreference.SYSTEM) },
|
||||
RadioButton(
|
||||
selected = selected == preference,
|
||||
onClick = {
|
||||
onSelect(preference)
|
||||
onDismiss()
|
||||
},
|
||||
)
|
||||
ThemeChip(
|
||||
label = stringResource(R.string.settings_theme_light),
|
||||
selected = selected == ThemePreference.LIGHT,
|
||||
onClick = { onSelect(ThemePreference.LIGHT) },
|
||||
)
|
||||
ThemeChip(
|
||||
label = stringResource(R.string.settings_theme_dark),
|
||||
selected = selected == ThemePreference.DARK,
|
||||
onClick = { onSelect(ThemePreference.DARK) },
|
||||
Text(
|
||||
text = stringResource(labelRes),
|
||||
modifier = Modifier.padding(start = 8.dp),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.settings_close))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ThemeChip(
|
||||
label: String,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
private fun ServerDialog(
|
||||
serverUrl: String,
|
||||
onServerUrlChange: (String) -> Unit,
|
||||
isTesting: Boolean,
|
||||
success: Boolean?,
|
||||
onTest: () -> Unit,
|
||||
onDismiss: () -> Unit,
|
||||
) {
|
||||
FilterChip(
|
||||
selected = selected,
|
||||
onClick = onClick,
|
||||
label = { Text(label) },
|
||||
AlertDialog(
|
||||
onDismissRequest = onDismiss,
|
||||
title = { Text(stringResource(R.string.settings_server)) },
|
||||
text = {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
OutlinedTextField(
|
||||
value = serverUrl,
|
||||
onValueChange = onServerUrlChange,
|
||||
label = { Text(stringResource(R.string.settings_server_url)) },
|
||||
singleLine = true,
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Uri,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
)
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
OutlinedButton(
|
||||
onClick = onTest,
|
||||
enabled = !isTesting,
|
||||
) {
|
||||
if (isTesting) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(18.dp),
|
||||
strokeWidth = 2.dp,
|
||||
)
|
||||
} else {
|
||||
Text(stringResource(R.string.settings_test_connection))
|
||||
}
|
||||
}
|
||||
success?.let {
|
||||
Spacer(Modifier.size(16.dp))
|
||||
Text(
|
||||
text = stringResource(
|
||||
if (it) R.string.settings_test_success
|
||||
else R.string.settings_test_failure,
|
||||
),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = if (it) {
|
||||
MaterialTheme.colorScheme.primary
|
||||
} else {
|
||||
MaterialTheme.colorScheme.error
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
confirmButton = {
|
||||
TextButton(onClick = onDismiss) {
|
||||
Text(stringResource(R.string.settings_close))
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -303,25 +401,3 @@ private fun SettingsRow(
|
||||
trailing()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SettingsSectionTitle(title: String) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
modifier = Modifier.padding(horizontal = 16.dp, vertical = 12.dp),
|
||||
)
|
||||
}
|
||||
|
||||
/** Libellé du statut serveur affiché sous le compte connecté. */
|
||||
@Composable
|
||||
private fun serverStatusLabel(status: ServerConnectionStatus): String = stringResource(
|
||||
when (status) {
|
||||
ServerConnectionStatus.Checking -> R.string.status_checking
|
||||
ServerConnectionStatus.Online -> R.string.status_online
|
||||
ServerConnectionStatus.Offline -> R.string.status_offline
|
||||
ServerConnectionStatus.Local -> R.string.status_local
|
||||
},
|
||||
)
|
||||
@@ -129,6 +129,13 @@
|
||||
<string name="settings_saf_folders_empty">No watched folders yet.</string>
|
||||
<string name="settings_watched_folders">Watched system folders</string>
|
||||
<string name="settings_watched_folders_hint">View watched folders</string>
|
||||
<string name="settings_theme_choose">Choose theme</string>
|
||||
<string name="settings_server_hint">Configure the server address</string>
|
||||
<string name="settings_sign_in_hint">Sign in to your server</string>
|
||||
<string name="settings_not_connected">Not signed in</string>
|
||||
<string name="settings_disconnect_confirm">Sign out from %1$s?</string>
|
||||
<string name="settings_close">Close</string>
|
||||
<string name="settings_cancel">Cancel</string>
|
||||
<string name="watched_count_many">99+</string>
|
||||
|
||||
<!-- Search -->
|
||||
|
||||
@@ -129,6 +129,13 @@
|
||||
<string name="settings_saf_folders_empty">Aucun dossier surveillé pour le moment.</string>
|
||||
<string name="settings_watched_folders">Dossiers système surveillés</string>
|
||||
<string name="settings_watched_folders_hint">Consulter les dossiers surveillés</string>
|
||||
<string name="settings_theme_choose">Choisir le thème</string>
|
||||
<string name="settings_server_hint">Configurer l\'adresse du serveur</string>
|
||||
<string name="settings_sign_in_hint">Se connecter à ton serveur</string>
|
||||
<string name="settings_not_connected">Non connecté</string>
|
||||
<string name="settings_disconnect_confirm">Se déconnecter du compte %1$s ?</string>
|
||||
<string name="settings_close">Fermer</string>
|
||||
<string name="settings_cancel">Annuler</string>
|
||||
<string name="watched_count_many">99+</string>
|
||||
|
||||
<!-- Recherche -->
|
||||
|
||||
Reference in New Issue
Block a user