Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mronkko committed Jan 19, 2012
1 parent e95205c commit e2b3a4c
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 247 deletions.
12 changes: 12 additions & 0 deletions DSActivityView/Sources/DSActivityView.m
Expand Up @@ -354,6 +354,18 @@ - (void)setShowNetworkActivityIndicator:(BOOL)showNetworkActivityIndicator;
[UIApplication sharedApplication].networkActivityIndicatorVisible = showNetworkActivityIndicator;
}

/*
These two methods are needed for the view to capture all touches. Otherwise the
touches just go through to the underlying view.
*/
- (BOOL)canBecomeFirstResponder {
return YES;
}

- (void)viewDidAppear {
[self becomeFirstResponder];
}

@end


Expand Down
18 changes: 9 additions & 9 deletions ZotPad/MainStoryboard_iPad.storyboard
Expand Up @@ -173,6 +173,15 @@
<rect key="frame" x="0.0" y="64" width="703" height="704"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view tag="2" contentMode="scaleToFill" id="mJe-AV-5Qd" customClass="iCarousel">
<rect key="frame" x="0.0" y="0.0" width="703" height="263"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="0zt-cp-Ihx" id="sGN-Da-Adl"/>
<outlet property="delegate" destination="0zt-cp-Ihx" id="p1b-vl-1KU"/>
</connections>
</view>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" scrollEnabled="NO" showsHorizontalScrollIndicator="NO" showsVerticalScrollIndicator="NO" dataMode="prototypes" style="grouped" separatorStyle="singleLineEtched" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="10" sectionFooterHeight="10" id="Qr8-AN-SJ9">
<rect key="frame" x="0.0" y="264" width="723" height="440"/>
<autoresizingMask key="autoresizingMask" heightSizable="YES"/>
Expand Down Expand Up @@ -239,15 +248,6 @@
<outlet property="delegate" destination="0zt-cp-Ihx" id="cKN-7a-ZKQ"/>
</connections>
</tableView>
<view tag="2" contentMode="scaleToFill" id="mJe-AV-5Qd" customClass="iCarousel">
<rect key="frame" x="0.0" y="0.0" width="703" height="263"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
<connections>
<outlet property="dataSource" destination="0zt-cp-Ihx" id="sGN-Da-Adl"/>
<outlet property="delegate" destination="0zt-cp-Ihx" id="p1b-vl-1KU"/>
</connections>
</view>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
Expand Down
6 changes: 5 additions & 1 deletion ZotPad/ZPAppDelegate.m
Expand Up @@ -39,10 +39,13 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application{
NSLog(@"Start freeing memory");
[ZPZoteroItem dropCache];
[ZPZoteroCollection dropCache];
[ZPZoteroLibrary dropCache];
[ZPLocalization dropCache];
NSLog(@"Done freeing memory");

}

- (void)applicationWillResignActive:(UIApplication *)application
Expand Down Expand Up @@ -85,7 +88,8 @@ - (void)applicationWillTerminate:(UIApplication *)application
Save data if appropriate.
See also applicationDidEnterBackground:.
*/

NSLog(@"Terminating");


}

Expand Down
211 changes: 116 additions & 95 deletions ZotPad/ZPCacheController.m

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions ZotPad/ZPDataLayer.h
Expand Up @@ -22,11 +22,12 @@
@interface ZPDataLayer : NSObject {


NSMutableSet* _itemObservers;
NSMutableSet* _libraryObservers;
NSMutableSet* _attachmentObservers;
//These sets are immutable due to concurrency issues
NSSet* _itemObservers;
NSSet* _libraryObservers;
NSSet* _attachmentObservers;

//Queut for ad hoc retrievals
//Queue for ad hoc retrievals
NSOperationQueue* _serverRequestQueue;

}
Expand Down
40 changes: 13 additions & 27 deletions ZotPad/ZPDataLayer.m
Expand Up @@ -233,7 +233,6 @@ -(void) notifyItemsAvailable:(NSArray*)items{
}

