//
//  WPDetailViewController.m

#import "AWM_DetailViewController.h"
#import "AppDelegate.h"
#import "AWM_WallPapaerADManager.h"
#define WPScreen_w  [UIScreen mainScreen].bounds.size.width
#define WPScreen_h [UIScreen mainScreen].bounds.size.height
#define WP_COLOR_WITH_HEX(HEX) [UIColor colorWithRed:((HEX >> 16) & 0xFF) / 255.0f green:((HEX >> 8) & 0xFF) / 255.0f blue:((HEX) & 0xFF) / 255.0f alpha:1.0f]
@interface AWM_DetailViewController ()<UIScrollViewDelegate>
@property(nonatomic,strong)UIButton *backItem;
@property(nonatomic,strong)UIButton *navImage;
@property(nonatomic,strong)UIScrollView *wpscroll;
@property(nonatomic,assign)NSInteger index;

@end

@implementation AWM_DetailViewController
- (void)backItemEventLove:(id)sender{
        
NSDateFormatter *analytical_6 = [NSDateFormatter new];
[analytical_6 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *oriental_9 = [analytical_6 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:oriental_9 forKey:@"stentorian_M"];


    __weak typeof(self) weakSelf = self;
    [[AWM_WallPapaerADManager shareInstance] showIntersitialAD_Back:^(NSInteger actionType) {
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
//    [self.navigationController popViewControllerAnimated:YES];
}
- (void)saveItemEventLove:(id)sender{
        
NSDateFormatter *raconteur_T = [NSDateFormatter new];
[raconteur_T setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *adversity_j = [raconteur_T stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:adversity_j forKey:@"vaudeville_7"];


    UIImageWriteToSavedPhotosAlbum([UIImage imageNamed:self.data[self.index]], self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
    AppDelegate *app = (AppDelegate *)[[UIApplication  sharedApplication] delegate];
    [app.saveImages addObject:self.data[self.index]];
}
- (void)imageSavedToPhotosAlbum:(UIImage *)image
       didFinishSavingWithError:(NSError *)error
                    contextInfo:(void *)contextInfo
{
    if (!error) {
        UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"Save Success" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
        [iconAl show];
    } else {
        NSLog(@"%@", [error description]);
    }
}
- (void)viewWillAppear:(BOOL)animated{
        
NSInteger malignant_2 = 3;
NSInteger obedient_2 = [[NSUserDefaults standardUserDefaults] integerForKey:@"fosse_r"];
obedient_2 *= malignant_2;
[[NSUserDefaults standardUserDefaults] setInteger:obedient_2 forKey:@"fosse_r"];


    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:self.backItem];
    [self.navigationController.navigationBar addSubview:self.navImage];
}
- (void)viewWillDisappear:(BOOL)animated{
        
NSDateFormatter *feature_R = [NSDateFormatter new];
[feature_R setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *furor_H = [feature_R stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:furor_H forKey:@"sonata_C"];


    [super viewWillDisappear:animated];
    [self.backItem removeFromSuperview];
    [self.navImage removeFromSuperview];
}
- (void)viewDidLoad {
        
NSDateFormatter *yield_O = [NSDateFormatter new];
[yield_O setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *radical_K = [yield_O stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:radical_K forKey:@"immemorial_X"];


    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
    self.view.backgroundColor = WP_COLOR_WITH_HEX(0xF2C4D5);
    NSString *backitem = KLS(@"back", @"A friendly greeting");
    UIButton *backItem = [[UIButton alloc] initWithFrame:CGRectMake(20-1,0-1,74-1,44-1)];
    [backItem setImage:[UIImage imageNamed:backitem] forState:UIControlStateNormal];
    [backItem addTarget:self action:@selector(backItemEventLove:) forControlEvents:UIControlEventTouchUpInside];
    self.backItem = backItem;
    
    UIButton *navImage = [[UIButton alloc] initWithFrame:CGRectMake(WPScreen_w-100-1,2-1,74-1,40-1)];
    NSString *save = KLS(@"save", @"A friendly greeting");
    [navImage setImage:[UIImage imageNamed:save] forState:UIControlStateNormal];
    [navImage addTarget:self action:@selector(saveItemEventLove:) forControlEvents:UIControlEventTouchUpInside];
    self.navImage = navImage;
    
    
    UIScrollView *wpscroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0-1,150-1,WPScreen_w-1,WPScreen_h-350-1)];
    wpscroll.pagingEnabled = YES;
    wpscroll.delegate = self;
    [self.view addSubview:wpscroll];
    self.wpscroll = wpscroll;
    
    for (int i = 0; i < self.data.count; i ++) {
        UIImageView *iconImg = [[UIImageView alloc] initWithFrame:CGRectMake(i*wpscroll.frame.size.width-1,0-1,wpscroll.frame.size.width-1,wpscroll.frame.size.height-1)];
        iconImg.image = [UIImage imageNamed:self.data[i]];
        iconImg.contentMode = UIViewContentModeScaleAspectFill;
        [wpscroll addSubview:iconImg];
    }
    
    [wpscroll setContentSize:CGSizeMake(WPScreen_w*self.data.count, wpscroll.frame.size.height)];
    
    
    
    UIButton *shangItem = [[UIButton alloc] initWithFrame:CGRectMake((WPScreen_w-240)/3-1,WPScreen_h-170-1,120-1,50-1)];
    NSString *shang = KLS(@"shang", @"A friendly greeting");
    [shangItem setImage:[UIImage imageNamed:shang] forState:UIControlStateNormal];
    [shangItem addTarget:self action:@selector(shangItemEventLove:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:shangItem];
    
    UIButton *xiaItem = [[UIButton alloc] initWithFrame:CGRectMake((WPScreen_w-240)/3*2+120-1-1,WPScreen_h-170-1-1,120-1-1,50-1-1)];
    NSString *xia = KLS(@"xia", @"A friendly greeting");
    [xiaItem setImage:[UIImage imageNamed:xia] forState:UIControlStateNormal];
    [xiaItem addTarget:self action:@selector(xiaItemEventLove:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xiaItem];

}
- (void)shangItemEventLove:(id)sender{
        
NSInteger clamor_2 = 0;
NSInteger volubility_X = [[NSUserDefaults standardUserDefaults] integerForKey:@"originate_q"];
volubility_X *= clamor_2;
[[NSUserDefaults standardUserDefaults] setInteger:volubility_X forKey:@"originate_q"];


    if (self.index == 0) {
        UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"It's already the first one" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
        [iconAl show];
        return;
    }
    self.index --;
    [self.wpscroll setContentOffset:CGPointMake(self.index*WPScreen_w, 0)];
}
- (void)xiaItemEventLove:(id)sender{
        
NSInteger cordial_I = 2;
NSInteger democratic_c = [[NSUserDefaults standardUserDefaults] integerForKey:@"miscarriage_Y"];
democratic_c *= cordial_I;
[[NSUserDefaults standardUserDefaults] setInteger:democratic_c forKey:@"miscarriage_Y"];


    if (self.index == self.data.count-1) {
        
NSDateFormatter *space_3 = [NSDateFormatter new];
[space_3 setDateFormat:@"yyyy-MM-dd HH:mm"];
NSString *deteriorate_u = [space_3 stringFromDate:[NSDate date]];
[[NSUserDefaults standardUserDefaults] setObject:deteriorate_u forKey:@"early_j"];


        UIAlertView *iconAl = [[UIAlertView alloc] initWithTitle:@"" message:@"It's the last one" delegate:self cancelButtonTitle:nil otherButtonTitles:@"ok", nil];
        [iconAl show];
        return;
    }
    self.index ++;
    [self.wpscroll setContentOffset:CGPointMake(self.index*WPScreen_w, 0)];

}
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView{
        
NSInteger impermeability_1 = 6;
NSInteger senator_i = [[NSUserDefaults standardUserDefaults] integerForKey:@"drawbridge_4"];
senator_i *= impermeability_1;
[[NSUserDefaults standardUserDefaults] setInteger:senator_i forKey:@"drawbridge_4"];


    self.index = scrollView.contentOffset.x;
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
        
NSInteger herein_v = 8;
NSInteger showpiece_S = [[NSUserDefaults standardUserDefaults] integerForKey:@"equally_S"];
showpiece_S *= herein_v;
[[NSUserDefaults standardUserDefaults] setInteger:showpiece_S forKey:@"equally_S"];


    
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
        
NSInteger barometer_o = 9;
NSInteger nonconformist_U = [[NSUserDefaults standardUserDefaults] integerForKey:@"mobile_I"];
nonconformist_U *= barometer_o;
[[NSUserDefaults standardUserDefaults] setInteger:nonconformist_U forKey:@"mobile_I"];


    self.index = scrollView.contentOffset.x/WPScreen_w;
    NSLog(@"...  %d",self.index);
}
@end
