MineViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. //
  2. // MineViewController.m
  3. // KulexiuForTeacher
  4. //
  5. // Created by Kyle on 2022/3/17.
  6. //
  7. #import "MineViewController.h"
  8. #import "MineNavView.h"
  9. #import "MineBodyView.h"
  10. #import "SettingViewController.h"
  11. #import "KSBaseWKWebViewController.h"
  12. #import "NetworkingCheckController.h"
  13. #import "DeviceCheckView.h"
  14. #import "KSEnterLiveroomManager.h"
  15. #import "UserInfoManager.h"
  16. #import "UserInfo.h"
  17. #import "MyCourseViewController.h"
  18. #import "HomeworkListViewController.h"
  19. #import "UserSettingViewController.h"
  20. #import "KSScanViewController.h"
  21. #import "KSPremissionAlert.h"
  22. #import <KSToolLibrary/RecordCheckManager.h>
  23. #import "FeedbackViewController.h"
  24. #import "UserInfoManager.h"
  25. #import "MineWorksViewController.h"
  26. @interface MineViewController ()<UIScrollViewDelegate>
  27. @property (nonatomic, strong) MineNavView *navView;
  28. @property (nonatomic, strong) MineBodyView *bodyView;
  29. @property (nonatomic, strong) DeviceCheckView *checkView;
  30. @property (nonatomic, strong) UserInfo *mineInfo;
  31. @end
  32. @implementation MineViewController
  33. - (void)viewDidLoad {
  34. [super viewDidLoad];
  35. // Do any additional setup after loading the view.
  36. self.ks_prefersNavigationBarHidden = YES;
  37. [self configUI];
  38. }
  39. - (void)configUI {
  40. NSString *bgName = IS_IPAD ? @"mine_navBgPad" : @"mine_navBg";
  41. UIImage *bgImage = [UIImage imageNamed:bgName];
  42. CGFloat height = bgImage.size.height / bgImage.size.width * KPortraitWidth;
  43. UIImageView *imageView = [[UIImageView alloc] initWithImage:bgImage];
  44. imageView.frame = CGRectMake(0, 0, KPortraitWidth, height);
  45. [self.view addSubview:imageView];
  46. self.scrollView.backgroundColor = [UIColor clearColor];
  47. self.scrollView.delegate = self;
  48. [self.view addSubview:self.navView];
  49. [self.view bringSubviewToFront:self.scrollView];
  50. [self.view bringSubviewToFront:self.navView];
  51. [self.navView mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.width.mas_equalTo(KPortraitWidth);
  53. make.right.top.mas_equalTo(self.view);
  54. make.height.mas_equalTo(kNaviBarHeight);
  55. }];
  56. [self.scrollView mas_remakeConstraints:^(MASConstraintMaker *make) {
  57. make.top.mas_equalTo(self.view.mas_top);
  58. make.left.right.mas_equalTo(self.view);
  59. make.bottom.mas_equalTo(self.view.mas_bottom);
  60. }];
  61. UIView *headView = [[UIView alloc] init];
  62. headView.backgroundColor = [UIColor clearColor];
  63. [self.scrollView addSubview:headView];
  64. [headView mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.mas_equalTo(self.scrollView.mas_top);
  66. make.left.right.mas_equalTo(self.view);
  67. make.height.mas_equalTo(kNaviBarHeight);
  68. }];
  69. // bodyView;
  70. _bodyView = [MineBodyView shareInstance];
  71. [self.scrollView addSubview:_bodyView];
  72. CGFloat contentMinHeight = [_bodyView getViewHeight];
  73. CGFloat contentHeight = kScreenHeight - kTabBarHeight - kNaviBarHeight;
  74. CGFloat viewHeight = contentMinHeight > contentHeight ? contentMinHeight : contentHeight;
  75. [_bodyView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.top.mas_equalTo(headView.mas_bottom);
  77. make.left.right.mas_equalTo(self.view);
  78. make.height.mas_equalTo(viewHeight);
  79. make.bottom.mas_equalTo(self.scrollView.mas_bottom);
  80. }];
  81. MJWeakSelf;
  82. [_bodyView operationCallback:^(MINEVIEWTYPE type) {
  83. [weakSelf operationAction:type];
  84. }];
  85. }
  86. - (void)viewWillAppear:(BOOL)animated {
  87. [super viewWillAppear:animated];
  88. if ([self checkIsLoginToLoginView:YES]) {
  89. [self requsetUserMessage];
  90. [self requestUserMemo];
  91. }
  92. }
  93. - (void)requsetUserMessage {
  94. [USER_MANAGER queryUserInfoCallback:^(UserInfo * _Nonnull userInfo) {
  95. self.mineInfo = userInfo;
  96. [self refreshView];
  97. }];
  98. }
  99. - (void)requestUserMemo {
  100. [[UserInfoManager shareInstance] requsetconfigCallback:^(BOOL success) {
  101. [self refreshBodyView:success];
  102. }];
  103. }
  104. - (void)refreshBodyView:(BOOL)isMember {
  105. self.bodyView.isMember = isMember;
  106. CGFloat contentMinHeight = [_bodyView getViewHeight];
  107. [self.bodyView mas_updateConstraints:^(MASConstraintMaker *make) {
  108. make.height.mas_equalTo(contentMinHeight);
  109. }];
  110. }
  111. - (void)refreshView {
  112. [self.bodyView configWithSource:self.mineInfo];
  113. }
  114. - (void)operationAction:(MINEVIEWTYPE)type {
  115. switch (type) {
  116. case MINEVIEWTYPE_MEMBER: // member center
  117. {
  118. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  119. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberCenter"];
  120. [self.navigationController pushViewController:ctrl animated:YES];
  121. }
  122. break;
  123. case MINEVIEWTYPE_COURSE:
  124. {
  125. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  126. [self.navigationController pushViewController:ctrl animated:YES];
  127. }
  128. break;
  129. case MINEVIEWTYPE_HOMEWORK:
  130. {
  131. HomeworkListViewController *ctrl = [[HomeworkListViewController alloc] init];
  132. [self.navigationController pushViewController:ctrl animated:YES];
  133. }
  134. break;
  135. case MINEVIEWTYPE_MUSIC:
  136. {
  137. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  138. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/music-personal"];
  139. [self.navigationController pushViewController:ctrl animated:YES];
  140. }
  141. break;
  142. case MINEVIEWTYPE_RECORD: // 评测记录
  143. {
  144. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  145. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/memberRecord"];
  146. [self.navigationController pushViewController:ctrl animated:YES];
  147. }
  148. break;
  149. case MINEVIEWTYPE_ORDER:
  150. {
  151. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  152. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/goodsOrder"];
  153. [self.navigationController pushViewController:ctrl animated:YES];
  154. }
  155. break;
  156. case MINEVIEWTYPE_DEAL:
  157. {
  158. KSBaseWKWebViewController *ctrl = [[KSBaseWKWebViewController alloc] init];
  159. ctrl.url = [NSString stringWithFormat:@"%@%@",WEBHOST,@"/#/tradeRecord"];
  160. [self.navigationController pushViewController:ctrl animated:YES];
  161. }
  162. break;
  163. case MINEVIEWTYPE_NETWORK:
  164. {
  165. NetworkingCheckController *checkVC = [[NetworkingCheckController alloc] init];
  166. [self.navigationController pushViewController:checkVC animated:YES];
  167. }
  168. break;
  169. case MINEVIEWTYPE_DEVICE:
  170. {
  171. [self.checkView showAlert];
  172. }
  173. break;
  174. case MINEVIEWTYPE_HELP:
  175. {
  176. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  177. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/helpCenter"];
  178. [self.navigationController pushViewController:webCtrl animated:YES];
  179. }
  180. break;
  181. case MINEVIEWTYPE_FINISHCOURSE:
  182. {
  183. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  184. [self.navigationController pushViewController:ctrl animated:YES];
  185. }
  186. break;
  187. case MINEVIEWTYPE_UNFINISHCOURSE:
  188. {
  189. MyCourseViewController *ctrl = [[MyCourseViewController alloc] init];
  190. [self.navigationController pushViewController:ctrl animated:YES];
  191. }
  192. break;
  193. case MINEVIEWTYPE_FOLLOW:
  194. {
  195. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  196. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/teacherFollow"];
  197. [self.navigationController pushViewController:webCtrl animated:YES];
  198. }
  199. break;
  200. case MINEVIEWTYPE_USER:
  201. {
  202. UserSettingViewController *ctrl = [[UserSettingViewController alloc] init];
  203. [self.navigationController pushViewController:ctrl animated:YES];
  204. }
  205. break;
  206. case MINEVIEWTYPE_FEEDBACK:
  207. {
  208. FeedbackViewController *ctrl = [[FeedbackViewController alloc] init];
  209. [self.navigationController pushViewController:ctrl animated:YES];
  210. }
  211. break;
  212. case MINEVIEWTYPE_TICKET:
  213. {
  214. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  215. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/coupons"];
  216. [self.navigationController pushViewController:webCtrl animated:YES];
  217. }
  218. break;
  219. case MINEVIEWTYPE_CONTACT:
  220. {
  221. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  222. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/contactus"];
  223. [self.navigationController pushViewController:webCtrl animated:YES];
  224. }
  225. break;
  226. case MINEVIEWTYPE_AWARD:
  227. {
  228. KSBaseWKWebViewController *webCtrl = [[KSBaseWKWebViewController alloc] init];
  229. webCtrl.url = [NSString stringWithFormat:@"%@%@", WEBHOST, @"/#/awardActivity"];
  230. [self.navigationController pushViewController:webCtrl animated:YES];
  231. }
  232. break;
  233. case MINEVIEWTAG_WORKS:
  234. {
  235. MineWorksViewController *ctrl = [[MineWorksViewController alloc] init];
  236. [self.navigationController pushViewController:ctrl animated:YES];
  237. }
  238. break;
  239. default:
  240. break;
  241. }
  242. }
  243. #pragma mark --- lazying
  244. - (MineNavView *)navView {
  245. if (!_navView) {
  246. _navView = [MineNavView shareInstance];
  247. MJWeakSelf;
  248. [_navView mineNavAction:^(MINENAV_ACTION action) {
  249. if (action == MINENAV_ACTION_SETTING) {
  250. [weakSelf settingAction];
  251. }
  252. else {
  253. [weakSelf scanAction];
  254. }
  255. }];
  256. }
  257. return _navView;
  258. }
  259. - (void)scanAction {
  260. // 判断是否有权限
  261. [RecordCheckManager checkCameraPremissionAvaiableCallback:^(PREMISSIONTYPE type) {
  262. if (type == PREMISSIONTYPE_YES) {
  263. KSScanViewController *ctrl = [[KSScanViewController alloc] init];
  264. [self.navigationController pushViewController:ctrl animated:YES];
  265. }
  266. else {
  267. [self showAlertWithMessage:@"请开启相机访问权限" type:CHECKDEVICETYPE_CAMREA];
  268. }
  269. }];
  270. }
  271. - (void)showAlertWithMessage:(NSString *)message type:(CHECKDEVICETYPE)deviceType {
  272. [KSPremissionAlert shareInstanceDisplayImage:deviceType message:message showInView:self.view cancel:^{
  273. } confirm:^{
  274. [self openSettingView];
  275. }];
  276. }
  277. - (void)openSettingView {
  278. if (@available(iOS 10, *)) {
  279. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString] options:@{} completionHandler:nil];
  280. } else {
  281. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
  282. }
  283. }
  284. - (DeviceCheckView *)checkView {
  285. if (!_checkView) {
  286. _checkView = [DeviceCheckView shareInstance];
  287. }
  288. return _checkView;
  289. }
  290. - (void)settingAction {
  291. SettingViewController *ctrl = [[SettingViewController alloc] init];
  292. [self.navigationController pushViewController:ctrl animated:YES];
  293. }
  294. - (void)dealloc {
  295. [[NSNotificationCenter defaultCenter] removeObserver:self];
  296. }
  297. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  298. CGFloat space = scrollView.contentOffset.y;
  299. if (space >= kNaviBarHeight) {
  300. self.navView.backgroundColor = [UIColor whiteColor];
  301. self.navView.lineView.hidden = NO;
  302. }
  303. else {
  304. self.navView.lineView.hidden = YES;
  305. CGFloat rate = space / kNaviBarHeight < 0 ? 0 : space / kNaviBarHeight;
  306. self.navView.backgroundColor = HexRGBAlpha(0xffffff, rate);
  307. }
  308. }
  309. /*
  310. #pragma mark - Navigation
  311. // In a storyboard-based application, you will often want to do a little preparation before navigation
  312. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  313. // Get the new view controller using [segue destinationViewController].
  314. // Pass the selected object to the new view controller.
  315. }
  316. */
  317. @end