test
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
package com.example.scanwich
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.net.Uri
|
||||
import android.widget.Toast
|
||||
import androidx.compose.foundation.layout.*
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
@@ -16,16 +14,27 @@ import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.content.edit
|
||||
import androidx.core.net.toUri
|
||||
|
||||
@Composable
|
||||
fun SettingsScreen(prefs: SharedPreferences, onLogout: () -> Unit, onProfileUpdated: () -> Unit) {
|
||||
var isEditing by remember { mutableStateOf(false) }
|
||||
val context = LocalContext.current
|
||||
|
||||
var stravaClientId by remember { mutableStateOf(prefs.getString("strava_client_id", "") ?: "") }
|
||||
var stravaClientSecret by remember { mutableStateOf(prefs.getString("strava_client_secret", "") ?: "") }
|
||||
val isStravaConnected = prefs.contains("strava_token")
|
||||
// État réactif pour la connexion Strava
|
||||
var isStravaConnected by remember { mutableStateOf(prefs.contains("strava_token")) }
|
||||
|
||||
// Écouteur pour mettre à jour l'état si le token change
|
||||
DisposableEffect(prefs) {
|
||||
val listener = SharedPreferences.OnSharedPreferenceChangeListener { p, key ->
|
||||
if (key == "strava_token") {
|
||||
isStravaConnected = p.contains("strava_token")
|
||||
}
|
||||
}
|
||||
prefs.registerOnSharedPreferenceChangeListener(listener)
|
||||
onDispose {
|
||||
prefs.unregisterOnSharedPreferenceChangeListener(listener)
|
||||
}
|
||||
}
|
||||
|
||||
if (isEditing) {
|
||||
SetupScreen(prefs) {
|
||||
@@ -48,51 +57,25 @@ fun SettingsScreen(prefs: SharedPreferences, onLogout: () -> Unit, onProfileUpda
|
||||
Button(onClick = { isEditing = true }, modifier = Modifier.fillMaxWidth()) { Icon(Icons.Default.Edit, null); Text(" Modifier le profil") }
|
||||
|
||||
Spacer(Modifier.height(32.dp))
|
||||
Text("Configuration Strava", style = MaterialTheme.typography.titleMedium)
|
||||
Text("Intégrations", style = MaterialTheme.typography.titleMedium)
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
OutlinedTextField(
|
||||
value = stravaClientId,
|
||||
onValueChange = { stravaClientId = it; prefs.edit { putString("strava_client_id", it) } },
|
||||
label = { Text("Strava Client ID") },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = stravaClientSecret,
|
||||
onValueChange = { stravaClientSecret = it; prefs.edit { putString("strava_client_secret", it) } },
|
||||
label = { Text("Strava Client Secret") },
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
)
|
||||
|
||||
Spacer(Modifier.height(8.dp))
|
||||
|
||||
if (!isStravaConnected) {
|
||||
Button(
|
||||
onClick = {
|
||||
if (stravaClientId.isBlank() || stravaClientSecret.isBlank()) {
|
||||
Toast.makeText(context, "Entrez votre ID et Secret Client", Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
val intent = Intent(Intent.ACTION_VIEW, "https://www.strava.com/oauth/mobile/authorize?client_id=$stravaClientId&redirect_uri=coloricam://localhost&response_type=code&approval_prompt=auto&scope=read,activity:read_all".toUri())
|
||||
context.startActivity(intent)
|
||||
}
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text("Connecter Strava")
|
||||
}
|
||||
} else {
|
||||
if (isStravaConnected) {
|
||||
OutlinedButton(
|
||||
onClick = {
|
||||
prefs.edit {
|
||||
remove("strava_token")
|
||||
remove("strava_refresh_token")
|
||||
}
|
||||
// L'écouteur mettra `isStravaConnected` à jour automatiquement
|
||||
Toast.makeText(context, "Strava déconnecté", Toast.LENGTH_SHORT).show()
|
||||
},
|
||||
modifier = Modifier.fillMaxWidth()
|
||||
) {
|
||||
Text("Déconnecter Strava (Connecté)")
|
||||
}
|
||||
} else {
|
||||
Text("Aucune intégration active. Allez dans l'onglet 'Sport' pour connecter Strava.", style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
|
||||
Spacer(Modifier.height(32.dp))
|
||||
|
||||
Reference in New Issue
Block a user