| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- //
- // HJMeViewController.m
- // HappyJob
- //
- // Created by Bob on 2019/3/13.
- // Copyright © 2019 Bob. All rights reserved.
- //
- #import "HJMeViewController.h"
- #import "HJMeNavBarView.h"
- #import "HJRefreshHeaderView.h"
- #import "UIView+FBProgressHUD.h"
- #import "HJExpectationViewController.h"
- #import "HJBasicInfoViewController.h"
- #import "HJExperienceViewController.h"
- #import "HJResumeViewController.h"
- #import "HJAuthViewController.h"
- #import "HJAuthingViewController.h"
- #import "HJAuthFailedViewController.h"
- #import "HJMeDataBox.h"
- #import "HJGetUserInfoAPIManager.h"
- #import "HJApproveStatusAPIManager.h"
- #import "UIViewController+HJNavBar.h"
- #import "HJSettingViewController.h"
- #import "HJMyFavoriteViewController.h"
- #import "HJMyApplyViewController.h"
- #import "HJMyInterviewViewController.h"
- #import "HJGetResumeAPIManager.h"
- #import "HJSalaryViewController.h"
- #import "HJResumeDataBox.h"
- @interface HJMeViewController () <UITableViewDelegate, UIScrollViewDelegate, HJMeProfileViewDelegate, HJMeResumeViewDelegate, FBAPIManagerInterceptor, FBAPIManagerDelegate>
- @property (nonatomic, strong) HJMeNavBarView *navBarView;
- @property (nonatomic, strong) UITableView *tableView;
- @property (nonatomic, strong) HJRefreshHeaderView *refreshHeader;
- @property (nonatomic, strong) HJResumeDataBox *resumeDataBox;
- @property (nonatomic, strong) HJMeDataBox *dataBox;
- @property (nonatomic, strong) HJGetUserInfoAPIManager *getUserInfoAPIManager;
- @property (nonatomic, strong) HJApproveStatusAPIManager *approveStatusAPIManager;
- @property (nonatomic, strong) HJGetResumeAPIManager *getResumeAPIManager;
- @end
- @implementation HJMeViewController
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self name:HJResumeUpdateNotification object:nil];
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return UIStatusBarStyleLightContent;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- // 这里配置导航栏是为了在Push子视图时,backItem的标题不显示文字
- [self hj_setupNavBar];
-
- [self.view addSubview:self.navBarView];
- [self.view insertSubview:self.tableView belowSubview:self.navBarView];
-
- [self makeConstraints];
-
- [self.getUserInfoAPIManager start];
- [self.getResumeAPIManager start];
- //添加简历更新通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateResume:) name:HJResumeUpdateNotification object:nil];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.navigationController setNavigationBarHidden:YES animated:YES];
- }
- - (void)makeConstraints {
- [self.navBarView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.left.right.equalTo(self.view);
- make.height.mas_equalTo(HJNavBarDefaultHeight);
- }];
- [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self.view);
- }];
- //使用自动布局的时候先设置tableView的布局再给tableView.tableHeaderView赋值,不然会有布局Bug
- self.tableView.tableHeaderView = self.dataBox.headerView;
- }
- #pragma mark - FBAPIManagerInterceptor
- - (BOOL)manager:(FBBaseAPIManager *)manager shouldStartCallAPIWithParams:(NSDictionary *)params {
- return YES;
- }
- - (void)managerShouldFinishCallAPI:(FBBaseAPIManager *)manager {
-
- }
- #pragma mark - FBAPIManagerDelegate
- - (void)managerCallAPIDidSuccess:(FBBaseAPIManager *)manager {
- if (manager == self.getUserInfoAPIManager) {
- // 不需要根据返回值来处理视图,在DataBox类中做了封装
- [manager fetchDataWithBox:self.dataBox];
- [self.refreshHeader endRefreshing];
- }
-
- if (manager == self.approveStatusAPIManager) {
- HJAuthStatusType status = (HJAuthStatusType)[[manager fetchDataWithBox:self.dataBox] integerValue];
-
- self.dataBox.headerView.profileView.auth = (status == HJAuthStatusTypeAuthSuccess) ? YES : NO;
-
- if (status == HJAuthStatusTypeNoAuth) {
- HJAuthViewController *authVC = [[HJAuthViewController alloc] init];
- authVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:authVC animated:YES];
- } else if (status == HJAuthStatusTypeAuthing) {
- HJAuthingViewController *authingVC = [[HJAuthingViewController alloc] init];
- authingVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:authingVC animated:YES];
- } else if (status == HJAuthStatusTypeAuthFailed) {
- HJAuthFailedViewController *authFailedVC = [[HJAuthFailedViewController alloc] init];
- authFailedVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:authFailedVC animated:YES];
- } else {
- [self.view fb_showSuccessWithStatus:@"已认证"];
- }
- }
-
- if (manager == self.getUserInfoAPIManager || manager == self.approveStatusAPIManager) {
- //在headerView布局修改后一定要先调用tableView layoutIfNeeded,然后再调用reloadData不然会有布局Bug
- [self.tableView layoutIfNeeded];
- [self.tableView reloadData];
- }
-
- if (manager == self.getResumeAPIManager) {
- // 不需要根据返回值来处理视图,在DataBox类中做了封装
- [manager fetchDataWithBox:self.resumeDataBox];
- }
- }
- - (void)managerCallAPIDidFailed:(FBBaseAPIManager *)manager {
- if (manager == self.approveStatusAPIManager) {
- id fetchData = [manager fetchDataWithBox:self.dataBox];
- if ([fetchData isKindOfClass:[NSString class]]) {
- [self.view fb_showFailureWithStatus:fetchData];
- }
- }
- }
- #pragma mark - UITableViewDelegate
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
- [tableView deselectRowAtIndexPath:indexPath animated:YES];
- if (indexPath.row == 0) {
- HJSalaryViewController *vc = [[HJSalaryViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- }
- #pragma mark - UIScrollViewDelegate
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- if (scrollView == self.tableView) {
- [self.navBarView shadeBackgroundColorWithContentOffset:scrollView.contentOffset];
- }
- }
- #pragma mark - HJMeProfileViewDelegate
- - (void)meProfileViewDidTextForward:(HJMeProfileView *)meProfileView {
- // 调用用户认证状态,根据状态进入不同页面
- [self.approveStatusAPIManager start];
- }
- #pragma mark - HJMeResumeViewDelegate
- - (void)meResumeViewDidForward:(HJMeResumeView *)meResumeView {
- if (self.dataBox.headerView.resumeView.percent > 0) {
- HJResumeViewController *resumeVC = [[HJResumeViewController alloc] init];
- resumeVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:resumeVC animated:YES];
- } else {
- HJBasicInfoViewController *profileVC = [[HJBasicInfoViewController alloc] init];
- profileVC.isPop = NO;
- profileVC.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:profileVC animated:YES];
- }
- }
- #pragma mark - event response
- - (void)updateResume:(NSNotification *)notification {
- NSDictionary *data = self.resumeDataBox.resume;
- self.dataBox.headerView.resumeView.name = data[kHJResumeKeyName];
- self.dataBox.headerView.resumeView.percent = [data[kHJResumeKeyPercent] floatValue];
- }
- - (void)setingButtonClicked:(UIButton *)sender {
- HJSettingViewController *vc = [[HJSettingViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)myFavoriteButtonClicked:(UIButton *)sender {
- HJMyFavoriteViewController *vc = [[HJMyFavoriteViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)myApplyButtonClicked:(UIButton *)sender {
- HJMyApplyViewController *vc = [[HJMyApplyViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)myInvitationButtonClicked:(UIButton *)sender {
- HJMyInterviewViewController *vc = [[HJMyInterviewViewController alloc] init];
- vc.hidesBottomBarWhenPushed = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }
- - (void)loadNewData {
- [self.refreshHeader beginRefreshing];
-
- [self.getUserInfoAPIManager start];
- [self.getResumeAPIManager start];
- }
- #pragma mark - getters and setters
- - (HJResumeDataBox *)resumeDataBox {
- if (_resumeDataBox == nil) {
- _resumeDataBox = [[HJResumeDataBox alloc] init];
- }
- return _resumeDataBox;
- }
- - (HJMeDataBox *)dataBox {
- if (_dataBox == nil) {
- _dataBox = [[HJMeDataBox alloc] init];
- _dataBox.headerView.profileView.delegate = self;
- _dataBox.headerView.resumeView.delegate = self;
- [_dataBox.headerView.distributeView.favoriteButton addTarget:self
- action:@selector(myFavoriteButtonClicked:)
- forControlEvents:UIControlEventTouchUpInside];
- [_dataBox.headerView.distributeView.applyButton addTarget:self
- action:@selector(myApplyButtonClicked:)
- forControlEvents:UIControlEventTouchUpInside];
- [_dataBox.headerView.distributeView.invitationButton addTarget:self
- action:@selector(myInvitationButtonClicked:)
- forControlEvents:UIControlEventTouchUpInside];
- }
- return _dataBox;
- }
- - (HJGetResumeAPIManager *)getResumeAPIManager {
- if (_getResumeAPIManager == nil) {
- _getResumeAPIManager = [[HJGetResumeAPIManager alloc] init];
- _getResumeAPIManager.APIManagerDelegate = self;
- _getResumeAPIManager.APIManagerInterceptor = self;
- }
- return _getResumeAPIManager;
- }
- - (HJGetUserInfoAPIManager *)getUserInfoAPIManager {
- if (_getUserInfoAPIManager == nil) {
- _getUserInfoAPIManager = [[HJGetUserInfoAPIManager alloc] init];
- _getUserInfoAPIManager.APIManagerDelegate = self;
- _getUserInfoAPIManager.APIManagerInterceptor = self;
- }
- return _getUserInfoAPIManager;
- }
- - (HJApproveStatusAPIManager *)approveStatusAPIManager {
- if (_approveStatusAPIManager == nil) {
- _approveStatusAPIManager = [[HJApproveStatusAPIManager alloc] init];
- _approveStatusAPIManager.APIManagerDelegate = self;
- _approveStatusAPIManager.APIManagerInterceptor = self;
- }
- return _approveStatusAPIManager;
- }
- - (HJMeNavBarView *)navBarView {
- if (_navBarView == nil) {
- _navBarView = [[HJMeNavBarView alloc] init];
- _navBarView.titleLabel.text = self.title;
- [_navBarView.setingButton addTarget:self action:@selector(setingButtonClicked:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _navBarView;
- }
- - (UITableView *)tableView {
- if (_tableView == nil) {
- _tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStyleGrouped];
- _tableView.delegate = self;
- _tableView.dataSource = self.dataBox;
- _tableView.mj_header = self.refreshHeader;
-
- // 去除顶部空白
- if (@available(iOS 11.0, *)) {
- _tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
- } else {
- self.automaticallyAdjustsScrollViewInsets = NO;
- }
- // 解决底部被UITabBar遮挡的问题
- self.edgesForExtendedLayout = UIRectEdgeNone;
- _tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
- // 修改分割线样式
- _tableView.separatorInset = UIEdgeInsetsZero;
- _tableView.separatorColor = [UIColor colorWithRed:221/255.0 green:221/255.0 blue:221/255.0 alpha:1.0];
- // 在内容显示不够满屏时,去除分割线
- _tableView.tableFooterView = [UIView new];
- }
- return _tableView;
- }
- - (HJRefreshHeaderView *)refreshHeader {
- if (_refreshHeader == nil) {
- _refreshHeader = [HJRefreshHeaderView headerWithRefreshingTarget:self refreshingAction:@selector(loadNewData)];
- }
- return _refreshHeader;
- }
- @end
|