Skip to content

Instantly share code, notes, and snippets.

@dphase
Created February 6, 2015 16:11
Show Gist options
  • Save dphase/f5bd020456145c824676 to your computer and use it in GitHub Desktop.
Save dphase/f5bd020456145c824676 to your computer and use it in GitHub Desktop.
class ImagesScreen < PM::CollectionScreen
collection_layout UICollectionViewFlowLayout
collection_cell ImagesCell
cell_identifier 'images_cell'
cell_width 78.5
cell_height 78.5
title 'Images'
attr_accessor :board, :thread
def on_load
@client = Singleton.instance
get_images
end
def collection_data
[{ :cells => Array(@thumbnails) }]
end
def get_images
@client.json_client.fetch("/#{board}/res/#{thread}.json") do |response|
@images = response['posts'].each.inject({
:cells => [], :list => [], :index => 0
}) do |img,(post,i)|
if post.has_key?('tim')
img[:cells] << {
:cell_identifier => self.class.cell_identifier,
:action => :tap_image,
:arguments => { :index => img[:index] },
:thumbnail => {
:url => @client.thumb_client.thumbnail(board, post['tim'])
},
}
img[:list] << @client.image_client.image(board, post['tim'], post['ext'])
img[:index] += 1
end ; img
end
@thumbnails = @images[:cells]
update_collection_data
end
end
def tap_image(args={})
open_modal ImageScreen.new(args.merge(:nav_bar => true,
:images => @images[:list]))
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment