Add: Play actions on play button

realtime_play_button
Juraj Nyíri 3 years ago
parent 09bb3bef5b
commit b61893b3e3

@ -19337,6 +19337,7 @@ class PlayController {
this.runAfter = false; this.runAfter = false;
this.supported = supported; this.supported = supported;
this.playActionButton = document.createElement('button'); this.playActionButton = document.createElement('button');
this.playActionClickFunction = false;
this.getKodiSearchResults = async () => { this.getKodiSearchResults = async () => {
return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data); return JSON.parse((await getState(this.hass, 'sensor.kodi_media_sensor_search')).attributes.data);
}; };
@ -19697,18 +19698,32 @@ class PlayController {
return playButton; return playButton;
}; };
this.setPlayActionButtonType = (mediaType) => { this.setPlayActionButtonType = (mediaType) => {
this.playActionButton = this.card.getElementsByClassName('detailPlayAction')[0]; // fix for innerHTML+= in main file overriding DOM const playActionButton = this.updateDetailPlayAction();
this.playActionButton.setAttribute('data-mediaType', mediaType); playActionButton.setAttribute('data-mediaType', mediaType);
const mockData = { const mockData = {
type: mediaType type: mediaType
}; };
if (lodash.isEmpty(this.getPlayService(mockData))) { if (lodash.isEmpty(this.getPlayService(mockData))) {
this.playActionButton.classList.add('disabled'); playActionButton.classList.add('disabled');
} }
else { else {
this.playActionButton.classList.remove('disabled'); playActionButton.classList.remove('disabled');
} }
}; };
this.updateDetailPlayAction = () => {
if (this.card.getElementsByClassName('detailPlayAction').length > 0) {
this.playActionButton = this.card.getElementsByClassName('detailPlayAction')[0]; // fix for innerHTML+= in main file overriding DOM
}
return this.playActionButton;
};
this.setPlayButtonClickFunction = (callbackFunc) => {
const playActionButton = this.updateDetailPlayAction();
if (this.playActionClickFunction) {
playActionButton.removeEventListener('click', this.playActionClickFunction);
}
playActionButton.addEventListener('click', callbackFunc);
this.playActionClickFunction = callbackFunc;
};
this.getPlayActionButton = () => { this.getPlayActionButton = () => {
return this.playActionButton; return this.playActionButton;
}; };
@ -22178,6 +22193,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.detailElem) { if (this.detailElem) {
if (this.playController) { if (this.playController) {
this.playController.setPlayActionButtonType(data.type); this.playController.setPlayActionButtonType(data.type);
this.playController.setPlayButtonClickFunction((event) => {
event.preventDefault();
event.stopPropagation();
if (this.playController) {
this.playController.play(data, true);
}
});
} }
this.detailElem.style.transition = '0s'; this.detailElem.style.transition = '0s';
this.detailElem.style.top = `${top - 1000}px`; this.detailElem.style.top = `${top - 1000}px`;
@ -22270,14 +22292,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
else { else {
this.getElementsByClassName('detailDesc')[0].innerHTML = ''; this.getElementsByClassName('detailDesc')[0].innerHTML = '';
} }
/* todo temp disabled
if (data.type === 'movie') {
(this.detailElem.children[5] as HTMLElement).style.visibility = 'visible';
this.detailElem.children[5].innerHTML = 'Play';
} else {
(this.detailElem.children[5] as HTMLElement).style.visibility = 'hidden';
}
*/
this.detailElem.style.color = 'rgba(255,255,255,1)'; this.detailElem.style.color = 'rgba(255,255,255,1)';
this.detailElem.style.zIndex = '4'; this.detailElem.style.zIndex = '4';
} }
@ -22453,6 +22467,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (seasonElem.dataset.clicked === 'false') { if (seasonElem.dataset.clicked === 'false') {
if (this.playController) { if (this.playController) {
this.playController.setPlayActionButtonType(seasonData.type); this.playController.setPlayActionButtonType(seasonData.type);
this.playController.setPlayButtonClickFunction((thisEvent) => {
thisEvent.preventDefault();
thisEvent.stopPropagation();
if (this.playController) {
this.playController.play(seasonData, true);
}
});
} }
if (typeof seasonElem.children[0].children[0] !== 'undefined') { if (typeof seasonElem.children[0].children[0] !== 'undefined') {
seasonElem.children[0].children[0].style.display = 'none'; seasonElem.children[0].children[0].style.display = 'none';

@ -34,6 +34,8 @@ class PlayController {
playActionButton: any = document.createElement('button'); playActionButton: any = document.createElement('button');
playActionClickFunction: any = false;
card: any; card: any;
constructor( constructor(
@ -453,18 +455,35 @@ class PlayController {
}; };
setPlayActionButtonType = (mediaType: string): void => { setPlayActionButtonType = (mediaType: string): void => {
this.playActionButton = this.card.getElementsByClassName('detailPlayAction')[0] as HTMLElement; // fix for innerHTML+= in main file overriding DOM const playActionButton = this.updateDetailPlayAction();
this.playActionButton.setAttribute('data-mediaType', mediaType); playActionButton.setAttribute('data-mediaType', mediaType);
const mockData = { const mockData = {
type: mediaType type: mediaType
}; };
if (_.isEmpty(this.getPlayService(mockData))) { if (_.isEmpty(this.getPlayService(mockData))) {
this.playActionButton.classList.add('disabled'); playActionButton.classList.add('disabled');
} else { } else {
this.playActionButton.classList.remove('disabled'); playActionButton.classList.remove('disabled');
} }
}; };
private updateDetailPlayAction = (): any => {
if (this.card.getElementsByClassName('detailPlayAction').length > 0) {
this.playActionButton = this.card.getElementsByClassName('detailPlayAction')[0] as HTMLElement; // fix for innerHTML+= in main file overriding DOM
}
return this.playActionButton;
};
setPlayButtonClickFunction = (callbackFunc: Function): void => {
const playActionButton = this.updateDetailPlayAction();
if (this.playActionClickFunction) {
playActionButton.removeEventListener('click', this.playActionClickFunction);
}
playActionButton.addEventListener('click', callbackFunc);
this.playActionClickFunction = callbackFunc;
};
getPlayActionButton = (): any => { getPlayActionButton = (): any => {
return this.playActionButton; return this.playActionButton;
}; };

@ -1071,6 +1071,14 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (this.detailElem) { if (this.detailElem) {
if (this.playController) { if (this.playController) {
this.playController.setPlayActionButtonType(data.type); this.playController.setPlayActionButtonType(data.type);
this.playController.setPlayButtonClickFunction((event: MouseEvent) => {
event.preventDefault();
event.stopPropagation();
if (this.playController) {
this.playController.play(data, true);
}
});
} }
this.detailElem.style.transition = '0s'; this.detailElem.style.transition = '0s';
@ -1167,15 +1175,6 @@ class PlexMeetsHomeAssistant extends HTMLElement {
(this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = ''; (this.getElementsByClassName('detailDesc')[0] as HTMLElement).innerHTML = '';
} }
/* todo temp disabled
if (data.type === 'movie') {
(this.detailElem.children[5] as HTMLElement).style.visibility = 'visible';
this.detailElem.children[5].innerHTML = 'Play';
} else {
(this.detailElem.children[5] as HTMLElement).style.visibility = 'hidden';
}
*/
this.detailElem.style.color = 'rgba(255,255,255,1)'; this.detailElem.style.color = 'rgba(255,255,255,1)';
this.detailElem.style.zIndex = '4'; this.detailElem.style.zIndex = '4';
} }
@ -1370,6 +1369,13 @@ class PlexMeetsHomeAssistant extends HTMLElement {
if (seasonElem.dataset.clicked === 'false') { if (seasonElem.dataset.clicked === 'false') {
if (this.playController) { if (this.playController) {
this.playController.setPlayActionButtonType(seasonData.type); this.playController.setPlayActionButtonType(seasonData.type);
this.playController.setPlayButtonClickFunction((thisEvent: MouseEvent) => {
thisEvent.preventDefault();
thisEvent.stopPropagation();
if (this.playController) {
this.playController.play(seasonData, true);
}
});
} }
if (typeof seasonElem.children[0].children[0] !== 'undefined') { if (typeof seasonElem.children[0].children[0] !== 'undefined') {
(seasonElem.children[0].children[0] as HTMLElement).style.display = 'none'; (seasonElem.children[0].children[0] as HTMLElement).style.display = 'none';

Loading…
Cancel
Save