RAHomeViewController.m 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. //
  2. // RAHomeViewController.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/1.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAHomeViewController.h"
  9. #import "RAOrderDetailViewController.h"
  10. #import "RAProgressHUD.h"
  11. #import "ApexDriverUploadListVC.h"
  12. #import "RAHomeMoreViewController.h"
  13. #import <UserNotifications/UserNotifications.h>
  14. #import "UIScrollView+Empty.h"
  15. #import "RAEmptyView.h"
  16. #import "RAHomeHeaderView.h"
  17. #import "RAMessageViewController.h"
  18. #import "RASettingViewController.h"
  19. #import <CoreLocation/CoreLocation.h>
  20. //#import "RABadgeButton.h"
  21. @implementation RAHomeSectionModel
  22. - (instancetype)init {
  23. if (self = [super init]) {
  24. }
  25. return self;
  26. }
  27. - (void)setOrders:(NSArray *)orders {
  28. NSMutableArray *orderArr = [NSMutableArray array];
  29. for (int i = 0; i < orders.count; i++) {
  30. NSDictionary *order = [orders objectAtIndex:i];
  31. RAHomeOrderModel *orderModel = [RAHomeOrderModel new];
  32. [orderModel setValuesForKeysWithDictionary:order];
  33. [orderArr addObject:orderModel];
  34. }
  35. _orders = orderArr;
  36. }
  37. - (void)setBackendFlagCount:(NSInteger)backendFlagCount {
  38. _backendFlagCount = backendFlagCount;
  39. if (self.delegate && [self.delegate respondsToSelector:@selector(refreshUI)]) {
  40. [self.delegate refreshUI];
  41. }
  42. }
  43. - (RAHomeOrderModel *)orderModelForIndex:(NSInteger)index {
  44. return [self.orders objectAtIndex:index];
  45. }
  46. - (NSInteger)ordersCount {
  47. return self.orders.count;
  48. }
  49. - (NSInteger)orderModelIndexForID:(NSString *)orderID {
  50. __block NSInteger curIndex = -1;;
  51. [self.orders enumerateObjectsUsingBlock:^(RAHomeOrderModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  52. if ([obj.orderID isEqualToString:orderID]) {
  53. curIndex = idx;
  54. return ;
  55. }
  56. }];
  57. return curIndex;
  58. }
  59. - (BOOL)hasMoreOrder {
  60. return self.totalCount > self.ordersCount;
  61. }
  62. - (RAHomeOrderModel *)modelForOrder:(NSString *)orderId {
  63. if (!orderId) {
  64. return nil;
  65. }
  66. __block RAHomeOrderModel *model = nil;
  67. [self.orders enumerateObjectsUsingBlock:^(RAHomeOrderModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  68. if ([obj.orderID isEqualToString:orderId]) {
  69. model = obj;
  70. }
  71. }];
  72. return model;
  73. }
  74. @end
  75. #pragma mark - View Controller
  76. @interface RAHomeViewController () <RAHomeHeaderDelegate>
  77. @property (nonatomic,strong) NSMutableArray <RAHomeSectionModel *> *sectionArray;
  78. @property (nonatomic,strong) NSIndexPath *currentIndexPath;
  79. @property (nonatomic,strong) UIRefreshControl *refreshControl;
  80. @property (nonatomic,assign) NSUInteger messageCount;///<未读消息数量
  81. @end
  82. @implementation RAHomeViewController
  83. + (instancetype)viewControllerFromStoryboard {
  84. RAHomeViewController *homeVC = [[UIStoryboard storyboardWithName:@"Home" bundle:nil] instantiateViewControllerWithIdentifier:[self storyboardID]];
  85. return homeVC;
  86. }
  87. - (void)viewDidLoad {
  88. [super viewDidLoad];
  89. // Do any additional setup after loading the view.
  90. self.label_cache.text = NSLocalizedString(@"cache content", nil);
  91. [self.label_cache sizeToFit];
  92. self.label_cache.layer.borderColor=ApexDriverGrayColor.CGColor;
  93. self.label_cache.layer.borderWidth = 1.0f;
  94. self.label_cache.layer.cornerRadius = 5.0f;
  95. self.label_cache.layer.masksToBounds = YES;
  96. [self checkPermission];
  97. [self configureNavigationBar];
  98. [self configureTable];
  99. [self registNotification];
  100. [self loadData];
  101. }
  102. - (void)viewWillAppear:(BOOL)animated {
  103. [super viewWillAppear:animated];
  104. }
  105. - (void)viewDidAppear:(BOOL)animated {
  106. [super viewDidAppear:animated];
  107. if (self.reloadFlag) {
  108. [self loadData];
  109. self.reloadFlag = !self.reloadFlag;
  110. }
  111. }
  112. - (void)dealloc {
  113. [[NSNotificationCenter defaultCenter] removeObserver:self];
  114. }
  115. - (void)didReceiveMemoryWarning {
  116. [super didReceiveMemoryWarning];
  117. // Dispose of any resources that can be recreated.
  118. }
  119. #pragma mark - Configure
  120. - (void)configureTable {
  121. if (@available(iOS 11, *)) {
  122. self.homeOrderTableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  123. } else {
  124. self.automaticallyAdjustsScrollViewInsets = NO;
  125. }
  126. self.homeOrderTableView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  127. self.homeOrderTableView.tableFooterView = [UIView new];
  128. self.homeOrderTableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
  129. UIRefreshControl *refresh = [[UIRefreshControl alloc] init];
  130. [refresh addTarget:self action:@selector(refreshControlValueChanged:) forControlEvents:UIControlEventValueChanged];
  131. [self.homeOrderTableView addSubview:refresh];
  132. self.refreshControl = refresh;
  133. // empty
  134. __weak typeof(self) weakSelf = self;
  135. self.homeOrderTableView.emptyView = [RAEmptyView emptyViewWithTapBlk:^(id sender) {
  136. [weakSelf loadData];
  137. }];
  138. // Header
  139. self.headerView = [RAHomeHeaderView homeHeader];
  140. self.headerView.delegate = self;
  141. self.homeOrderTableView.tableHeaderView = self.headerView;
  142. }
  143. - (void)configureNavigationBar {
  144. UIImage *logo = [[UIImage imageNamed:@"apex_logo"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  145. // UIImage *logo = [[UIImage imageNamed:@"apexlogo-2"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
  146. UIBarButtonItem *logoItem = [[UIBarButtonItem alloc] initWithImage:logo landscapeImagePhone:logo style:UIBarButtonItemStylePlain target:nil action:nil];
  147. // logoItem.enabled = NO;
  148. self.navigationItem.leftBarButtonItem = logoItem;
  149. UIBarButtonItem *uploadListItem = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"upload_list"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  150. style:UIBarButtonItemStylePlain
  151. target:self
  152. action:@selector(uploadListItemClick:)];
  153. self.navigationItem.rightBarButtonItems = @[uploadListItem];
  154. [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationRequestUploadCount object:nil];
  155. self.title = [NSString stringWithFormat:@"%@ %@",RASingleton.sharedInstance.user,RASingleton.sharedInstance.firstName];
  156. }
  157. - (void)registNotification {
  158. // [RASingleton.sharedInstance writeLog:[NSString stringWithFormat:@"%s",__func__]];
  159. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNewOrderNotification:) name:RANotificationHandleOrder object:nil];
  160. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveReloadNotification:) name:RANotificationReloadHome object:nil];
  161. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveCheckDetailNofitication:) name:RANotificationCheckDetail object:nil];
  162. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveUploadFinishNotification:) name:RANotificationChangeUpload object:nil];
  163. }
  164. - (void)checkPermission {
  165. CLAuthorizationStatus locationAuthoriztionAstatus = [CLLocationManager authorizationStatus];
  166. [[UNUserNotificationCenter currentNotificationCenter] getNotificationSettingsWithCompletionHandler:^(UNNotificationSettings * _Nonnull settings) {
  167. UNAuthorizationStatus notificationAuthorizationStatus = settings.authorizationStatus;
  168. BOOL enableLocation = locationAuthoriztionAstatus != kCLAuthorizationStatusRestricted && locationAuthoriztionAstatus != kCLAuthorizationStatusDenied;
  169. BOOL enableRemoteNotification = notificationAuthorizationStatus != UNAuthorizationStatusDenied;
  170. if (!enableLocation | !enableRemoteNotification) {
  171. NSMutableString *msg = [NSMutableString stringWithString:NSLocalizedString(@"you should open", nil)];
  172. if (!enableLocation) {
  173. [msg appendString:NSLocalizedString(@" location permissions", nil)];
  174. }
  175. if (!enableRemoteNotification) {
  176. if (!enableLocation) {
  177. [msg appendString:NSLocalizedString(@" and notification permissions", nil)];
  178. } else {
  179. [msg appendString:NSLocalizedString(@" notification permissions", nil)];
  180. }
  181. }
  182. dispatch_async(dispatch_get_main_queue(), ^{
  183. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
  184. UIAlertAction *okAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  185. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  186. if ([[UIApplication sharedApplication] canOpenURL:url]) {
  187. [[UIApplication sharedApplication] openURL:url];
  188. }
  189. }];
  190. [alertVC addAction:okAction];
  191. [self presentViewController:alertVC animated:YES completion:nil];
  192. });
  193. }
  194. }];
  195. }
  196. #pragma mark - Private
  197. - (void)_checkOrder:(NSString *)orderId {
  198. if (orderId) {
  199. for (RAHomeSectionModel *section in self.sectionArray) {
  200. RAHomeOrderModel *model = [section modelForOrder:orderId];
  201. dispatch_async(dispatch_get_main_queue(), ^{
  202. if (model && model.backendFlag) {
  203. if (section.backendFlagCount > 0) {
  204. section.backendFlagCount = section.backendFlagCount - 1;
  205. }
  206. model.backendFlag = NO;
  207. self.messageCount = self.messageCount - 1;
  208. }
  209. });
  210. }
  211. }
  212. }
  213. - (void)_updateUploadItem:(UIBarButtonItem *)item withUploadCount:(NSUInteger)count {
  214. item.tintColor = ApexDriverWhiteColor;
  215. // if (item) {
  216. //
  217. // if (count > 0) {
  218. // item.tintColor = UIColorFromRGB(0x299D4D);
  219. // } else {
  220. // item.tintColor = ApexDriverWhiteColor;
  221. // }
  222. // }
  223. }
  224. #pragma mark - Action
  225. - (void)uploadListItemClick:(UIBarButtonItem *)sender {
  226. ApexDriverUploadListVC *vc = [ApexDriverUploadListVC viewControllerFromStoryboard];
  227. [self.navigationController pushViewController:vc animated:YES];
  228. }
  229. - (void)logoutItemClick:(UIBarButtonItem *)sender {
  230. // show progress
  231. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  232. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  233. [RADataProvider logout];
  234. dispatch_async(dispatch_get_main_queue(), ^{
  235. // dismiss progress
  236. [hud dismiss];
  237. [RASingleton.sharedInstance logout];
  238. [[NSNotificationCenter defaultCenter] postNotificationName:RANotificationLogout object:nil];
  239. });
  240. });
  241. }
  242. - (void)refreshControlValueChanged:(UIRefreshControl *)refresh {
  243. self.currentIndexPath = nil;
  244. [self loadData];
  245. }
  246. #pragma mark - Setter
  247. - (void)setHeaderView:(RAHomeHeaderView *)headerView {
  248. _headerView = headerView;
  249. }
  250. - (void)setMessageCount:(NSUInteger)messageCount {
  251. _messageCount = messageCount;
  252. dispatch_async(dispatch_get_main_queue(), ^{
  253. self.headerView.existNewMessage = messageCount > 0;
  254. });
  255. }
  256. #pragma mark - Getter
  257. - (NSMutableArray *)sectionArray {
  258. if (!_sectionArray) {
  259. _sectionArray = [NSMutableArray array];
  260. }
  261. return _sectionArray;
  262. }
  263. - (RAHomeSectionModel *)modelForSection:(NSInteger)section {
  264. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  265. return sectionModel;
  266. }
  267. - (NSUInteger)orderSectionCount {
  268. return self.sectionArray.count;
  269. }
  270. - (NSUInteger)orderCountForSection:(NSInteger)section {
  271. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  272. return [sectionModel ordersCount];
  273. }
  274. - (RAHomeOrderModel *)orderModelForIndexPath:(NSIndexPath *)indexPath {
  275. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:indexPath.section];
  276. return [sectionModel orderModelForIndex:indexPath.row];
  277. }
  278. - (NSString *)titleForSection:(NSInteger)section {
  279. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  280. return sectionModel.title;
  281. }
  282. - (BOOL)hasMoreOrderForSection:(NSInteger)section {
  283. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  284. return [sectionModel hasMoreOrder];
  285. }
  286. - (NSInteger)backendCountForSection:(NSInteger)section {
  287. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  288. return sectionModel.backendFlagCount;
  289. }
  290. #pragma mark - Set/Update
  291. - (void)setBackendFlagCount:(NSInteger)count forSection:(NSInteger)section {
  292. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  293. sectionModel.backendFlagCount = count;
  294. }
  295. - (void)decreaseBackendFlagCountForSection:(NSInteger)section {
  296. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  297. NSInteger count = sectionModel.backendFlagCount;
  298. sectionModel.backendFlagCount = --count;
  299. }
  300. - (void)setHeaderDelegate:(id<RAHomeSectionModelDelegate>)delegate forSection:(NSInteger)section {
  301. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  302. sectionModel.delegate = delegate;
  303. }
  304. #pragma mark - Data
  305. - (void)loadData {
  306. self.label_cache.hidden=true;
  307. if (self.loading) {
  308. return;
  309. }
  310. self.loading = YES;
  311. [self.homeOrderTableView hideEmpty];
  312. // show progress
  313. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  314. __weak typeof(self) weakSelf = self;
  315. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  316. NSDictionary *json = [RADataProvider requestOrderList];
  317. dispatch_async(dispatch_get_main_queue(), ^{
  318. // dismiss progress
  319. [hud dismiss];
  320. if (weakSelf.refreshControl.isRefreshing) {
  321. [weakSelf.refreshControl endRefreshing];
  322. }
  323. if (weakSelf) {
  324. __strong typeof(weakSelf) strongSelf = weakSelf;
  325. // header
  326. BOOL driverAvailable = [[json objectForKey:@"driver_available"] boolValue];
  327. strongSelf.headerView.availabel = driverAvailable;
  328. NSInteger newCount = [[json objectForKey:@"new_count"] integerValue];
  329. NSInteger processingCount = [[json objectForKey:@"processing_count"] integerValue];
  330. NSInteger finishCount = [[json objectForKey:@"finish_count"] integerValue];
  331. NSInteger messageCount = [[json objectForKey:@"message_count"] integerValue];
  332. strongSelf.headerView.NewOrderCount = newCount;
  333. strongSelf.headerView.ProcessingOrderCount = processingCount;
  334. strongSelf.headerView.FinishOrderCount = finishCount;
  335. strongSelf.messageCount = messageCount;
  336. int result = [[json objectForKey:@"result"] intValue];
  337. if (result == RESULT_TRUE) {
  338. BOOL requiredLocation = [[json objectForKey:@"requiredLocation"] boolValue];
  339. [RASingleton sharedInstance].requiredBackgroundLocation = requiredLocation;
  340. NSArray *sectionArray = [json objectForKey:@"sections"];
  341. NSMutableArray *tmpSectionArr = [NSMutableArray array];
  342. strongSelf.currentIndexPath = nil;
  343. for (int i = 0; i < sectionArray.count; i++) {
  344. NSDictionary *section = [sectionArray objectAtIndex:i];
  345. RAHomeSectionModel *sectionModel = [RAHomeSectionModel new];
  346. sectionModel.section = i;
  347. [sectionModel setValuesForKeysWithDictionary:section];
  348. [tmpSectionArr addObject:sectionModel];
  349. if (strongSelf.currentOrderID.length > 0) {
  350. NSInteger idx = [sectionModel orderModelIndexForID:self.currentOrderID];
  351. if (idx > -1) {
  352. strongSelf.currentIndexPath = [NSIndexPath indexPathForRow:idx inSection:i];
  353. }
  354. }
  355. }
  356. strongSelf.sectionArray = tmpSectionArr;
  357. [strongSelf.homeOrderTableView reloadData];
  358. if (strongSelf.currentIndexPath) {
  359. // [strongSelf.homeOrderTableView scrollToRowAtIndexPath:self.currentIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:NO];
  360. [strongSelf.homeOrderTableView selectRowAtIndexPath:strongSelf.currentIndexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
  361. } else {
  362. }
  363. if([json[@"iscache"] boolValue]==true)
  364. {
  365. self.label_cache.hidden=false;
  366. }
  367. } else {
  368. [strongSelf.sectionArray removeAllObjects];
  369. strongSelf.homeOrderTableView.contentOffset = CGPointZero;
  370. [strongSelf.homeOrderTableView reloadData];
  371. // process error
  372. NSString *msg = [json objectForKey:@"err_msg"];
  373. // [strongSelf showAlert:msg];
  374. [strongSelf showAlertTilte:NSLocalizedString(@"Warning", nil) message:msg];
  375. }
  376. }
  377. weakSelf.loading = NO;
  378. if (weakSelf.orderSectionCount == 0) {
  379. [weakSelf.homeOrderTableView showEmpty];
  380. } else {
  381. [weakSelf.homeOrderTableView hideEmpty];
  382. }
  383. });
  384. });
  385. }
  386. - (void)updateDriverAvailable:(BOOL)available {
  387. // show progress
  388. RAProgressHUD *hud = [RAProgressHUD showHUDOnView:self.view];
  389. __weak typeof(self) weakSelf = self;
  390. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  391. NSDictionary *json = [RADataProvider updateDriverAvailable:available];
  392. dispatch_async(dispatch_get_main_queue(), ^{
  393. [hud dismiss];
  394. int result = [[json objectForKey:@"result"] intValue];
  395. if (result == RESULT_TRUE) {
  396. weakSelf.headerView.availabel = available;
  397. } else {
  398. NSString *msg = [json objectForKey:@"err_msg"];
  399. [weakSelf showAlertTilte:NSLocalizedString(@"Warning", nil) message:msg];
  400. }
  401. });
  402. });
  403. }
  404. #pragma mark - Controller Action
  405. - (void)pushDetailViewControllerForModel:(RAHomeOrderModel *)model {
  406. [self pushDetailViewControllerForOrderID:model.orderID type:model.status type2:model.order_type2 statusNo:model.status_no];
  407. }
  408. - (void)pushDetailViewControllerForOrderID:(NSString *)orderID type:(NSInteger)type type2:(NSString *)type2 statusNo:(NSString *)statusNo {
  409. if (!orderID) {
  410. return;
  411. }
  412. RAOrderDetailViewController *detailVC = [RAOrderDetailViewController viewControllerFromStoryboard];
  413. detailVC.orderID = orderID;
  414. detailVC.orderType = type;
  415. detailVC.orderType2 = type2;
  416. detailVC.status_no = statusNo;
  417. [self.navigationController pushViewController:detailVC animated:YES];
  418. }
  419. - (void)showMoreControllerWithTitle:(NSString *)title Type:(RAOrderStatus)type {
  420. RAHomeMoreViewController *homeMoreVC = [RAHomeMoreViewController viewControllerFromStoryboard];
  421. homeMoreVC.title = title;
  422. homeMoreVC.type = type;
  423. __weak typeof(self) weakSelf = self;
  424. homeMoreVC.backendFlagOrderClickBlk = ^{
  425. weakSelf.reloadFlag = YES;
  426. };
  427. [self.navigationController pushViewController:homeMoreVC animated:YES];
  428. }
  429. - (void)showMoreOrderForSection:(NSInteger)section {
  430. RAHomeSectionModel *sectionModel = [self.sectionArray objectAtIndex:section];
  431. [self showMoreControllerWithTitle:sectionModel.title Type:sectionModel.type];
  432. }
  433. #pragma mark - Nofitication Selector
  434. - (void)receiveNewOrderNotification:(NSNotification *)notification {
  435. [self loadData];
  436. }
  437. - (void)receiveReloadNotification:(NSNotification *)notification {
  438. [self loadData];
  439. }
  440. - (void)receiveCheckDetailNofitication:(NSNotification *)notification {
  441. NSDictionary *userInfo = [notification userInfo];
  442. if (userInfo) {
  443. NSString *orderId = [userInfo objectForKey:@"order_id"];
  444. if (orderId) {
  445. [self _checkOrder:orderId];
  446. }
  447. }
  448. }
  449. - (void)receiveUploadFinishNotification:(NSNotification *)notification {
  450. NSUInteger count = [notification.userInfo[@"upload_count"] integerValue];
  451. UIBarButtonItem *item = self.navigationItem.rightBarButtonItem;
  452. [self _updateUploadItem:item withUploadCount:count];
  453. }
  454. #pragma mark - Header Delegate
  455. - (void)signoutClick:(UIButton *)sender {
  456. [self logoutItemClick:nil];
  457. }
  458. - (void)settingClick:(UIButton *)sender {
  459. dispatch_async(dispatch_get_main_queue(), ^{
  460. RASettingViewController *settingVC = [RASettingViewController viewControllerFromStoryboard];
  461. [self.navigationController pushViewController:settingVC animated:YES];
  462. });
  463. }
  464. - (void)availableClick:(UIButton *)sender {
  465. NSString *msg = [NSString localizedStringWithFormat:NSLocalizedString(@"are you sure to change status to %@", nil),self.headerView.availabel ? NSLocalizedString(@"Unavailable", nil) : NSLocalizedString(@"Available", nil)];
  466. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Warning", nil) message:msg preferredStyle:UIAlertControllerStyleAlert];
  467. UIAlertAction *yesAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"YES", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  468. [self updateDriverAvailable:!self.headerView.availabel];
  469. }];
  470. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  471. }];
  472. [alertVC addAction:cancelAction];
  473. [alertVC addAction:yesAction];
  474. [self presentViewController:alertVC animated:YES completion:nil];
  475. }
  476. - (void)messageClick:(UIButton *)sender {
  477. RAMessageViewController *messageVC = [RAMessageViewController viewControllerFromStoryboard];
  478. [self.navigationController pushViewController:messageVC animated:YES];
  479. }
  480. - (void)newOrderClick:(id)sender {
  481. [self showMoreControllerWithTitle:NSLocalizedString(@"New Order", nil) Type:RAOrderStatusNew];
  482. }
  483. - (void)processingOrderClick:(id)sender {
  484. [self showMoreControllerWithTitle:NSLocalizedString(@"Processing Order", nil) Type:RAOrderStatusProcessing];
  485. }
  486. - (void)finishedOrderClick:(id)sender {
  487. [self showMoreControllerWithTitle:NSLocalizedString(@"Finished Order", nil) Type:RAOrderStatusFinish];
  488. }
  489. @end