Digital PCT265 story MVAPCT-48 - Loading overlay cleanup
This commit is contained in:
parent
54e2ecb313
commit
f89bad1c7a
@ -383,28 +383,9 @@
|
|||||||
if (requestParameters.backgroundRequest) {
|
if (requestParameters.backgroundRequest) {
|
||||||
return [self loadBackgroundRequest:requestParameters dataForPage:dataForPage delegateObject:delegateObject];
|
return [self loadBackgroundRequest:requestParameters dataForPage:dataForPage delegateObject:delegateObject];
|
||||||
} else {
|
} else {
|
||||||
BOOL loadingOverlay = NO;
|
|
||||||
if (!requestParameters.noloadingOverlay && [self.blockingLoadQueue.operations indexOfObjectPassingTest:^BOOL(__kindof NSOperation * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
|
|
||||||
if (!obj.isExecuting) {
|
|
||||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: T No executor"]];
|
|
||||||
return NO; }
|
|
||||||
if (![obj isKindOfClass:[MVMCoreLoadRequestOperation class]]) {
|
|
||||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: T Not load request"]];
|
|
||||||
return NO; }
|
|
||||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: T %@ %i",((MVMCoreLoadRequestOperation *)obj).loadObject.requestParameters.pageType,((MVMCoreLoadRequestOperation *)obj).loadObject.requestParameters.noloadingOverlay]];
|
|
||||||
return ((MVMCoreLoadRequestOperation *)obj).requestParameters.noloadingOverlay;
|
|
||||||
}] != NSNotFound) {
|
|
||||||
loadingOverlay = YES;
|
|
||||||
[MVMCoreLoggingHandler logDebugMessageWithDelegate:[NSString stringWithFormat:@"CACHEDFEED: We need a loading indicator"]];
|
|
||||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading];
|
|
||||||
}
|
|
||||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject backgroundLoad:NO];
|
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithRequestParameters:requestParameters dataForPage:dataForPage delegateObject:delegateObject backgroundLoad:NO];
|
||||||
loadOperation.identifier = requestParameters.identifier;
|
loadOperation.identifier = requestParameters.identifier;
|
||||||
[loadOperation setCompletionBlock:^{
|
[loadOperation startLoadingAnimationIfNeeded];
|
||||||
if (loadingOverlay) {
|
|
||||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:YES];
|
|
||||||
}
|
|
||||||
}];
|
|
||||||
[self.blockingLoadQueue addOperation:loadOperation];
|
[self.blockingLoadQueue addOperation:loadOperation];
|
||||||
return loadOperation;
|
return loadOperation;
|
||||||
}
|
}
|
||||||
@ -419,6 +400,8 @@
|
|||||||
|
|
||||||
- (MVMCoreLoadRequestOperation *)loadObject:(nonnull MVMCoreLoadObject *)loadObject {
|
- (MVMCoreLoadRequestOperation *)loadObject:(nonnull MVMCoreLoadObject *)loadObject {
|
||||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithLoadObject:loadObject backgroundLoad:NO];
|
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithLoadObject:loadObject backgroundLoad:NO];
|
||||||
|
loadOperation.identifier = loadObject.requestParameters.identifier;
|
||||||
|
[loadOperation startLoadingAnimationIfNeeded];
|
||||||
[self.blockingLoadQueue addOperation:loadOperation];
|
[self.blockingLoadQueue addOperation:loadOperation];
|
||||||
return loadOperation;
|
return loadOperation;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -118,11 +118,9 @@ public extension MVMCoreLoadRequestOperation {
|
|||||||
// stop any loading animation we may have started if we are about to display
|
// stop any loading animation we may have started if we are about to display
|
||||||
cancellable = NavigationHandler.shared().onNavigation
|
cancellable = NavigationHandler.shared().onNavigation
|
||||||
.filter { $0.0 == .willNavigate }
|
.filter { $0.0 == .willNavigate }
|
||||||
.sink { (event, operation) in
|
.sink { [weak self] (event, operation) in
|
||||||
if navigationOperation == operation,
|
if navigationOperation == operation {
|
||||||
!self.backgroundLoad,
|
self?.stopLoadingAnimationIfNeeded()
|
||||||
!(loadObject?.requestParameters?.noloadingOverlay ?? false) {
|
|
||||||
MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(false)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await NavigationHandler.shared().navigate(with: navigationOperation)
|
await NavigationHandler.shared().navigate(with: navigationOperation)
|
||||||
|
|||||||
@ -42,6 +42,12 @@
|
|||||||
// Initializes the operation with the load object, data for page, and mvm view controller to handle the loading with. Can be used for loading a screen without going to the cache or server.
|
// Initializes the operation with the load object, data for page, and mvm view controller to handle the loading with. Can be used for loading a screen without going to the cache or server.
|
||||||
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad;
|
- (nullable instancetype)initWithLoadObject:(nullable MVMCoreLoadObject *)loadObject backgroundLoad:(BOOL)backgroundLoad;
|
||||||
|
|
||||||
|
/// Begins the loading animation if needed.
|
||||||
|
- (void)startLoadingAnimationIfNeeded;
|
||||||
|
|
||||||
|
/// Ends the loading animation if needed.
|
||||||
|
- (void)stopLoadingAnimationIfNeeded;
|
||||||
|
|
||||||
/* Checks the cache for the data and calls the completion handler with any found data.
|
/* Checks the cache for the data and calls the completion handler with any found data.
|
||||||
* @param completionHandler The block that gets called with any fetched data. */
|
* @param completionHandler The block that gets called with any fetched data. */
|
||||||
+ (void)checkCacheForDataForRequest:(nonnull MVMCoreRequestParameters *)requestParameters completionHandler:(nonnull void (^)(NSDictionary * _Nullable pageFromCache, NSDictionary * _Nullable modulesFromCache))completionHandler;
|
+ (void)checkCacheForDataForRequest:(nonnull MVMCoreRequestParameters *)requestParameters completionHandler:(nonnull void (^)(NSDictionary * _Nullable pageFromCache, NSDictionary * _Nullable modulesFromCache))completionHandler;
|
||||||
|
|||||||
@ -34,6 +34,8 @@
|
|||||||
@property (nonatomic, readwrite) BOOL alertToShow;
|
@property (nonatomic, readwrite) BOOL alertToShow;
|
||||||
@property (strong, nonatomic, nullable) MVMCoreErrorObject *errorForAlertToShow;
|
@property (strong, nonatomic, nullable) MVMCoreErrorObject *errorForAlertToShow;
|
||||||
|
|
||||||
|
@property (nonatomic, readwrite) BOOL loadingAnimationRunning;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation MVMCoreLoadRequestOperation
|
@implementation MVMCoreLoadRequestOperation
|
||||||
@ -64,14 +66,13 @@
|
|||||||
- (void)cancel {
|
- (void)cancel {
|
||||||
[super cancel];
|
[super cancel];
|
||||||
[self.sessionTask cancel];
|
[self.sessionTask cancel];
|
||||||
|
[self stopLoadingAnimationIfNeeded];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)start {
|
- (void)start {
|
||||||
|
|
||||||
// Adds a loading overlay if necessary.
|
// Adds a loading overlay if necessary.
|
||||||
if (!self.backgroundLoad && !self.requestParameters.noloadingOverlay) {
|
[self startLoadingAnimationIfNeeded];
|
||||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading];
|
|
||||||
}
|
|
||||||
|
|
||||||
[super start];
|
[super start];
|
||||||
}
|
}
|
||||||
@ -83,9 +84,7 @@
|
|||||||
- (void)markAsFinished {
|
- (void)markAsFinished {
|
||||||
|
|
||||||
// stop any loading animation we may have started
|
// stop any loading animation we may have started
|
||||||
if (!self.backgroundLoad && !self.requestParameters.noloadingOverlay) {
|
[self stopLoadingAnimationIfNeeded];
|
||||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:NO];
|
|
||||||
}
|
|
||||||
|
|
||||||
MVMCoreLog(@"Load Operation finished for page type %@, background load %@", self.requestParameters.pageType, @(self.backgroundLoad));
|
MVMCoreLog(@"Load Operation finished for page type %@, background load %@", self.requestParameters.pageType, @(self.backgroundLoad));
|
||||||
[super markAsFinished];
|
[super markAsFinished];
|
||||||
@ -205,6 +204,20 @@
|
|||||||
|
|
||||||
#pragma mark - Load Functions
|
#pragma mark - Load Functions
|
||||||
|
|
||||||
|
- (void)startLoadingAnimationIfNeeded {
|
||||||
|
if (self.loadingAnimationRunning) { return; }
|
||||||
|
if (self.backgroundLoad) { return; }
|
||||||
|
if (self.requestParameters.noloadingOverlay) { return; }
|
||||||
|
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading];
|
||||||
|
self.loadingAnimationRunning = YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)stopLoadingAnimationIfNeeded {
|
||||||
|
if (!self.loadingAnimationRunning) { return; }
|
||||||
|
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:YES];
|
||||||
|
self.loadingAnimationRunning = NO;
|
||||||
|
}
|
||||||
|
|
||||||
+ (void)checkCacheForDataForRequest:(nonnull MVMCoreRequestParameters *)requestParameters completionHandler:(nonnull void (^)(NSDictionary * _Nullable pageFromCache, NSDictionary * _Nullable modulesFromCache))completionHandler {
|
+ (void)checkCacheForDataForRequest:(nonnull MVMCoreRequestParameters *)requestParameters completionHandler:(nonnull void (^)(NSDictionary * _Nullable pageFromCache, NSDictionary * _Nullable modulesFromCache))completionHandler {
|
||||||
|
|
||||||
if (requestParameters.neverLoadFromCache) {
|
if (requestParameters.neverLoadFromCache) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user