-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor table and collection views pull to refresh and infinite scro…
…lling
- Loading branch information
Showing
103 changed files
with
3,007 additions
and
3,207 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
BIObjCHelpers/Batch/Common/BIBatchHelper.h → BIObjCHelpers/Batch/BIBatchHelpers.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
// | ||
// BIBatchHelper.h | ||
// BIBatchHelpers.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Mihai Chifor on 8/31/15. | ||
|
4 changes: 2 additions & 2 deletions
4
BIObjCHelpers/Batch/Common/BIBatchHelper.m → BIObjCHelpers/Batch/BIBatchHelpers.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// BIBatchRequest.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
FOUNDATION_EXPORT const NSInteger kDefaultBatchRequestSize; | ||
|
||
@class BIBatchResponse; | ||
|
||
typedef void(^BIBatchRequestCompletionBlock)(BIBatchResponse * __nonnull response); | ||
|
||
/*! | ||
@brief Helper values for batch insert position. | ||
*/ | ||
typedef NS_ENUM(NSUInteger, BIBatchInsertPosition) { | ||
/*! | ||
* @brief insert new elements at the beggining. | ||
*/ | ||
BIBatchInsertPositionTop = 0, | ||
/*! | ||
* @brief insert new elements at the end. | ||
*/ | ||
BIBatchInsertPositionBottom = UINT_MAX | ||
}; | ||
|
||
/*! | ||
* @brief Defines a set of data request values. | ||
* Mostly used in table and collection views for inserting sets of data. | ||
*/ | ||
@interface BIBatchRequest : NSObject | ||
|
||
/*! | ||
* @brief Designated initializer for a table view batch. | ||
* @param sectionIndex The index of the section where to fetch data. | ||
* @param batchSize The size of the batch to fetch. | ||
* @param completionBlock Code block to be called when fetching is done or in case of error. | ||
*/ | ||
- (nonnull instancetype)initWithSection:(NSUInteger)sectionIndex | ||
batchSize:(NSUInteger)batchSize | ||
completionBlock:(nullable BIBatchRequestCompletionBlock)completionBlock NS_DESIGNATED_INITIALIZER; | ||
|
||
/*! | ||
* @brief Convenience kDefaultTableViewBatchSize for a table view batch. | ||
* @discussion Fetches kCardDefaultBatchSize elements in section index 0. | ||
* @param completionBlock Code block to be called when fetching is done or in case of error. | ||
*/ | ||
- (nonnull instancetype)initWithCompletionBlock:(nullable BIBatchRequestCompletionBlock)completionBlock; | ||
|
||
/*! | ||
* @brief Size of the batch that is fetching. | ||
*/ | ||
@property (nonatomic, assign, readonly) NSUInteger batchSize; | ||
|
||
/*! | ||
* @brief Section index for which data is fetching. | ||
*/ | ||
@property (nonatomic, assign, readonly) NSUInteger sectionIndex; | ||
|
||
/*! | ||
* @brief Code block to be called when fetching is done or in case of error. | ||
*/ | ||
@property (nonatomic, copy, nullable, readonly) BIBatchRequestCompletionBlock completionBlock; | ||
|
||
/*! | ||
* @brief Specify an index from where to start inserting the new elements that will be fetched. | ||
* Defaults to BIBatchInsertPositionBottom; | ||
*/ | ||
@property (nonatomic, assign) NSUInteger insertPosition; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// BIBatchRequest.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIBatchRequest.h" | ||
|
||
const NSInteger kDefaultBatchRequestSize = 3; | ||
|
||
@interface BIBatchRequest () | ||
|
||
@property (nonatomic, assign, readwrite) NSUInteger batchSize; | ||
@property (nonatomic, assign, readwrite) NSUInteger sectionIndex; | ||
@property (nonatomic, copy, nullable, readwrite) BIBatchRequestCompletionBlock completionBlock; | ||
|
||
@end | ||
|
||
|
||
@implementation BIBatchRequest | ||
|
||
#pragma mark - Init methods | ||
|
||
- (instancetype)initWithSection:(NSUInteger)sectionIndex | ||
batchSize:(NSUInteger)batchSize | ||
completionBlock:(BIBatchRequestCompletionBlock)completionBlock { | ||
self = [super init]; | ||
if (self) { | ||
self.sectionIndex = sectionIndex; | ||
self.batchSize = batchSize; | ||
self.completionBlock = completionBlock; | ||
self.insertPosition = BIBatchInsertPositionBottom; | ||
} | ||
return self; | ||
} | ||
|
||
- (instancetype)initWithCompletionBlock:(BIBatchRequestCompletionBlock)completionBlock { | ||
return [self initWithSection:0 | ||
batchSize:kDefaultBatchRequestSize | ||
completionBlock:completionBlock]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// BIBatchResponse.h | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@class BIBatchRequest; | ||
|
||
@interface BIBatchResponse : NSObject | ||
|
||
+ (nonnull instancetype)batchResponseForRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths; | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths; | ||
|
||
- (nonnull instancetype)init NS_UNAVAILABLE; | ||
+ (nonnull instancetype)new NS_UNAVAILABLE; | ||
|
||
@property (nonatomic, strong, nullable, readonly) NSError *error; | ||
@property (nonatomic, copy, nullable, readonly) NSArray *indexPaths; | ||
@property (nonatomic, strong, nullable, readonly) BIBatchRequest *batchRequest; | ||
|
||
@end | ||
|
||
@interface BIBatchResponse (UITableView) | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
tableView:(nonnull UITableView *)tableView | ||
countNewItems:(NSUInteger)countNewItems; | ||
|
||
@end | ||
|
||
@interface BIBatchResponse (UICollectionView) | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
collectionView:(nonnull UICollectionView *)collectionView | ||
countNewItems:(NSUInteger)countNewItems; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// BIBatchResponse.m | ||
// BIObjCHelpers | ||
// | ||
// Created by Bogdan Iusco on 08/09/15. | ||
// Copyright (c) 2015 iGama Apps. All rights reserved. | ||
// | ||
|
||
#import "BIBatchResponse.h" | ||
#import "BIBatchRequest.h" | ||
|
||
@interface BIBatchResponse () | ||
|
||
@property (nonatomic, strong, nullable, readwrite) NSError *error; | ||
@property (nonatomic, copy, nullable, readwrite) NSArray *indexPaths; | ||
@property (nonatomic, strong, nullable, readwrite) BIBatchRequest *batchRequest; | ||
|
||
@end | ||
|
||
@implementation BIBatchResponse | ||
|
||
#pragma mark - Factory methods | ||
|
||
+ (nonnull instancetype)batchResponseForRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths { | ||
return [[self alloc] initWithBatchRequest:batch | ||
error:error | ||
newIndexPaths:newIndexPaths]; | ||
} | ||
|
||
#pragma mark - Init methods | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batch | ||
error:(nullable NSError *)error | ||
newIndexPaths:(nullable NSArray *)newIndexPaths { | ||
self = [super init]; | ||
if (self) { | ||
self.batchRequest = batch; | ||
self.error = error; | ||
self.indexPaths = newIndexPaths; | ||
} | ||
return self; | ||
} | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batchRequest | ||
tableView:(nonnull UITableView *)tableView | ||
countNewItems:(NSUInteger)countNewItems { | ||
NSUInteger sectionIndex = batchRequest.sectionIndex; | ||
NSUInteger countSectionItems = [tableView numberOfRowsInSection:sectionIndex]; | ||
self = [self initWithBatchRequest:batchRequest | ||
countSectionItems:countSectionItems | ||
countNewItems:countNewItems]; | ||
return self; | ||
} | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batchRequest | ||
collectionView:(nonnull UICollectionView *)collectionView | ||
countNewItems:(NSUInteger)countNewItems { | ||
NSUInteger sectionIndex = batchRequest.sectionIndex; | ||
NSUInteger countSectionItems = [collectionView numberOfItemsInSection:sectionIndex]; | ||
self = [self initWithBatchRequest:batchRequest | ||
countSectionItems:countSectionItems | ||
countNewItems:countNewItems]; | ||
return self; | ||
} | ||
|
||
- (nonnull instancetype)initWithBatchRequest:(nonnull BIBatchRequest *)batchRequest | ||
countSectionItems:(NSUInteger)countSectionItems | ||
countNewItems:(NSUInteger)countNewItems { | ||
NSUInteger sectionIndex = batchRequest.sectionIndex; | ||
NSUInteger newRowIndex = 0; | ||
switch (batchRequest.insertPosition) { | ||
case BIBatchInsertPositionTop: | ||
newRowIndex = 0; | ||
break; | ||
case BIBatchInsertPositionBottom: | ||
newRowIndex = countSectionItems; | ||
break; | ||
default: | ||
newRowIndex = batchRequest.insertPosition; | ||
break; | ||
} | ||
|
||
NSUInteger lastRowIndex = newRowIndex + countNewItems; | ||
NSMutableArray *mutableArray = [NSMutableArray new]; | ||
for (NSUInteger index = newRowIndex; index < lastRowIndex; index++) { | ||
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:sectionIndex]; | ||
[mutableArray addObject:indexPath]; | ||
} | ||
|
||
self = [self initWithBatchRequest:batchRequest | ||
error:nil | ||
newIndexPaths:[mutableArray copy]]; | ||
|
||
return self; | ||
} | ||
|
||
@end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.