radio/lorgar/views/player.js

164 lines
6.7 KiB
JavaScript
Raw Normal View History

2018-10-28 21:32:44 +00:00
"use strict";
(function() {
var moduleName = "views/player"
var deps = [];
deps.push("views/gridLayout");
deps.push("views/button");
deps.push("views/label");
deps.push("views/view");
deps.push("views/image");
deps.push("views/songProgress");
2019-01-30 20:36:33 +00:00
deps.push("views/slider");
2018-10-28 21:32:44 +00:00
deps.push("lib/wController/localModel");
deps.push("lib/utils/enum");
define(moduleName, deps, function() {
var GridLayout = require("views/gridLayout");
var Button = require("views/button");
var Label = require("views/label");
var View = require("views/view");
var Image = require("views/image");
var SongProgress = require("views/songProgress");
2019-01-30 20:36:33 +00:00
var Slider = require("views/slider");
2018-10-28 21:32:44 +00:00
var Model = require("lib/wController/localModel");
var Enum = require("lib/utils/enum");
var Player = GridLayout.inherit({
className: "Player",
constructor: function(ctrl, options) {
GridLayout.fn.constructor.call(this, ctrl, options);
this._playPause = null;
this._prev = null;
this._next = null;
this._picture = null;
2018-10-28 21:32:44 +00:00
this._cpbCtrl = null;
2018-10-28 21:32:44 +00:00
this._infoModels = {
artist: new Model(null, "artist: unknown"),
album: new Model(null, "album: unknown"),
song: new Model(null, "song: unknown")
}
ctrl.on("newElement", this._onNewElement, this);
ctrl.on("removeElement", this._onRemoveElement, this);
2018-10-28 21:32:44 +00:00
var artist = new Label(this._infoModels.artist);
var album = new Label(this._infoModels.album);
var song = new Label(this._infoModels.song);
2019-01-30 20:36:33 +00:00
var spacer = new View(helper, {maxWidth: 10});
var progress = new SongProgress(ctrl.progress);
2019-01-30 20:36:33 +00:00
var volume = new Slider(ctrl.volume, {maxWidth: 100});
2018-10-28 21:32:44 +00:00
this.append(artist, 0, 4, 1, 1, GridLayout.Aligment.LeftCenter);
this.append(song, 1, 4, 1, 1, GridLayout.Aligment.LeftCenter);
this.append(album, 2, 4, 1, 1, GridLayout.Aligment.LeftCenter);
this.append(spacer, 0, 6, 3, 1, GridLayout.Aligment.LeftCenter);
this.append(progress, 1, 5, 1, 1, GridLayout.Aligment.CenterCenter);
2019-01-30 20:36:33 +00:00
this.append(volume, 1, 7, 1, 1, GridLayout.Aligment.CenterCenter);
2018-10-28 21:32:44 +00:00
this._uncyclic.push(this._infoModels.artist.destructor.bind(this._infoModels.artist));
this._uncyclic.push(this._infoModels.song.destructor.bind(this._infoModels.song));
this._uncyclic.push(this._infoModels.album.destructor.bind(this._infoModels.album));
},
destructor: function() {
this._f.off("newElement", this._onNewElement, this);
this._f.off("removeElement", this._onRemoveElement, this);
2018-10-28 21:32:44 +00:00
this._clearCpbCtrl();
GridLayout.fn.destructor.call(this);
},
_clearCpbCtrl: function() {
if (this._cpbCtrl !== null) {
this._cpbCtrl.off("newElement", this._onCpbNewElement, this);
this._cpbCtrl.off("removeElement", this._onCpbRemoveElement, this);
this._cpbCtrl = null;
}
},
_onNewElement: function(ctrl, type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause = new Button(ctrl);
this.append(this._playPause, 0, 2, 3, 1);
break;
case ItemType.straight.prev:
this._prev = new Button(ctrl);
this.append(this._prev, 0, 1, 3, 1);
break;
case ItemType.straight.next:
this._next = new Button(ctrl);
this.append(this._next, 0, 3, 3, 1);
2018-10-28 21:32:44 +00:00
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
this._cpbCtrl = ctrl;
this._cpbCtrl.on("newElement", this._onCpbNewElement, this);
this._cpbCtrl.on("removeElement", this._onCpbRemoveElement, this);
break;
case ItemType.straight.picture:
this._picture = new Image(ctrl, {
maxWidth: 100,
maxHeight: 100
});
this.append(this._picture, 0, 0, 3, 1);
break;
2018-10-28 21:32:44 +00:00
}
},
_onRemoveElement: function(type) {
var ItemType = Enum.storage["ItemType"];
switch (type) {
case ItemType.straight.playPause:
this._playPause.destructor();
this._playPause = null;
break;
case ItemType.straight.prev:
this._prev.destructor();
this._prev = null;
break;
case ItemType.straight.next:
this._next.destructor();
this._next = null;
break;
case ItemType.straight.queue:
break;
case ItemType.straight.currentPlayback:
this._clearCpbCtrl();
break;
case ItemType.straight.picture:
this._picture.destructor();
this._picture = null;
break;
}
},
2018-10-28 21:32:44 +00:00
_onCpbNewElement: function(key, value) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": " + value.toString());
}
},
_onCpbRemoveElement: function(key) {
var model = this._infoModels[key];
if (model) {
model.setData(key + ": unknown");
}
}
});
var helper = new Model();
2018-10-28 21:32:44 +00:00
return Player;
});
})()