|
|
@@ -47,6 +47,10 @@ typedef enum {
|
|
|
@property (nonatomic,assign) HomeMode mode;///<
|
|
|
@property (nonatomic,assign) NSInteger currentKPI;
|
|
|
|
|
|
+@property (nonatomic,strong) UIAlertController *progressDialog;
|
|
|
+@property (nonatomic,assign) BOOL recentRefresh;
|
|
|
+@property (nonatomic,assign) BOOL kpiRefresh;
|
|
|
+
|
|
|
@end
|
|
|
|
|
|
@implementation HomeViewController
|
|
|
@@ -61,6 +65,8 @@ typedef enum {
|
|
|
}
|
|
|
self.currentKPI = 1;
|
|
|
self.segmentControl.tintColor = APGRAYCOLOR;
|
|
|
+ self.recentRefresh = NO;
|
|
|
+ self.kpiRefresh = NO;
|
|
|
|
|
|
[self registNotification];
|
|
|
[self configureTableView];
|
|
|
@@ -89,18 +95,18 @@ typedef enum {
|
|
|
[self clearNavigationbar];
|
|
|
[self configureNavigationBar];
|
|
|
|
|
|
- if (self.shipArray.count == 0) {
|
|
|
- [self loadData];
|
|
|
- }
|
|
|
|
|
|
- if (self.mode == HomeModeKPI) {
|
|
|
- if (self.KPIArray.count) {
|
|
|
+ if (self.mode == HomeModeRecent) {
|
|
|
+ if (self.shipArray.count == 0 || self.recentRefresh) {
|
|
|
+ [self loadData];
|
|
|
+ }
|
|
|
+ } else if (self.mode == HomeModeKPI) {
|
|
|
+ if (self.KPIArray.count == 0 || self.kpiRefresh) {
|
|
|
+ [self loadKPIData];
|
|
|
+ } else {
|
|
|
NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
|
|
|
self.parentViewController.title = str;
|
|
|
- } else {
|
|
|
- [self loadKPIData];
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|
|
|
@@ -196,6 +202,57 @@ typedef enum {
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
}
|
|
|
|
|
|
+#pragma mark - Private
|
|
|
+
|
|
|
+- (UIAlertController *)progressDialog {
|
|
|
+ if (!_progressDialog) {
|
|
|
+ UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil
|
|
|
+ message: @"loading..."
|
|
|
+ preferredStyle: UIAlertControllerStyleAlert];
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ UIViewController *customVC = [[UIViewController alloc] init];
|
|
|
+
|
|
|
+
|
|
|
+ UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
|
|
+// spinner.color = [UIColor redColor];
|
|
|
+ [spinner startAnimating];
|
|
|
+ [customVC.view addSubview:spinner];
|
|
|
+
|
|
|
+ [customVC.view addConstraint:[NSLayoutConstraint
|
|
|
+ constraintWithItem: spinner
|
|
|
+ attribute:NSLayoutAttributeCenterX
|
|
|
+ relatedBy:NSLayoutRelationEqual
|
|
|
+ toItem:customVC.view
|
|
|
+ attribute:NSLayoutAttributeCenterX
|
|
|
+ multiplier:1.0f
|
|
|
+ constant:0.0f]];
|
|
|
+
|
|
|
+ [customVC.view addConstraint:[NSLayoutConstraint
|
|
|
+ constraintWithItem: spinner
|
|
|
+ attribute:NSLayoutAttributeCenterY
|
|
|
+ relatedBy:NSLayoutRelationEqual
|
|
|
+ toItem:customVC.view
|
|
|
+ attribute:NSLayoutAttributeCenterY
|
|
|
+ multiplier:1.0f
|
|
|
+ constant:0.0f]];
|
|
|
+
|
|
|
+
|
|
|
+ [alertController setValue:customVC forKey:@"contentViewController"];
|
|
|
+ _progressDialog = alertController;
|
|
|
+ }
|
|
|
+ return _progressDialog;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showProgressDialog {
|
|
|
+ [self presentViewController:self.progressDialog animated:true completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)dismissProgressDialog {
|
|
|
+ [self.progressDialog dismissViewControllerAnimated:YES completion:nil];
|
|
|
+}
|
|
|
+
|
|
|
#pragma mark - Load Data
|
|
|
|
|
|
- (NSMutableArray *)shipArray {
|
|
|
@@ -215,8 +272,16 @@ typedef enum {
|
|
|
- (void)reloadContent {
|
|
|
NSLog(@"Home Person Mode Change");
|
|
|
|
|
|
- [self loadData];
|
|
|
- [self loadKPIData];
|
|
|
+ self.recentRefresh = YES;
|
|
|
+ self.kpiRefresh = YES;
|
|
|
+ if (((UITabBarController *)self.parentViewController).selectedIndex == 0) {
|
|
|
+ if (self.mode == HomeModeRecent) {
|
|
|
+ [self loadData];
|
|
|
+ } else {
|
|
|
+ [self loadKPIData];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- (void)loadData {
|
|
|
@@ -232,6 +297,8 @@ typedef enum {
|
|
|
|
|
|
[self.ShipLoading startAnimating];
|
|
|
|
|
|
+ [self showProgressDialog];
|
|
|
+
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
|
|
|
@@ -248,6 +315,8 @@ typedef enum {
|
|
|
|
|
|
[self.ShipLoading stopAnimating];
|
|
|
|
|
|
+ [weakSelf dismissProgressDialog];
|
|
|
+
|
|
|
int result = [[json objectForKey:@"result"] intValue];
|
|
|
if (result == RESULT_TRUE) {
|
|
|
|
|
|
@@ -264,6 +333,7 @@ typedef enum {
|
|
|
if (self.shipArray.count) {
|
|
|
[self.shipTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
|
|
|
}
|
|
|
+ weakSelf.recentRefresh = NO;
|
|
|
});
|
|
|
|
|
|
});
|
|
|
@@ -276,6 +346,7 @@ typedef enum {
|
|
|
}
|
|
|
|
|
|
[self.KPILoading startAnimating];
|
|
|
+ [self showProgressDialog];
|
|
|
|
|
|
__weak typeof(self) weakSelf = self;
|
|
|
dispatch_async(dispatch_get_global_queue(0, 0), ^{
|
|
|
@@ -284,18 +355,20 @@ typedef enum {
|
|
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
|
|
- if (self.KPIRefresh.isRefreshing) {
|
|
|
- [self.KPIRefresh endRefreshing];
|
|
|
+ if (weakSelf.KPIRefresh.isRefreshing) {
|
|
|
+ [weakSelf.KPIRefresh endRefreshing];
|
|
|
}
|
|
|
|
|
|
- [self.KPILoading stopAnimating];
|
|
|
+ [weakSelf.KPILoading stopAnimating];
|
|
|
+
|
|
|
+ [weakSelf dismissProgressDialog];
|
|
|
|
|
|
int result = [[json objectForKey:@"result"] intValue];
|
|
|
if (result == RESULT_TRUE) {
|
|
|
- self.currentKPI = 1;
|
|
|
- self.monthArray = [json objectForKey:@"month"];
|
|
|
+// self.currentKPI = 1;
|
|
|
+ weakSelf.monthArray = [json objectForKey:@"month"];
|
|
|
|
|
|
- [self.KPIArray removeAllObjects];
|
|
|
+ [weakSelf.KPIArray removeAllObjects];
|
|
|
NSArray *kpiArr = [json objectForKey:@"KPI"];
|
|
|
|
|
|
// [self.KPIArray addObject:[[kpiArr firstObject] mutableCopy]];
|
|
|
@@ -310,22 +383,24 @@ typedef enum {
|
|
|
[kpiModel setObject:itemMutArr forKey:@"arr_val"];
|
|
|
|
|
|
// [self.KPIArray addObjectsFromArray:kpiArr];
|
|
|
- [self.KPIArray addObject:kpiModel];
|
|
|
+ [weakSelf.KPIArray addObject:kpiModel];
|
|
|
}
|
|
|
// [self.KPIArray addObject:[[kpiArr lastObject] mutableCopy]];
|
|
|
|
|
|
|
|
|
- [self.KPITableView reloadData];
|
|
|
+ [weakSelf.KPITableView reloadData];
|
|
|
|
|
|
- NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
|
|
|
- self.parentViewController.title = str;
|
|
|
+ if (((UITabBarController *)weakSelf.parentViewController).selectedIndex == 0) {
|
|
|
+ NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
|
|
|
+ weakSelf.parentViewController.title = str;
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
NSString *msg = [json objectForKey:@"err_msg"];
|
|
|
[RAUtils message_alert:msg title:@"Warning" controller:weakSelf];
|
|
|
}
|
|
|
- self.KPINoDataBtn.hidden = self.KPIArray.count > 0;
|
|
|
-
|
|
|
+ weakSelf.KPINoDataBtn.hidden = self.KPIArray.count > 0;
|
|
|
+ weakSelf.kpiRefresh = NO;
|
|
|
});
|
|
|
|
|
|
});
|
|
|
@@ -358,7 +433,7 @@ typedef enum {
|
|
|
self.ShipContainer.hidden = YES;
|
|
|
self.KPIContainer.hidden = NO;
|
|
|
|
|
|
- if (self.KPIArray.count == 0) {
|
|
|
+ if (self.KPIArray.count == 0 || self.kpiRefresh) {
|
|
|
[self loadKPIData];
|
|
|
} else {
|
|
|
NSString *str = [NSString stringWithFormat:@"%ld / %ld",self.currentKPI,self.KPIArray.count];
|
|
|
@@ -371,7 +446,7 @@ typedef enum {
|
|
|
self.KPIContainer.hidden = YES;
|
|
|
self.ShipContainer.hidden = NO;
|
|
|
self.parentViewController.title = nil;
|
|
|
- if (self.shipArray.count == 0) {
|
|
|
+ if (self.shipArray.count == 0 || self.recentRefresh) {
|
|
|
[self loadData];
|
|
|
}
|
|
|
}
|
|
|
@@ -400,7 +475,7 @@ typedef enum {
|
|
|
|
|
|
|
|
|
[self postPersonModeChangeNotification];
|
|
|
- [RAUtils alert_view:msg title:@"Personal Mode"];
|
|
|
+// [RAUtils alert_view:msg title:@"Personal Mode"];
|
|
|
}
|
|
|
|
|
|
- (IBAction)ShipNoDataBtnClick:(UIButton *)sender {
|