Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data caching from Github #22

Merged
merged 3 commits into from Apr 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 1 addition & 12 deletions app/app_delegate.rb
Expand Up @@ -37,18 +37,7 @@ def appearance
end

def on_activate
cache_talks
end

def cache_talks
AFMotion::HTTP.get("http://rubymotion.com/conference/talks.plist", q: Time.now.to_i) do |result|
if result && result.body
path = "talks.plist".document_path
path.remove_file! if path.file_exists?
NSFileManager.defaultManager.createFileAtPath(path, contents: result.body, attributes: nil)
"talks_cached".post_notification
end
end
Networking.cache_data
end

def show_menu
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/speaker_view_controller.rb
Expand Up @@ -26,9 +26,8 @@ def on_init

def will_appear
@view_is_set_up ||= begin
ap "speaker: #{@speaker}"
s = speaker_properties
ap s
ap s if BW.debug?
@speaker_image.image = s['speaker_image'].uiimage
@speaker_name.text = s['name']
@speaker_company.text = " #{s['company']} "
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/talks_view_controller.rb
Expand Up @@ -129,9 +129,9 @@ def scrollViewDidScroll(scrollView)
scrollDirection = (@lastContentOffset > scrollView.contentOffset.y) ? SCROLL_DIRECTION_UP : SCROLL_DIRECTION_DOWN

if scrollDirection == SCROLL_DIRECTION_DOWN
ap 'scrolling down'
ap 'scrolling down' if BW.debug?
elsif scrollDirection == SCROLL_DIRECTION_UP
ap 'scrolling up'
ap 'scrolling up' if BW.debug?
end

# currentOffset = scrollView.contentOffset.y
Expand Down
17 changes: 17 additions & 0 deletions app/models/network.rb
@@ -0,0 +1,17 @@
class Networking
def self.cache_data
raw_path = 'https://raw.githubusercontent.com/MohawkApps/rubymotion-inspect2014/master/resources/'
['talks.plist', 'speakers.plist', 'sponsors.plist'].each do |cache_file|
AFMotion::HTTP.get("#{raw_path}#{cache_file}", q: Time.now.to_i) do |result|
ap "Caching #{cache_file}" if BW.debug?
if result && result.body
path = cache_file.document_path
path.remove_file! if path.file_exists?
NSFileManager.defaultManager.createFileAtPath(path, contents: result.body, attributes: nil)

"talks_cached".post_notification if cache_file.start_with?('talks')
end
end
end
end
end