Digital PCT265 story MVAPCT-48 - Loading overlay cleanup
This commit is contained in:
parent
54e2ecb313
commit
f89bad1c7a
@ -383,28 +383,9 @@
|
||||
if (requestParameters.backgroundRequest) {
|
||||
return [self loadBackgroundRequest:requestParameters dataForPage:dataForPage delegateObject:delegateObject];
|
||||
} 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];
|
||||
loadOperation.identifier = requestParameters.identifier;
|
||||
[loadOperation setCompletionBlock:^{
|
||||
if (loadingOverlay) {
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:YES];
|
||||
}
|
||||
}];
|
||||
[loadOperation startLoadingAnimationIfNeeded];
|
||||
[self.blockingLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
@ -419,6 +400,8 @@
|
||||
|
||||
- (MVMCoreLoadRequestOperation *)loadObject:(nonnull MVMCoreLoadObject *)loadObject {
|
||||
MVMCoreLoadRequestOperation *loadOperation = [[MVMCoreLoadRequestOperation alloc] initWithLoadObject:loadObject backgroundLoad:NO];
|
||||
loadOperation.identifier = loadObject.requestParameters.identifier;
|
||||
[loadOperation startLoadingAnimationIfNeeded];
|
||||
[self.blockingLoadQueue addOperation:loadOperation];
|
||||
return loadOperation;
|
||||
}
|
||||
|
||||
@ -118,11 +118,9 @@ public extension MVMCoreLoadRequestOperation {
|
||||
// stop any loading animation we may have started if we are about to display
|
||||
cancellable = NavigationHandler.shared().onNavigation
|
||||
.filter { $0.0 == .willNavigate }
|
||||
.sink { (event, operation) in
|
||||
if navigationOperation == operation,
|
||||
!self.backgroundLoad,
|
||||
!(loadObject?.requestParameters?.noloadingOverlay ?? false) {
|
||||
MVMCoreLoadingOverlayHandler.sharedLoadingOverlay()?.stopLoading(false)
|
||||
.sink { [weak self] (event, operation) in
|
||||
if navigationOperation == operation {
|
||||
self?.stopLoadingAnimationIfNeeded()
|
||||
}
|
||||
}
|
||||
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.
|
||||
- (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.
|
||||
* @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;
|
||||
|
||||
@ -34,6 +34,8 @@
|
||||
@property (nonatomic, readwrite) BOOL alertToShow;
|
||||
@property (strong, nonatomic, nullable) MVMCoreErrorObject *errorForAlertToShow;
|
||||
|
||||
@property (nonatomic, readwrite) BOOL loadingAnimationRunning;
|
||||
|
||||
@end
|
||||
|
||||
@implementation MVMCoreLoadRequestOperation
|
||||
@ -64,14 +66,13 @@
|
||||
- (void)cancel {
|
||||
[super cancel];
|
||||
[self.sessionTask cancel];
|
||||
[self stopLoadingAnimationIfNeeded];
|
||||
}
|
||||
|
||||
- (void)start {
|
||||
|
||||
// Adds a loading overlay if necessary.
|
||||
if (!self.backgroundLoad && !self.requestParameters.noloadingOverlay) {
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] startLoading];
|
||||
}
|
||||
[self startLoadingAnimationIfNeeded];
|
||||
|
||||
[super start];
|
||||
}
|
||||
@ -83,9 +84,7 @@
|
||||
- (void)markAsFinished {
|
||||
|
||||
// stop any loading animation we may have started
|
||||
if (!self.backgroundLoad && !self.requestParameters.noloadingOverlay) {
|
||||
[[MVMCoreLoadingOverlayHandler sharedLoadingOverlay] stopLoading:NO];
|
||||
}
|
||||
[self stopLoadingAnimationIfNeeded];
|
||||
|
||||
MVMCoreLog(@"Load Operation finished for page type %@, background load %@", self.requestParameters.pageType, @(self.backgroundLoad));
|
||||
[super markAsFinished];
|
||||
@ -205,6 +204,20 @@
|
||||
|
||||
#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 {
|
||||
|
||||
if (requestParameters.neverLoadFromCache) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user