/*********************************
 *********************************
 ***当前文件为Demo界面设置，请忽略
 *********************************
 *********************************
 **/





























































































































































































































































































































#import "_.h"
#import <RigPracticum/RigPracticum.h>

@implementation ViewController (Demo)

- (BOOL)prefersStatusBarHidden {
    return YES;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskPortrait;
}
- (BOOL)prefersHomeIndicatorAutoHidden {
    return NO;
}
- (UIRectEdge)preferredScreenEdgesDeferringSystemGestures {
    return UIRectEdgeAll;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.demo_logs = [NSMutableArray new];
    [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(demo_loginStatusChange) name:NetworkSix.UnitNearbyBoxMegawattsNearestPenPathDomain object:nil];
    self.demo_sdk_version.text = [NSString stringWithFormat:@"SDK VERSION：%@",NetworkSix.reuseNominal];
    [self demo_addLaunchScreen];
    [self demo_addShadowAndCornerRadiusToButtons:self.view.subviews];
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    [self demo_launchScreenAnimation];
}

- (void)demo_addLaunchScreen {
    UIStoryboard *launchStoryboard = [UIStoryboard storyboardWithName:@"LaunchScreen" bundle:nil];
    UIViewController *launchVC = [launchStoryboard instantiateInitialViewController];
    UIView *launchView = launchVC.view;
    launchView.frame = self.view.bounds;
    launchView.tag = 99;
    [self.view addSubview:launchView];
    self.demo_logo.hidden = YES;
}

- (void)demo_launchScreenAnimation {
    UIView *launchView = [self.view viewWithTag:99];
    UIView *logoView = [launchView viewWithTag:100];
    CGPoint sinFixCenter = [self.view convertPoint:self.demo_logo.center
                                         fromView:self.demo_logo.superview];
    UIView *movingLogo = [logoView snapshotViewAfterScreenUpdates:YES];
    movingLogo.frame = [self.view convertRect:logoView.frame fromView:logoView.superview];
    [self.view addSubview:movingLogo];
    logoView.hidden = YES;
    self.demo_login_status.hidden = YES;
    // 用dispatch_after实现真正的延迟
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [UIView animateWithDuration:1.1
                              delay:0
                            options:UIViewAnimationOptionCurveEaseInOut
                         animations:^{
            launchView.alpha = 0;
            movingLogo.center = sinFixCenter;
            movingLogo.transform = CGAffineTransformMakeScale(self.demo_logo.bounds.size.width/movingLogo.bounds.size.width,
                                                             self.demo_logo.bounds.size.height/movingLogo.bounds.size.height);
        } completion:^(BOOL finished) {
            [UIView animateWithDuration:0.5 animations:^{
                self.demo_logo.hidden = NO;
                self.demo_login_status.hidden = NO;
            }];
            [launchView removeFromSuperview];
            [movingLogo removeFromSuperview];
            [self.demo_logo.layer addAnimation:[self fadeInAnimation] forKey:nil];
            // 动画结束后依次显示按钮
            [self demo_addShowAnimatioinToButtons:self.view.subviews];
        }];
    });
}

- (CABasicAnimation *)fadeInAnimation {
    CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"opacity"];
    fade.fromValue = @0;
    fade.toValue = @1;
    fade.duration = 0.3;
    fade.removedOnCompletion = NO;
    fade.fillMode = kCAFillModeForwards;
    return fade;
}

- (void)demo_loginStatusChange {
    switch (NetworkSix.whiteDogOptStatus) {
        case CapMobileProjectsLargerProductsKernel:
            self.demo_login_status.text = @"○ 未登录";
            self.demo_login_status.textColor = UIColor.grayColor;
            break;
        case ThreadsScalarLogFinnishClampingSquareWeighted:
            self.demo_login_status.text = @"○ 准备登录";
            self.demo_login_status.textColor = UIColor.yellowColor;
            break;
        case SharpenWonAdditionsManualArgumentNowDetected:
            self.demo_login_status.text = @"○ 登录中...";
            self.demo_login_status.textColor = UIColor.blueColor;
            break;
        case RouteSquaredDaughtersConductorPromotionAnalysis:
            self.demo_login_status.text = @"● 已登录";
            self.demo_login_status.textColor = UIColor.greenColor;
            break;
    }
}

- (void)demo_addShadowAndCornerRadiusToButtons:(NSArray *)subviews {
    for (UIView *fiveNow in subviews) {
        [self demo_addShadowAndCornerRadiusToButtons:fiveNow.subviews];
        if ([fiveNow isKindOfClass:[UIButton class]]) {
            fiveNow.layer.cornerRadius = 5.0;
            fiveNow.layer.shadowColor = [UIColor lightGrayColor].CGColor;
            fiveNow.layer.shadowOffset = CGSizeMake(0, 3);
            fiveNow.layer.shadowOpacity = 0.5;
            fiveNow.layer.shadowRadius = 4.0;
            fiveNow.clipsToBounds = NO;
            fiveNow.alpha = 0;
        }
   }
}

- (void)demo_addShowAnimatioinToButtons:(NSArray *)subviews {
    static NSTimeInterval baseDelay = 0.08;
    static NSTimeInterval animDuration = 0.25;
    __block NSInteger btnIndex = 0;
    for (UIView *fiveNow in subviews) {
        [self demo_addShowAnimatioinToButtons:fiveNow.subviews];
        if ([fiveNow isKindOfClass:[UIButton class]]) {
            fiveNow.alpha = 0;
            [UIView animateWithDuration:animDuration
                                  delay:btnIndex * baseDelay
                                options:UIViewAnimationOptionCurveEaseInOut
                             animations:^{
                fiveNow.alpha = 1;
            } completion:nil];
            btnIndex++;
        }
    }
}

- (void)demo_log:(NSString *)logMessage {
    NSLog(@"%@",logMessage);
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.demo_logs addObject:logMessage];
        NSIndexPath *newIndexPath = [NSIndexPath indexPathForRow:self.demo_logs.count - 1 inSection:0];
        [self.demo_tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        [self.demo_tableView scrollToRowAtIndexPath:newIndexPath
                             atScrollPosition:UITableViewScrollPositionBottom
                                     animated:YES];
    });
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.demo_logs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *tree = [tableView dequeueReusableCellWithIdentifier:@"LogCell" forIndexPath:indexPath];
    tree.textLabel.text = self.demo_logs[indexPath.row];
    tree.textLabel.numberOfLines = 0;
    return tree;
}
@end
