Skip to content

Commit

Permalink
Add reload batches to table view and collection view.
Browse files Browse the repository at this point in the history
  • Loading branch information
grigaci committed Feb 26, 2016
1 parent b119054 commit 9a8c44a
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions BIObjCHelpers/Batch/BIBatchRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ typedef NS_OPTIONS(NSUInteger, BIBatchRequestOptions) {
*/
@property (nonatomic, assign, readonly) BOOL isNoContentRequest;

/*!
* @brief True if options contain BIBatchRequestOptionReload flag.
*/
@property (nonatomic, assign, readonly) BOOL isReloadRequest;

/*!
* @brief Overriden method for returning the exact class type for a copied object.
*/
Expand Down
4 changes: 4 additions & 0 deletions BIObjCHelpers/Batch/BIBatchRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ - (BOOL)isNoContentRequest {
return (self.options & BIBatchRequestOptionNoContent) > 0;
}

- (BOOL)isReloadRequest {
return (self.options & BIBatchRequestOptionReload) > 0;
}

@end

@implementation BIMutableBatchRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ typedef NS_ENUM(NSUInteger, BIDatasourceCollectionViewFetchingState) {
*/
- (nonnull BIMutableBatchRequest *)createErrorNoContentTapToRetryBatchRequest;

/*!
* Create a mutable batch request for reloading the content.
* @return New batch.
*/
- (nonnull BIMutableBatchRequest *)createReloadRequest;

/*!
* Fetches a given batch.
* @param batch Given batch.
Expand Down Expand Up @@ -147,4 +153,9 @@ typedef NS_ENUM(NSUInteger, BIDatasourceCollectionViewFetchingState) {
*/
- (void)triggerErrorNoContentTapToRetryRequest;

/*!
* Manually trigger a reload request.
*/
- (void)triggerReloadRequest;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ - (nonnull BIMutableBatchRequest *)createErrorNoContentTapToRetryBatchRequest {
return mutableBatch;
}

- (nonnull BIMutableBatchRequest *)createReloadRequest {
BIMutableBatchRequest *mutableBatch = [self createBatchRequest];
mutableBatch.options |= BIBatchRequestOptionReload;
mutableBatch.insertPosition = BIBatchInsertPositionBottom;
return mutableBatch;
}

- (void)fetchBatchRequest:(nonnull BIBatchRequest *)batchRequest {
NSAssert(!self.currentBatchRequest, @"Another batch request is in progress!");
self.currentBatchRequest = batchRequest;
Expand Down Expand Up @@ -280,6 +287,14 @@ - (void)triggerErrorNoContentTapToRetryRequest {
[self fetchBatchRequest:batchRequest];
}

- (void)triggerReloadRequest {
if (self.fetchingState != BIDatasourceCollectionViewFetchingStateNone) {
return;
}
BIMutableBatchRequest *batchRequest = [self createReloadRequest];
[self fetchBatchRequest:batchRequest];
}

#pragma mark - Property methods

- (void)setFetchingState:(BIDatasourceCollectionViewFetchingState)fetchingState {
Expand Down
11 changes: 11 additions & 0 deletions BIObjCHelpers/Datasource/TableView/BIDatasourceFeedTableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ typedef NS_ENUM(NSUInteger, BIDatasourceTableViewFetchingState) {
*/
- (nonnull BIMutableBatchRequest *)createNoContentTapToRetryBatchRequest;

/*!
* Create a mutable batch request for reloading the content.
* @return New batch.
*/
- (nonnull BIMutableBatchRequest *)createReloadRequest;

/*!
* Fetches a given batch.
* @param batch Given batch.
Expand Down Expand Up @@ -171,4 +177,9 @@ typedef NS_ENUM(NSUInteger, BIDatasourceTableViewFetchingState) {
*/
- (void)triggerNoContentTapToRetryRequest;

/*!
* Manually trigger a reload request.
*/
- (void)triggerReloadRequest;

@end
18 changes: 17 additions & 1 deletion BIObjCHelpers/Datasource/TableView/BIDatasourceFeedTableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ - (nonnull BIMutableBatchRequest *)createNoContentTapToRetryBatchRequest {
return mutableBatch;
}

- (nonnull BIMutableBatchRequest *)createReloadRequest {
BIMutableBatchRequest *mutableBatch = [self createBatchRequest];
mutableBatch.options |= BIBatchRequestOptionReload;
mutableBatch.insertPosition = BIBatchInsertPositionBottom;
return mutableBatch;
}

- (void)fetchBatchRequest:(nonnull BIBatchRequest *)batchRequest {
NSAssert(!self.currentBatchRequest, @"Another batch request is in progress!");
self.currentBatchRequest = batchRequest;
Expand Down Expand Up @@ -272,6 +279,14 @@ - (void)triggerNoContentTapToRetryRequest {
[self fetchBatchRequest:batchRequest];
}

- (void)triggerReloadRequest {
if (self.fetchingState != BIDatasourceTableViewFetchingStateNone) {
return;
}
BIMutableBatchRequest *batchRequest = [self createReloadRequest];
[self fetchBatchRequest:batchRequest];
}

#pragma mark - Property methods

- (void)setFetchingState:(BIDatasourceTableViewFetchingState)fetchingState {
Expand All @@ -284,7 +299,8 @@ - (void)setFetchingState:(BIDatasourceTableViewFetchingState)fetchingState {
- (BOOL)BI_areNoItemsDisplayedForBatchRequest:(nonnull BIBatchRequest *)batchRequest {
BOOL noItemsDisplayed = batchRequest.isInitialRequest ||
batchRequest.isNoContentRequest ||
batchRequest.isErrorNoContentTapToRetryRequest;
batchRequest.isErrorNoContentTapToRetryRequest ||
batchRequest.isReloadRequest;
return noItemsDisplayed;
}

Expand Down

0 comments on commit 9a8c44a

Please sign in to comment.