for(item in itemsToBeNotifiedAbout){
@synchronized(_itemObservers){
NSEnumerator* e = [_itemObservers objectEnumerator];
NSObject* id;

Expand All @@ -242,74 +241,61 @@ -(void) notifyItemsAvailable:(NSArray*)items{
[(NSObject <ZPItemObserver>*) id notifyItemAvailable:item];
}
}
}
}
}


-(void) notifyLibraryWithCollectionsAvailable:(ZPZoteroLibrary*) library{

@synchronized(_libraryObservers){

NSEnumerator* e = [_libraryObservers objectEnumerator];
NSObject* id;

while( id= [e nextObject]) {
[(NSObject <ZPLibraryObserver>*) id notifyLibraryWithCollectionsAvailable:library];
}
}
}


-(void) notifyAttachmentDownloadCompleted:(ZPZoteroAttachment*) attachment{
@synchronized(_attachmentObservers){
NSEnumerator* e = [_attachmentObservers objectEnumerator];
NSObject* id;

while( id= [e nextObject]) {
[(NSObject <ZPAttachmentObserver>*) id notifyAttachmentDownloadCompleted:attachment];
}
}
}


//Adds and removes observers
//Adds and removes observers. Because of concurrency issues we are not using mutable sets here.
-(void) registerItemObserver:(NSObject<ZPItemObserver>*)observer{
@synchronized(_itemObservers){
[_itemObservers addObject:observer];
}
_itemObservers = [_itemObservers setByAddingObject:observer];

}
-(void) removeItemObserver:(NSObject<ZPItemObserver>*)observer{
@synchronized(_itemObservers){
[_itemObservers removeObject:observer];
}
NSMutableSet* tempSet =[NSMutableSet setWithSet:_itemObservers];
[tempSet removeObject:observer];
_itemObservers = tempSet;
}

-(void) registerLibraryObserver:(NSObject<ZPLibraryObserver>*)observer{
@synchronized(_libraryObservers){
[_libraryObservers addObject:observer];
}

_libraryObservers = [_libraryObservers setByAddingObject:observer];
}
-(void) removeLibraryObserver:(NSObject<ZPLibraryObserver>*)observer{
@synchronized(_libraryObservers){
[_libraryObservers removeObject:observer];
}
NSMutableSet* tempSet =[NSMutableSet setWithSet:_libraryObservers];
[tempSet removeObject:observer];
_libraryObservers = tempSet;
}



-(void) registerAttachmentObserver:(NSObject<ZPAttachmentObserver>*)observer{
@synchronized(_attachmentObservers){
[_attachmentObservers addObject:observer];
}
_attachmentObservers = [_attachmentObservers setByAddingObject:observer];
}

-(void) removeAttachmentObserver:(NSObject<ZPAttachmentObserver>*)observer{
@synchronized(_attachmentObservers){
[_attachmentObservers removeObject:observer];
}
NSMutableSet* tempSet =[NSMutableSet setWithSet:_attachmentObservers];
[tempSet removeObject:observer];
_attachmentObservers = tempSet;
}


