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





























































































































































































































































































































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

@implementation ViewController (Demo)

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

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    static dispatch_once_t daysToken;
    dispatch_once(&daysToken, ^{
        self.demo_logs = [NSMutableArray new];
        [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(demo_loginStatusChange) name:WorkoutTip.DisappearLookupShakeRhythmCurrentlyGuideAxialNiacin object:nil];
        self.demo_sdk_version.text = [NSString stringWithFormat:@"SDK VERSION：%@",WorkoutTip.anyDigitOnly];
        [self demo_addLaunchScreen];
        [self demo_addShadowAndCornerRadiusToButtons:self.view.subviews];
    });
}

- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    static dispatch_once_t daysToken;
    dispatch_once(&daysToken, ^{
        [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 eyeCanCenter = [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 = eyeCanCenter;
            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 (WorkoutTip.irishStrideStatus) {
        case LossyGroupingRemovesFirstEarUnsaved:
            self.demo_login_status.text = @"○ 未登录";
            self.demo_login_status.textColor = UIColor.grayColor;
            break;
        case HangWeightedHandballDemandFastVersionWrapped:
            self.demo_login_status.text = @"○ 准备登录";
            self.demo_login_status.textColor = UIColor.yellowColor;
            break;
        case AskDegreeReplacedOuterFormatsMobileUse:
            self.demo_login_status.text = @"○ 登录中...";
            self.demo_login_status.textColor = UIColor.blueColor;
            break;
        case HasPlanExceptionSoccerAvailBrown:
            self.demo_login_status.text = @"● 已登录";
            self.demo_login_status.textColor = UIColor.greenColor;
            break;
    }
}

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

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