RQHomePageViewController.m 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. //
  2. // RQHomePageViewController.m
  3. // RQCommon
  4. //
  5. // Created by 张嵘 on 2018/11/21.
  6. // Copyright © 2018 张嵘. All rights reserved.
  7. //
  8. #import "RQHomePageViewController.h"
  9. #import "MapManager.h"
  10. #import "RQQRCodeViewController.h"
  11. #import "ScanVC.h"
  12. #import "ScanPageVC.h"
  13. #import "DistenceTooLongMapVC.h"
  14. @interface RQHomePageViewController () <JXCategoryViewDelegate, JXPagerViewDelegate, JXPagerMainTableViewGestureDelegate, SDCycleScrollViewDelegate>
  15. /// viewModel
  16. @property (nonatomic, readonly, strong) RQHomePageViewModel *viewModel;
  17. @property (nonatomic, readwrite, strong) RQHomePageTitleView *homePageTitleView;
  18. @property (nonatomic, readwrite, strong) JXPagerView *pagerView;
  19. @property (nonatomic, readwrite, strong) JXCategoryTitleView *categoryView;
  20. @property (nonatomic, readwrite, copy) NSArray <NSString *> *titles;
  21. //投诉建议入口-可共用
  22. @property (nonatomic, readwrite, strong) NYFloatingSuggestViewModel *floatingSuggestViewModel;
  23. @property (nonatomic, readwrite, strong) NYFloatingSuggestView *floatingSuggestView;
  24. //集中式理论
  25. @property (nonatomic, readwrite, assign) BOOL isNeedTest;
  26. @property (nonatomic, readwrite, assign) BOOL isCloseAudio;
  27. @property (nonatomic, readwrite, assign) NSInteger maxTime;
  28. @property (nonatomic, readwrite, copy) NSString *scanType;
  29. @property (nonatomic, readwrite, copy) NSString *scanData;
  30. @property (nonatomic, readwrite, assign) CLLocationCoordinate2D myLocation;
  31. @end
  32. @implementation RQHomePageViewController
  33. @dynamic viewModel;
  34. #pragma mark - SystemMethod
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. /// 初始化
  38. [self rq_setup];
  39. // if (myDelegate.isLogin) {
  40. // //更新登录信息 如果是登录状态的时候
  41. // reLogin(self);
  42. // }
  43. }
  44. - (void)viewDidAppear:(BOOL)animated {
  45. [super viewDidAppear:animated];
  46. if (RQ_COMMON_MANAGER.JSJP_APP_ICON_NEED_CHANGE) {
  47. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_NewRule" completionHandler:^(NSError * _Nullable error) {
  48. if (error != nil) {
  49. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  50. }
  51. }];
  52. } else {
  53. [[UIApplication sharedApplication] setAlternateIconName:@"AppIcon_Old" completionHandler:^(NSError * _Nullable error) {
  54. if (error != nil) {
  55. NSLog(@"set alternative icon error:%@", error.localizedDescription);
  56. }
  57. }];
  58. }
  59. }
  60. - (void)viewDidLayoutSubviews {
  61. [super viewDidLayoutSubviews];
  62. self.pagerView.frame = CGRectMake(0, (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT), RQ_SCREEN_WIDTH, RQ_SCREEN_HEIGHT - (RQ_APPLICATION_NAV_BAR_HEIGHT + RQ_APPLICATION_STATUS_BAR_HEIGHT) - RQ_APPLICATION_TAB_BAR_HEIGHT - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT);
  63. }
  64. - (void)dealloc{
  65. //移除指定的通知,不然会造成内存泄露
  66. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"Tiku_Change" object:nil];
  67. }
  68. #pragma mark - PrivateMethods
  69. /// 初始化
  70. - (void)rq_setup {
  71. /// set up ...
  72. @weakify(self)
  73. [self.view addSubview:self.pagerView];
  74. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  75. @strongify(self)
  76. //头像
  77. CGFloat sBoader = (kNavBarHeight - 35)/2.0;
  78. UIButton *sideBtn = [[UIButton alloc] initWithFrame:CGRectMake(sBoader, kStatusHeight + sBoader, kNavBarHeight - sBoader*2, kNavBarHeight - sBoader*2)];
  79. [self.view addSubview:sideBtn];
  80. UIImageView *iv = [[UIImageView alloc] initWithFrame:sideBtn.bounds];
  81. [iv sd_setImageWithURL:[NSURL URLWithString:userModel.photo] placeholderImage:[UIImage imageNamed:@"头像"]];
  82. iv.contentMode = UIViewContentModeScaleAspectFill;
  83. [iv setBoardWid:1 Color:RQ_MAIN_COLOR CornerRadius:6];
  84. [iv setRound];
  85. [sideBtn addSubview:iv];
  86. [sideBtn addTarget:self action:@selector(showLeftViewAction) forControlEvents:UIControlEventTouchUpInside];
  87. UIBarButtonItem* bbi0 = [[UIBarButtonItem alloc] initWithCustomView:sideBtn];
  88. self.navigationItem.leftBarButtonItem = bbi0;
  89. }];
  90. if (myDelegate.isSyn) {
  91. myDelegate.isSyn = NO;
  92. if ([myDelegate.markQuestionTableData isKindOfClass:[NSMutableArray class]]) {
  93. if (myDelegate.markQuestionTableData.count == 0) {
  94. [DB_Que_Helper moveIsDoneToMarkQuestion];//移动已做题
  95. if (myDelegate.isLogin)//更新版本 先做一次同步
  96. {
  97. [self syncQuestion];
  98. }
  99. }
  100. }
  101. }
  102. //监听题库变化
  103. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationAction:) name:@"Tiku_Change" object:nil];
  104. // 注册手势驱动
  105. // __weak typeof(self)weakSelf = self;
  106. // [self cw_registerShowIntractiveWithEdgeGesture:YES transitionDirectionAutoBlock:^(CWDrawerTransitionDirection direction) {
  107. // if (direction == CWDrawerTransitionFromLeft) { // 左侧滑出
  108. // [weakSelf defaultAnimationFromLeft];
  109. // }
  110. // }];
  111. self.navigationItem.titleView = self.homePageTitleView;
  112. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  113. if (RQ_COMMON_MANAGER.JSJP_APP_JSQ_ICON_OPEN) {//广告(福袋)-是否开启
  114. self.homePageTitleView.chad_layout_W.constant = 25;
  115. [self.homePageTitleView layoutIfNeeded];
  116. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  117. [NY_AD_MANAGER loadAdWithPosid:@"50164389" customView:self.homePageTitleView.chadView];
  118. });
  119. }
  120. [self.homePageTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
  121. make.size.mas_equalTo(CGSizeMake(RQ_SCREEN_WIDTH / 3.f, RQ_APPLICATION_NAV_BAR_HEIGHT));
  122. }];
  123. //二维码扫描登录网页
  124. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"erWeiMa.png"] originImageScaleToSize:CGSizeMake(22.5, 22.5)] style:UIBarButtonItemStyleDone target:self action:@selector(clickToScan)];
  125. item.tintColor = RQ_MAIN_COLOR;
  126. if (RQ_USER_MANAGER.currentUser.city && ![RQ_USER_MANAGER.currentUser.city isEqualToString:@""] && [RQ_USER_MANAGER.currentUser.city isEqualToString:@""]) {
  127. }
  128. [RACObserve(RQ_USER_MANAGER, currentUser) subscribeNext:^(RQUserModel *userModel) {
  129. @strongify(self)
  130. if ([RQ_USER_MANAGER.currentUser.isOpenScan boolValue]) {
  131. [self.navigationItem setRightBarButtonItem:item];
  132. } else {
  133. self.navigationItem.rightBarButtonItems = @[];
  134. }
  135. }];
  136. [[[[RQNotificationCenter rac_addObserverForName:RQCarTypeChangeNotification object:nil] takeUntil:self.rac_willDeallocSignal] deliverOnMainThread] subscribeNext:^(NSNotification * _Nullable x) {
  137. @strongify(self)
  138. self.pagerView.defaultSelectedIndex = 0;
  139. self.categoryView.defaultSelectedIndex = 0;
  140. [self.pagerView reloadData];
  141. [self.categoryView reloadData];
  142. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  143. self.homePageTitleView.carTypeLabel.text = [RQ_YDTQuestion_Module getCarTypeCNNameWithCarType:RQ_YDTQuestion_Module.carType];
  144. }];
  145. [[[[RACObserve(RQ_COMMON_MANAGER, APP_SWITCH) distinctUntilChanged] deliverOnMainThread] takeUntil:self.rac_willDeallocSignal] subscribeNext:^(id _Nullable x) {
  146. @strongify(self)
  147. // self.pagerView.defaultSelectedIndex = 0;
  148. // self.categoryView.defaultSelectedIndex = 0;
  149. [self.pagerView reloadData];
  150. [self.categoryView reloadData];
  151. }];
  152. //投诉建议
  153. [self addFloatingSuggestView];
  154. // [[RACSignal combineLatest:@[RACObserve(RQ_VIP_Module, isVip), RACObserve(RQ_COMMON_MANAGER, APP_SWITCH)] reduce:^id (NSNumber *isVip, NSNumber *APP_SWITCH) {
  155. // if (RQ_VIP_Module.isVip && RQ_COMMON_MANAGER.APP_SWITCH) {
  156. // return @(NO);
  157. // } else {
  158. // return @(RQ_COMMON_MANAGER.APP_SWITCH);
  159. // }
  160. // }] subscribeNext:^(NSNumber *APP_SWITCH) {
  161. // if (APP_SWITCH.boolValue != RQ_COMMON_MANAGER.APP_SWITCH) {
  162. // RQ_COMMON_MANAGER.APP_SWITCH = NO;
  163. // }
  164. // }];
  165. }
  166. //添加到主窗口
  167. - (void)addFloatingSuggestView {
  168. NSInteger SP_COMPLAINT_DQBH = 0;
  169. for (ParamsItem *item in RQ_USER_MANAGER.currentUser.params) {
  170. if ([item.KEY isEqualToString:@"SP_COMPLAINT_DQBH"]) {
  171. SP_COMPLAINT_DQBH = [item.VALUE integerValue];
  172. }
  173. }
  174. if(SP_COMPLAINT_DQBH>0&&(SP_COMPLAINT_DQBH == [RQ_USER_MANAGER.currentUser.city intValue])){
  175. [self.view addSubview:self.floatingSuggestView];
  176. [self.floatingSuggestView mas_makeConstraints:^(MASConstraintMaker *make) {
  177. make.right.mas_equalTo(self.view).offset(-20.f);
  178. make.bottom.mas_equalTo(self.view).offset(-60.f);
  179. make.width.mas_equalTo(116.f);
  180. make.height.mas_equalTo(89.f);
  181. }];
  182. [self.floatingSuggestView bindViewModel:self.floatingSuggestViewModel];//绑定RAC
  183. }
  184. }
  185. - (void)notificationAction:(NSNotification *)notification{
  186. self.pagerView.defaultSelectedIndex = 0;
  187. self.categoryView.defaultSelectedIndex = 0;
  188. [self.pagerView reloadData];
  189. [self.categoryView reloadData];
  190. self.pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  191. if ([notification.userInfo[@"zhigezhengChanged"] isEqualToString:@"NO"]) {
  192. return;
  193. }
  194. }
  195. /**显示左边抽屉
  196. */
  197. - (void)showLeftViewAction {
  198. [self defaultAnimationFromLeft];
  199. }
  200. - (void)clickToScan {
  201. @weakify(self)
  202. if (RQ_USER_MANAGER.isShouldLogin) {
  203. [RQ_VIP_Module isActiveWithCcomplete:^(RQActivationModel * _Nullable activationModel, BOOL isSuccess) {
  204. @strongify(self)
  205. if (isSuccess) {
  206. if (activationModel.isShare) {
  207. if (activationModel.isActive == 1) {
  208. [self gotoPt];
  209. } else {
  210. [RQ_VIP_Module gotoVipViewWithDictType:RQ_USER_MANAGER.currentUser.city];
  211. }
  212. } else {
  213. [self gotoPt];
  214. }
  215. }
  216. }];
  217. }
  218. }
  219. - (void)gotoPt {
  220. @weakify(self)
  221. [QMUITips showLoadingInView:DefaultTipsParentView];
  222. RQQRCodeViewController *vc = [[RQQRCodeViewController alloc] init];
  223. vc.modalPresentationStyle = UIModalPresentationFullScreen;
  224. [vc initBlock:^(NSString * _Nonnull result, BOOL isSuccess) {
  225. if (isSuccess) {
  226. [RQ_PT_Object_Module uploadScanCodeVerifyWithQRCodeResultStr:result resultBlock:^(BOOL isSuccess) {
  227. }];
  228. } else {
  229. ShowMsg(result);
  230. }
  231. }];
  232. [LOCATION_MANAGER updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  233. @strongify(self)
  234. if (success) {
  235. if (RQ_USER_MANAGER.verifyLevel == 0) {
  236. [self presentViewController:vc animated:YES completion:^{
  237. [QMUITips hideAllTips];
  238. }];
  239. } else {
  240. if (bmkLocation.mockProbability <= RQ_USER_MANAGER.verifyLevel) {
  241. [self presentViewController:vc animated:YES completion:^{
  242. [QMUITips hideAllTips];
  243. }];
  244. } else {
  245. [RQ_SHARE_FUNCTION showAlertWithMessage:@"请勿篡改定位信息!" completion:^(NSUInteger selectedOtherButtonIndex) {
  246. [QMUITips hideAllTips];
  247. }];
  248. }
  249. }
  250. } else {
  251. [RQ_SHARE_FUNCTION showAlertWithMessage:@"定位失败!" completion:^(NSUInteger selectedOtherButtonIndex) {
  252. [QMUITips hideAllTips];
  253. }];
  254. }
  255. }];
  256. }
  257. - (void)getMyLocation {
  258. //定位功能
  259. [MBProgressHUD rq_showProgressHUD:@"正在获取当前位置..."];
  260. [[MapManager sharedManager] updateLocationWithCompleteBlock:^(BOOL success, CLLocation * _Nonnull location, BMKLocation * _Nullable bmkLocation) {
  261. [MBProgressHUD rq_hideHUD];
  262. if (success) {
  263. _myLocation = location.coordinate;
  264. [self studentQrcode];
  265. }
  266. }];
  267. }
  268. /** 扫描二维码调取接口 */
  269. - (void)studentQrcode {
  270. if (![Util connectedToNetWork]) {
  271. showMsgUnconnect();
  272. return;
  273. }
  274. if (_myLocation.longitude == 0.0) {
  275. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置获取失败,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  276. return;
  277. }
  278. NSMutableArray *arr=[NSMutableArray array];
  279. [arr addPro:@"studentOutid" Value:RQ_USER_MANAGER.currentUser.outId];
  280. [arr addPro:@"qrcode" Value:_scanData];
  281. [arr addPro:@"dqbh" Value:RQ_USER_MANAGER.currentUser.city];
  282. [arr addPro:@"lng" Value:[NSString stringWithFormat:@"%f",_myLocation.longitude]];
  283. [arr addPro:@"lat" Value:[NSString stringWithFormat:@"%f",_myLocation.latitude]];
  284. [arr addPro:@"type" Value:_scanType];
  285. [arr addPro:@"telType" Value:@"ios"];
  286. NSString *method = @"studentQrcode";
  287. NSString *str = [_scanType isEqualToString: @"1"] ? @"签到中...":@"签退中...";
  288. [MBProgressHUD rq_showProgressHUD:str];
  289. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary * root) {
  290. [MBProgressHUD rq_hideHUD];
  291. if (!root) {
  292. ShowMsg(@"操作失败,请重试!");
  293. [Tools playAudioWithString:@"操作失败,请重试!"];
  294. return;
  295. }
  296. if ([root[@"code"] integerValue] == 0) {//代表操作成功
  297. if ([_scanType isEqualToString:@"1"] || [_scanType isEqualToString:@"3"]) {
  298. myDelegate.trainStateLabel.text = @"理论学习中...";
  299. }
  300. if ([_scanType isEqualToString:@"2"]) {
  301. myDelegate.trainStateLabel.text = @"";
  302. }
  303. if (_isNeedTest) {
  304. switch ([_scanType integerValue]) { //1、签到 2、签退 3、过程验证
  305. case 1://签到成功
  306. if (_maxTime > 0) {
  307. [self setNotificationWithFireTime:_maxTime];
  308. }
  309. break;
  310. case 2://签退
  311. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  312. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  313. }
  314. break;
  315. case 3://验证成功
  316. if (_maxTime > 0) {
  317. [self setNotificationWithFireTime:_maxTime];
  318. }
  319. break;
  320. default:
  321. break;
  322. }
  323. }
  324. }
  325. if ([root[@"code"] integerValue] == 2) {//距离理论教室位置较远
  326. NSString *str = root[@"msg"];
  327. if (str.length < 1) {
  328. return;
  329. }
  330. NSArray *mapArray = [str componentsSeparatedByString:@";"];
  331. UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:[mapArray lastObject] preferredStyle:UIAlertControllerStyleAlert];
  332. [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleCancel handler:nil]];
  333. [alert addAction:[UIAlertAction actionWithTitle:@"查看位置详情" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
  334. //进入地图页面 传入两个点 一个距离 lng lat len
  335. if (mapArray.count > 3) {
  336. // lng = 123.467129,
  337. // lat = 41.813997
  338. //122.769684;41.515881;66822;您当前距离理论教室位置66822米,请到理论教室扫码!
  339. DistenceTooLongMapVC *mapVC = [[DistenceTooLongMapVC alloc] init];
  340. mapVC.lat1 = _myLocation.latitude;
  341. mapVC.lng1 = _myLocation.longitude;
  342. mapVC.lat2 = [mapArray[1] floatValue];
  343. mapVC.lng2 = [mapArray[0] floatValue];
  344. mapVC.distence = mapArray[2];
  345. mapVC.skipMspBlock = ^{
  346. _myLocation.longitude = 0.0;
  347. [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"位置已重置,请重新扫描二维码!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
  348. };
  349. [self navPushHideTabbarToVC:mapVC];
  350. }
  351. }]];
  352. [self presentViewController:alert animated:true completion:nil];
  353. return;
  354. }
  355. [Tools playAudioWithString:root[@"msg"]];
  356. ShowMsg(root[@"msg"]);
  357. }];
  358. }
  359. //语音播报或者推送
  360. - (void)setNotificationWithFireTime:(NSInteger)fireTime {
  361. //移除旧的通知
  362. if ([[[UIApplication sharedApplication] scheduledLocalNotifications] count] > 0) {
  363. [[UIApplication sharedApplication] cancelAllLocalNotifications];
  364. }
  365. //定义本地通知对象
  366. UILocalNotification *notification = [[UILocalNotification alloc]init];
  367. //设置调用时间
  368. notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:fireTime];
  369. //设置通知属性
  370. notification.alertBody = @"极速驾培提醒您"; //通知主体
  371. notification.applicationIconBadgeNumber = 1;//应用程序图标右上角显示的消息数
  372. notification.alertAction = @"打开应用"; //待机界面的滑动动作提示
  373. notification.soundName = @"TrainTest.mp3";//收到通知时播放的声音,默认消息声音
  374. // 通知参数
  375. NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:@"nothing",@"ShiCaoPeriodVC_reTakePhoto", nil];
  376. notification.userInfo = userDict;
  377. //调用通知
  378. [[UIApplication sharedApplication] scheduleLocalNotification:notification];
  379. }
  380. //更新第一次进入同步数据
  381. - (void)syncQuestion {
  382. if (![Util connectedToNetWork]) {
  383. return;
  384. }
  385. [self getMyQuestionType:@"" Subject:@""];
  386. }
  387. - (void)getMyQuestionType:(NSString*)type Subject:(NSString*)subject {
  388. NSMutableArray *arr = [NSMutableArray array];
  389. [arr addPro:@"user" Value:RQ_USER_MANAGER.currentUser._id];
  390. [arr addPro:@"type" Value:type];
  391. [arr addPro:@"subject" Value:subject];
  392. [arr addPro:@"carType" Value:RQ_YDTQuestion_Module.car_type];
  393. [arr addPro:@"isPage" Value:@"0"];
  394. [arr addPro:@"pageSize" Value:@"0"];
  395. [arr addPro:@"currentPage" Value:@"0"];
  396. NSString* method = @"getMyQuestionFavs";
  397. [MBProgressHUD rq_showProgressHUD:@"收藏、错题同步中,请稍后..."];
  398. [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
  399. //NSLog(@"同步错题收藏---->%@--->%@",arr,root);
  400. if (!root || [root[@"code"] integerValue] == 1) {
  401. [MBProgressHUD rq_hideHUD];
  402. ShowMsg(@"题库错题、收藏、排除同步失败,请在侧栏手动同步");
  403. return;
  404. }
  405. NSArray *body = [root objectForKey:@"body"];
  406. if (body.count > 0) {
  407. if ([DB_Que_Helper deleteAllMarkQuestion]) {
  408. [DB_Que_Helper setMarkQuestionWithArray:body];
  409. }
  410. }
  411. [MBProgressHUD rq_hideHUD];
  412. [MBProgressHUD rq_showTips:@"题库错题、收藏、排除已同步完毕"];
  413. }];
  414. }
  415. // 仿QQ从左侧划出
  416. - (void)defaultAnimationFromLeft {
  417. if (RQ_USER_MANAGER.isShouldLogin) {
  418. [RQ_APPDELEGATE.services pushViewModel:[[RQSettingViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil] animated:YES];
  419. }
  420. }
  421. #pragma mark - JXPagerViewDelegate
  422. - (UIView *)tableHeaderViewInPagerView:(JXPagerView *)pagerView {
  423. return [UIView new];
  424. }
  425. - (NSUInteger)tableHeaderViewHeightInPagerView:(JXPagerView *)pagerView {
  426. return 0.f;
  427. }
  428. - (NSUInteger)heightForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  429. return [RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"]? 0.f : 49.f;
  430. }
  431. - (UIView *)viewForPinSectionHeaderInPagerView:(JXPagerView *)pagerView {
  432. return self.categoryView;
  433. }
  434. - (NSInteger)numberOfListsInPagerView:(JXPagerView *)pagerView {
  435. //和categoryView的item数量一致
  436. return self.categoryView.titles.count;
  437. }
  438. - (id<JXPagerViewListViewDelegate>)pagerView:(JXPagerView *)pagerView initListAtIndex:(NSInteger)index {
  439. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  440. NSInteger myIndex = index;
  441. RQ_YDTQuestion_Module.subject = myIndex;
  442. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  443. RQHomePageSubjectOneOrFourViewModel *homePageSubjectFourViewModel = [[RQHomePageSubjectOneOrFourViewModel alloc] initWithServices:self.viewModel.services params:@{RQHomePageCarTypeKey : @(RQHomePageCarType_Car), RQHomePageSubjectTypeKey : @(myIndex)}];
  444. RQHomePageSubjectOneOrFourViewController *homePageSubjectFourViewController = [[RQHomePageSubjectOneOrFourViewController alloc] initWithViewModel:homePageSubjectFourViewModel];
  445. return homePageSubjectFourViewController;
  446. }
  447. #pragma mark - JXCategoryViewDelegate
  448. - (void)categoryView:(JXCategoryBaseView *)categoryView didSelectedItemAtIndex:(NSInteger)index {
  449. RQ_YDTQuestion_Module.subject = index;
  450. RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
  451. myDelegate.subject = [NSString stringWithFormat:@"%d",(int)index + 1];
  452. self.navigationController.interactivePopGestureRecognizer.enabled = (index == 0);
  453. }
  454. - (void)categoryView:(JXCategoryBaseView *)categoryView didClickSelectedItemAtIndex:(NSInteger)index {
  455. }
  456. - (void)categoryView:(JXCategoryBaseView *)categoryView didScrollSelectedItemAtIndex:(NSInteger)index {
  457. }
  458. - (void)categoryView:(JXCategoryBaseView *)categoryView scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio {
  459. // if (RQ_YDTQuestion_Module.subject == leftIndex) {
  460. // /// 向左滑 向右滚动
  461. // if (1.f - ratio > 0.7) {
  462. // RQ_YDTQuestion_Module.subject = rightIndex;
  463. // }
  464. // } else if (RQ_YDTQuestion_Module.subject == rightIndex) {
  465. // /// 向右滑 向左滚动
  466. // if (1.f - ratio > 0.3) {
  467. // RQ_YDTQuestion_Module.subject = leftIndex;
  468. // }
  469. // }
  470. }
  471. #pragma mark - JXPagerMainTableViewGestureDelegate
  472. - (BOOL)mainTableViewGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
  473. if ([self checkIsNestContentScrollView:(UIScrollView *)gestureRecognizer.view] || [self checkIsNestContentScrollView:(UIScrollView *)otherGestureRecognizer.view]) {
  474. //如果交互的是嵌套的contentScrollView,证明在左右滑动,就不允许同时响应
  475. return NO;
  476. }
  477. return [gestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]] && [otherGestureRecognizer isKindOfClass:[UIPanGestureRecognizer class]];
  478. }
  479. - (BOOL)checkIsNestContentScrollView:(UIScrollView *)scrollView {
  480. for (RQHomeSubPageViewController *list in self.pagerView.validListDict.allValues) {
  481. if (list.contentScrollView == scrollView) {
  482. return YES;
  483. }
  484. }
  485. return NO;
  486. }
  487. #pragma mark - SDCycleScrollViewDelegate
  488. - (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
  489. }
  490. #pragma mark - LazyLoad
  491. - (JXPagerView *)pagerView {
  492. if (!_pagerView) {
  493. _pagerView = [[JXPagerView alloc] initWithDelegate:self];
  494. _pagerView.mainTableView.gestureDelegate = self;
  495. _pagerView.defaultSelectedIndex = 0;
  496. _pagerView.mainTableView.bounces = NO;
  497. _pagerView.isListHorizontalScrollEnabled = ![RQ_YDTQuestion_Module.isZhiGeZheng isEqualToString:@"YES"];
  498. }
  499. return _pagerView;
  500. }
  501. - (JXCategoryTitleView *)categoryView {
  502. if (!_categoryView) {
  503. _categoryView = [[JXCategoryTitleView alloc] init];
  504. _categoryView.titles = self.titles;
  505. _categoryView.backgroundColor = [UIColor whiteColor];
  506. _categoryView.titleSelectedColor = RQ_MAIN_TEXT_COLOR_1;
  507. _categoryView.titleColor = RQ_MAIN_TEXT_COLOR_2;
  508. _categoryView.titleFont = RQRegularFont(17);
  509. _categoryView.titleSelectedFont = RQSemiboldFont(22);
  510. _categoryView.titleColorGradientEnabled = YES;
  511. _categoryView.titleLabelZoomEnabled = YES;
  512. _categoryView.contentScrollViewClickTransitionAnimationEnabled = YES;
  513. _categoryView.titleLabelZoomSelectedVerticalOffset = 0.0f;
  514. JXCategoryIndicatorLineView *lineView = [[JXCategoryIndicatorLineView alloc] init];
  515. lineView.indicatorColor = RQ_MAIN_COLOR;
  516. lineView.indicatorHeight = 4;
  517. lineView.verticalMargin = 0;
  518. _categoryView.indicators = @[lineView];
  519. _categoryView.defaultSelectedIndex = 0;
  520. _categoryView.listContainer = (id<JXCategoryViewListContainer>)self.pagerView.listContainerView;
  521. _categoryView.delegate = self;
  522. }
  523. return _categoryView;
  524. }
  525. - (NSArray<NSString *> *)titles {
  526. return @[@"科一", @"科二", @"科三", @"科四"];
  527. }
  528. - (RQHomePageTitleView *)homePageTitleView {
  529. if (!_homePageTitleView) {
  530. _homePageTitleView = [RQHomePageTitleView homePageTitleViewView];
  531. _homePageTitleView.frame = CGRectMake(0, 0, RQ_SCREEN_WIDTH / 3.f, RQ_APPLICATION_NAV_BAR_HEIGHT);
  532. }
  533. return _homePageTitleView;
  534. }
  535. - (NYFloatingSuggestViewModel *)floatingSuggestViewModel {
  536. if(!_floatingSuggestViewModel){
  537. _floatingSuggestViewModel = [[NYFloatingSuggestViewModel alloc] init];
  538. }
  539. return _floatingSuggestViewModel;
  540. }
  541. - (NYFloatingSuggestView *)floatingSuggestView {
  542. if (!_floatingSuggestView) {
  543. _floatingSuggestView = [NYFloatingSuggestView floatingSuggestView];
  544. }
  545. return _floatingSuggestView;
  546. }
  547. @end