Skip to content

Commit

Permalink
Fix/Handling ButtonPress for SOURCE button (#691)
Browse files Browse the repository at this point in the history
* Add check for AUDIO module type under onButtonPressEvent

* Revert "Add check for AUDIO module type under onButtonPressEvent"

This reverts commit 72ac073.

* Add transitionInBackground method

* Prevent is_background param being overwritten by DOM event and fix formatting

* Apply suggestions from code review

Co-authored-by: Jacob Keeler <jacob.keeler@livioradio.com>

* Address review comments

Co-authored-by: Jacob Keeler <jacob.keeler@livioradio.com>
  • Loading branch information
ShobhitAd and jacobkeeler authored Sep 21, 2022
1 parent cd8ebe0 commit f71955c
Showing 1 changed file with 86 additions and 46 deletions.
132 changes: 86 additions & 46 deletions app/model/media/AudioModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,73 +260,85 @@ SDL.AudioModel = Em.Object.extend({
/**
* Turn on CD
*/
turnOnCD: function () {
turnOnCD: function (event=null, is_background=false) {
if (!SDL.States.media.player.cd.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.cd');
this.changeAudioSource('media.player.cd', is_background);
}
if (!is_background) {
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.cdModel, 'cd');
}
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.cdModel, 'cd');
this.returnParameters();
},

/**
* Turn on USB
*/
turnOnUSB: function () {
turnOnUSB: function (event=null, is_background=false) {
if (!SDL.States.media.player.usb.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.usb');
this.changeAudioSource('media.player.usb', is_background);
}
if (!is_background) {
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.usbModel, 'usb');
}
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.usbModel, 'usb');
this.returnParameters();
},

/**
* Turn on Radio
*/
turnOnRadio: function () {
turnOnRadio: function (event=null, is_background=false) {
if (!SDL.States.media.player.radio.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.radio');
this.changeAudioSource('media.player.radio', is_background);
}
SDL.RCModulesController.currentRadioModel.saveCurrentOptions();
SDL.RCModulesController.currentRadioModel.set('active', true);
if (!is_background) {
SDL.RCModulesController.currentRadioModel.set('active', true);
}
this.returnParameters();
},

/**
* Turn on Bluetooth
*/
turnOnBluetooth: function () {
turnOnBluetooth: function (event=null, is_background=false) {
if (!SDL.States.media.player.bluetooth.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.bluetooth');
this.changeAudioSource('media.player.bluetooth', is_background);
}
if (!is_background) {
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.bluetoothModel, 'bluetooth');
}
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.bluetoothModel, 'bluetooth');
this.returnParameters();
},

/**
* Turn on LineIn
*/
turnOnLineIn: function () {
turnOnLineIn: function (event=null, is_background=false) {
if (!SDL.States.media.player.lineIn.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.lineIn');
this.changeAudioSource('media.player.lineIn', is_background);
}
if (!is_background) {
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.lineInModel, 'lineIn');
}
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.lineInModel, 'lineIn');
this.returnParameters();
},

/**
* Turn on IPod
*/
turnOnIPod: function () {
turnOnIPod: function (event=null, is_background=false) {
if (!SDL.States.media.player.ipod.active) {
this.deactivateAll();
SDL.States.goToStates('media.player.ipod');
this.changeAudioSource('media.player.ipod', is_background);
}
if (!is_background) {
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.ipodModel, 'ipod');
}
this.onPlayerEnter(SDL.RCModulesController.currentAudioModel.ipodModel, 'ipod');
this.returnParameters();
},

Expand Down Expand Up @@ -558,17 +570,63 @@ SDL.AudioModel = Em.Object.extend({
}
},

/**
* Switch RC Audio source based on whether the app is in focus
* @param nextState Audio source to transition to
* @param isBackground
*/
changeAudioSource : function (nextState, isBackground){
if (!isBackground) {
SDL.States.goToStates(nextState);
return;
}

SDL.RCModulesController.currentAudioModel.set('activeState', nextState);
if (FFW.RC.isSetVdInProgress) {
return;
}
let currentAudioModel = this.getAudioModel(nextState);
currentAudioModel.sendAudioNotification();
},

/**
* Get audio model based on state name
* @param stateName name of audio source state(e.g. 'media.player.ipod')
*/
getAudioModel : function (stateName){
switch (stateName) {
case 'media.player.radio': {
return SDL.RCModulesController.currentRadioModel;
}
case 'media.player.cd': {
return SDL.RCModulesController.currentAudioModel.cdModel;
}
case 'media.player.usb': {
return SDL.RCModulesController.currentAudioModel.usbModel;
}
case 'media.player.bluetooth': {
return SDL.RCModulesController.currentAudioModel.bluetoothModel;
}
case 'media.player.lineIn': {
return SDL.RCModulesController.currentAudioModel.lineInModel;
}
case 'media.player.ipod': {
return SDL.RCModulesController.currentAudioModel.ipodModel;
}
default: { // Default to RADIO
return SDL.RCModulesController.currentRadioModel;
}
}
},

/**
* Switches to next after radio source
* @param is source switched from background or not
*/
changeSourceFromRadio: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.deactivateRadio();
this.turnOnCD();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnCD(null, is_background);
},

/**
Expand All @@ -578,10 +636,7 @@ SDL.AudioModel = Em.Object.extend({
changeSourceFromCD: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.deactivateCD();
this.turnOnUSB();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnUSB(null, is_background);
},

/**
Expand All @@ -591,10 +646,7 @@ SDL.AudioModel = Em.Object.extend({
changeSourceFromUSB: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.deactivateUSB();
this.turnOnBluetooth();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnBluetooth(null, is_background);
},

/**
Expand All @@ -604,10 +656,7 @@ SDL.AudioModel = Em.Object.extend({
changeSourceFromBluetooth: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.deactivateBluetooth();
this.turnOnLineIn();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnLineIn(null, is_background);
},

/**
Expand All @@ -617,10 +666,7 @@ SDL.AudioModel = Em.Object.extend({
changeSourceFromLineIn: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.deactivateLineIn();
this.turnOnIPod();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnIPod(null, is_background);
},

/**
Expand All @@ -633,10 +679,7 @@ SDL.AudioModel = Em.Object.extend({
if (SDL.SDLMediaController.currentAppId != null && !is_background) {
SDL.SDLMediaController.activateCurrentApp();
} else {
this.turnOnRadio();
}
if (is_background) {
SDL.States.goToStates(old_state);
this.turnOnRadio(null, is_background);
}
},

Expand All @@ -646,10 +689,7 @@ SDL.AudioModel = Em.Object.extend({
*/
changeSourceFromUnknown: function (is_background) {
var old_state = SDL.States.currentState.get('path');
this.turnOnRadio();
if (is_background) {
SDL.States.goToStates(old_state);
}
this.turnOnRadio(null, is_background);
},

/**
Expand Down

0 comments on commit f71955c

Please sign in to comment.