From f943393adef4672008c357228b77fa7f051db609 Mon Sep 17 00:00:00 2001 From: Joakim Plate Date: Tue, 30 Apr 2019 19:21:43 +0200 Subject: [PATCH] Switch source selection to same logic as SoundMode with using (#3136) actual value as selected item instead of index. This avoids the bug with selected: https://github.com/PolymerElements/paper-dropdown-menu/issues/197 https://github.com/PolymerElements/paper-dropdown-menu/issues/114 Fixes: #3022 Side note: it actually mainly hides the issue. If we should allow a key, value setup with source being a key and the display value being a localized value it likely would return. --- .../controls/more-info-media_player.js | 38 ++++++++----------- 1 file changed, 16 insertions(+), 22 deletions(-) diff --git a/src/dialogs/more-info/controls/more-info-media_player.js b/src/dialogs/more-info/controls/more-info-media_player.js index 0251f67f07..fd22c1a111 100644 --- a/src/dialogs/more-info/controls/more-info-media_player.js +++ b/src/dialogs/more-info/controls/more-info-media_player.js @@ -154,9 +154,13 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { label-float="" label="[[localize('ui.card.media_player.source')]]" > - + @@ -214,9 +218,9 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { observer: "playerObjChanged", }, - sourceIndex: { - type: Number, - value: 0, + SourceInput: { + type: String, + value: "", observer: "handleSourceChanged", }, @@ -249,7 +253,7 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { playerObjChanged(newVal, oldVal) { if (newVal && newVal.sourceList !== undefined) { - this.sourceIndex = newVal.sourceList.indexOf(newVal.source); + this.SourceInput = newVal.source; } if (newVal && newVal.soundModeList !== undefined) { @@ -342,26 +346,16 @@ class MoreInfoMediaPlayer extends LocalizeMixin(EventsMixin(PolymerElement)) { this.playerObj.nextTrack(); } - handleSourceChanged(sourceIndex, sourceIndexOld) { + handleSourceChanged(newVal, oldVal) { // Selected Option will transition to '' before transitioning to new value if ( - !this.playerObj || - !this.playerObj.supportsSelectSource || - this.playerObj.sourceList === undefined || - sourceIndex < 0 || - sourceIndex >= this.playerObj.sourceList || - sourceIndexOld === undefined + oldVal && + newVal && + newVal !== this.playerObj.source && + this.playerObj.supportsSelectSource ) { - return; + this.playerObj.selectSource(newVal); } - - const sourceInput = this.playerObj.sourceList[sourceIndex]; - - if (sourceInput === this.playerObj.source) { - return; - } - - this.playerObj.selectSource(sourceInput); } handleSoundModeChanged(newVal, oldVal) {