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");
|
2018-11-28 06:54:14 +00:00
|
|
|
deps.push("views/view");
|
2018-12-02 15:07:43 +00:00
|
|
|
deps.push("views/image");
|
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");
|
2018-11-28 06:54:14 +00:00
|
|
|
var View = require("views/view");
|
2018-12-02 15:07:43 +00:00
|
|
|
var Image = require("views/image");
|
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;
|
2019-01-03 00:26:42 +00:00
|
|
|
this._prev = null;
|
|
|
|
this._next = null;
|
2018-12-02 15:07:43 +00:00
|
|
|
this._picture = null;
|
2018-10-28 21:32:44 +00:00
|
|
|
this._cpbCtrl = null;
|
|
|
|
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);
|
2019-01-03 00:26:42 +00:00
|
|
|
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);
|
2018-11-28 06:54:14 +00:00
|
|
|
var spacer = new View(helper);
|
2018-10-28 21:32:44 +00:00
|
|
|
|
2019-01-03 00:26:42 +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, 5, 3, 1, GridLayout.Aligment.LeftCenter);
|
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);
|
2019-01-03 00:26:42 +00:00
|
|
|
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);
|
2019-01-03 00:26:42 +00:00
|
|
|
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;
|
2018-12-02 15:07:43 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
},
|
2019-01-03 00:26:42 +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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-11-28 06:54:14 +00:00
|
|
|
var helper = new Model();
|
|
|
|
|
2018-10-28 21:32:44 +00:00
|
|
|
return Player;
|
|
|
|
});
|
|
|
|
})()
|