Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Refactor

  • Loading branch information...
commit 4a20befec16e91cf24d605506d80ebf40c8e7246 1 parent 3c0f96d
@satococoa authored
View
18 app/friend_controller.rb
@@ -1,5 +1,5 @@
-class FriendController < UIViewController
- attr_accessor :friend
+class PhotoController < UIViewController
+ attr_accessor :photo
def init
super
self.hidesBottomBarWhenPushed = true
@@ -8,7 +8,7 @@ def init
def viewDidLoad
super
- view.styleId = 'friend'
+ view.styleId = 'photo'
action_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemAction, target:self, action:'action_tapped')
delete_button = UIBarButtonItem.alloc.initWithBarButtonSystemItem(UIBarButtonSystemItemTrash, target:self, action:'delete_tapped')
navigationItem.rightBarButtonItems = [action_button, delete_button]
@@ -39,7 +39,7 @@ def viewWillAppear(animated)
end
def setup_image_frame
- image_size = @friend.image.size
+ image_size = @photo.image.size
frame_size = CGSizeMake(App.bounds.size.width, App.bounds.size.height - 20)
if image_size.height > frame_size.height
height = frame_size.height
@@ -59,12 +59,12 @@ def setup_image_frame
y = (frame_size.height - height) / 2
@image_view.frame = [[x, y], [width, height]]
- @image_view.image = @friend.image
+ @image_view.image = @photo.image
end
def setup_label
@label.frame = [[0, App.bounds.size.height - 20 - 30], [content_frame.size.width, 30]]
- @label.text = @friend.created_at.strftime('%Y/%m/%d %H:%M ')
+ @label.text = @photo.created_at.strftime('%Y/%m/%d %H:%M ')
end
def action_tapped
@@ -87,7 +87,7 @@ def actionSheet(action_sheet, clickedButtonAtIndex:button_index)
when 1 # facebook
open_share(:facebook)
when 2 # save to album
- @friend.image.saveToPhotosAlbum
+ @photo.image.saveToPhotosAlbum
SVProgressHUD.showSuccessWithStatus('Saved!')
when action_sheet.cancelButtonIndex
return
@@ -104,7 +104,7 @@ def actionSheet(action_sheet, clickedButtonAtIndex:button_index)
private
def delete
- @friend.delete
+ @photo.delete
navigationController.viewControllers[0].reload
navigationController.popViewControllerAnimated(true)
end
@@ -119,7 +119,7 @@ def open_share(type)
if SLComposeViewController.isAvailableForServiceType(service_type)
controller = SLComposeViewController.composeViewControllerForServiceType(service_type).tap do |t|
t.setInitialText(AppDelegate::HASHTAG + ' ')
- t.addImage(@friend.image)
+ t.addImage(@photo.image)
t.completionHandler = lambda {|result|
dismissModalViewControllerAnimated(true)
}
View
6 app/friend.rb → app/photo.rb
@@ -1,4 +1,4 @@
-class Friend < NanoStore::Model
+class Photo < NanoStore::Model
attribute :image_path
attribute :image_orientation
attribute :thumbnail_path
@@ -53,14 +53,14 @@ def self.save_with_image(image)
path = NSString.pathWithComponents([App.documents_path, thumbnail_path])
thumbnail.saveToPath(path, type:NYXImageTypePNG, backgroundFillColor:nil)
- friend = self.create(
+ photo = self.create(
:image_path => image_path,
:image_orientation => image.imageOrientation,
:thumbnail_path => thumbnail_path,
:created_at => Time.now
)
Dispatch::Queue.main.async {
- App.notification_center.post('FriendDidCreate', self, {friend: friend})
+ App.notification_center.post('PhotoDidCreate', self, {photo: photo})
}
}
end
View
8 app/friend_cell.rb → app/photo_cell.rb
@@ -1,4 +1,4 @@
-class FriendCell < UICollectionViewCell
+class PhotoCell < UICollectionViewCell
def initWithFrame(rect)
super
@image_view ||= LoadableImageView.new.tap do |iv|
@@ -20,12 +20,12 @@ def layoutSubviews
end
end
- def friend=(friend)
- if friend.thumbnail.nil?
+ def photo=(photo)
+ if photo.thumbnail.nil?
@image_view.loading = true
else
@image_view.loading = false
- @image_view.image = friend.thumbnail
+ @image_view.image = photo.thumbnail
end
end
end
View
34 app/photos_controller.rb
@@ -15,7 +15,7 @@ def viewDidLoad
self.toolbarItems = [open_rubyfriends_button, spacer, info_button]
self.collectionView.styleId = 'photos'
- self.collectionView.registerClass(FriendCell, forCellWithReuseIdentifier:'friend_cell')
+ self.collectionView.registerClass(PhotoCell, forCellWithReuseIdentifier:'photo_cell')
self.collectionView.collectionViewLayout.tap do |l|
l.itemSize = CGSizeMake(128, 128)
@@ -30,13 +30,13 @@ def viewDidLoad
def viewWillAppear(animated)
navigationController.navigationBar.translucent = false
- @add_friend_observer = App.notification_center.observe('FriendDidCreate', Friend) do |notif|
+ @add_photo_observer = App.notification_center.observe('PhotoDidCreate', Photo) do |notif|
reload
end
end
def viewWillDisappear(animated)
- App.notification_center.unobserve(@add_friend_observer)
+ App.notification_center.unobserve(@add_photo_observer)
end
def viewDidAppear(animated)
@@ -46,12 +46,12 @@ def viewDidAppear(animated)
open_tweet(@image)
@saving_image = @image
Dispatch::Queue.concurrent.async {
- @friends = [Friend.new] + @friends
+ @photos = [Photo.new] + @photos
path = NSIndexPath.indexPathForRow(0, inSection:0)
Dispatch::Queue.main.async {
@tutorial.removeFromSuperview unless @tutorial.nil?
collectionView.insertItemsAtIndexPaths([path])
- Friend.save_with_image(@saving_image)
+ Photo.save_with_image(@saving_image)
}
}
@image = nil
@@ -63,14 +63,14 @@ def numberOfSectionsInCollectionView(collection_view)
end
def collectionView(collection_view, numberOfItemsInSection:section)
- @friends.count
+ @photos.count
end
def collectionView(collection_view, cellForItemAtIndexPath:index_path)
- cell = collection_view.dequeueReusableCellWithReuseIdentifier('friend_cell', forIndexPath:index_path)
- friend = @friends[index_path.row]
- cell.friend = friend
- cell.tag = @friends.count - index_path.row
+ cell = collection_view.dequeueReusableCellWithReuseIdentifier('photo_cell', forIndexPath:index_path)
+ photo = @photos[index_path.row]
+ cell.photo = photo
+ cell.tag = @photos.count - index_path.row
tap = UITapGestureRecognizer.alloc.initWithTarget(self, action:'image_tapped:')
cell.addGestureRecognizer(tap)
cell
@@ -78,17 +78,17 @@ def collectionView(collection_view, cellForItemAtIndexPath:index_path)
def image_tapped(target)
index = target.view.tag
- friend = @friends[-index]
- if !friend.image.nil?
- @friend_controller ||= FriendController.new
- @friend_controller.friend = friend
- navigationController.pushViewController(@friend_controller, animated:true)
+ photo = @photos[-index]
+ if !photo.image.nil?
+ @photo_controller ||= PhotoController.new
+ @photo_controller.photo = photo
+ navigationController.pushViewController(@photo_controller, animated:true)
end
end
def reload
- @friends = Friend.find({}, {:sort => {:created_at => :desc}})
- if @friends.count == 0
+ @photos = Photo.find({}, {:sort => {:created_at => :desc}})
+ if @photos.count == 0
tutorial_frame = [[0, 0], [content_frame.size.width, content_frame.size.height-44]]
@tutorial ||= TutorialView.alloc.initWithFrame(tutorial_frame)
collectionView.addSubview(@tutorial)
View
2  resources/default.css
@@ -34,6 +34,6 @@ nav-buttons, bar-button-item {
background-color: transparent;
}
-#friend, #photos {
+#photo, #photos {
background-image: url(background.png);
}
Please sign in to comment.
Something went wrong with that request. Please try again.