Skip to content

Commit

Permalink
Merge branch 'feature/always_show_votes' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
whomwah committed Jan 14, 2014
2 parents 5b68527 + 9835b65 commit b3a846f
Show file tree
Hide file tree
Showing 11 changed files with 526 additions and 432 deletions.
59 changes: 46 additions & 13 deletions app/_views/album_art_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,42 @@ def init
v.addSubview(@vote_view)

@vote_slider_in_progress = false

@vote_toggle_state_active = always_show_votes?
slidein_vote_view

@update_observer = App.notification_center.observe JB_TOGGLE_VOTE_SLIDER do |n|
state = n.userInfo[:state]
@vote_toggle_state_active = state
handle_vote_toggle_update
end
end
end

def handle_vote_toggle_update
vote_toggle_state_active? ? slidein_vote_view : slideout_vote_view
end

def slidein_vote_view
return if @vote_slider_in_progress
return if vote_slider_in_progress?

new_frame = @vote_view.frame
new_frame.origin.x += VOTE_VIEW_W
new_frame.origin.x = 0

@vote_slider_in_progress = true

NSAnimationContext.beginGrouping
NSAnimationContext.currentContext.setCompletionHandler(
lambda do
timer = NSTimer.scheduledTimerWithTimeInterval(
5.0,
target:self,
selector:'slideout_vote_view',
userInfo:nil,
repeats: false
)
NSRunLoop.mainRunLoop.addTimer(timer, forMode:NSRunLoopCommonModes)
if !vote_toggle_state_active?
timer = NSTimer.scheduledTimerWithTimeInterval(
5.0,
target:self,
selector:'slideout_vote_view',
userInfo:nil,
repeats: false
)
NSRunLoop.mainRunLoop.addTimer(timer, forMode:NSRunLoopCommonModes)
end
end
)
NSAnimationContext.currentContext.setDuration(0.5)
Expand All @@ -42,12 +55,13 @@ def slidein_vote_view

def slideout_vote_view
new_frame = @vote_view.frame
new_frame.origin.x -= VOTE_VIEW_W
new_frame.origin.x = -VOTE_VIEW_W

NSAnimationContext.beginGrouping
NSAnimationContext.currentContext.setCompletionHandler(
lambda do
@vote_slider_in_progress = false
slidein_vote_view if vote_toggle_state_active?
end
)
NSAnimationContext.currentContext.setDuration(0.5)
Expand All @@ -57,7 +71,6 @@ def slideout_vote_view

def handle_vote(score, rating)
@vote_view.do_vote(score, rating)

make_turd if !score.nil? && score < -6

slidein_vote_view
Expand Down Expand Up @@ -94,4 +107,24 @@ def make_turd
setImage(turd)
end

def always_show_votes?
Persistence.get("alwaysShowVotes") == true ? 1 : 0
end

def vote_slider_in_progress?
@vote_slider_in_progress
end

def vote_toggle_state_active?
@vote_toggle_state_active == 1 ? true : false
end

def ok_to_slide_vote_in?
!vote_slider_in_progress? && @vote_toggle_state_active
end

def ok_to_slide_vote_out?
vote_slider_in_progress? && @vote_toggle_state_active
end

end
30 changes: 20 additions & 10 deletions app/_views/nowplaying_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ def draw_title_box
v.setDrawsBackground(false)
v.setSelectable(false)
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setContentCompressionResistancePriority(
NSLayoutPriorityDefaultLow,
forOrientation:NSLayoutConstraintOrientationHorizontal
)
v.cell.setBackgroundStyle(NSBackgroundStyleRaised)
end
end

Expand All @@ -132,6 +137,11 @@ def draw_artist_box
v.setDrawsBackground(false)
v.setSelectable(false)
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setContentCompressionResistancePriority(
NSLayoutPriorityDefaultLow,
forOrientation:NSLayoutConstraintOrientationHorizontal
)
v.cell.setBackgroundStyle(NSBackgroundStyleRaised)
end
end

