-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
147 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
src/js/foreground/view/listItemButton/playPauseSongButtonView.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
define(function(require) { | ||
'use strict'; | ||
|
||
var ListItemButtonView = require('foreground/view/listItemButton/listItemButtonView'); | ||
var PlayPauseSongButtonTemplate = require('text!template/listItemButton/playPauseSongButton.html'); | ||
var PlayIconTemplate = require('text!template/icon/playIcon_18.svg'); | ||
var PauseIconTemplate = require('text!template/icon/pauseIcon_18.svg'); | ||
var PlayerState = require('common/enum/playerState'); | ||
|
||
var PlayPauseSongButtonView = ListItemButtonView.extend({ | ||
template: _.template(PlayPauseSongButtonTemplate), | ||
templateHelpers: { | ||
playIcon: _.template(PlayIconTemplate)(), | ||
pauseIcon: _.template(PauseIconTemplate)() | ||
}, | ||
|
||
attributes: { | ||
title: chrome.i18n.getMessage('play') | ||
}, | ||
|
||
ui: function() { | ||
return { | ||
playIcon: '.playIcon', | ||
pauseIcon: '.pauseIcon' | ||
}; | ||
}, | ||
|
||
streamItems: null, | ||
player: null, | ||
|
||
initialize: function() { | ||
this.streamItems = Streamus.backgroundPage.stream.get('items'); | ||
this.player = Streamus.backgroundPage.player; | ||
|
||
this.listenTo(this.player, 'change:state', this._onPlayerChangeState); | ||
this.listenTo(this.streamItems, 'change:active', this._onStreamItemsChangeActive); | ||
|
||
ListItemButtonView.prototype.initialize.apply(this, arguments); | ||
}, | ||
|
||
onRender: function() { | ||
this._setState(); | ||
}, | ||
|
||
doOnClickAction: function() { | ||
var isPausable = this._isPausable(); | ||
|
||
if (isPausable) { | ||
this.player.pause(); | ||
} else { | ||
this._playSong(); | ||
} | ||
}, | ||
|
||
_onPlayerChangeState: function() { | ||
this._setState(); | ||
}, | ||
|
||
_onStreamItemsChangeActive: function() { | ||
this._setState(); | ||
}, | ||
|
||
_setState: function() { | ||
var isPausable = this._isPausable(); | ||
|
||
// TODO: There's a difference between buffering-->play and buffering-->paused. Don't want to change button when buffering-->paused. How to tell the difference? | ||
this.ui.pauseIcon.toggleClass('is-hidden', !isPausable); | ||
this.ui.playIcon.toggleClass('is-hidden', isPausable); | ||
}, | ||
|
||
_isPausable: function() { | ||
var activeSongId = this.streamItems.getActiveSongId(); | ||
// The pause icon is visible only if the player is playing/buffering and the song is this model's song. | ||
var songId = this.model.get('song').get('id'); | ||
var isPlayerPausable = this.player.isPausable(); | ||
var isPausable = activeSongId === songId && isPlayerPausable; | ||
|
||
return isPausable; | ||
}, | ||
|
||
_playSong: function() { | ||
var song = this.model.get('song'); | ||
|
||
// If there's only one song to be played - check if it's already in the stream. | ||
var streamItem = this.streamItems.getBySong(song); | ||
|
||
if (_.isUndefined(streamItem)) { | ||
this.streamItems.addSongs(song, { | ||
playOnAdd: true | ||
}); | ||
} else { | ||
this._playStreamItem(streamItem); | ||
} | ||
}, | ||
|
||
_playStreamItem: function(streamItem) { | ||
if (streamItem.get('active')) { | ||
this.player.play(); | ||
} else { | ||
this.player.set('playOnActivate', true); | ||
streamItem.save({ active: true }); | ||
} | ||
} | ||
}); | ||
|
||
return PlayPauseSongButtonView; | ||
}); |
58 changes: 0 additions & 58 deletions
58
src/js/foreground/view/listItemButton/playSongButtonView.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<span class="pauseIcon"> | ||
<%= pauseIcon %> | ||
</span> | ||
|
||
<span class="playIcon"> | ||
<%= playIcon %> | ||
</span> |