+ Added preliminary load mechanics for Feedback Images.

This commit is contained in:
moritz haarmann 2014-04-16 11:24:39 +02:00
parent 5038c3e4e9
commit 3aa45bbb9f
5 changed files with 113 additions and 49 deletions

View File

@ -152,12 +152,12 @@
} }
if(nil == _networkDidBecomeReachableObserver) { if(nil == _networkDidBecomeReachableObserver) {
_networkDidBecomeReachableObserver = [[NSNotificationCenter defaultCenter] addObserverForName:BITHockeyNetworkDidBecomeReachableNotification _networkDidBecomeReachableObserver = [[NSNotificationCenter defaultCenter] addObserverForName:BITHockeyNetworkDidBecomeReachableNotification
object:nil object:nil
queue:NSOperationQueue.mainQueue queue:NSOperationQueue.mainQueue
usingBlock:^(NSNotification *note) { usingBlock:^(NSNotification *note) {
typeof(self) strongSelf = weakSelf; typeof(self) strongSelf = weakSelf;
[strongSelf didBecomeActiveActions]; [strongSelf didBecomeActiveActions];
}]; }];
} }
} }
@ -306,8 +306,8 @@
if ([BITHockeyManager sharedHockeyManager].delegate && if ([BITHockeyManager sharedHockeyManager].delegate &&
[[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) { [[BITHockeyManager sharedHockeyManager].delegate respondsToSelector:@selector(userNameForHockeyManager:componentManager:)]) {
userName = [[BITHockeyManager sharedHockeyManager].delegate userName = [[BITHockeyManager sharedHockeyManager].delegate
userNameForHockeyManager:[BITHockeyManager sharedHockeyManager] userNameForHockeyManager:[BITHockeyManager sharedHockeyManager]
componentManager:self]; componentManager:self];
} }
if (userName) { if (userName) {
@ -734,6 +734,15 @@
message.id = [(NSDictionary *)objMessage objectForKey:@"id"]; message.id = [(NSDictionary *)objMessage objectForKey:@"id"];
message.status = BITFeedbackMessageStatusUnread; message.status = BITFeedbackMessageStatusUnread;
for (NSDictionary *attachmentData in objMessage[@"attachments"]){
BITFeedbackMessageAttachment *newAttachment = [BITFeedbackMessageAttachment new];
newAttachment.originalFilename = attachmentData[@"file_name"];
newAttachment.id = attachmentData[@"id"];
newAttachment.sourceURL = attachmentData[@"url"];
newAttachment.contentType = @"image/jpg";
[message addAttachmentsObject:newAttachment];
}
[_feedbackList addObject:message]; [_feedbackList addObject:message];
newMessage = YES; newMessage = YES;
@ -790,11 +799,45 @@
[self markSendInProgressMessagesAsPending]; [self markSendInProgressMessagesAsPending];
} }
[self synchronizeMissingAttachments];
[self saveMessages]; [self saveMessages];
return; return;
} }
/**
Load all attachments without any local data to have them available.
*/
-(BOOL)synchronizeMissingAttachments {
// Extract all Attachments.
NSMutableArray *allAttachments = [NSMutableArray new];
for (int i = 0; i < [self numberOfMessages]; i++){
BITFeedbackMessage *message = [self messageAtIndex:i];
for (BITFeedbackMessageAttachment *attachment in message.attachments){
if (attachment.needsLoadingFromURL){
[allAttachments addObject:attachment];
}
}
}
for (BITFeedbackMessageAttachment *attachment in allAttachments){
// we will just update the objects here and perform a save after each successful load operation.
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:attachment.sourceURL]];
__weak BITFeedbackManager *weakSelf = self;
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *responseData, NSError *err) {
if (responseData.length){
[attachment replaceData:responseData];
[weakSelf saveMessages];
}
}];
}
return NO;
}
- (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BITFeedbackMessage *)message completionHandler:(void (^)(NSError *err))completionHandler { - (void)sendNetworkRequestWithHTTPMethod:(NSString *)httpMethod withMessage:(BITFeedbackMessage *)message completionHandler:(void (^)(NSError *err))completionHandler {
NSString *boundary = @"----FOO"; NSString *boundary = @"----FOO";
@ -1045,7 +1088,7 @@
-(void)setFeedbackObservationMode:(BITFeedbackObservationMode)mode { -(void)setFeedbackObservationMode:(BITFeedbackObservationMode)mode {
if (mode == BITFeedbackObservationModeOnScreenshot){ if (mode == BITFeedbackObservationModeOnScreenshot){
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenshotNotificationReceived:) name:UIApplicationUserDidTakeScreenshotNotification object:nil]; // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(screenshotNotificationReceived:) name:UIApplicationUserDidTakeScreenshotNotification object:nil];
} }
} }

