Class: Motion::AssetsLibrary::AssetsDataSource

Inherits:
Object
  • Object
show all
Defined in:
lib/project/assets_library/data_sources/assets_data_source.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(collection_view) ⇒ AssetsDataSource

Returns a new instance of AssetsDataSource.



6
7
8
9
10
11
12
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 6

def initialize(collection_view)
  self.collection_view = collection_view

  register_cells

  asset_loader.load_assets
end

Instance Attribute Details

#collection_viewObject

Returns the value of attribute collection_view.



4
5
6
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 4

def collection_view
  @collection_view
end

Instance Method Details

#asset_loaderObject



36
37
38
39
40
41
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 36

def asset_loader
  @_asset_loader ||= AssetsLibrary::Loader.new.tap do |loader|
    loader.delegate = WeakRef.new(self)
    loader.denied denied_callback
  end
end

#cell_classObject



20
21
22
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 20

def cell_class
  AssetsLibrary::AssetCell
end

#collectionView(collection_view, cellForItemAtIndexPath: index_path) ⇒ Object



24
25
26
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 24

def collectionView(collection_view, numberOfItemsInSection: section)
  asset_loader.assets.count
end

#denied_callbackObject



43
44
45
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 43

def denied_callback
  -> { show_alert('Access to the Photo Library has been denied') }
end

#did_load_assets(asset) ⇒ Object



56
57
58
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 56

def did_load_assets(asset)
  collection_view.reloadData
end

#register_cellsObject



14
15
16
17
18
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 14

def register_cells
  collection_view.registerClass(
    cell_class,
    forCellWithReuseIdentifier: cell_class::IDENTIFIER)
end

#show_alert(message) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/project/assets_library/data_sources/assets_data_source.rb', line 47

def show_alert(message)
  UIAlertView.alloc.initWithTitle(
    nil,
    message:           message,
    delegate:          nil,
    cancelButtonTitle: 'Ok',
    otherButtonTitles: nil).show
end