Expand Down
40 changes: 24 additions & 16 deletions ZotPad/ZPDetailedItemListViewController.m
Expand Up @@ -59,7 +59,7 @@ - (void)configureView
{

if([NSThread isMainThread]){

NSLog(@"Started configuring view");
// Update the user interface for the detail item.

if (self.masterPopoverController != nil) {
Expand All @@ -75,10 +75,17 @@ - (void)configureView

[_activityIndicator startAnimating];

//Clear item keys shown so that UI knows to stop drawing the old items
_itemKeysShown = NULL;

//This is required because a background thread might be modifying the table
@synchronized(_tableView){
_itemKeysNotInCache = [NSMutableArray array];
_itemKeysShown = [NSArray array];
NSLog(@"Entering table lock");
@synchronized(_tableView){

_itemKeysNotInCache = [NSMutableArray array];
_itemKeysShown = [NSArray array];

NSLog(@"Entered table lock");
//TODO: Investigate why a relaodsection call a bit below causes a crash. Then uncomment these both.
//[_tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
[_tableView reloadData];
Expand All @@ -89,6 +96,9 @@ - (void)configureView


[self performSelectorInBackground:@selector(_configureCachedKeys) withObject:nil];

NSLog(@"Finished configuring view");

}
}
else{
Expand All @@ -99,11 +109,19 @@ - (void)configureView

- (void)_makeBusy{
if(_activityView==NULL){
[_tableView setUserInteractionEnabled:FALSE];
_activityView = [DSBezelActivityView newActivityViewForView:_tableView];
_activityView = [DSBezelActivityView newActivityViewForView:[_tableView superview] withLabel:@"Loading data from\nZotero server..."];
}
}

/*
Called from data layer to notify that there is data for this view and it can be shown
*/

- (void)_makeAvailable{
[DSBezelActivityView removeViewAnimated:YES];
_activityView = NULL;
}

- (void) _configureCachedKeys{

//Store references to these two strings to prevent deallocation.
Expand Down Expand Up @@ -137,16 +155,6 @@ - (void) _configureCachedKeys{
}
}

/*
Called from data layer to notify that there is data for this view and it can be shown
*/

- (void)_makeAvailable{
[DSBezelActivityView removeViewAnimated:YES];

[_tableView setUserInteractionEnabled:TRUE];
_activityView = NULL;
}

- (void) configureUncachedKeys:(NSArray*)uncachedItems{

Expand Down
47 changes: 26 additions & 21 deletions ZotPad/ZPFileThumbnailAndQuicklookController.m
Expand Up @@ -338,30 +338,35 @@ -(void) _configurePreview:(UIView*)view withAttachment:(ZPZoteroAttachment*)atta
//Render images

UIImage* image;
if([view superview] != nil && attachment.fileExists && [attachment.attachmentType isEqualToString:@"application/pdf"]) image = [self _renderThumbnailFromPDFFile:attachment.fileSystemPath];

if([view superview] != nil){
if( attachment.fileExists && [attachment.attachmentType isEqualToString:@"application/pdf"]){
//TODO: Figure out a way to stop rendering if the user has switched to another item

image = [self _renderThumbnailFromPDFFile:attachment.fileSystemPath];

UIView* subview;
NSArray* subviews=[NSArray arrayWithArray:view.subviews];
for(subview in subviews){
[subview removeFromSuperview];
}

UIImageView* imageView = [[UIImageView alloc] initWithImage:image];
if(image!=NULL){

UIView* subview;
NSArray* subviews=[NSArray arrayWithArray:view.subviews];
for(subview in subviews){
[subview removeFromSuperview];
}

UIImageView* imageView = [[UIImageView alloc] initWithImage:image];

view.layer.frame = [self _getDimensionsWithImage:image];
imageView.layer.frame = [self _getDimensionsWithImage:image];
[view setNeedsLayout];

[view addSubview:imageView];
//Add the subviews back, but not the imageview
for(subview in subviews){
if(! [subview isKindOfClass:[UIImageView class]]) [view addSubview:subview];
}

[view setNeedsDisplay];
[[(ZPItemDetailViewController*) _viewController carousel] reloadItemAtIndex:[_item.attachments indexOfObject:attachment] animated:YES];

view.layer.frame = [self _getDimensionsWithImage:image];
imageView.layer.frame = [self _getDimensionsWithImage:image];
[view setNeedsLayout];

[view addSubview:imageView];
//Add the subviews back, but not the imageview
for(subview in subviews){
if(! [subview isKindOfClass:[UIImageView class]]) [view addSubview:subview];
}
[view setNeedsDisplay];
[[(ZPItemDetailViewController*) _viewController carousel] reloadItemAtIndex:[_item.attachments indexOfObject:attachment] animated:YES];

}
}

Expand Down
3 changes: 1 addition & 2 deletions ZotPad/ZPItemDetailViewController.h
Expand Up @@ -22,10 +22,9 @@
iCarousel* _carousel;
ZPSimpleItemListViewController* _itemListController;
ZPFileThumbnailAndQuicklookController* _previewController;
NSMutableArray* _carouselViews;
UIActivityIndicatorView* _activityIndicator;
NSInteger _detailTitleWidth;

NSArray* _carouselViews;
}

@property (nonatomic, retain) IBOutlet iCarousel* carousel;
Expand Down

0 comments on commit e2b3a4c

Please sign in to comment.