Added Photo Picker functionality to Feedback Composer (#3)

This commit is contained in:
moritz haarmann
2014-02-12 18:15:24 +01:00
parent ab241aaa1f
commit 9b57875a47
4 changed files with 143 additions and 8 deletions

View File

@@ -42,15 +42,22 @@
#import "BITHockeyHelper.h"
@interface BITFeedbackComposeViewController () <BITFeedbackUserDataDelegate> {
@interface BITFeedbackComposeViewController () <BITFeedbackUserDataDelegate, UIImagePickerControllerDelegate> {
UIStatusBarStyle _statusBarStyle;
}
@property (nonatomic, weak) BITFeedbackManager *manager;
@property (nonatomic, strong) UITextView *textView;
@property (nonatomic, strong) UIView *contentViewContainer;
@property (nonatomic, strong) UIScrollView *photoScrollView;
@property (nonatomic, strong) NSMutableArray *photoScrollViewImageViews;
@property (nonatomic, strong) NSString *text;
@property (nonatomic, strong) NSMutableArray *photos;
@property (nonatomic, strong) UIView *textAccessoryView;
@end
@@ -68,6 +75,8 @@
_blockUserDataScreen = NO;
_delegate = nil;
_manager = [BITHockeyManager sharedHockeyManager].feedbackManager;
_photos = [NSMutableArray new];
_photoScrollViewImageViews = [NSMutableArray new];
_text = nil;
}
@@ -122,12 +131,12 @@
frame.size.height = windowSize.width - navBarHeight - modalGap - kbSize.width;
}
}
[self.textView setFrame:frame];
[self.contentViewContainer setFrame:frame];
}
- (void)keyboardWillBeHidden:(NSNotification*)aNotification {
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.textView setFrame:frame];
[self.contentViewContainer setFrame:frame];
}
@@ -142,20 +151,49 @@
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self
action:@selector(dismissAction:)];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:BITHockeyLocalizedString(@"HockeyFeedbackComposeSend")
style:UIBarButtonItemStyleDone
target:self
action:@selector(sendAction:)];
// Container that contains both the textfield and eventually the photo scroll view on the right side
self.contentViewContainer = [[UIView alloc] initWithFrame:self.view.bounds];
[self.view addSubview:self.contentViewContainer];
// message input textfield
self.textView = [[UITextView alloc] initWithFrame:self.view.frame];
self.textView = [[UITextView alloc] initWithFrame:self.view.bounds];
self.textView.font = [UIFont systemFontOfSize:17];
self.textView.delegate = self;
self.textView.backgroundColor = [UIColor whiteColor];
self.textView.returnKeyType = UIReturnKeyDefault;
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[self.view addSubview:self.textView];
self.textView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.contentViewContainer addSubview:self.textView];
// Add Photo Button + Container that's displayed above the keyboard.
self.textAccessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 44)];
self.textAccessoryView.backgroundColor = [UIColor colorWithRed:0.9f green:0.9f blue:0.9f alpha:1.0f];
UIButton *addPhotoButton = [UIButton buttonWithType:UIButtonTypeSystem];
[addPhotoButton setTitle:@"+ Add Photo" forState:UIControlStateNormal];
addPhotoButton.frame = CGRectMake(0, 0, 100, 44);
[addPhotoButton addTarget:self action:@selector(addPhotoAction:) forControlEvents:UIControlEventTouchUpInside];
[self.textAccessoryView addSubview:addPhotoButton];
self.textView.inputAccessoryView = self.textAccessoryView;
self.photoScrollView = [[UIScrollView alloc] initWithFrame:CGRectZero];
self.photoScrollView.scrollEnabled = YES;
self.photoScrollView.bounces = YES;
self.photoScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
[self.contentViewContainer addSubview:self.photoScrollView];
}
- (void)viewWillAppear:(BOOL)animated {
@@ -178,7 +216,7 @@
[[UIApplication sharedApplication] setStatusBarStyle:(self.navigationController.navigationBar.barStyle == UIBarStyleDefault) ? UIStatusBarStyleDefault : UIStatusBarStyleBlackOpaque];
#endif
[self.textView setFrame:self.view.frame];
// [self.textView setFrame:self.view.frame];
if (_text) {
self.textView.text = _text;
@@ -218,6 +256,69 @@
[super viewDidDisappear:animated];
}
-(void)refreshPhotoScrollview {
CGFloat scrollViewWidth = 0;
if (self.photos.count){
scrollViewWidth = 100;
}
CGRect textViewFrame = self.textView.frame;
CGRect scrollViewFrame = self.photoScrollView.frame;
BOOL alreadySetup = CGRectGetWidth(scrollViewFrame) == scrollViewWidth;
if (!alreadySetup){
textViewFrame.size.width -= scrollViewWidth;
// status bar?
scrollViewFrame = CGRectMake(CGRectGetMaxX(textViewFrame), self.view.frame.origin.y, scrollViewWidth, CGRectGetHeight(textViewFrame));
self.textView.frame = textViewFrame;
self.photoScrollView.frame = scrollViewFrame;
self.photoScrollView.contentInset = self.textView.contentInset;
}
for (UIView *subview in self.photoScrollView.subviews){
[subview removeFromSuperview];
}
if (self.photos.count > self.photoScrollViewImageViews.count){
NSInteger numberOfViewsToCreate = self.photos.count - self.photoScrollViewImageViews.count;
for (int i = 0;i<numberOfViewsToCreate;i++){
UIImageView *newImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
[self.photoScrollViewImageViews addObject:newImageView];
}
}
int index = 0;
CGFloat currentYOffset = 0.0f;
for (UIImage* photo in self.photos){
UIImageView *imageView = self.photoScrollViewImageViews[index];
// determine the factor by which we scale..
CGFloat scaleFactor = CGRectGetWidth(self.photoScrollView.frame) / photo.size.width;
CGFloat height = photo.size.height * scaleFactor;
imageView.frame = CGRectInset(CGRectMake(0, currentYOffset, scaleFactor * photo.size.width, height),10,10);
currentYOffset += height;
[self.photoScrollView addSubview:imageView];
imageView.image = photo;
index++;
}
[self.photoScrollView setContentSize:CGSizeMake(CGRectGetWidth(self.photoScrollView.frame), currentYOffset)];
}
#pragma mark - UIViewController Rotation
@@ -268,6 +369,32 @@
}
}
-(void)addPhotoAction:(id)sender {
// add photo.
UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate = self;
pickerController.editing = NO;
[self presentModalViewController:pickerController animated:YES];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *pickedImage = info[UIImagePickerControllerOriginalImage];
if (pickedImage){
[self.photos addObject:pickedImage];
}
[picker dismissModalViewControllerAnimated:YES];
[self refreshPhotoScrollview];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
}
#pragma mark - BITFeedbackUserDataDelegate
- (void)userDataUpdateCancelled {

BIN
Resources/iconCamera.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 346 B

BIN
Resources/iconCamera@2x.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

View File

@@ -131,6 +131,8 @@
1EF95CA7162CB037000AE3AD /* BITFeedbackActivity.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EF95CA5162CB036000AE3AD /* BITFeedbackActivity.m */; };
1EF95CAA162CB314000AE3AD /* BITFeedbackComposeViewControllerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 1EF95CA9162CB313000AE3AD /* BITFeedbackComposeViewControllerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
1EFF03E517F2485500A5F13C /* BITCrashManagerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 1EFF03E417F2485500A5F13C /* BITCrashManagerTests.m */; };
97F0F9FD18ABAECD00EF50AA /* iconCamera.png in Resources */ = {isa = PBXBuildFile; fileRef = 97F0F9FB18ABAECD00EF50AA /* iconCamera.png */; };
97F0F9FE18ABAECD00EF50AA /* iconCamera@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 97F0F9FC18ABAECD00EF50AA /* iconCamera@2x.png */; };
E405266217A2AD300096359C /* BITFeedbackManagerDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
E40E0B0917DA19DC005E38C1 /* BITHockeyAppClientTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E40E0B0817DA19DC005E38C1 /* BITHockeyAppClientTests.m */; };
E40E0B0C17DA1AFF005E38C1 /* BITHockeyAppClient.h in Headers */ = {isa = PBXBuildFile; fileRef = E40E0B0A17DA1AFF005E38C1 /* BITHockeyAppClient.h */; };
@@ -289,6 +291,8 @@
1EF95CA9162CB313000AE3AD /* BITFeedbackComposeViewControllerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITFeedbackComposeViewControllerDelegate.h; sourceTree = "<group>"; };
1EFF03D717F20F8300A5F13C /* BITCrashManagerPrivate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BITCrashManagerPrivate.h; sourceTree = "<group>"; };
1EFF03E417F2485500A5F13C /* BITCrashManagerTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BITCrashManagerTests.m; sourceTree = "<group>"; };
97F0F9FB18ABAECD00EF50AA /* iconCamera.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = iconCamera.png; sourceTree = "<group>"; };
97F0F9FC18ABAECD00EF50AA /* iconCamera@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "iconCamera@2x.png"; sourceTree = "<group>"; };
BEE0207C16C5107E004426EA /* hu */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = hu; path = hu.lproj/HockeySDK.strings; sourceTree = "<group>"; };
E400561D148D79B500EB22B9 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E405266117A2AD300096359C /* BITFeedbackManagerDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BITFeedbackManagerDelegate.h; sourceTree = "<group>"; };
@@ -346,6 +350,8 @@
1E5955A415B71BDC00A03429 /* Images */ = {
isa = PBXGroup;
children = (
97F0F9FB18ABAECD00EF50AA /* iconCamera.png */,
97F0F9FC18ABAECD00EF50AA /* iconCamera@2x.png */,
1E5955BB15B71C8600A03429 /* authorize_denied.png */,
1E5955BC15B71C8600A03429 /* authorize_denied@2x.png */,
1E5955BF15B71C8600A03429 /* bg.png */,
@@ -784,6 +790,7 @@
1E5955C615B71C8600A03429 /* authorize_denied.png in Resources */,
1E5955C715B71C8600A03429 /* authorize_denied@2x.png in Resources */,
1E5955CA15B71C8600A03429 /* bg.png in Resources */,
97F0F9FD18ABAECD00EF50AA /* iconCamera.png in Resources */,
1E5955CB15B71C8600A03429 /* buttonHighlight.png in Resources */,
1E5955CC15B71C8600A03429 /* buttonHighlight@2x.png in Resources */,
1E5955CF15B71C8600A03429 /* IconGradient.png in Resources */,
@@ -797,6 +804,7 @@
1E1127C616580C87007067A2 /* buttonRoundedDeleteHighlighted.png in Resources */,
1E1127C716580C87007067A2 /* buttonRoundedDeleteHighlighted@2x.png in Resources */,
1E1127C816580C87007067A2 /* buttonRoundedRegular.png in Resources */,
97F0F9FE18ABAECD00EF50AA /* iconCamera@2x.png in Resources */,
1E1127C916580C87007067A2 /* buttonRoundedRegular@2x.png in Resources */,
1E1127CA16580C87007067A2 /* buttonRoundedRegularHighlighted.png in Resources */,
1E1127CB16580C87007067A2 /* buttonRoundedRegularHighlighted@2x.png in Resources */,