Expand All @@ -142,6 +152,11 @@ def draw_album_box
v.setDrawsBackground(false)
v.setSelectable(false)
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setContentCompressionResistancePriority(
NSLayoutPriorityDefaultLow,
forOrientation:NSLayoutConstraintOrientationHorizontal
)
v.cell.setBackgroundStyle(NSBackgroundStyleRaised)
end
end

Expand All @@ -156,6 +171,11 @@ def draw_addedby_box
v.setDrawsBackground(false)
v.setSelectable(false)
v.setTranslatesAutoresizingMaskIntoConstraints(false)
v.setContentCompressionResistancePriority(
NSLayoutPriorityDefaultLow,
forOrientation:NSLayoutConstraintOrientationHorizontal
)
v.cell.setBackgroundStyle(NSBackgroundStyleRaised)
end
end

Expand All @@ -169,7 +189,6 @@ def update_title
'NSParagraphStyle' => paragraph
}) unless track.title.nil?
@title.setAttributedStringValue(txt)
@title.invalidateIntrinsicContentSize
@title.setToolTip(track.title)
end

Expand All @@ -184,15 +203,6 @@ def update_artist
}) unless track.artist.nil?
@artist.setAttributedStringValue(txt)
@artist.invalidateIntrinsicContentSize
# @artistsetContentHuggingPriority(
# NSLayoutPriorityFittingSizeCompression-1.0,
# forOrientation:NSLayoutConstraintOrientationVertical
# )

# Think You Can Wait (from the Film Win Win)
# The National
# Think You Can Wait (from the Film Win Win) / The National

@artist.setToolTip(track.artist)
end

Expand Down
1 change: 1 addition & 0 deletions app/_views/vote_view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def init
txt.setBezeled(false)
txt.setDrawsBackground(false)
txt.setAlignment(NSCenterTextAlignment)
txt.cell.setBackgroundStyle(NSBackgroundStyleRaised)
end

v.addSubview(@label)
Expand Down
11 changes: 4 additions & 7 deletions app/_windows/jukebox_control_window.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ def canBecomeMainWindow
end

def register_vote(button)
if VoteHandler.register(button.vote)
puts "vote registered"
else
puts "vote registerinf failed!"
end
VoteHandler.register(button.vote)
end

def build_views
Expand All @@ -39,7 +35,8 @@ def build_views

metrics_dict = {
"padding" => 10,
"default_width" => 200
"default_width" => 200,
"max_width" => 350
}

views_dictionary.each do |key, view|
Expand All @@ -60,7 +57,7 @@ def build_views
views:views_dictionary
)
constraints += NSLayoutConstraint.constraintsWithVisualFormat(
"H:|[now_playing(==default_width@750)]-5-[vote_buttons]-padding-|",
"H:|[now_playing(>=default_width,<=max_width)]-5-[vote_buttons]-padding-|",
options:0,
metrics:metrics_dict,
views:views_dictionary
Expand Down
1 change: 1 addition & 0 deletions app/config/constants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
JB_MESSAGE_RECEIVED="JukeboxMessageReceived"
JB_UPDATED="JukeboxUpdated"
JB_DO_VOTE="JukeboxDoVote"
JB_TOGGLE_VOTE_SLIDER="ToggleVoteSlider"

CHOSEN_BY_TXT="Chosen by"
4 changes: 4 additions & 0 deletions app/controllers/preferences_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,8 @@ def awakeFromNib
)
end

def toggle_always_show_votes(button)
App.notification_center.post(JB_TOGGLE_VOTE_SLIDER, nil, {state:button.state})
end

end
1 change: 1 addition & 0 deletions ib.xcodeproj/Stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@

-(IBAction) init;
-(IBAction) awakeFromNib;
-(IBAction) toggle_always_show_votes:(id) button;

@end

Expand Down
Loading

0 comments on commit b3a846f

Please sign in to comment.