Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix architectural issue with +[CLURecordIndicatorViewManager currentViewController] #8

Open
Geek-1001 opened this issue Apr 24, 2017 · 0 comments

Comments

@Geek-1001
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant