RAHomeViewController.m 23 KB

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