HJMeViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. //
  2. // HJMeViewController.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/3/13.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJMeViewController.h"
  9. #import "HJMeNavBarView.h"
  10. #import "HJRefreshHeaderView.h"
  11. #import "UIView+FBProgressHUD.h"
  12. #import "HJExpectationViewController.h"
  13. #import "HJBasicInfoViewController.h"
  14. #import "HJExperienceViewController.h"
  15. #import "HJResumeViewController.h"
  16. #import "HJAuthViewController.h"
  17. #import "HJAuthingViewController.h"
  18. #import "HJAuthFailedViewController.h"
  19. #import "HJMeDataBox.h"
  20. #import "HJGetUserInfoAPIManager.h"
  21. #import "HJApproveStatusAPIManager.h"
  22. #import "UIViewController+HJNavBar.h"
  23. #import "HJSettingViewController.h"
  24. #import "HJMyFavoriteViewController.h"
  25. #import "HJMyApplyViewController.h"
  26. #import "HJMyInterviewViewController.h"
  27. #import "HJGetResumeAPIManager.h"
  28. #import "HJSalaryViewController.h"
  29. #import "HJResumeDataBox.h"
  30. @interface HJMeViewController () <UITableViewDelegate, UIScrollViewDelegate, HJMeProfileViewDelegate, HJMeResumeViewDelegate, FBAPIManagerInterceptor, FBAPIManagerDelegate>
  31. @property (nonatomic, strong) HJMeNavBarView *navBarView;
  32. @property (nonatomic, strong) UITableView *tableView;
  33. @property (nonatomic, strong) HJRefreshHeaderView *refreshHeader;
  34. @property (nonatomic, strong) HJResumeDataBox *resumeDataBox;
  35. @property (nonatomic, strong) HJMeDataBox *dataBox;
  36. @property (nonatomic, strong) HJGetUserInfoAPIManager *getUserInfoAPIManager;
  37. @property (nonatomic, strong) HJApproveStatusAPIManager *approveStatusAPIManager;
  38. @property (nonatomic, strong) HJGetResumeAPIManager *getResumeAPIManager;
  39. @end
  40. @implementation HJMeViewController
  41. - (void)dealloc {
  42. [[NSNotificationCenter defaultCenter] removeObserver:self name:HJResumeUpdateNotification object:nil];
  43. }
  44. - (UIStatusBarStyle)preferredStatusBarStyle {
  45. return UIStatusBarStyleLightContent;
  46. }
  47. - (void)viewDidLoad {
  48. [super viewDidLoad];
  49. // 这里配置导航栏是为了在Push子视图时,backItem的标题不显示文字
  50. [self hj_setupNavBar];
  51. [self.view addSubview:self.navBarView];
  52. [self.view insertSubview:self.tableView belowSubview:self.navBarView];
  53. [self makeConstraints];
  54. [self.getUserInfoAPIManager start];
  55. [self.getResumeAPIManager start];
  56. //添加简历更新通知
  57. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateResume:) name:HJResumeUpdateNotification object:nil];
  58. }
  59. - (void)viewWillAppear:(BOOL)animated {
  60. [super viewWillAppear:animated];
  61. [self.navigationController setNavigationBarHidden:YES animated:YES];
  62. }
  63. - (void)makeConstraints {
  64. [self.navBarView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.left.right.equalTo(self.view);
  66. make.height.mas_equalTo(HJNavBarDefaultHeight);
  67. }];
  68. [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.edges.equalTo(self.view);
  70. }];
  71. //使用自动布局的时候先设置tableView的布局再给tableView.tableHeaderView赋值,不然会有布局Bug
  72. self.tableView.tableHeaderView = self.dataBox.headerView;
  73. }
  74. #pragma mark - FBAPIManagerInterceptor
  75. - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
  76. return YES;
  77. }
  78. - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
  79. }
  80. #pragma mark - FBAPIManagerDelegate
  81. - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
  82. if (manager == self.getUserInfoAPIManager) {
  83. // 不需要根据返回值来处理视图,在DataBox类中做了封装
  84. [manager fetchDataWithBox:self.dataBox];
  85. [self.refreshHeader endRefreshing];
  86. }
  87. if (manager == self.approveStatusAPIManager) {
  88. HJAuthStatusType status = (HJAuthStatusType)[[manager fetchDataWithBox:self.dataBox] integerValue];
  89. self.dataBox.headerView.profileView.auth = (status == HJAuthStatusTypeAuthSuccess) ? YES : NO;
  90. if (status == HJAuthStatusTypeNoAuth) {
  91. HJAuthViewController *authVC = [[HJAuthViewController alloc] init];
  92. authVC.hidesBottomBarWhenPushed = YES;
  93. [self.navigationController pushViewController:authVC animated:YES];
  94. } else if (status == HJAuthStatusTypeAuthing) {
  95. HJAuthingViewController *authingVC = [[HJAuthingViewController alloc] init];
  96. authingVC.hidesBottomBarWhenPushed = YES;
  97. [self.navigationController pushViewController:authingVC animated:YES];
  98. } else if (status == HJAuthStatusTypeAuthFailed) {
  99. HJAuthFailedViewController *authFailedVC = [[HJAuthFailedViewController alloc] init];
  100. authFailedVC.hidesBottomBarWhenPushed = YES;
  101. [self.navigationController pushViewController:authFailedVC animated:YES];
  102. } else {
  103. [self.view fb_showSuccessWithStatus:@"已认证"];
  104. }
  105. }
  106. if (manager == self.getUserInfoAPIManager || manager == self.approveStatusAPIManager) {
  107. //在headerView布局修改后一定要先调用tableView layoutIfNeeded,然后再调用reloadData不然会有布局Bug
  108. [self.tableView layoutIfNeeded];
  109. [self.tableView reloadData];
  110. }
  111. if (manager == self.getResumeAPIManager) {
  112. // 不需要根据返回值来处理视图,在DataBox类中做了封装
  113. [manager fetchDataWithBox:self.resumeDataBox];
  114. }
  115. }
  116. - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
  117. if (manager == self.approveStatusAPIManager) {
  118. id fetchData = [manager fetchDataWithBox:self.dataBox];
  119. if ([fetchData isKindOfClass:[NSString class]]) {
  120. [self.view fb_showFailureWithStatus:fetchData];
  121. }
  122. }
  123. }
  124. #pragma mark - UITableViewDelegate
  125. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  126. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  127. if (indexPath.row == 0) {
  128. HJSalaryViewController *vc = [[HJSalaryViewController alloc] init];
  129. vc.hidesBottomBarWhenPushed = YES;
  130. [self.navigationController pushViewController:vc animated:YES];
  131. }
  132. }
  133. #pragma mark - UIScrollViewDelegate
  134. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  135. if (scrollView == self.tableView) {
  136. [self.navBarView shadeBackgroundColorWithContentOffset:scrollView.contentOffset];
  137. }
  138. }
  139. #pragma mark - HJMeProfileViewDelegate
  140. - (void)meProfileViewDidTextForward:(HJMeProfileView *)meProfileView {
  141. // 调用用户认证状态,根据状态进入不同页面
  142. [self.approveStatusAPIManager start];
  143. }
  144. #pragma mark - HJMeResumeViewDelegate
  145. - (void)meResumeViewDidForward:(HJMeResumeView *)meResumeView {
  146. if (self.dataBox.headerView.resumeView.percent > 0) {
  147. HJResumeViewController *resumeVC = [[HJResumeViewController alloc] init];
  148. resumeVC.hidesBottomBarWhenPushed = YES;
  149. [self.navigationController pushViewController:resumeVC animated:YES];
  150. } else {
  151. HJBasicInfoViewController *profileVC = [[HJBasicInfoViewController alloc] init];
  152. profileVC.isPop = NO;
  153. profileVC.hidesBottomBarWhenPushed = YES;
  154. [self.navigationController pushViewController:profileVC animated:YES];
  155. }
  156. }
  157. #pragma mark - event response
  158. - (void)updateResume:(NSNotification *)notification {
  159. NSDictionary *data = self.resumeDataBox.resume;
  160. self.dataBox.headerView.resumeView.name = data[kHJResumeKeyName];
  161. self.dataBox.headerView.resumeView.percent = [data[kHJResumeKeyPercent] floatValue];
  162. }
  163. - (void)setingButtonClicked:(UIButton *)sender {
  164. HJSettingViewController *vc = [[HJSettingViewController alloc] init];
  165. vc.hidesBottomBarWhenPushed = YES;
  166. [self.navigationController pushViewController:vc animated:YES];
  167. }
  168. - (void)myFavoriteButtonClicked:(UIButton *)sender {
  169. HJMyFavoriteViewController *vc = [[HJMyFavoriteViewController alloc] init];
  170. vc.hidesBottomBarWhenPushed = YES;
  171. [self.navigationController pushViewController:vc animated:YES];
  172. }
  173. - (void)myApplyButtonClicked:(UIButton *)sender {
  174. HJMyApplyViewController *vc = [[HJMyApplyViewController alloc] init];
  175. vc.hidesBottomBarWhenPushed = YES;
  176. [self.navigationController pushViewController:vc animated:YES];
  177. }
  178. - (void)myInvitationButtonClicked:(UIButton *)sender {
  179. HJMyInterviewViewController *vc = [[HJMyInterviewViewController alloc] init];
  180. vc.hidesBottomBarWhenPushed = YES;
  181. [self.navigationController pushViewController:vc animated:YES];
  182. }
  183. - (void)loadNewData {
  184. [self.refreshHeader beginRefreshing];
  185. [self.getUserInfoAPIManager start];
  186. [self.getResumeAPIManager start];
  187. }
  188. #pragma mark - getters and setters
  189. - (HJResumeDataBox *)resumeDataBox {
  190. if (_resumeDataBox == nil) {
  191. _resumeDataBox = [[HJResumeDataBox alloc] init];
  192. }
  193. return _resumeDataBox;
  194. }
  195. - (HJMeDataBox *)dataBox {
  196. if (_dataBox == nil) {
  197. _dataBox = [[HJMeDataBox alloc] init];
  198. _dataBox.headerView.profileView.delegate = self;
  199. _dataBox.headerView.resumeView.delegate = self;
  200. [_dataBox.headerView.distributeView.favoriteButton addTarget:self
  201. action:@selector(myFavoriteButtonClicked:)
  202. forControlEvents:UIControlEventTouchUpInside];
  203. [_dataBox.headerView.distributeView.applyButton addTarget:self
  204. action:@selector(myApplyButtonClicked:)
  205. forControlEvents:UIControlEventTouchUpInside];
  206. [_dataBox.headerView.distributeView.invitationButton addTarget:self
  207. action:@selector(myInvitationButtonClicked:)
  208. forControlEvents:UIControlEventTouchUpInside];
  209. }
  210. return _dataBox;
  211. }
  212. - (HJGetResumeAPIManager *)getResumeAPIManager {
  213. if (_getResumeAPIManager == nil) {
  214. _getResumeAPIManager = [[HJGetResumeAPIManager alloc] init];
  215. _getResumeAPIManager.APIManagerDelegate = self;
  216. _getResumeAPIManager.APIManagerInterceptor = self;
  217. }
  218. return _getResumeAPIManager;
  219. }
  220. - (HJGetUserInfoAPIManager *)getUserInfoAPIManager {
  221. if (_getUserInfoAPIManager == nil) {
  222. _getUserInfoAPIManager = [[HJGetUserInfoAPIManager alloc] init];
  223. _getUserInfoAPIManager.APIManagerDelegate = self;
  224. _getUserInfoAPIManager.APIManagerInterceptor = self;
  225. }
  226. return _getUserInfoAPIManager;
  227. }
  228. - (HJApproveStatusAPIManager *)approveStatusAPIManager {
  229. if (_approveStatusAPIManager == nil) {
  230. _approveStatusAPIManager = [[HJApproveStatusAPIManager alloc] init];
  231. _approveStatusAPIManager.APIManagerDelegate = self;
  232. _approveStatusAPIManager.APIManagerInterceptor = self;
  233. }
  234. return _approveStatusAPIManager;
  235. }
  236. - (HJMeNavBarView *)navBarView {
  237. if (_navBarView == nil) {
  238. _navBarView = [[HJMeNavBarView alloc] init];
  239. _navBarView.titleLabel.text = self.title;
  240. [_navBarView.setingButton addTarget:self action:@selector(setingButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
  241. }
  242. return _navBarView;
  243. }
  244. - (UITableView *)tableView {
  245. if (_tableView == nil) {
  246. _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
  247. _tableView.delegate = self;
  248. _tableView.dataSource = self.dataBox;
  249. _tableView.mj_header = self.refreshHeader;
  250. // 去除顶部空白
  251. if (@available(iOS 11.0, *)) {
  252. _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  253. } else {
  254. self.automaticallyAdjustsScrollViewInsets = NO;
  255. }
  256. // 解决底部被UITabBar遮挡的问题
  257. self.edgesForExtendedLayout = UIRectEdgeNone;
  258. _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
  259. // 修改分割线样式
  260. _tableView.separatorInset = UIEdgeInsetsZero;
  261. _tableView.separatorColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0];
  262. // 在内容显示不够满屏时,去除分割线
  263. _tableView.tableFooterView = [UIView new];
  264. }
  265. return _tableView;
  266. }
  267. - (HJRefreshHeaderView *)refreshHeader {
  268. if (_refreshHeader == nil) {
  269. _refreshHeader = [HJRefreshHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
  270. }
  271. return _refreshHeader;
  272. }
  273. @end