//
//  sendArticleProgressViewController.m
//  melody app
//
//  Created by Odin on 15/03/2017.
//  Copyright © 2017 demain un autre jour. All rights reserved.
//

#import "sendArticleProgressViewController.h"

@interface sendArticleProgressViewController () {
	
}
@property (weak, nonatomic) IBOutlet UIImageView *waitGif;

@end

@implementation sendArticleProgressViewController

- (void)viewDidLoad {
	[super viewDidLoad];
	
	CGRect screen = [[UIScreen mainScreen] bounds];
	self.view.frame = screen;
	
	[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeThisView:) name:@"articleSent" object:nil];
	[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
	[[NSNotificationCenter defaultCenter] addObserver:self
											 selector:@selector(orientationChanged:)
												 name:UIDeviceOrientationDidChangeNotification
											   object:nil];
	
	self.waitGif.animationImages= [NSArray arrayWithObjects:
								   [UIImage imageNamed:@"waitGifFrames/waitGif-1.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-2.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-3.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-4.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-5.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-6.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-7.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-8.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-9.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-10.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-11.gif"],
								   [UIImage imageNamed:@"waitGifFrames/waitGif-12.gif"],
								   nil];
	self.waitGif.animationDuration = 1.0f;
	self.waitGif.animationRepeatCount = 0;
	[self.waitGif startAnimating];
	[self.view addSubview: self.waitGif];
}

- (void)orientationChanged:(NSNotification *)notification
{
	CGRect screen = [[UIScreen mainScreen] bounds];
	self.view.frame = screen;
}

- (void)showInView:(UIView *)aView animated:(BOOL)animated {
	[aView addSubview:self.view];
	[self showAnimate];
}

- (void)showAnimate {
	self.view.transform = CGAffineTransformMakeScale(1.0, 1.0);
	self.view.alpha = 0;
	[UIView animateWithDuration:.25 animations:^{
		self.view.alpha = 1;
		self.view.transform = CGAffineTransformMakeScale(1, 1);
	}];
}

- (void) closeThisView :(NSNotification*)note {
	[UIView beginAnimations:nil context:NULL];
	[UIView setAnimationDuration:0.25];
	[UIView  setAnimationDelegate:self];
	[self.view setAlpha:0.00];
	[UIView commitAnimations];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
