Skip to content

Commit 385c589

Browse files
committed
add play/pause shortcut
1 parent 6fe27f0 commit 385c589

11 files changed

Lines changed: 35 additions & 11 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ Actions disponibles — celles qui dépendent du firmware n'apparaissent pas sur
109109
| Conduite | 1 Pédale · Régénération : niveau suivant · Éco. énergie |
110110
| Sécurité | ESC · Somnolence · Somnolence : sensibilité · Système Anticollision · ADAS · Panneaux (TSR) · Alerte survitesse · Alerte changement de limite · Son |
111111
| Confort | Siège chauffant gauche · Siège chauffant droit · Volant chauffant · Clim ON/OFF · Clim : température ± · Clim : ventilation ± · Dégivrage avant · Dégivrage arrière · Recirculation · Luminosité ± |
112-
| Média | Piste suivante · Piste précédente |
112+
| Média | Lecture / Pause · Piste suivante · Piste précédente |
113113
| Application et véhicule | Lancer un profil · Sélecteur de profil · Ouvrir MG4Control · Lancer une application · Éteindre la voiture |
114114

115115
Les actions de confort et de sécurité **relisent l'état sur le véhicule à chaque pression** au lieu
@@ -813,7 +813,7 @@ Available actions — those depending on the firmware do not show up on the othe
813813
| Driving | One Pedal · Regeneration: next level · Energy saving |
814814
| Safety | ESC · Drowsiness · Drowsiness: sensitivity · Forward collision · ADAS · Traffic signs (TSR) · Overspeed alert · Speed limit change alert · Sound |
815815
| Comfort | Left seat heating · Right seat heating · Heated steering · Climate ON/OFF · Climate: temperature ± · Climate: fan ± · Front defrost · Rear defrost · Recirculation · Brightness ± |
816-
| Media | Next track · Previous track |
816+
| Media | Play / Pause · Next track · Previous track |
817817
| App and vehicle | Apply a profile · Profile picker · Open MG4Control · Launch an app · Power the car off |
818818

819819
Comfort and safety actions **re-read the state from the vehicle on every press** instead of

