123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- //
- // MineViewController.m
- // KulexiuForTeacher
- //
- // Created by Kyle on 2022/3/17.
- //
- #import "MineViewController.h"
- #import "MineNavView.h"
- #import "MineBodyView.h"
- #import "SettingViewController.h"
- #import "KSBaseWKWebViewController.h"
- #import "NetworkingCheckController.h"
- #import "DeviceCheckView.h"
- #import "KSEnterLiveroomManager.h"
- #import "UserInfoManager.h"
- #import "UserInfo.h"
- #import "MyCourseViewController.h"
- #import "HomeworkListViewController.h"
- #import "UserSettingViewController.h"
- #import "KSScanViewController.h"
- #import "KSPremissionAlert.h"
- #import <KSToolLibrary/RecordCheckManager.h>
- #import "FeedbackViewController.h"
- #import "UserInfoManager.h"
- #import "MineWorksViewController.h"
- @interface MineViewController ()<UIScrollViewDelegate>
- @property (nonatomic, strong) MineNavView *navView;
- @property (nonatomic, strong) MineBodyView *bodyView;
- @property (nonatomic, strong) DeviceCheckView *checkView;
- @property (nonatomic, strong) UserInfo *mineInfo;
- @end
- @implementation MineViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- self.ks_prefersNavigationBarHidden = YES;
- [self configUI];
- }
- - (void)configUI {
- NSString *bgName = IS_IPAD ? @"mine_navBgPad" : @"mine_navBg";
- UIImage *bgImage = [UIImage imageNamed:bgName];
- CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
- UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
- imageView.frame = CGRectMake(0, 0, KPortraitWidth, height);
- [self.view addSubview:imageView];
- self.scrollView.backgroundColor = [UIColor clearColor];
- self.scrollView.delegate = self;
-
- [self.view addSubview:self.navView];
- [self.view bringSubviewToFront:self.scrollView];
- [self.view bringSubviewToFront:self.navView];
- [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.width.mas_equalTo(KPortraitWidth);
- make.right.top.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
-
- [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.view.mas_top);
- make.left.right.mas_equalTo(self.view);
- make.bottom.mas_equalTo(self.view.mas_bottom);
- }];
-
- UIView *headView = [[UIView alloc] init];
- headView.backgroundColor = [UIColor clearColor];
- [self.scrollView addSubview:headView];
- [headView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.scrollView.mas_top);
- make.left.right.mas_equalTo(self.view);
- make.height.mas_equalTo(kNaviBarHeight);
- }];
-
- // bodyView;
- _bodyView = [MineBodyView shareInstance];
- [self.scrollView addSubview:_bodyView];
- CGFloat contentMinHeight = [_bodyView getViewHeight];
- CGFloat contentHeight = kScreenHeight - kTabBarHeight - kNaviBarHeight;
- CGFloat viewHeight = contentMinHeight > contentHeight ? contentMinHeight : contentHeight;
- [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(headView.mas_bottom);
- make.left.right.mas_equalTo(self.view);
- make.height.mas_equalTo(viewHeight);
- make.bottom.mas_equalTo(self.scrollView.mas_bottom);
- }];
- MJWeakSelf;
- [_bodyView operationCallback:^(MINEVIEWTYPE type) {
- [weakSelf operationAction:type];
- }];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- if ([self checkIsLoginToLoginView:YES]) {
- [self requsetUserMessage];
- [self requestUserMemo];
- }
- }
- - (void)requsetUserMessage {
- [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
- self.mineInfo = userInfo;
- [self refreshView];
- }];
- }
- - (void)requestUserMemo {
- [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
- [self refreshBodyView:success];
- }];
- }
- - (void)refreshBodyView:(BOOL)isMember {
- self.bodyView.isMember = isMember;
- CGFloat contentMinHeight = [_bodyView getViewHeight];
- [self.bodyView mas_updateConstraints:^(MASConstraintMaker *make) {
- make.height.mas_equalTo(contentMinHeight);
- }];
- }
- - (void)refreshView {
- [self.bodyView configWithSource:self.mineInfo];
- }
- - (void)operationAction:(MINEVIEWTYPE)type {
- switch (type) {
- case MINEVIEWTYPE_MEMBER: // member center
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberCenter"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_COURSE:
- {
- MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_HOMEWORK:
- {
- HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_MUSIC:
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/music-personal"];
- [self.navigationController pushViewController:ctrl animated:YES];
-
- }
- break;
- case MINEVIEWTYPE_RECORD: // 评测记录
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_ORDER:
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/goodsOrder"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_DEAL:
- {
- KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
- ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/tradeRecord"];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_NETWORK:
- {
- NetworkingCheckController *checkVC = [[NetworkingCheckController alloc] init];
- [self.navigationController pushViewController:checkVC animated:YES];
- }
- break;
- case MINEVIEWTYPE_DEVICE:
- {
- [self.checkView showAlert];
- }
- break;
- case MINEVIEWTYPE_HELP:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/helpCenter"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_FINISHCOURSE:
- {
- MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_UNFINISHCOURSE:
- {
- MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_FOLLOW:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherFollow"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_USER:
- {
- UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_FEEDBACK:
- {
- FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_TICKET:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/coupons"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_CONTACT:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/contactus"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case MINEVIEWTYPE_AWARD:
- {
- KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
- webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
- [self.navigationController pushViewController:webCtrl animated:YES];
- }
- break;
- case MINEVIEWTAG_WORKS:
- {
- MineWorksViewController *ctrl = [[MineWorksViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- break;
- default:
- break;
- }
- }
- #pragma mark --- lazying
- - (MineNavView *)navView {
- if (!_navView) {
- _navView = [MineNavView shareInstance];
- MJWeakSelf;
- [_navView mineNavAction:^(MINENAV_ACTION action) {
- if (action == MINENAV_ACTION_SETTING) {
- [weakSelf settingAction];
- }
- else {
- [weakSelf scanAction];
- }
- }];
- }
- return _navView;
- }
- - (void)scanAction {
- // 判断是否有权限
- [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
- if (type == PREMISSIONTYPE_YES) {
- KSScanViewController *ctrl = [[KSScanViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- else {
- [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
- }
- }];
- }
- - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
- [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
-
- } confirm:^{
- [self openSettingView];
- }];
-
- }
- - (void)openSettingView {
- if (@available(iOS 10, *)) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
- } else {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
- }
- }
- - (DeviceCheckView *)checkView {
- if (!_checkView) {
- _checkView = [DeviceCheckView shareInstance];
- }
- return _checkView;
- }
- - (void)settingAction {
- SettingViewController *ctrl = [[SettingViewController alloc] init];
- [self.navigationController pushViewController:ctrl animated:YES];
- }
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
- CGFloat space = scrollView.contentOffset.y;
- if (space >= kNaviBarHeight) {
- self.navView.backgroundColor = [UIColor whiteColor];
- self.navView.lineView.hidden = NO;
- }
- else {
- self.navView.lineView.hidden = YES;
- CGFloat rate = space / kNaviBarHeight < 0 ? 0 : space / kNaviBarHeight;
- self.navView.backgroundColor = HexRGBAlpha(0xffffff, rate);
- }
- }
- /*
- #pragma mark - Navigation
- // In a storyboard-based application, you will often want to do a little preparation before navigation
- - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
- // Get the new view controller using [segue destinationViewController].
- // Pass the selected object to the new view controller.
- }
- */
- @end
|