-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from kyan/feature/upcoming_tracks
Upcoming tracks
- Loading branch information
Showing
8 changed files
with
164 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,5 +9,5 @@ gem 'sugarcube', :require => [ | |
'sugarcube-attributedstring', | ||
] | ||
gem "ib" | ||
#gem "kyan_jukebox_websocket_lib", :path => "/Users/duncan/_dev/kyan/gems/kyan_jukebox_websocket_lib" | ||
#gem "kyan_jukebox", :path => "/Users/duncan/_dev/kyan/gems/kyan_jukebox_websocket_lib" | ||
gem "kyan_jukebox", :git => '[email protected]:kyan/kyan_jukebox_websocket_lib.git' |
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
GIT | ||
remote: [email protected]:kyan/kyan_jukebox_websocket_lib.git | ||
revision: 60178464e15c2465357326aa40906c1e71377de5 | ||
revision: 8bfe8b70b4ed6fefb491591d9e62279c262ade7d | ||
specs: | ||
kyan_jukebox (0.2.0) | ||
kyan_jukebox (0.2.3) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
|
@@ -85,4 +85,4 @@ DEPENDENCIES | |
sugarcube | ||
|
||
BUNDLED WITH | ||
1.10.6 | ||
1.11.2 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class UpcomingTableView < NSTableView | ||
|
||
def init | ||
super.tap do |v| | ||
v.translatesAutoresizingMaskIntoConstraints = false | ||
|
||
col2 = NSTableColumn.alloc.initWithIdentifier "col2" | ||
col2.setWidth 20 | ||
col2.identifier = :thumb | ||
v.addTableColumn col2 | ||
|
||
col3 = NSTableColumn.alloc.initWithIdentifier "col3" | ||
col3.setWidth 220 | ||
col3.identifier = :title | ||
v.addTableColumn col3 | ||
|
||
col4 = NSTableColumn.alloc.initWithIdentifier "col4" | ||
col4.setWidth 40 | ||
col4.identifier = :duration | ||
v.addTableColumn col4 | ||
end | ||
end | ||
|
||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
class UpcomingController < NSViewController | ||
|
||
def init | ||
super.tap do |c| | ||
c.init_data | ||
c.build_view | ||
|
||
@update_observer = App.notification_center.observe JB_UPDATED do |n| | ||
refresh(n.userInfo[:jukebox]) | ||
end | ||
end | ||
end | ||
|
||
def refresh(jukebox) | ||
@jukebox = jukebox | ||
refresh_tracks | ||
@table_view.reloadData | ||
end | ||
|
||
def init_data | ||
@upcoming_tracks = [] | ||
end | ||
|
||
def build_view | ||
@table_view = UpcomingTableView.alloc.init | ||
@table_view.setBoundsOrigin([-10,0]); | ||
@table_view.setBoundsSize([@table_view.bounds.size.width+20, @table_view.bounds.size.height]); | ||
@table_view.delegate = self | ||
@table_view.dataSource = self | ||
self.setView(@table_view) | ||
end | ||
|
||
def numberOfRowsInTableView(table_view) | ||
@upcoming_tracks.count | ||
end | ||
|
||
def tableView(table_view, objectValueForTableColumn:table_column, row:row) | ||
case table_column.identifier.to_sym | ||
when :thumb | ||
if @upcoming_tracks[row].artwork_url.nil? | ||
NSImage.imageNamed("missing_artwork.png") | ||
else | ||
url = NSURL.URLWithString(@upcoming_tracks[row].artwork_url) | ||
NSImage.alloc.initWithContentsOfURL(url) | ||
end | ||
when :title | ||
str = "#{@upcoming_tracks[row].heading} (#{@upcoming_tracks[row].added_by})" | ||
paragraph = NSMutableParagraphStyle.new | ||
paragraph.setLineBreakMode(NSLineBreakByTruncatingTail) | ||
|
||
str.attrd({ | ||
'NSParagraphStyle' => paragraph | ||
}) | ||
when :duration | ||
@upcoming_tracks[row].eta | ||
end | ||
end | ||
|
||
def tableView(table_view, heightOfRow:row) | ||
20 | ||
end | ||
|
||
def tableView(table_view, viewForTableColumn:table_column, row:row) | ||
tview = table_view.makeViewWithIdentifier(table_column.identifier, owner:self) | ||
|
||
case table_column.identifier.to_sym | ||
when :thumb | ||
tview = NSImageView.new.tap do |v| | ||
v.setTranslatesAutoresizingMaskIntoConstraints(false) | ||
v.setEditable(false) | ||
v.setImageScaling(NSImageScaleAxesIndependently) | ||
v.identifier = 'thumbid' | ||
end | ||
when :title | ||
tview = NSTextField.new.tap do |v| | ||
v.frame = CGRectZero | ||
v.font = NSFont.systemFontOfSize(12.0) | ||
v.setEditable(false) | ||
v.setBezeled(false) | ||
v.setDrawsBackground(false) | ||
v.setSelectable(false) | ||
v.identifier = 'titleid' | ||
end | ||
else | ||
tview = NSTextField.new.tap do |v| | ||
v.frame = CGRectZero | ||
v.setEditable(false) | ||
v.setBezeled(false) | ||
v.setAlignment(NSRightTextAlignment) | ||
v.setDrawsBackground(false) | ||
v.setSelectable(false) | ||
v.identifier = 'defaultid' | ||
end | ||
end | ||
|
||
tview | ||
end | ||
|
||
private | ||
|
||
def refresh_tracks | ||
@upcoming_tracks = @jukebox.playlist.upcoming_tracks(current_track)[0...5] | ||
end | ||
|
||
def current_track | ||
return @jukebox.track.file if @jukebox.last_change?(:track) | ||
nil | ||
end | ||
end |
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