Skip to content
Snippets Groups Projects
Commit 5cd310de authored by cramakri's avatar cramakri
Browse files

Prepare code refactoring to get images asynchronously

SVN: 27171
parent 48820241
No related branches found
No related tags found
No related merge requests found
......@@ -45,6 +45,9 @@
@property (nonatomic, retain) NSString * propertiesJson;
@property (readonly) NSArray * properties;
///! The image contained at the imageUrl or nil if there is no image.
@property (nonatomic, strong) UIImage * image;
// Actions
//! Take the values from the raw entity.
- (void)initializeFromRawEntity:(CISDOBIpadRawEntity *)rawEntity;
......
......@@ -37,6 +37,8 @@
@dynamic childrenPermIdsJson;
@dynamic propertiesJson;
@synthesize image;
- (NSArray *)properties
{
[self willAccessValueForKey: @"properties"];
......
......@@ -29,6 +29,8 @@
@property (strong, nonatomic) UIPopoverController *masterPopoverController;
@property (readonly) CISDOBIpadEntity *detailItem;
- (void)requestServerSync;
- (void)configureViewProvisionally;
- (void)configureView;
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
......@@ -36,11 +38,18 @@
@implementation CISDOBDetailViewController
#pragma mark - Managing the detail item
- (void)requestServerSync
{
// Ask the server to synchronize the detail object and nofiy me when the complete data is available
SuccessBlock success = ^(id result) { [self configureView]; };
[self.openBisModel syncSelectedObjectOnSuccess: success];
}
- (void)selectionDidChange
{
// Update the view.
[self configureView];
[self configureViewProvisionally];
[self requestServerSync];
if (self.masterPopoverController != nil) {
[self.masterPopoverController dismissPopoverAnimated:YES];
......@@ -49,19 +58,23 @@
- (CISDOBIpadEntity *)detailItem { return [self.openBisModel selectedObject]; }
- (void)configureViewProvisionally
{
// We have a detail item which might not be up-to-date. Update the user interface.
[self configureView];
}
- (void)configureView
{
// Update the user interface for the detail item.
// The detail item is now up-to-date. Update the user interface.
if (!self.detailItem) return;
self.summaryHeaderLabel.text = [self.detailItem.summaryHeader description];
self.summaryLabel.text = [self.detailItem.summary description];
self.identifierLabel.text = [self.detailItem.identifier description];
if (self.detailItem.imageUrl) {
NSURL *imageUrl = [NSURL URLWithString: self.detailItem.imageUrl];
NSData *imageData = [NSData dataWithContentsOfURL: imageUrl];
self.imageView.image =[UIImage imageWithData: imageData];
if (self.detailItem.image) {
self.imageView.image = self.detailItem.image;
}
[self.propertiesTableView reloadData];
......@@ -71,7 +84,7 @@
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self configureView];
[self configureViewProvisionally];
}
- (void)didReceiveMemoryWarning
......
......@@ -21,6 +21,7 @@
//
#import <Foundation/Foundation.h>
#import "CISDOBShared.h"
@class CISDOBIpadEntity;
......@@ -51,5 +52,9 @@
- (BOOL)insertNewObjectOrError:(NSError **)error; //!< Return YES if operation succeeded
- (BOOL)deleteObjectAtIndexPath:(NSIndexPath *)indexPath error:(NSError **)error; //!< Return YES if operation succeeded
// Server Communication
//! Get the selected object from the server and invoke the succes block when the data is here
- (void)syncSelectedObjectOnSuccess:(SuccessBlock)success;
@end
......@@ -88,6 +88,20 @@
return [context save: error];
}
#pragma mark - Server Communication
- (void)syncSelectedObjectOnSuccess:(SuccessBlock)success
{
// Update the image
if (_selectedObject.imageUrl) {
NSURL *imageUrl = [NSURL URLWithString: _selectedObject.imageUrl];
NSData *imageData = [NSData dataWithContentsOfURL: imageUrl];
_selectedObject.image = [UIImage imageWithData: imageData];
success(_selectedObject);
} else {
success(_selectedObject);
}
}
#pragma mark - Fetched results controller
- (NSFetchedResultsController *)fetchedResultsController
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment