Ver código fonte

1.修改iOS Apex Mobile Home和History数据加载指示器以及Person Mode改变引起的刷新。

Pen Li 8 anos atrás
pai
commit
6ea64054a8

+ 100 - 25
Apex Mobile/Apex Mobile/HomeViewController.m

@@ -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 {

+ 67 - 4
Apex Mobile/Apex Mobile/OrderHistoryViewController.m

@@ -28,6 +28,9 @@ static const int history_delta = 7;
 @property (strong, nonatomic) IBOutlet UIActivityIndicatorView *loadIndicator;
 @property (strong, nonatomic) IBOutlet UIButton *emptyBtn;
 
+@property (nonatomic,strong) UIAlertController *progressDialog;
+@property (nonatomic,assign) BOOL historyRefresh;
+
 @end
 
 @implementation OrderHistoryViewController
@@ -47,6 +50,7 @@ static const int history_delta = 7;
     self.emptyBtn.layer.cornerRadius = 10.0f;
     self.emptyBtn.layer.masksToBounds = YES;
     self.emptyBtn.hidden = YES;
+    self.historyRefresh = NO;
     
     [self registNotification];
     [self.loadIndicator stopAnimating];
@@ -67,7 +71,7 @@ static const int history_delta = 7;
     [self clearNavigationbar];
     [self configureNavigationBar];
     
-    if (self.shipArray.count == 0) {
+    if (self.shipArray.count == 0 || self.historyRefresh) {
         [self loadData];
     }
 }
@@ -135,6 +139,57 @@ static const int history_delta = 7;
     [[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 {
@@ -147,7 +202,10 @@ static const int history_delta = 7;
 - (void)reloadContent {
     NSLog(@"History Person Mode Change");
     
-    [self loadData];
+    self.historyRefresh = YES;
+    if (((UITabBarController *)self.parentViewController).selectedIndex == 1) {
+        [self loadData];
+    }
 }
 
 - (void)loadData {
@@ -181,6 +239,8 @@ static const int history_delta = 7;
     
     [self.loadIndicator startAnimating];
     
+    [self showProgressDialog];
+    
     NSMutableDictionary *params = [@{
                                     @"offset" : @(offset),
                                     @"limit"  : @(history_delta)
@@ -197,6 +257,9 @@ static const int history_delta = 7;
         dispatch_async(dispatch_get_main_queue(), ^{
             
             [weakSelf.loadIndicator stopAnimating];
+            
+            [weakSelf dismissProgressDialog];
+            
             int result = [[json objectForKey:@"result"] intValue];
             
             result = 2;
@@ -226,7 +289,7 @@ static const int history_delta = 7;
             if (finish) {
                 finish(result,count);
             }
-            
+            weakSelf.historyRefresh = NO;
         });
         
     });
@@ -259,7 +322,7 @@ static const int history_delta = 7;
     }
     
     [self postPersonModeChangeNotification];
-    [RAUtils alert_view:msg title:@"Personal Mode"];
+//    [RAUtils alert_view:msg title:@"Personal Mode"];
 }
 
 #pragma mark - TableView DataSource && Delegate