Class: MultimediaParadise::Rubio::Model::RadioPresenter

Inherits:
Object
  • Object
show all
Defined in:
lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb

Overview

Rubio::Model::RadioPresenter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RadioPresenter

#

initialize

Initializes with view options below:

:backend, :initial_width, :initial_height, :radio_station_count, :debug, :show_menu, :show_page_count, :show_bookmarks, :show_margins :gradually_fetch_stations, :table_per_page

#


39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 39

def initialize(options = {})
  reset
  @options = options
  @options[:radio_station_count] = 1_000_000 if options[:radio_station_count] == -1
  @loaded_station_count = [options[:gradually_fetch_stations] ? 100 : options[:radio_station_count], options[:radio_station_count]].min
  @loaded_station_offset = 0
  @stations = Model::RadioBrowser.topvote(@loaded_station_count, offset: @loaded_station_offset)
  @player = Model::Player.new(options[:backend], show_currently_playing: options[:show_currently_playing])
  @initial_width = (options[:initial_width] || (options[:show_bookmarks] ? 740 : 620)).to_i
  @initial_height = (options[:initial_height] || calculate_initial_height).to_i
  @window_height = @initial_height
  Glimmer::DataBinding::Observer::Proc.new {
    self.window_height = calculate_initial_height
  }.observe(@player, :currently_playing)
end

Instance Attribute Details

#current_stationObject

Returns the value of attribute current_station.



26
27
28
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 26

def current_station
  @current_station
end

#initial_heightObject (readonly)

Returns the value of attribute initial_height.



22
23
24
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 22

def initial_height
  @initial_height
end

#initial_widthObject (readonly)

Returns the value of attribute initial_width.



21
22
23
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 21

def initial_width
  @initial_width
end

#optionsObject (readonly)

Returns the value of attribute options.



23
24
25
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 23

def options
  @options
end

#playerObject (readonly)

Returns the value of attribute player.



20
21
22
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 20

def player
  @player
end

#stationsObject

Returns the value of attribute stations.



25
26
27
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 25

def stations
  @stations
end

#viewObject

Returns the value of attribute view.



27
28
29
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 27

def view
  @view
end

#window_heightObject

Returns the value of attribute window_height.



28
29
30
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 28

def window_height
  @window_height
end

Instance Method Details

#fetch_more_stationsObject

#

fetch_more_stations

#


104
105
106
107
108
109
110
111
112
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 104

def fetch_more_stations
  @loaded_station_offset += @loaded_station_count
  @loaded_station_count *= 2
  new_station_count = [@loaded_station_count, options[:radio_station_count] - @loaded_station_offset].min
  old_station_count = @stations.count
  self.stations += Model::RadioBrowser.topvote(new_station_count, offset: @loaded_station_offset)
  @all_stations_fetched = @stations.count == old_station_count
  self.stations
end

#play_stationObject



78
79
80
81
82
83
84
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 78

def play_station
  @player.play(current_station.url, station_name: current_station.name)
  current_station.playing = true
rescue => error
  self.current_station = nil
  raise error
end

#resetObject

#

reset

#


58
59
60
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 58

def reset
  @view = :all
end

#select_station(station) ⇒ Object



62
63
64
65
66
67
68
69
70
71
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 62

def select_station(station)
  playing = station.playing?
  stop_station
  self.current_station = station
  if playing
    self.current_station = nil
  else
    play_station
  end
end

#stations_incomplete?Boolean

#

stations_incomplete?

#

Returns:

  • (Boolean)


97
98
99
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 97

def stations_incomplete?
  !@all_stations_fetched && @stations.count < options[:radio_station_count]
end

#stop_stationObject

stop_station



87
88
89
90
91
92
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 87

def stop_station
  return if current_station.nil?
  @player.stop
  current_station.playing = false
  self.current_station = nil
end

#toggle_bookmarked_station(station) ⇒ Object



73
74
75
76
# File 'lib/multimedia_paradise/gui/glimmer/rubio/model/radio_presenter.rb', line 73

def toggle_bookmarked_station(station)
  return unless station
  station.bookmarked = !station.bookmarked?
end