Skip to content

Commit 6ad7b27

Browse files
committed
add new advanced option to return to the default profile each time the car enters READY, even after a profile was chosen by hand
1 parent 66f1c08 commit 6ad7b27

19 files changed

Lines changed: 276 additions & 28 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.mg4.control.profile
2+
3+
import android.content.Context
4+
import com.mg4.control.debug.AppLogger
5+
6+
/**
7+
* Passage en READY : ce que devient un profil choisi à la main.
8+
*
9+
* Par défaut il est RÉAPPLIQUÉ à chaque passage en READY, jusqu'à l'extinction de la voiture —
10+
* c'est le respect du choix explicite de l'utilisateur (voir [ProfileApplier.lastManualProfileId]).
11+
*
12+
* L'option « Revenir au profil par défaut à chaque passage en READY » (Réglages avancés) le fait
13+
* OUBLIER. La chaîne habituelle reprend alors la main, sans rien changer à son ordre : profil lié
14+
* à la température, puis au téléphone Bluetooth, puis profil par défaut. Demande d'un utilisateur
15+
* qui voulait retrouver son profil par défaut après chaque arrêt, même court.
16+
*/
17+
object ReadyProfilePolicy {
18+
19+
private const val TAG = "MG4_PROFILE"
20+
21+
/** Même fichier que les autres réglages avancés. */
22+
private const val PREFS = "mg4_settings"
23+
24+
/** Défaut false : le comportement d'origine ne change pour personne. */
25+
const val KEY = "ready_back_to_default"
26+
27+
fun isEnabled(ctx: Context?): Boolean =
28+
ctx?.getSharedPreferences(PREFS, Context.MODE_PRIVATE)?.getBoolean(KEY, false) ?: false
29+
30+
fun setEnabled(ctx: Context, actif: Boolean) {
31+
ctx.getSharedPreferences(PREFS, Context.MODE_PRIVATE).edit().putBoolean(KEY, actif).apply()
32+
AppLogger.i(TAG, "Retour au profil par défaut à chaque READY : ${if (actif) "activé" else "désactivé"}")
33+
}
34+
35+
// ── La règle, sans Android ───────────────────────────────────────────────
36+
37+
/**
38+
* Profil choisi à la main à réappliquer au passage en READY, ou `null` quand c'est la chaîne
39+
* automatique qui décide (température, Bluetooth, profil par défaut).
40+
*/
41+
fun manualToReapply(manualId: String?, backToDefault: Boolean): String? =
42+
if (backToDefault) null else manualId
43+
44+
/**
45+
* Vrai s'il faut OUBLIER le choix manuel, pas seulement l'écarter : resté en mémoire, il
46+
* reviendrait au READY suivant si l'option était décochée entre-temps.
47+
*/
48+
fun forgetsManual(manualId: String?, backToDefault: Boolean): Boolean =
49+
backToDefault && manualId != null
50+
}

