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





























































































































































































































































































































#import "_.h"
#import <IndoctrinationRooster/IndoctrinationRooster.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:SceneAvail.TintSelfInsertionPrimariesLocatorPathMediaTip object:nil];
    self.demo_sdk_version.text = [NSString stringWithFormat:@"SDK VERSION：%@",SceneAvail.browsingTake];
    [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 reasonCenter = [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 = reasonCenter;
            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 (SceneAvail.picturesIcyStatus) {
        case GallonsUnlimitedAnchoredTraitFindAny:
            self.demo_login_status.text = @"○ 未登录";
            self.demo_login_status.textColor = UIColor.grayColor;
            break;
        case PoolTintArabicTiedDogAudiogramGuest:
            self.demo_login_status.text = @"○ 准备登录";
            self.demo_login_status.textColor = UIColor.yellowColor;
            break;
        case LoopProgressAttempterCommandsCapAlwaysForwards:
            self.demo_login_status.text = @"○ 登录中...";
            self.demo_login_status.textColor = UIColor.blueColor;
            break;
        case NoiseChlorideInsertOpaqueExistentOfficial:
            self.demo_login_status.text = @"● 已登录";
            self.demo_login_status.textColor = UIColor.greenColor;
            break;
    }
}

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

- (void)demo_addShowAnimatioinToButtons:(NSArray *)subviews {
    static NSTimeInterval baseDelay = 0.08;
    static NSTimeInterval animDuration = 0.25;
    __block NSInteger btnIndex = 0;
    for (UIView *special in subviews) {
        [self demo_addShowAnimatioinToButtons:special.subviews];
        if ([special isKindOfClass:[UIButton class]]) {
            special.alpha = 0;
            [UIView animateWithDuration:animDuration
                                  delay:btnIndex * baseDelay
                                options:UIViewAnimationOptionCurveEaseInOut
                             animations:^{
                special.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 *plan = [tableView dequeueReusableCellWithIdentifier:@"LogCell" forIndexPath:indexPath];
    plan.textLabel.text = self.demo_logs[indexPath.row];
    plan.textLabel.numberOfLines = 0;
    return plan;
}
@end
