Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Commit

Permalink
Added sharing button
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew committed Apr 16, 2013
1 parent 9e59282 commit dbdfea2
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions app/web_view_controller.rb
Expand Up @@ -7,26 +7,38 @@ def initWithStory(story)
def viewDidLoad
self.view = UIWebView.alloc.init
self.view.scalesPageToFit = true
loadURL(@story['url']) if @story
loadWebview if @story
end

def loadStory(story)
@story = story
loadURL(@story['url'])
navigationItem.title = @story['title']
loadWebview
end

def loadComments(story)
@story = story
loadURL("https://news.ycombinator.com/item?id=#{@story['id']}")
navigationItem.title = @story['title']
loadWebview("https://news.ycombinator.com/item?id=#{@story['id']}")
end

def loadURL(url)
def loadWebview(url = @story['url'])
self.view.loadRequest NSURLRequest.requestWithURL(NSURL.URLWithString(url))
navigationItem.title = @story['title']
share_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemAction, target: self, action: 'share_button_action')
navigationItem.setRightBarButtonItem(share_button, true)
end

def share_button_action
activityViewController = UIActivityViewController.alloc.initWithActivityItems(["#{@story['title']} - #{@story['url']}"], applicationActivities:nil)
if Device.iphone?
self.presentViewController(activityViewController, animated:true, completion:nil)
else
open_share_popup(activityViewController)
end
end

def viewWillAppear(animated)
navigationItem.title = @story['title'] if @story
def open_share_popup(activityViewController)
rect = [[Device.screen.width, -8], [1, 1]]
@popup = UIPopoverController.alloc.initWithContentViewController(activityViewController)
@popup.presentPopoverFromRect(rect, inView:self.view, permittedArrowDirections:UIPopoverArrowDirectionUp, animated:true)
end
end

0 comments on commit dbdfea2

Please sign in to comment.