View File

@ -29,6 +29,8 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
@class BITFeedbackMessageAttachment;
/** /**
* Status for each feedback message * Status for each feedback message
*/ */
@ -79,5 +81,7 @@ typedef NS_ENUM(NSInteger, BITFeedbackMessageStatus) {
*/ */
-(void)deleteContents; -(void)deleteContents;
-(void)addAttachmentsObject:(BITFeedbackMessageAttachment *)object;
@end @end

View File

@ -90,5 +90,10 @@
[attachment deleteContents]; [attachment deleteContents];
} }
} }
-(void)addAttachmentsObject:(BITFeedbackMessageAttachment *)object{
if (!self.attachments){
self.attachments = [NSArray array];
}
self.attachments = [self.attachments arrayByAddingObject:object];
}
@end @end

View File

@ -35,6 +35,7 @@
@property (nonatomic, copy) NSNumber *id; @property (nonatomic, copy) NSNumber *id;
@property (nonatomic, copy) NSString *originalFilename; @property (nonatomic, copy) NSString *originalFilename;
@property (nonatomic, copy) NSString *contentType; @property (nonatomic, copy) NSString *contentType;
@property (nonatomic, copy) NSString *sourceURL;
@property (nonatomic, readonly) NSData *data; @property (nonatomic, readonly) NSData *data;
@property (readonly) UIImage *imageRepresentation; @property (readonly) UIImage *imageRepresentation;
@ -48,4 +49,6 @@
- (void)deleteContents; - (void)deleteContents;
-(BOOL)needsLoadingFromURL;
@end @end

View File

@ -39,6 +39,7 @@
@property (nonatomic, strong) NSData *internalData; @property (nonatomic, strong) NSData *internalData;
@property (nonatomic, copy) NSString *filename; @property (nonatomic, copy) NSString *filename;
@end @end
@implementation BITFeedbackMessageAttachment @implementation BITFeedbackMessageAttachment
@ -92,12 +93,18 @@
self.thumbnailRepresentations = [NSMutableDictionary new]; self.thumbnailRepresentations = [NSMutableDictionary new];
} }
-(BOOL)needsLoadingFromURL {
return (self.sourceURL);
}
#pragma mark NSCoding #pragma mark NSCoding
- (void)encodeWithCoder:(NSCoder *)aCoder { - (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.contentType forKey:@"contentType"]; [aCoder encodeObject:self.contentType forKey:@"contentType"];
[aCoder encodeObject:self.filename forKey:@"filename"]; [aCoder encodeObject:self.filename forKey:@"filename"];
[aCoder encodeObject:self.originalFilename forKey:@"originalFilename"]; [aCoder encodeObject:self.originalFilename forKey:@"originalFilename"];
[aCoder encodeObject:self.sourceURL forKey:@"url"];
} }
@ -109,6 +116,8 @@
self.filename = [aDecoder decodeObjectForKey:@"filename"]; self.filename = [aDecoder decodeObjectForKey:@"filename"];
self.thumbnailRepresentations = [NSMutableDictionary new]; self.thumbnailRepresentations = [NSMutableDictionary new];
self.originalFilename = [aDecoder decodeObjectForKey:@"originalFilename"]; self.originalFilename = [aDecoder decodeObjectForKey:@"originalFilename"];
self.sourceURL = [aDecoder decodeObjectForKey:@"sourceURL"];
} }
return self; return self;
@ -117,7 +126,7 @@
#pragma mark - Thubmnails / Image Representation #pragma mark - Thubmnails / Image Representation
- (UIImage *)imageRepresentation { - (UIImage *)imageRepresentation {
if ([self.contentType rangeOfString:@"image"].location != NSNotFound){ if ([self.contentType rangeOfString:@"image"].location != NSNotFound || [self.sourceURL rangeOfString:@"jpeg"].location != NSNotFound){
return [UIImage imageWithData:self.data]; return [UIImage imageWithData:self.data];
} else { } else {
return bit_imageNamed(@"feedbackActiviy.png", BITHOCKEYSDK_BUNDLE); // TODO add another placeholder. return bit_imageNamed(@"feedbackActiviy.png", BITHOCKEYSDK_BUNDLE); // TODO add another placeholder.