Skip to content

Commit

Permalink
add delete button to TTPhotoViewController
Browse files Browse the repository at this point in the history
  • Loading branch information
a4agarwal committed Oct 6, 2009
1 parent 6718985 commit cc4ef1a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 3 deletions.
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@ distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
s
41 changes: 40 additions & 1 deletion src/TTPhotoViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ - (void)updateChrome {
playButton.enabled = _photoSource.numberOfPhotos > 1;
_previousButton.enabled = _centerPhotoIndex > 0;
_nextButton.enabled = _centerPhotoIndex >= 0 && _centerPhotoIndex < _photoSource.numberOfPhotos-1;
_deleteButton.enabled = _photoSource.numberOfPhotos > 0;
}

- (void)updateToolbarWithOrientation:(UIInterfaceOrientation)interfaceOrientation {
Expand Down Expand Up @@ -267,6 +268,38 @@ - (void)previousAction {
}
}


-(void)deleteFromSource
{
[_photoSource deletePhotoAtIndex:_centerPhotoIndex+1];
[self updateChrome];
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
if (!buttonIndex == [actionSheet cancelButtonIndex])
{
[_photoSource deletePhotoAtIndex:_centerPhotoIndex];
//[self previousAction];
[self showActivity:nil];
[self moveToNextValidPhoto];
[_scrollView reloadData];
[self refresh];
}
}

- (void)deleteAction {
UIActionSheet *actionSheet = [[UIActionSheet alloc]
initWithTitle:@"Are you sure you want to delete this photo?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles: nil];

[actionSheet showInView:self.view];
[actionSheet release];
}

- (void)showBarsAnimationDidStop {
self.navigationController.navigationBarHidden = NO;
}
Expand Down Expand Up @@ -304,6 +337,7 @@ - (id)init {
_captionStyle = nil;
_nextButton = nil;
_previousButton = nil;
_deleteButton = nil;
_statusText = nil;
_thumbsController = nil;
_slideshowTimer = nil;
Expand Down Expand Up @@ -365,6 +399,10 @@ - (void)loadView {
TTIMAGE(@"bundle://Three20.bundle/images/previousIcon.png")
style:UIBarButtonItemStylePlain target:self action:@selector(previousAction)];

_deleteButton = [[UIBarButtonItem alloc] initWithImage:
TTIMAGE(@"bundle://Three20.bundle/images/deleteIcon.png")
style:UIBarButtonItemStylePlain target:self action:@selector(deleteAction)];

UIBarButtonItem* playButton = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemPlay target:self action:@selector(playAction)] autorelease];
playButton.tag = 1;
Expand All @@ -378,7 +416,7 @@ - (void)loadView {
_toolbar.barStyle = self.navigationBarStyle;
_toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleTopMargin;
_toolbar.items = [NSArray arrayWithObjects:
space, _previousButton, space, _nextButton, space, nil];
space, _previousButton, space, _nextButton, space, _deleteButton, nil];
[_innerView addSubview:_toolbar];
}

Expand All @@ -391,6 +429,7 @@ - (void)viewDidUnload {
TT_RELEASE_SAFELY(_photoStatusView);
TT_RELEASE_SAFELY(_nextButton);
TT_RELEASE_SAFELY(_previousButton);
TT_RELEASE_SAFELY(_deleteButton);
TT_RELEASE_SAFELY(_toolbar);
}

Expand Down
Binary file added src/Three20.bundle/images/deleteIcon.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/Three20/TTPhotoSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ typedef enum {
*/
- (id<TTPhoto>)photoAtIndex:(NSInteger)index;

/**
*
*/
- (void)deletePhotoAtIndex:(NSInteger)index;

@end

///////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/Three20/TTPhotoViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
@class TTScrollView, TTPhotoView, TTStyle;

@interface TTPhotoViewController : TTModelViewController
<TTScrollViewDelegate, TTScrollViewDataSource, TTThumbsViewControllerDelegate> {
<TTScrollViewDelegate, TTScrollViewDataSource, TTThumbsViewControllerDelegate, UIActionSheetDelegate> {
id<TTPhotoSource> _photoSource;
id<TTPhoto> _centerPhoto;
NSInteger _centerPhotoIndex;
Expand All @@ -16,6 +16,7 @@
UIToolbar* _toolbar;
UIBarButtonItem* _nextButton;
UIBarButtonItem* _previousButton;
UIBarButtonItem* _deleteButton;
TTStyle* _captionStyle;
UIImage* _defaultImage;
NSString* _statusText;
Expand Down

0 comments on commit cc4ef1a

Please sign in to comment.