mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-17 11:50:56 +00:00
Added Delete/Edit ActionSheet
Fixed a Bug where the Feedback cannot be sent if no text is entered.
This commit is contained in:
parent
6b09e75cd6
commit
2146788f7b
@ -43,7 +43,7 @@
|
|||||||
#import "BITHockeyHelper.h"
|
#import "BITHockeyHelper.h"
|
||||||
|
|
||||||
|
|
||||||
@interface BITFeedbackComposeViewController () <BITFeedbackUserDataDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
|
@interface BITFeedbackComposeViewController () <BITFeedbackUserDataDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UIActionSheetDelegate> {
|
||||||
UIStatusBarStyle _statusBarStyle;
|
UIStatusBarStyle _statusBarStyle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,6 +58,7 @@
|
|||||||
@property (nonatomic, strong) NSMutableArray *attachments;
|
@property (nonatomic, strong) NSMutableArray *attachments;
|
||||||
|
|
||||||
@property (nonatomic, strong) UIView *textAccessoryView;
|
@property (nonatomic, strong) UIView *textAccessoryView;
|
||||||
|
@property (nonatomic) NSInteger selectedAttachmentIndex;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@ -217,10 +218,9 @@
|
|||||||
|
|
||||||
if (_text) {
|
if (_text) {
|
||||||
self.textView.text = _text;
|
self.textView.text = _text;
|
||||||
self.navigationItem.rightBarButtonItem.enabled = YES;
|
|
||||||
} else {
|
|
||||||
self.navigationItem.rightBarButtonItem.enabled = NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[self updateBarButtonState];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)viewDidAppear:(BOOL)animated {
|
- (void)viewDidAppear:(BOOL)animated {
|
||||||
@ -253,7 +253,7 @@
|
|||||||
[super viewDidDisappear:animated];
|
[super viewDidDisappear:animated];
|
||||||
}
|
}
|
||||||
|
|
||||||
-(void)refreshPhotoScrollview {
|
-(void)refreshAttachmentScrollview {
|
||||||
CGFloat scrollViewWidth = 0;
|
CGFloat scrollViewWidth = 0;
|
||||||
|
|
||||||
if (self.attachments.count){
|
if (self.attachments.count){
|
||||||
@ -281,8 +281,9 @@
|
|||||||
if (self.attachments.count > self.attachmentScrollViewImageViews.count){
|
if (self.attachments.count > self.attachmentScrollViewImageViews.count){
|
||||||
NSInteger numberOfViewsToCreate = self.attachments.count - self.attachmentScrollViewImageViews.count;
|
NSInteger numberOfViewsToCreate = self.attachments.count - self.attachmentScrollViewImageViews.count;
|
||||||
for (int i = 0;i<numberOfViewsToCreate;i++){
|
for (int i = 0;i<numberOfViewsToCreate;i++){
|
||||||
UIImageView *newImageView = [[UIImageView alloc] initWithFrame:CGRectZero];
|
UIButton *newImageButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
||||||
[self.attachmentScrollViewImageViews addObject:newImageView];
|
[newImageButton addTarget:self action:@selector(imageButtonAction:) forControlEvents:UIControlEventTouchUpInside];
|
||||||
|
[self.attachmentScrollViewImageViews addObject:newImageButton];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,7 +292,7 @@
|
|||||||
CGFloat currentYOffset = 0.0f;
|
CGFloat currentYOffset = 0.0f;
|
||||||
|
|
||||||
for (BITFeedbackMessageAttachment* attachment in self.attachments){
|
for (BITFeedbackMessageAttachment* attachment in self.attachments){
|
||||||
UIImageView *imageView = self.attachmentScrollViewImageViews[index];
|
UIButton *imageButton = self.attachmentScrollViewImageViews[index];
|
||||||
|
|
||||||
UIImage *image = [attachment thumbnailWithSize:CGSizeMake(100, 100)];
|
UIImage *image = [attachment thumbnailWithSize:CGSizeMake(100, 100)];
|
||||||
|
|
||||||
@ -300,17 +301,27 @@
|
|||||||
|
|
||||||
CGFloat height = image.size.height * scaleFactor;
|
CGFloat height = image.size.height * scaleFactor;
|
||||||
|
|
||||||
imageView.frame = CGRectInset(CGRectMake(0, currentYOffset, scaleFactor * image.size.width, height),10,10);
|
imageButton.frame = CGRectInset(CGRectMake(0, currentYOffset, scaleFactor * image.size.width, height),10,10);
|
||||||
|
|
||||||
currentYOffset += height;
|
currentYOffset += height;
|
||||||
|
|
||||||
[self.attachmentScrollView addSubview:imageView];
|
[self.attachmentScrollView addSubview:imageButton];
|
||||||
|
|
||||||
imageView.image = image;
|
[imageButton setImage:image forState:UIControlStateNormal];
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.attachmentScrollView setContentSize:CGSizeMake(CGRectGetWidth(self.attachmentScrollView.frame), currentYOffset)];
|
[self.attachmentScrollView setContentSize:CGSizeMake(CGRectGetWidth(self.attachmentScrollView.frame), currentYOffset)];
|
||||||
|
|
||||||
|
[self updateBarButtonState];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)updateBarButtonState {
|
||||||
|
if (self.textView.text.length == 0 && self.attachments.count == 0 ) {
|
||||||
|
self.navigationItem.rightBarButtonItem.enabled = NO;
|
||||||
|
} else {
|
||||||
|
self.navigationItem.rightBarButtonItem.enabled = YES;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -387,13 +398,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
[picker dismissModalViewControllerAnimated:YES];
|
[picker dismissModalViewControllerAnimated:YES];
|
||||||
[self refreshPhotoScrollview];
|
[self refreshAttachmentScrollview];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||||
[picker dismissModalViewControllerAnimated:YES];
|
[picker dismissModalViewControllerAnimated:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)imageButtonAction:(UIButton *)sender {
|
||||||
|
// determine the index of the feedback
|
||||||
|
NSInteger index = [self.attachmentScrollViewImageViews indexOfObject:sender];
|
||||||
|
self.selectedAttachmentIndex = index;
|
||||||
|
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil
|
||||||
|
delegate: self
|
||||||
|
cancelButtonTitle: @"Delete Attachment"
|
||||||
|
destructiveButtonTitle: nil
|
||||||
|
otherButtonTitles: @"Edit Attachment", nil];
|
||||||
|
|
||||||
|
[actionSheet showFromRect: sender.frame inView: self.attachmentScrollView animated: YES];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark - BITFeedbackUserDataDelegate
|
#pragma mark - BITFeedbackUserDataDelegate
|
||||||
|
|
||||||
- (void)userDataUpdateCancelled {
|
- (void)userDataUpdateCancelled {
|
||||||
@ -424,15 +448,25 @@
|
|||||||
#pragma mark - UITextViewDelegate
|
#pragma mark - UITextViewDelegate
|
||||||
|
|
||||||
- (void)textViewDidChange:(UITextView *)textView {
|
- (void)textViewDidChange:(UITextView *)textView {
|
||||||
NSUInteger newLength = [textView.text length];
|
[self updateBarButtonState];
|
||||||
if (newLength == 0) {
|
|
||||||
self.navigationItem.rightBarButtonItem.enabled = NO;
|
|
||||||
} else {
|
|
||||||
self.navigationItem.rightBarButtonItem.enabled = YES;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark - UIActionSheet Delegate
|
||||||
|
|
||||||
|
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
|
||||||
|
if (buttonIndex == [actionSheet cancelButtonIndex]){
|
||||||
|
|
||||||
|
if (self.selectedAttachmentIndex != NSNotFound){
|
||||||
|
BITFeedbackMessageAttachment* attachment = [self.attachments objectAtIndex:self.selectedAttachmentIndex];
|
||||||
|
[self.attachments removeObject:attachment];
|
||||||
|
}
|
||||||
|
|
||||||
|
[self refreshAttachmentScrollview];
|
||||||
|
}
|
||||||
|
|
||||||
|
self.selectedAttachmentIndex = NSNotFound;
|
||||||
|
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif /* HOCKEYSDK_FEATURE_FEEDBACK */
|
#endif /* HOCKEYSDK_FEATURE_FEEDBACK */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user