‎app/src/main/java/com/mg4/control/hardware/MG4Hardware.kt‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,6 +3692,16 @@ object MG4Hardware {
36923692
/** Piste précédente. Mêmes réserves que [mediaNext]. */
36933693
fun mediaPrevious(): Boolean = envoyerToucheMedia(KeyEvent.KEYCODE_MEDIA_PREVIOUS)
36943694

3695+
/**
3696+
* Bascule lecture / pause. Mêmes réserves que [mediaNext].
3697+
*
3698+
* On envoie bien `PLAY_PAUSE` et non `PLAY` ou `PAUSE` : c'est la **source** qui connaît son
3699+
* état, pas nous. Choisir à sa place supposerait de savoir si elle joue, ce qu'`isMusicActive`
3700+
* ne dit que globalement — au premier écart, la touche mettrait en pause une lecture déjà
3701+
* arrêtée et paraîtrait sans effet une fois sur deux.
3702+
*/
3703+
fun mediaPlayPause(): Boolean = envoyerToucheMedia(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)
3704+
36953705
/**
36963706
* Envoie une touche média au système, qui la remet à la session active.
36973707
*

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

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ class MG4ControlService : Service() {
6464
ShortcutAction.DEFROST_FRONT_TOGGLE, ShortcutAction.DEFROST_REAR_TOGGLE,
6565
ShortcutAction.HVAC_RECIRC_CYCLE,
6666
ShortcutAction.BRIGHTNESS_UP, ShortcutAction.BRIGHTNESS_DOWN,
67-
ShortcutAction.MEDIA_NEXT, ShortcutAction.MEDIA_PREVIOUS
67+
ShortcutAction.MEDIA_NEXT, ShortcutAction.MEDIA_PREVIOUS,
68+
ShortcutAction.MEDIA_PLAY_PAUSE
6869
)
6970

7071

@@ -533,14 +534,19 @@ class MG4ControlService : Service() {
533534
MG4Hardware.setDrowsinessSensitivity(suivant)
534535
}
535536

536-
ShortcutAction.MEDIA_NEXT, ShortcutAction.MEDIA_PREVIOUS -> {
537+
ShortcutAction.MEDIA_NEXT, ShortcutAction.MEDIA_PREVIOUS,
538+
ShortcutAction.MEDIA_PLAY_PAUSE -> {
537539
// Aucune lecture préalable : contrairement aux autres actions de ce bloc, il n'y
538-
// a pas d'« état de piste » à connaître. On envoie la commande, c'est la source
539-
// qui décide — d'où le passage par ce chemin plutôt que par les bascules à état
540-
// mémorisé, qui alterneraient une fois sur deux.
541-
val suivant = action == ShortcutAction.MEDIA_NEXT
542-
AppLogger.i(TAG, "SHORTCUT piste ${if (suivant) "suivante" else "précédente"}")
543-
if (suivant) MG4Hardware.mediaNext() else MG4Hardware.mediaPrevious()
540+
// a rien à connaître avant d'agir. Même la pause n'en demande pas — la touche
541+
// PLAY_PAUSE est une bascule que la source résout elle-même. D'où le passage par
542+
// ce chemin plutôt que par les bascules à état mémorisé, qui se désynchroniseraient
543+
// dès que l'utilisateur toucherait à la lecture depuis l'écran d'origine.
544+
AppLogger.i(TAG, "SHORTCUT média : ${action.name}")
545+
when (action) {
546+
ShortcutAction.MEDIA_NEXT -> MG4Hardware.mediaNext()
547+
ShortcutAction.MEDIA_PREVIOUS -> MG4Hardware.mediaPrevious()
548+
else -> MG4Hardware.mediaPlayPause()
549+
}
544550
}
545551

546552
ShortcutAction.REGEN_CYCLE -> {

‎app/src/main/java/com/mg4/control/shortcut/ShortcutAction.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ enum class ShortcutAction(val id: Int) {
4343
// Média : seules actions qui ne touchent NI au véhicule NI à un état mémorisé — elles
4444
// envoient une touche au système, qui la remet à l'application en train de jouer.
4545
MEDIA_NEXT(31),
46-
MEDIA_PREVIOUS(32);
46+
MEDIA_PREVIOUS(32),
47+
MEDIA_PLAY_PAUSE(33);
4748

4849
companion object {
4950
fun fromId(id: Int) = values().firstOrNull { it.id == id } ?: NONE

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class ShortcutsFragment : Fragment() {
139139
// session média d'Android, identique sur les six firmwares.
140140
add(ActionItem(getString(R.string.shortcuts_action_media_next), ShortcutAction.MEDIA_NEXT))
141141
add(ActionItem(getString(R.string.shortcuts_action_media_prev), ShortcutAction.MEDIA_PREVIOUS))
142+
add(ActionItem(getString(R.string.shortcuts_action_media_play_pause), ShortcutAction.MEDIA_PLAY_PAUSE))
142143
add(ActionItem(getString(R.string.shortcuts_action_apply_profile), ShortcutAction.APPLY_PROFILE))
143144
add(ActionItem(getString(R.string.shortcuts_action_profile_picker), ShortcutAction.PROFILE_PICKER))
144145
add(ActionItem(getString(R.string.shortcuts_action_open_app), ShortcutAction.OPEN_APP))

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,5 @@
467467
<!-- Raccourcis : pistes audio -->
468468
<string name="shortcuts_action_media_next">Nächster Titel</string>
469469
<string name="shortcuts_action_media_prev">Vorheriger Titel</string>
470+
<string name="shortcuts_action_media_play_pause">Wiedergabe / Pause</string>
470471
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,5 @@
467467
<!-- Raccourcis : pistes audio -->
468468
<string name="shortcuts_action_media_next">Next track</string>
469469
<string name="shortcuts_action_media_prev">Previous track</string>
470+
<string name="shortcuts_action_media_play_pause">Play / Pause</string>
470471
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,5 @@
467467
<!-- Raccourcis : pistes audio -->
468468
<string name="shortcuts_action_media_next">Pista siguiente</string>
469469
<string name="shortcuts_action_media_prev">Pista anterior</string>
470+
<string name="shortcuts_action_media_play_pause">Reproducir / Pausa</string>
470471
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,5 @@
467467
<!-- Raccourcis : pistes audio -->
468468
<string name="shortcuts_action_media_next">Traccia successiva</string>
469469
<string name="shortcuts_action_media_prev">Traccia precedente</string>
470+
<string name="shortcuts_action_media_play_pause">Riproduci / Pausa</string>
470471
</resources>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,4 +467,5 @@
467467
<!-- Raccourcis : pistes audio -->
468468
<string name="shortcuts_action_media_next">Faixa seguinte</string>
469469
<string name="shortcuts_action_media_prev">Faixa anterior</string>
470+
<string name="shortcuts_action_media_play_pause">Reproduzir / Pausa</string>
470471
</resources>

0 commit comments

Comments
 (0)