‎app/src/main/java/com/mg4/control/service/MG4ControlService.kt‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import com.mg4.control.model.WindowCommand
4444
import com.mg4.control.profile.ActiveProfile
4545
import com.mg4.control.profile.ProfileApplier
4646
import com.mg4.control.profile.ProfileManager
47+
import com.mg4.control.profile.ReadyProfilePolicy
4748
import com.mg4.control.shortcut.RegenCycle
4849
import com.mg4.control.update.UpdateChecker
4950
import com.mg4.control.update.UpdateNotifier
@@ -1519,8 +1520,15 @@ class MG4ControlService : Service() {
15191520
val pm = ProfileManager(applicationContext)
15201521

15211522
// Choix manuel récent (popup volant / app) → prioritaire sur BT et défaut.
1522-
// L'utilisateur a explicitement sélectionné un profil depuis le démarrage : on le respecte.
1523-
val manualId = ProfileApplier.lastManualProfileId
1523+
// L'utilisateur a explicitement sélectionné un profil depuis le démarrage : on le respecte,
1524+
// SAUF s'il a demandé à revenir au profil par défaut à chaque passage en READY
1525+
// ([ReadyProfilePolicy]) : le choix est alors oublié et la chaîne ci-dessous décide.
1526+
val retourDefaut = ReadyProfilePolicy.isEnabled(this)
1527+
if (ReadyProfilePolicy.forgetsManual(ProfileApplier.lastManualProfileId, retourDefaut)) {
1528+
AppLogger.i(TAG, "IGNITION → choix manuel oublié (option « revenir au profil par défaut »)")
1529+
ProfileApplier.lastManualProfileId = null
1530+
}
1531+
val manualId = ReadyProfilePolicy.manualToReapply(ProfileApplier.lastManualProfileId, retourDefaut)
15241532
if (manualId != null) {
15251533
val manualProfile = pm.getById(manualId)
15261534
if (manualProfile != null) {

‎app/src/main/java/com/mg4/control/ui/SettingsFragment.kt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.mg4.control.debug.CrashLogger
4141
import com.mg4.control.hardware.EnergyProbe
4242
import com.mg4.control.hardware.MG4Hardware
4343
import com.mg4.control.hardware.VehicleWriteGate
44+
import com.mg4.control.profile.ReadyProfilePolicy
4445
import com.mg4.control.update.ApkCleanup
4546
import com.mg4.control.update.UpdateChecker
4647
import com.mg4.control.update.UpdateNotifier
@@ -258,6 +259,15 @@ class SettingsFragment : Fragment() {
258259
}
259260
}
260261

262+
// Passage en READY : oublier le profil choisi à la main et reprendre la chaîne habituelle
263+
// (température, Bluetooth, profil par défaut). Lu par le service à chaque passage en
264+
// READY : rien à lui signaler, le réglage vaut dès le prochain.
265+
val switchRetour = view.findViewById<Switch>(R.id.switch_ready_default)
266+
switchRetour.isChecked = ReadyProfilePolicy.isEnabled(requireContext())
267+
switchRetour.setOnCheckedChangeListener { _, checked ->
268+
ReadyProfilePolicy.setEnabled(requireContext(), checked)
269+
}
270+
261271
// ── Sécurité conduite (verrou d'écriture par vitesse) ────────────────
262272
val switchSpeedGate = view.findViewById<Switch>(R.id.switch_speed_gate)
263273
val rowSpeedGateMax = view.findViewById<View>(R.id.row_speed_gate_max)

‎app/src/main/res/layout/fragment_settings.xml‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,56 @@
626626

627627
</LinearLayout>
628628

629+
<View
630+
android:layout_width="match_parent"
631+
android:layout_height="1dp"
632+
android:background="@color/dash_border" />
633+
634+
<!-- Retour au profil par défaut à chaque passage en READY. Sous le Mode Garage :
635+
les deux décident du profil appliqué sans qu'on le demande. Décoché par
636+
défaut — un profil choisi à la main reste alors en place jusqu'à l'extinction. -->
637+
<LinearLayout
638+
android:id="@+id/row_ready_default"
639+
android:layout_width="match_parent"
640+
android:layout_height="wrap_content"
641+
android:orientation="vertical"
642+
android:padding="12dp">
643+
644+
<LinearLayout
645+
android:layout_width="match_parent"
646+
android:layout_height="wrap_content"
647+
android:orientation="horizontal"
648+
android:gravity="center_vertical">
649+
650+
<TextView
651+
android:layout_width="0dp"
652+
android:layout_height="wrap_content"
653+
android:layout_weight="1"
654+
android:text="@string/settings_ready_default"
655+
android:textColor="@color/text_secondary"
656+
android:textSize="16sp" />
657+
658+
<Switch
659+
android:scaleX="1.3"
660+
android:scaleY="1.3"
661+
android:layout_marginHorizontal="8dp"
662+
android:id="@+id/switch_ready_default"
663+
android:layout_width="wrap_content"
664+
android:layout_height="wrap_content"
665+
android:checked="false" />
666+
667+
</LinearLayout>
668+
669+
<TextView
670+
android:layout_width="match_parent"
671+
android:layout_height="wrap_content"
672+
android:layout_marginTop="6dp"
673+
android:text="@string/settings_ready_default_desc"
674+
android:textColor="@color/dash_text_lo"
675+
android:textSize="13sp" />
676+
677+
</LinearLayout>
678+
629679
<View
630680
android:layout_width="match_parent"
631681
android:layout_height="1dp"

‎app/src/main/res/values-de/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Weitere Einstellungen</string>
246246
<string name="settings_garage_mode">Werkstattmodus</string>
247247
<string name="settings_garage_mode_desc">Versetzt MG4Control vollständig in den Ruhezustand: keine Tastenkürzel (die Tasten haben wieder ihre ursprüngliche Funktion), kein Profil beim Start, keine Automatisierung. Praktisch, wenn das Fahrzeug in die Werkstatt kommt, ohne die App zu deinstallieren. Ihre Einstellungen bleiben erhalten und kehren zurück, sobald der Modus ausgeschaltet wird.</string>
248+
<string name="settings_ready_default">Bei jedem Wechsel in READY zum Standardprofil zurückkehren</string>
249+
<string name="settings_ready_default_desc">Standardmäßig bleibt ein von Hand gewähltes Profil aktiv, bis das Fahrzeug ausgeschaltet wird. Mit dieser Option wird es bei jedem Wechsel in READY vergessen, auch nach einem kurzen Halt, und das Standardprofil wird erneut angewendet. Ein Profil, das an die Außentemperatur oder an ein Bluetooth-Telefon gebunden ist, behält wie beim Start den Vorrang.</string>
248250
<string name="notif_service_active">Dienst aktiv</string>
249251
<string name="notif_garage_mode">Werkstattmodus — im Ruhezustand</string>
250252
<string name="settings_auto_update_desc">Beim Start automatisch nach Updates suchen</string>

‎app/src/main/res/values-en/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Additional settings</string>
246246
<string name="settings_garage_mode">Garage mode</string>
247247
<string name="settings_garage_mode_desc">Puts MG4Control fully to sleep: no shortcuts (buttons regain their original function), no profile applied at startup, no automation. Useful when leaving the car at a workshop without uninstalling the app. Your settings are kept and come back as soon as the mode is turned off.</string>
248+
<string name="settings_ready_default">Return to the default profile each time the car enters READY</string>
249+
<string name="settings_ready_default_desc">By default, a profile chosen by hand stays in place until the car is switched off. With this option, it is forgotten each time the car enters READY, including after a short stop, and the default profile is applied again. If a profile tied to the outside temperature or to a Bluetooth phone should apply, it keeps priority, as at start-up.</string>
248250
<string name="notif_service_active">Service running</string>
249251
<string name="notif_garage_mode">Garage mode — asleep</string>
250252
<string name="settings_auto_update_desc">Automatically check for updates at launch</string>

‎app/src/main/res/values-es/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Ajustes adicionales</string>
246246
<string name="settings_garage_mode">Modo taller</string>
247247
<string name="settings_garage_mode_desc">Pone MG4Control en reposo total: sin atajos (los botones recuperan su función original), sin perfil al arrancar, sin automatizaciones. Útil para dejar el vehículo en el taller sin desinstalar la aplicación. Sus ajustes se conservan y vuelven en cuanto se desactiva el modo.</string>
248+
<string name="settings_ready_default">Volver al perfil predeterminado cada vez que el coche pasa a READY</string>
249+
<string name="settings_ready_default_desc">De forma predeterminada, un perfil elegido a mano se mantiene hasta que se apaga el coche. Con esta opción, se olvida cada vez que el coche pasa a READY, incluso tras una parada corta, y se vuelve a aplicar el perfil predeterminado. Si debe aplicarse un perfil vinculado a la temperatura exterior o a un teléfono Bluetooth, conserva la prioridad, como al arrancar.</string>
248250
<string name="notif_service_active">Servicio activo</string>
249251
<string name="notif_garage_mode">Modo taller — en reposo</string>
250252
<string name="settings_auto_update_desc">Buscar actualizaciones automáticamente al iniciar</string>

‎app/src/main/res/values-it/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Impostazioni aggiuntive</string>
246246
<string name="settings_garage_mode">Modalità officina</string>
247247
<string name="settings_garage_mode_desc">Mette MG4Control completamente in pausa: niente scorciatoie (i pulsanti tornano alla loro funzione originale), nessun profilo all\'avvio, nessuna automazione. Utile per lasciare l\'auto in officina senza disinstallare l\'app. Le impostazioni restano e tornano appena la modalità viene disattivata.</string>
248+
<string name="settings_ready_default">Tornare al profilo predefinito a ogni passaggio in READY</string>
249+
<string name="settings_ready_default_desc">Per impostazione predefinita, un profilo scelto a mano resta attivo fino allo spegnimento dell\'auto. Con questa opzione viene dimenticato a ogni passaggio in READY, anche dopo una sosta breve, e viene riapplicato il profilo predefinito. Se deve applicarsi un profilo legato alla temperatura esterna o a un telefono Bluetooth, mantiene la priorità, come all\'avvio.</string>
248250
<string name="notif_service_active">Servizio attivo</string>
249251
<string name="notif_garage_mode">Modalità officina — in pausa</string>
250252
<string name="settings_auto_update_desc">Controlla aggiornamenti automaticamente all\'avvio</string>

‎app/src/main/res/values-pt/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Definições adicionais</string>
246246
<string name="settings_garage_mode">Modo oficina</string>
247247
<string name="settings_garage_mode_desc">Coloca o MG4Control totalmente em pausa: sem atalhos (os botões recuperam a função original), sem perfil ao arrancar, sem automações. Útil para deixar o veículo na oficina sem desinstalar a aplicação. As suas definições são mantidas e voltam assim que o modo for desativado.</string>
248+
<string name="settings_ready_default">Voltar ao perfil padrão sempre que o carro passa a READY</string>
249+
<string name="settings_ready_default_desc">Por predefinição, um perfil escolhido à mão mantém-se até o carro ser desligado. Com esta opção, é esquecido sempre que o carro passa a READY, mesmo após uma paragem curta, e o perfil padrão volta a ser aplicado. Se um perfil ligado à temperatura exterior ou a um telemóvel Bluetooth tiver de ser aplicado, mantém a prioridade, como no arranque.</string>
248250
<string name="notif_service_active">Serviço ativo</string>
249251
<string name="notif_garage_mode">Modo oficina — em pausa</string>
250252
<string name="settings_auto_update_desc">Verificar atualizações automaticamente no arranque</string>

‎app/src/main/res/values-tr/strings.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@
245245
<string name="settings_auto_apply">Ek ayarlar</string>
246246
<string name="settings_garage_mode">Garaj modu</string>
247247
<string name="settings_garage_mode_desc">MG4Control’ü tamamen uyutur: kısayol yok (düğmeler özgün işlevlerine döner), açılışta profil uygulanmaz, otomasyon çalışmaz. Aracı servise bırakırken uygulamayı kaldırmak zorunda kalmamak için kullanışlıdır. Ayarlarınız korunur ve mod kapatılır kapatılmaz geri gelir.</string>
248+
<string name="settings_ready_default">Araç her READY konumuna geçtiğinde varsayılan profile dön</string>
249+
<string name="settings_ready_default_desc">Varsayılan olarak, elle seçilen profil araç kapatılana kadar geçerli kalır. Bu seçenekle, kısa bir duruştan sonra bile araç her READY konumuna geçtiğinde unutulur ve varsayılan profil yeniden uygulanır. Dış sıcaklığa veya bir Bluetooth telefona bağlı bir profil uygulanacaksa, açılışta olduğu gibi önceliğini korur.</string>
248250
<string name="notif_service_active">Hizmet çalışıyor</string>
249251
<string name="notif_garage_mode">Garaj modu — uykuda</string>
250252
<string name="settings_auto_update_desc">Açılışta güncellemeleri kendiliğinden denetle</string>

0 commit comments

Comments
 (0)