Clue icon indicating copy to clipboard operation
Clue copied to clipboard

Fix architectural issue with +[CLURecordIndicatorViewManager currentViewController]

Open Geek-1001 opened this issue 7 years ago • 0 comments

Description

+[CLURecordIndicatorViewManager currentViewController] is a universal method which returns current top/active UIViewController instance. Based on this method Clue can show Record indicator view, record only current view controller's view structure and use it as a main overall context for Clue framework. Right now this method is a part of CLURecordIndicatorViewManager class. But CLURecordIndicatorViewManager is responsible only for managing CLURecordIndicatorView.

Here are places, where Clue use -currentViewController method:

  1. In CLUViewStructureModule to get current view controller and view stature data from it
- (void)addNewFrameWithTimestamp:(CFTimeInterval)timestamp {
    @synchronized (self) {
        NSDictionary *currentViewStructure;
        UIViewController *rootViewController = [CLURecordIndicatorViewManager currentViewController];
        if (rootViewController && [rootViewController.view isKindOfClass:[UIView class]]) {
            currentViewStructure = [rootViewController.view clue_viewPropertiesDictionary];
        }
        if (!_lastRecordedViewStructure || ![_lastRecordedViewStructure isEqualToDictionary:currentViewStructure]) {
            [self addViewStructureProperties:currentViewStructure
                                      forKey:DEFAULT_VIEW_KEY
                            withTimeInterval:timestamp
                                      forKey:TIMESTAMP_KEY];
            _lastRecordedViewStructure = currentViewStructure;
        }
        [super addNewFrameWithTimestamp:timestamp];
    }
}
  1. In ClueController to get current view controller and show record indicator view and utils alert
- (void)startRecording {
    UIViewController *currentViewController = [CLURecordIndicatorViewManager currentViewController];
    // If user has previous report file (caused by exception) suggest him to resend it
    if ([[CLUReportFileManager sharedManager] isReportZipFileAvailable]) {
        [self showAlertWithTitle:@"Send Previous Clue Report"
                         message:@"Do you want to send your previous Clue Report caused by internal excpetion?"
              successActionTitle:@"Send Report"
              failureActionTitle:@"Delete Report"
                  successHandler:^{
                      [self sendReportWithEmailService];
                  } failureHandler:^{
                      [[CLUReportFileManager sharedManager] removeReportZipFile];
                  }
                inViewController:currentViewController];
        return;
    }
    
    if (!_isRecording) {
        _isRecording = YES;
        [_reportComposer startRecording];
        NSDateComponents *maxTime = [CLURecordIndicatorViewManager defaultMaxTime];
        [CLURecordIndicatorViewManager showRecordIndicatorInViewController:currentViewController
                                                               withMaxTime:maxTime
                                                                    target:self
                                                                 andAction:@selector(stopRecording)];
    }
}
  1. In ClueController to get current view controller and show modal mail window
- (void)sendReportWithEmailService {
    UIViewController *currentViewController = [CLURecordIndicatorViewManager currentViewController];
    CLUMailHelper *mailHelper = [[CLUMailHelper alloc] initWithOption:_options];
     [mailHelper setMailDelegate:_mailDelegate];
    // TODO: test it on real device. Mail isn't working on simulator
    if (currentViewController) {
        [mailHelper showMailComposeWindowWithViewController:currentViewController];
    }
}

Problem

+[CLURecordIndicatorViewManager currentViewController] method should not belong to CLURecordIndicatorViewManager. because it's universal method for getting current view controller across the framework

References

Geek-1001 avatar Apr 24 '17 17:04 Geek-1001