RAOrderDetailViewController+TableViewDataSource.m 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // RAOrderDetailViewController+TableViewDataSource.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/2.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAOrderDetailViewController+TableViewDataSource.h"
  9. #import "RADetailBaseModel.h"
  10. #import "RADetailSingleLineModel.h"
  11. #import "RADetailMultLineModel.h"
  12. #import "RADetailLocationModel.h"
  13. #import "RADetailActionCollectionModel.h"
  14. #import "RADetailActionModel.h"
  15. #import "RADetailSingleLineCell.h"
  16. #import "RADetailMultLineCell.h"
  17. #import "RADetailActionSubCell.h"
  18. #import <MapKit/MapKit.h>
  19. #import "RADetailActionSelectionModel.h"
  20. #import "RAOrderEditViewController.h"
  21. @implementation RAOrderDetailViewController (TableViewDataSource)
  22. - (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
  23. RADetailBaseModel *model = [self modelForIndexPath:indexPath];
  24. RAOrderDetailValueType type = model.type;
  25. switch (type) {
  26. case RAOrderDetailValueTypeSingleLine: {
  27. RADetailSingleLineModel *singleModel = (RADetailSingleLineModel *)model;
  28. RADetailSingleLineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RADetailSingleLineCell" forIndexPath:indexPath];
  29. [cell setModel:singleModel];
  30. return cell;
  31. }
  32. break;
  33. case RAOrderDetailValueTypeMultipleLine: {
  34. RADetailMultLineModel *multModel = (RADetailMultLineModel *)model;
  35. RADetailMultLineCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RADetailMultLineCell" forIndexPath:indexPath];
  36. [cell setModel:multModel];
  37. return cell;
  38. }
  39. break;
  40. case RAOrderDetailValueTypeAction: {
  41. RADetailActionCollectionModel *actionModel = (RADetailActionCollectionModel *)model;
  42. RADetailActionsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RADetailActionsCell" forIndexPath:indexPath];
  43. cell.actionLayout.delegate = actionModel;
  44. [cell setModel:actionModel];
  45. cell.delegate = self;
  46. return cell;
  47. }
  48. break;
  49. case RAOrderDetailValueTypeLocation: {
  50. RADetailLocationModel *locationModel = (RADetailLocationModel *)model;
  51. RADetailLocationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RADetailLocationCell" forIndexPath:indexPath];
  52. [cell setModel:locationModel];
  53. cell.delegate = self;
  54. return cell;
  55. }
  56. break;
  57. default:
  58. break;
  59. }
  60. UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"detaulCell"];
  61. return cell;
  62. }
  63. - (NSInteger)tableView:(nonnull UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  64. return [self numberOfItemForSection:section];
  65. }
  66. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  67. return [self sectionNumber];
  68. }
  69. #pragma mark - Location Delegate
  70. - (void)locationCell:(RADetailLocationCell *)cell didClickNavigation:(RADetailLocationModel *)model {
  71. UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
  72. // __weak typeof(self) weakSelf = self;
  73. if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]) {
  74. UIAlertAction *googleMapAction = [UIAlertAction actionWithTitle:@"Google Map" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  75. NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?center=37.782652,-122.410126&directionsmode=driving"]
  76. stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
  77. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString] options:@{} completionHandler:^(BOOL success) {
  78. NSLog(@"%u",success);
  79. }];
  80. // NSString *urlString = [[NSString stringWithFormat:@"comgooglemaps://?center=37.782652,-122.410126&directionsmode=driving"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  81. // [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]];
  82. }];
  83. [alertVC addAction:googleMapAction];
  84. }
  85. UIAlertAction *appleMapAction = [UIAlertAction actionWithTitle:@"Apple Map" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  86. MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
  87. MKMapItem *toLocation = [[MKMapItem alloc] initWithPlacemark:[[MKPlacemark alloc] initWithCoordinate:CLLocationCoordinate2DMake(37.782652, -122.410126) addressDictionary:nil]];
  88. [MKMapItem openMapsWithItems:@[currentLocation, toLocation] launchOptions:@{
  89. MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeDriving,
  90. MKLaunchOptionsShowsTrafficKey: @(YES)
  91. }];
  92. }];
  93. [alertVC addAction:appleMapAction];
  94. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
  95. }];
  96. [alertVC addAction:cancelAction];
  97. [self presentViewController:alertVC animated:YES completion:nil];
  98. }
  99. #pragma mark - Action Delegate
  100. - (void)actionsCell:(RADetailActionsCell *)cell didClickSubCell:(RADetailActionSubCell *)subCell forModel:(RADetailActionModel *)model {
  101. switch (model.actionType) {
  102. case RADetailActionTypeRemote: {
  103. }
  104. break;
  105. case RADetailActionTypeLocal: {
  106. switch (model.actionSubType) {
  107. case RADetailActionSubTypeEnum: {
  108. [self handleEnumAction:model forCell:subCell];
  109. }
  110. break;
  111. default:
  112. break;
  113. }
  114. }
  115. break;
  116. default:
  117. break;
  118. }
  119. }
  120. #pragma mark - Action
  121. - (void)handleEnumAction:(RADetailActionModel *)model forCell:(RADetailActionSubCell *)subCell {
  122. RADetailActionSelectionViewController *vc = [RADetailActionSelectionViewController viewControllerFromStoryboard];
  123. vc.actions = model.enums;
  124. vc.delegate = self;
  125. vc.modalPresentationStyle = UIModalPresentationPopover;
  126. vc.preferredContentSize = CGSizeMake(250, 300);
  127. vc.popoverPresentationController.sourceView = subCell;
  128. vc.popoverPresentationController.sourceRect = subCell.bounds;
  129. vc.popoverPresentationController.delegate = self;
  130. [self presentViewController:vc animated:YES completion:nil];
  131. }
  132. #pragma mark - Popover Delegate
  133. -(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
  134. return UIModalPresentationNone;//不适配
  135. }
  136. #pragma mark - ActionSelection Delegate
  137. - (void)detailSelectAction:(RADetailActionSelectionModel *)model {
  138. RAOrderEditViewController *vc = [RAOrderEditViewController viewControllerFromStoryboard];
  139. // RAOrderEditViewController *vc = [[RAOrderEditViewController alloc] init]; // 使用代码直接创建,在Push动画过程中会卡一下,具体原因不明
  140. vc.title = model.detailActionTitle;
  141. vc.orderID = self.orderID;
  142. vc.actionID = model.actionID;
  143. [self.navigationController pushViewController:vc animated:YES];
  144. }
  145. @end