1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499 |
- /**
- 先试一试循环滚动吧。
- */
- #import "ExerciseVC.h"
- #import "ExerView.h"
- #import "ExamResultVC.h"
- #import "Grade.h"
- #import "EXButton.h"
- #import "ExerciseSetting.h"
- #import "BtnCollectionViewCell.h"
- #import "ADLinkVC.h"
- #import "DES3Util.h"
- #import "ThirdLoginBindYunGuanVC.h"
- /**
- AlertTypeSubmit 提交
- AlertTypePause 暂停
- AlertTypeTimeOut 时间到
- */
- typedef NS_ENUM(NSInteger, AlertType){
- AlertTypeSubmit = 1,
- AlertTypePause,
- AlertTypeTimeOut,
- AlertTypeIsLoad,
- AlertTypeIsQuit
- };
- @interface ExerciseVC ()<UIScrollViewDelegate,ExerViewDelegate,UIAlertViewDelegate,UICollectionViewDelegateFlowLayout,UICollectionViewDataSource,UITextFieldDelegate>
- //@property(nonatomic,strong)UIToolbar* toolBar;
- {
- // ExerView* exerV;
- //我的错题
- NSArray* questions;
- //0 到 (cont-1)
- NSInteger qIndex;
-
- /**就是考试时,用来选择题号的view。在页面底部
- */
- UIView * contantV;
-
- STButton* bbi0,*bbi1,*bbi2,*bbi3,*bbi4;
-
- UIScrollView* scroll;
- /**保存scroll主页面。最后一次滚动的offset
- */
- CGPoint lastOffset;
-
- #define answersLen 4000
- #define correctLen 100
-
- //#define sub1Minutes 45
- //#define sub4Minutes 30
-
- /**最大的错误分数
- */
- //#define faultCntMaxSub1 11
- //#define faultCntMaxSub4 6
-
- // NSInteger faultCntMax;
-
- /**用于保存用户的答题情况,默认值是0表示没答题
- */
- int answers[answersLen];
- /**表示这题是否展开解释。0是不展开,1是展开。
- */
- int showAnsw[answersLen];
- /**表示这题是否正确。1未答题,2正确,0错误。
- */
- int correct[correctLen];
- /**保存做错的题目数量
- */
- int faultCnt,rigCnt;
-
- /**保存做错的分数
- */
- int faultMark;
- /**保存做对的分数
- */
- int correctMark;
-
- /**保存剩余的秒数。
- */
- int secCnt;
-
- /**考试计时用的.
- */
- // NSTimer *timer;
-
- /**保存这次考试的信息。
- */
- Grade *grade;
-
- /**保存各种考试成绩的称号。例如,赛车之神
- */
- NSArray *honors;
-
- /**选择题目序号,view
- */
- UIView *chooseView;
-
- UILabel *rigLbl,*errorLbl,*indexLbl,*barRigLbl,*barErrLbl;
-
- /**选择题号的按钮
- */
- NSMutableArray *choBtns;
-
- /**是否自动翻页
- */
- BOOL isSkip;
- /**是否自动显示答案
- */
- BOOL isExplain;
- /**声音模式
- */
-
- /// 是否继续考试
- BOOL isContinue;
-
- UIView *adView;
- UIButton *adBtn;
-
- NSDictionary *adDic;
-
-
- //学时相关
-
- UIView *rightView;//右侧视图
- UIView *show_hideView;//左侧详情栏
- UILabel *trainStateLabel;//右侧计时状态展示
- UILabel *timeLabel1;//右侧按钮上 显示时分
- UILabel *timeLabel2;//弹出View上 显示时分秒
- UIButton *begin_endBtn;//开始结束按钮
- UITextField *searchTf;//搜索题目框
- UIButton *sureBtn;//搜索确定按钮
-
-
- // NSInteger seconds;//时间
- NSDateFormatter *formatter;
- }
- /**科一45分钟100题。
- 科四45分钟50题。
- */
- @property (nonatomic, readwrite, assign) CGFloat adWidth;
- @property (nonatomic, readwrite, assign) CGFloat adHeight;
- @property (nonatomic, readwrite, strong) UIView *bannerView;
- @property (assign, readwrite, nonatomic) NSInteger seconds;
- @property (strong, readwrite, nonatomic) NSTimer *timer;
- //@property (strong, readwrite, nonatomic) UIButton *on_offBtn;
- @property (nonatomic, copy) NSString *secondString;
- @end
- @implementation ExerciseVC
- {
- NSMutableArray *navBtns;
- ExerciseSetting *setView;
- /**用于滚动的练习题的页面,总共3个
- */
- NSMutableArray *exVs;
- }
- #pragma mark -
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- RQ_COMMON_MANAGER.bannerOnVC = self;
- //关于模式选择
- [self loadQuestion];//==>设置qIndex 和 questions
- //通用导航栏
- [self configNavBar];
- //展示题目
- [self configExerV:NO];//==>setQueIndex
- //默认设置
- isSkip = YES;
- isExplain = YES;
- isContinue = NO;
- // //计时
- // [[RQ_HTTP_Service getIsUsePhone] subscribeNext:^(NSString *timeStr) {
- // if ([timeStr containsString:@"-"] || [timeStr containsString:@":"]) {
- // if ([timeStr componentsSeparatedByString:@"-"].firstObject.integerValue >= 2023) {
- // [self initTrainView];
- // }
- // }
- // } error:^(NSError * _Nullable error) {
- //// NSString *timeStr = @"2022-12-19 16:11:57";
- //
- // }];
-
- for (NSDictionary * dic in defUser.userDict[@"params"]) {
- if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) {
- BOOL isShow = [dic[@"VALUE"] boolValue];
- if (isShow) {
- // [self initTrainView];
- [self.view bringSubviewToFront:RQ_TIMING_VIEW];
- }
- }
- }
-
-
- }
- //页面将要进入前台,开启定时器
- -(void)viewWillAppear:(BOOL)animated
- {
- [super viewWillAppear:animated];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- //开启定时器
- [self.timer setFireDate:[NSDate distantPast]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
-
- } else {
- //开启定时器
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }
-
-
-
- if (!adView) {
- if (QuestionTypeExam != myDelegate.type.intValue) {
- [self creatADView];
- }
- }
- for (NSDictionary * dic in defUser.userDict[@"params"]) {
- if ([dic[@"KEY"] isEqualToString:@"SP_SHOW_YC"]) {
- BOOL isShow = [dic[@"VALUE"] boolValue];
- if (isShow) {
- RQ_TIMING_VIEW.hidden = NO;
- }
- }
- }
-
- }
- -(void)viewWillDisappear:(BOOL)animated
- {
- [super viewWillDisappear:animated];
- [self setNavBarNormalColor];
- RQ_TIMING_VIEW.hidden = YES;
- }
- //页面消失,进入后台不显示该页面,关闭定时器
- -(void)viewDidDisappear:(BOOL)animated
- {
- [super viewDidDisappear:animated];
- for (ExerView* v in exVs) {
- [v stopMovie];
- }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- //关闭定时器
- [self.timer setFireDate:[NSDate distantFuture]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
- } else {
- //关闭定时器
- [self.timer setFireDate:[NSDate distantFuture]];
- }
- }
-
-
- if (myDelegate.timer) {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
- }
- }
- - (void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- }
- - (void)dealloc {
-
- }
- #pragma mark -
- -(void)configButtomBar
- {
- if (QuestionTypeExam == myDelegate.type.intValue){
-
- CGFloat h = 40 , w = 60;
- CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
- CGFloat height = RQ_SCREEN_HEIGHT;
- CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT;
- UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h)];
- [self.view addSubview:buttomBar];
- [buttomBar setBackgroundColor:KlineColor];
-
- UILabel* label;
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w*2, h)];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:subTitleColor];
- NSInteger examQuestionCount = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam].count;
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if (1 == myDelegate.subject.intValue) {
- [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"];
- }else{
- [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"];
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [label setText:@"1/50"];
- } else {
- if (1 == myDelegate.subject.intValue) {
- [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : [defUser.car_type isEqualToString:@"D"]? @"1/50" : @"1/100"];
- }else{
- [label setText:examQuestionCount > 0? [NSString stringWithFormat:@"1/%ld",examQuestionCount] : @"1/50"];
- }
- }
- }
-
- [buttomBar addSubview:label];
- indexLbl = label;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - w, 0, w, h)];
- [label setFont:[UIFont scaleSize:13]];
- [label setTextColor:[UIColor redColor]];
- [buttomBar addSubview:label];
- barErrLbl = label;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(kSize.width - 2*w, 0, w, h)];
- [label setFont:[UIFont scaleSize:13]];
- [label setTextColor:defGreen];
- [buttomBar addSubview:label];
- barRigLbl = label;
-
- UIButton* btn = [[UIButton alloc] initWithFrame:buttomBar.bounds];
- [btn addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
-
- [buttomBar addSubview:btn];
-
-
- [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]];
- [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]];
- }else{
- // if (myDelegate.type.intValue != QuestionTypeRandom) {
-
- CGFloat h = 40;
- CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
- CGFloat height = RQ_SCREEN_HEIGHT;
- CGFloat buttomBarY = height - topHeight - h - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT;
- UIView *buttomBar = [[UIView alloc] initWithFrame:CGRectMake(0, buttomBarY, RQ_SCREEN_WIDTH, h + RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT)];
- [self.view addSubview:buttomBar];
- [buttomBar setBackgroundColor:backGroundColor];
-
- UILabel* label;
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, kSize.width/3, h)];
- [label setTextAlignment:NSTextAlignmentCenter];
- [label setTextColor:subTitleColor];
- [label setText:[NSString stringWithFormat:@"1/%d",(int)questions.count]];
- [buttomBar addSubview:label];
- indexLbl = label;
-
- // label = [[UILabel alloc] initWithFrame:CGRectMake(w*2, 0, kSize.width - w*2 - 20, h)];
- // [label setTextAlignment:NSTextAlignmentRight];
- // [label setTextColor:subTitleColor];
- // [label setText:[NSString stringWithFormat:@"点我选择题号哦!"]];
- // [buttomBar addSubview:label];
-
- NSArray *arr = @[@"",@"上一题",@"下一题"];
- CGFloat wid = kSize.width/4;
- for (int i=0; i<arr.count; i++) {
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
- if (i==0) {
- btn.frame = CGRectMake(0, 0, wid*2, h);
- }else{
- btn.frame = CGRectMake(wid*(i+1), 0, wid, h);
- }
- [btn setTitle:arr[i] textColor:subTitleColor font:NormalFont fotState:UIControlStateNormal];
- [btn addTarget:self action:@selector(buttomBarClick:) forControlEvents:UIControlEventTouchUpInside];
- btn.tag = 1000+i;
- [buttomBar addSubview:btn];
- // }
-
-
- }
- }
- }
- -(void)buttomBarClick:(UIButton *)sender
- {
- switch (sender.tag) {
- case 1000:
- [self showChooseView];
- break;
- case 1001:
- if (0 == qIndex) {
- [LoadingView showMsg:@"已经是第一道题了!"];
- return;
- }
- [self preExAction];
- break;
- case 1002:
- if(questions.count-1 == qIndex){
- [LoadingView showMsg:@"已经是最后一道题了!"];
- return;
- }
- [self nextExAction];
- break;
-
- default:
- break;
- }
-
- }
- -(void)configExerV:(BOOL)isLoad
- {
- [self.view setBackgroundColor:backGroundColor];
- if (questions.count < 1)
- {
- //这个地方判断下是题库没导进来 还是无错题、收藏、排除
- switch (myDelegate.type.integerValue) {
- case QuestionTypeFault:
- [LoadingView showMsg:@"您还没有错题!"];
- break;
- case QuestionTypeFavorite:
- [LoadingView showMsg:@"您还没有收藏的题目!"];
- break;
- case QuestionTypeUndo:
- [LoadingView showMsg:@"您还没有排除的题目!"];
- break;
- default:
- [LoadingView showMsg:@"暂未找到相关题目!"];
- break;
- }
- return;
- }
-
- //放置题目和选项的scroll
- CGFloat bottomheight = RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT + 40;
- CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
- CGFloat height = RQ_SCREEN_HEIGHT;
- CGFloat scrollHeight = height - topHeight - bottomheight;
- if (!scroll) {
- scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, RQ_SCREEN_WIDTH, scrollHeight)];//40 是bottombar 60是顶部隐藏的广告
- scroll.delegate = self;
- scroll.bounces = NO;
- scroll.showsHorizontalScrollIndicator = NO;
- [self.view addSubview:scroll];
-
- }
-
- //如果没值 要先设置一个默认值
- if (myDelegate.optionFont < 14 || myDelegate.optionFont > 28) {
- myDelegate.optionFont = 17;
- }
- exVs = [NSMutableArray array];
-
- for (int i =0; i<3; i++)
- {
- ExerView* exv = [[ExerView alloc] initWithFrame:CGRectMake(RQ_SCREEN_WIDTH * i, 0, RQ_SCREEN_WIDTH, scrollHeight)];//40 是bottombar 60是顶部隐藏的广告
- exv.index = i;
- exv.questions = questions;
- [scroll addSubview:exv];
- [exVs addObject:exv];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [exv setYdtQuestionModel:questions[0]];
- if ( i>1 && questions.count > 1)
- {
- [exv setYdtQuestionModel:questions[1]];
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [exv setQuestion:questions[0]];
- if ( i>1 && questions.count > 1)
- {
- [exv setQuestion:questions[1]];
- }
- } else {
- [exv setYdtQuestionModel:questions[0]];
- if ( i>1 && questions.count > 1)
- {
- [exv setYdtQuestionModel:questions[1]];
- }
- }
- }
-
- exv.delegate2 = self;
- }
-
- //夜间模式
- [self checkIsNightMode];
-
- int pageCnt = (int)questions.count;
-
- if (pageCnt >3)
- {
- pageCnt = 3;
- }
- [scroll setContentSize:CGSizeMake(RQ_SCREEN_WIDTH*pageCnt, 0)];
- [scroll setPagingEnabled:YES];
-
- [self setQueIndex];
- if (!isLoad) {//isload:yes改变字体进来的(无须括号内操作),no初始化
- [self configButtomBar];
- }
- }
- - (void)creatADView {
- @weakify(self)
- //获取广告总数量 取一个随机数
- NSMutableArray *newAD = [NSMutableArray array];
- for (NSDictionary *dic in myDelegate.adArray) {
-
- if ([dic[@"LOCATION"] isEqualToString:@"3"]) {
- [newAD addObject:dic];
- }
- }
- CGFloat topHeight = RQ_APPLICATION_TOP_BAR_HEIGHT;
- CGFloat height = RQ_SCREEN_HEIGHT;
- adView = [[UIView alloc] initWithFrame:CGRectMake(0, height - topHeight - RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - self.adHeight, self.adWidth, self.adHeight)];
- [self.view addSubview:adView];
-
- [adView mas_remakeConstraints:^(MASConstraintMaker *make) {
- @strongify(self)
- make.left.mas_equalTo(self.view).mas_offset(0);
- make.bottom.mas_equalTo(self.view).mas_offset(- RQ_APPLICATION_SAFEAREA_BOTTOM_HEIGHT - 40 - 8);
- make.size.mas_equalTo(CGSizeMake(self.adWidth, self.adHeight));
- }];
-
- UIImageView *adImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.adWidth, self.adHeight)];
- adImg.layer.cornerRadius = 0;
- adImg.contentMode = UIViewContentModeScaleAspectFill;
- [adImg setClipsToBounds:YES];
- [adView addSubview:adImg];
-
- adBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- adBtn.frame = CGRectMake(adView.frame.size.width - 40, 5, 30, 30);
- [adBtn setImage:[[UIImage imageNamed:@"community6"] tint:[UIColor redColor]] forState:UIControlStateNormal];
- [adBtn borderColor:[UIColor redColor] width:2 cornorRadios:15];
- [adBtn addTarget:self action:@selector(removeRandomAD) forControlEvents:UIControlEventTouchUpInside];
- [adView addSubview:adBtn];
-
- if (newAD.count < 1) {
- [adImg setImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
- }else{
-
- NSInteger rendomIndex = arc4random()%newAD.count;
- NSDictionary *dic = newAD[rendomIndex];
- adDic = [NSDictionary dictionaryWithDictionary:dic];
- NSString *path = dic[@"IMG"];
- [adImg sd_setImageWithURL:[NSURL URLWithString:path] placeholderImage:[UIImage imageNamed:@"subject_main_banner.jpg"]];
-
- //把手势添加到指定视图上
- [adImg setUserInteractionEnabled:YES];
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(skipToADLink:)];
- [adImg addGestureRecognizer:tapGesture];
- }
-
- // if (scroll.y < 10.0) {
- // scroll.y = adView.height;
- // }
- adView.hidden = NO;
- BOOL isShow1;
- BOOL isShow2;
-
-
- NSInteger begin1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].firstObject.integerValue? : 23;
- NSInteger end1 = [RQ_COMMON_MANAGER.YYXC_AD_TIME1 componentsSeparatedByString:@"-"].lastObject.integerValue? :24;
- NSInteger begin2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].firstObject.integerValue? : 0;
- NSInteger end2 = [RQ_COMMON_MANAGER.YYXC_AD_TIME2 componentsSeparatedByString:@"-"].lastObject.integerValue? : 6;
-
- isShow1 = [NSDate isBetweenFromHour:begin1 toHour:end1];
- isShow2 = [NSDate isBetweenFromHour:begin2 toHour:end2];
-
- if (RQ_COMMON_MANAGER.YYXC_AD_OPEN) {
- if (RQ_COMMON_MANAGER.YYXC_BANNER_AD_OPEN) {
- if (isShow1 || isShow2) {
- [self loadAdAndShow];
- }
- }
- }
-
- }
- - (void)loadAdAndShow {
- @weakify(self)
- [adView addSubview:self.bannerView];
- [RQ_AD_MODULE loadAdWithAdType:GromoreAdTypeBanner customView:self.bannerView];
- [RQ_AD_MODULE initADStatusChangeBlock:^(GromoreAdType adType, RQADDoType adDoType) {
- @strongify(self)
- if (adType == GromoreAdTypeBanner) {
- if (adDoType == RQADDoType_Close) {
- [self removeRandomAD];
- } else if (adDoType == RQADDoType_Success) {
- [adView bringSubviewToFront:adBtn];
- }
- }
- }];
- }
- - (void)removeAd:(id)sender {
- [RQ_AD_MODULE closeAdWithAdType:GromoreAdTypeBanner];
- [self.bannerView removeFromSuperview];
- self.bannerView = nil;
- }
- -(void)skipToADLink:(UITapGestureRecognizer *)gesture
- {
- //1是程序内 2是程序外
- NSString *skipType = adDic[@"OPENTYPE"];
-
- if ([skipType isEqualToString:@"1"]) {
-
- ADLinkVC *ad = [[ADLinkVC alloc] init];
- ad.title = adDic[@"TITLE"];
- ad.urlString = adDic[@"URL"];
- if (ad.urlString && ad.urlString.length != 0) {
- [self navPushHideTabbarToVC:ad];
- }
-
- }else{
-
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:adDic[@"URL"]]];
- }
- }
- /**0,16,32,64,128
- 这里还要告诉是否答题正确,如果正确,自动翻页。否则显示正确答案。
- */
- -(void)didChooseOption:(NSInteger)opt isRight:(BOOL)isRig
- {
- @weakify(self)
- CGPoint off = scroll.contentOffset;
-
- Question* q = questions[qIndex];
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [RQ_YDT_USER_Question_Module doQuestionWithID:ydtQuestionModel.ID myAnswer:(ydtQuestionModel.Type == 3)? opt : opt/10000 trueAnswer:ydtQuestionModel.AnswerTrue.integerValue carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential];
- } else {
- //标记做过的题
- if ([defUser.car_type isEqualToString:@"2"]) {
- [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1];
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [RQ_YDT_USER_Question_Module doQuestionWithID:ydtQuestionModel.ID myAnswer:(ydtQuestionModel.Type == 3)? opt : opt/10000 trueAnswer:ydtQuestionModel.AnswerTrue.integerValue carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject exerciseType:RQExerciseType_Sequential];
- }
- }
- // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"4" State:1];
-
-
-
-
- //计算分数
- int mark = 1;//每题的分值
- if ([defUser.car_type isEqualToString:@"1"] || [defUser.car_type isEqualToString:@"5"] || [defUser.car_type isEqualToString:@"6"]) {
- Question *q = questions[qIndex];
- //q.option_type 0判断 1单选 2多选
- if ([q.option_type intValue] == 2) {
- mark = 2;
- }else {
- mark = 1;
- }
- } else if ([defUser.car_type isEqualToString:@"2"]) {
- mark = 2;
- }else if ([defUser.car_type isEqualToString:@"3"] || [defUser.car_type isEqualToString:@"4"]) {
- mark = 1;
- }else if([defUser.car_type isEqualToString:@"D"]) {
- mark = 2;
- }else {
- if ([myDelegate.subject isEqualToString:@"1"]) {//C1 A1 A2 科一一题一分
- mark = 1;
- }else {//C1 A1 A2 科四一题两分
- mark = 2;
- }
- }
-
- if (isRig) {
- correctMark += mark;
- }else {
- faultMark += mark;
- }
-
-
- //记录做题状态
- if (qIndex < answersLen) {
- answers[qIndex] = (int)opt;
- }
-
- if (isRig)
- {
- if (qIndex < correctLen ) {
- correct[qIndex] = CorrectTypeRignt;
- rigCnt ++;
- }
- //判断是否自动翻页
- if (!isSkip)
- {
- if (!isExplain) {
- return;
- }
- /**非考试模式答对了在不自动翻页模式下就展示答案 不知道这样行不行--对之前用户反映的回馈
- */
- if(QuestionTypeExam != myDelegate.type.intValue) {
- showAnsw[qIndex] = YES;
- [self setShowAnsw];
- }
- return;
- }
- /**已经到最后一题了。
- */
- if (qIndex >= questions.count -1) {
- [LoadingView showMsg:@"做完了!请交卷!"];
- //这一句修复错题模式下 做完左后一题 数据库以及网络都没有请求的问题 修复1.0.2BUG
- [self faultExAction:isRig];
- return;
- }
- [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{
- [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)];
- } completion:^(BOOL finished) {
- @strongify(self)
- [self nextExAction];
- lastOffset = scroll.contentOffset;
- }];
- }
- else
- {
- if (qIndex < correctLen)
- {
- faultCnt++;
- correct[qIndex] = CorrectTypeFault;
- }
- //如果是考试模式 要自动翻页
- if (QuestionTypeExam == myDelegate.type.intValue)
- {
- /**已经到最后一题了
- */
- if (qIndex >= questions.count -1) {
- UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"考题已全部做完,考试结束" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
- [self isUploadGrade];
- return;
- }
- [UIView animateWithDuration:.5 delay:.3 options:0 animations:^{
- [scroll setContentOffset:CGPointMake(off.x + kSize.width, off.y)];
- } completion:^(BOOL finished) {
- @strongify(self)
- [self nextExAction];
- lastOffset = scroll.contentOffset;
- }];
- }
- //考试模式中 错太多自动结束
- if (QuestionTypeExam == myDelegate.type.intValue && faultMark > _loseMark && !isContinue)
- {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- if (myDelegate.timer) {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
-
- if (self.seconds < 60) {
- ShowMsg(@"学时未满一分钟不统计");
- [self isUploadGrade];
- return;
- }
- [self saveTrain];
- [self upLoadTrainRecord];
- }
-
- [self isUploadGrade];
- }];
-
- [alert addAction:saveAction];
-
- [self presentViewController:alert animated:YES completion:nil];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试失败!",faultMark,_loseMark];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"重新开始" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- [self.navigationController popViewControllerAnimated:NO];
- }];
-
- UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:@"继续考试" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- isContinue = YES;
- }];
-
- [alert addAction:saveAction];
- [alert addAction:cancleAction];
- [self presentViewController:alert animated:YES completion:nil];
- } else {
- NSString *msg = [NSString stringWithFormat: @"本次考试做错%d分,超过%d分,考试结束!",faultMark,_loseMark];
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:msg preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- if (myDelegate.timer) {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
-
- if (self.seconds < 60) {
- ShowMsg(@"学时未满一分钟不统计");
- [self isUploadGrade];
- return;
- }
- [self saveTrain];
- [self upLoadTrainRecord];
- }
-
- [self isUploadGrade];
- }];
-
- [alert addAction:saveAction];
-
- [self presentViewController:alert animated:YES completion:nil];
- }
- }
-
-
-
- }
- //判断 答错是否自动展示答案
- if (!isExplain)
- {
- return;
- }
- /**非考试模式答错了就展示答案
- */
- if(QuestionTypeExam != myDelegate.type.intValue)
- {
- showAnsw[qIndex] = YES;
- [self setShowAnsw];
- //[v setShowAnswer:YES];
- }
- }
- [barRigLbl setText:[NSString stringWithFormat:@"对 %d",rigCnt]];
- [barErrLbl setText:[NSString stringWithFormat:@"错 %d",faultCnt]];
-
- //根据原本状态和本次对错判定现在是否移除状态
- [self faultExAction:isRig];
-
- }
- /**做章节练习,可以把listView加入进来。
- **在listView里面设置好where。这里换成present好了。每次willAppear的时候,看是否已经选好了。
- 如果选好了。直接dismiss。
- */
- -(void)loadQuestion
- {
- @weakify(self)
- qIndex = 0;
-
- NSString* sql = [NSString string];//QuestionTypeOrdered QuestionTypeRecite QuestionTypeChapt QuestionTypeFault QuestionTypeStrenth QuestionTypeUndo
-
- NSInteger lastQid = 0;
-
- switch (myDelegate.type.intValue) {
- //顺序模式
- case QuestionTypeOrdered:
- {
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Sequential]);//除去排除的所有当前学科当前车型的题目
- //@"C1",@"A2",@"A1",@"D",@"4",@"1",@"2",@"3",@"5" defUser.car_type
-
- if ([defUser.car_type isEqualToString:@"4"]) {
- qIndex = defUser.coachIndex.intValue;
- lastQid = qIndex;
- }
- if ([defUser.car_type isEqualToString:@"1"]) {
- qIndex = defUser.A1Index.intValue;
- lastQid = qIndex;
- }
- if ([defUser.car_type isEqualToString:@"2"]) {
- qIndex = defUser.A2Index.intValue;
- lastQid = qIndex;
- }
- if ([defUser.car_type isEqualToString:@"3"]) {
- qIndex = defUser.dangerIndex.intValue;
- lastQid = qIndex;
- }
- if ([defUser.car_type isEqualToString:@"5"]) {
- qIndex = defUser.texiIndex.intValue;
- lastQid = qIndex;
- }
- if ([defUser.car_type isEqualToString:@"6"]) {
- qIndex = defUser.wycIndex.intValue;
- lastQid = qIndex;
- }
-
- if ([defUser.car_type isEqualToString:@"C1"]) {
- if (myDelegate.subject.intValue == 1) {
- qIndex = defUser.userSubj1Index.intValue;
- lastQid = qIndex;
- }else{
- qIndex = defUser.userSubj4Index.intValue;
- lastQid = qIndex;
- }
- }
-
- if ([defUser.car_type isEqualToString:@"A2"]) {
- if (myDelegate.subject.intValue == 1) {
- qIndex = defUser.A2Subj1Index.intValue;
- lastQid = qIndex;
- }else{
- qIndex = defUser.A2Subj4Index.intValue;
- lastQid = qIndex;
- }
- }
-
- if ([defUser.car_type isEqualToString:@"A1"]) {
- if (myDelegate.subject.intValue == 1) {
- qIndex = defUser.A1Subj1Index.intValue;
- lastQid = qIndex;
- }else{
- qIndex = defUser.A1Subj4Index.intValue;
- lastQid = qIndex;
- }
- }
-
- if ([defUser.car_type isEqualToString:@"D"]) {
- if (myDelegate.subject.intValue == 1) {
- qIndex = defUser.DSubj1Index.intValue;
- lastQid = qIndex;
- }else{
- qIndex = defUser.DSubj4Index.intValue;
- lastQid = qIndex;
- }
- }
-
-
- if (qIndex > questions.count-1) {
- qIndex = 0;
- }
- // 查找缺失那些数据库图片
- // {
- // questions=[DB_Que_Helper queryQuestion:@"zhaobucunzai"];
- //
- // NSLog(@"----><>%d",(int)questions.count);
- //
- // NSMutableArray *imgString = [NSMutableArray array];
- // for (Question *q in questions) {
- //
- // UIImage *img = [UIImage imageNamed:q.media];
- // if (!img) {
- // [imgString addObject:q.media];
- // }
- // }
- // NSLog(@"imgString----><>%@",imgString);
- // }
- }
- break;
- //背题模式
- case QuestionTypeRecite:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Recitation] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Recitation]);//除去排除的所有当前学科当前车型的题目
-
- if (myDelegate.subject.intValue == 1) {
- qIndex = defUser.user1Index.intValue;
- lastQid = qIndex;
- }else{
- qIndex = defUser.user4Index.intValue;
- lastQid = qIndex;
- }
- if (qIndex > questions.count-1) {
- qIndex = 0;
- }
- break;
- //随机模式
- case QuestionTypeRandom:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Random] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"5"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Random]);//除去排除的所有当前学科当前车型的题目
-
-
- if (questions && questions.count < 1)
- {
- return;
- }
- // qIndex = arc4random()%(questions.count - 1);
- break;
- //章节模式 章节模式 还用之前的方式 里边不涉及错题排错题的查询
- case QuestionTypeChapt: {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- sql=[NSString stringWithFormat:@"%@",myDelegate.where];
- questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYQuestion:sql];
- } else {
- // sql=[NSString stringWithFormat:@"subject = '%@' and %@",myDelegate.subject,myDelegate.where];
- questions=[RQ_YDTQuestion_Module getChapterQuestionWithChapterName:self.chapterName];
- }
- }
- break;
- }
- //强化练习 强化练习 还用之前的方式 里边不涉及错题排错题的查询
- case QuestionTypeStrenth:
- // sql=[NSString stringWithFormat:@"strong"];
- // questions=[DB_Que_Helper queryQuestion:sql];
- questions = [RQ_YDTQuestion_Module getPointQuestionWithPointID:self.pointId];
- break;
- //我的错题
- case QuestionTypeFault:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"1"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong]);//所有当前学科当前车型的错题
- //NSLog(@"错题count = %d",(int)questions.count);
- break;
- //排除的题
- case QuestionTypeUndo:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Remove] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"3"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Remove]);//所有当前学科当前车型的排错题
- //NSLog(@"排除count ==== %d",(int)questions.count);
- break;
- //我的收藏
- case QuestionTypeFavorite:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"2"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Collect]);//所有当前学科当前车型的收藏题
- //NSLog(@"收藏count = %d",(int)questions.count);
- break;
- //模拟考试
- case QuestionTypeExam:
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- questions = [DB_Que_Helper queryGZPZ_EXAM_CYRYExamQuestion];
- } else {
- questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Exam];
- }
- }
- // NSLog(@"examCount = %d",(int)questions.count);
- break;
- //未做题
- case QuestionTypeNotDo:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo] : ([defUser.car_type isEqualToString:@"2"]? [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithType:@"4"] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_UnDo]);
- // NSLog(@"未做count = %d",(int)questions.count);
- break;
- case QuestionTypeNewRule:
- questions = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule] : ([defUser.car_type isEqualToString:@"2"]? @[] : [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_NewRule]);
- break;
- case QuestionTypeMiOne:
- questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_One];
- break;
- case QuestionTypeMiTwo:
- questions = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Mi_Two];
- break;
-
- default:
- break;
- }
-
- if (lastQid != 0) {
-
- UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:@"您上次已练习到%d题,是否继续答题",(int)lastQid + 1] delegate:self cancelButtonTitle:@"是" otherButtonTitles:@"否", nil];
-
- alert.tag = 100;
- [alert show];
- }else {
- //如果这个提示没有 就去看是否有未上传学时
- NSString *pxkm = defUser.userDict[@"pxjd"];
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
- NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm];
- if (array.count > 0 && defUser.isycbd != 1) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- [self upLoadTrainRecord];
- }];
- [alert addAction:saveAction];
-
- [self presentViewController:alert animated:YES completion:nil];
- }
- }
-
- for(int i = 0;i<answersLen;i++)
- {
- answers[i] = 0;
- showAnsw[i]= 0;
- if (i< correctLen)
- {
- correct[i] = CorrectTypeUndo;
- }
- }
- faultCnt = 0;
- faultMark = 0;
- correctMark = 0;
- secCnt = _testTime*60;
-
- if (QuestionTypeExam == myDelegate.type.intValue) {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
- } else {
- self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
- }
- }
-
-
- //每1秒运行一次function方法。
-
- grade = [[Grade alloc] init];
-
- NSDateFormatter *dateFormatter = [NSDateFormatter rq_defaultDateFormatter];
- grade.startDate = [dateFormatter stringFromDate:[NSDate date]];
- }
- }
- -(void)configNavBar
- {
- //通用导航栏设置
- UIBarButtonItem* backBbi = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"question_pre_checked_icon.png"] style:UIBarButtonItemStylePlain target:self action:@selector(goBackByNavigation)];
- [backBbi setTintColor:defGreen];
- [self.navigationItem setLeftBarButtonItem:backBbi];
- self.navigationController.navigationBar.translucent = NO;
-
-
- navBtns = [NSMutableArray array];
-
- NSArray* titles1;
- NSArray* titles2;
- NSArray* imagesN;
- NSArray* imagesS;
- if (myDelegate.type.intValue == QuestionTypeExam)
- {
- titles1 = @[@"00/0000",@"收藏本题",@"交卷",@"设置"];
- titles2 = @[@"00/0000",@"取消收藏",@"交卷",@"设置"];
- //最后一张图是title_setting_ico.png。 但是60X60尺寸太大。无法显示
- imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top3",@"exerise_top5.png"];
- imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_topH3",@"exerise_top5.png"];
- }
- else if(myDelegate.type.intValue == QuestionTypeRecite){
- titles1 = @[@"00/0000",@"收藏本题",@"设置"];
- titles2 = @[@"00/0000",@"取消收藏",@"设置"];
-
- imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top5.png"];
- imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_top5.png"];
- }
- else
- {
- titles1 = @[@"00/0000",@"收藏本题",@"排除本题",@"展开解释",@"设置"];
- titles2 = @[@"00/0000",@"取消收藏",@"取消排除",@"收起解释",@"设置"];
-
- imagesN = @[@"exerise_top1",@"exerise_top2",@"exerise_top3",@"exerise_top4",@"exerise_top5.png"];
- imagesS = @[@"exerise_topH1",@"exerise_topH2",@"exerise_topH3",@"exerise_topH4",@"exerise_top5.png"];
- }
-
- CGFloat barBtnH = self.navigationController.navigationBar.frame.size.height;
- CGFloat barBtnW = kSize.width / (titles1.count + 3);
- for (int i = 0; i < titles1.count && i< titles2.count; i++) {
- STButton* btn = [[STButton alloc] initWithFrame:CGRectMake(0, 0, barBtnW, barBtnH) ];
- if (IOS11) {
- NSLayoutConstraint *widthConstraint = [btn.widthAnchor constraintEqualToConstant:barBtnW];
- NSLayoutConstraint *heightConstraint = [btn.heightAnchor constraintEqualToConstant:barBtnH];
- [heightConstraint setActive:YES];
- [widthConstraint setActive:YES];
-
- }
- [btn setImage:[UIImage imageNamed:imagesN[i]] withTitle:titles1[i] Font:SmallFont forState:UIControlStateNormal];
- [btn setImage:[UIImage imageNamed:imagesS[i]] withTitle:titles2[i] Font:SmallFont forState:UIControlStateSelected];
- [btn setTitleColor:subTitleColor forState:UIControlStateNormal];
- [btn setTitleColor:defGreen forState:UIControlStateHighlighted];
- [btn setTitleColor:defGreen forState:UIControlStateSelected];
- [btn setTag:i];
- [navBtns addObject:btn];
- }
- [[navBtns lastObject] setImage:[[UIImage imageNamed:[imagesS lastObject]] tint:[UIColor colorWithWhite:135.0/255 alpha:1]] forState:UIControlStateNormal];
-
- /**这里要倒序加入。
- */
- NSMutableArray* bbiArr = [NSMutableArray array];
- for (int i = (int)titles1.count - 1 ; i>=0; i--) {
- STButton* btn = navBtns[i];
- UIBarButtonItem* bbi = [[UIBarButtonItem alloc] initWithCustomView:btn];
- [bbiArr addObject:bbi];
- }
- self.navigationItem.rightBarButtonItems = bbiArr;
-
- if (QuestionTypeExam == myDelegate.type.intValue)
- {
- [navBtns[0] addTarget:self action:@selector(pauseExamAction) forControlEvents:UIControlEventTouchUpInside];
- [navBtns[2] addTarget:self action:@selector(submitExam) forControlEvents:UIControlEventTouchUpInside];
- }else if (myDelegate.type.intValue == QuestionTypeRecite) {
-
- [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
- }else{
-
- [navBtns[0] addTarget:self action:@selector(showChooseView) forControlEvents:UIControlEventTouchUpInside];
- [navBtns[2] addTarget:self action:@selector(moveExAction) forControlEvents:UIControlEventTouchUpInside];
- [navBtns[3] addTarget:self action:@selector(showAnswAction) forControlEvents:UIControlEventTouchUpInside];
- }
- [navBtns[1] addTarget:self action:@selector(favAction) forControlEvents:UIControlEventTouchUpInside];
- [[navBtns lastObject] addTarget:self action:@selector(settingBtn:) forControlEvents:UIControlEventTouchUpInside];
-
- //除了随机 都要有
- if (QuestionTypeRandom == myDelegate.type.intValue) {
- return;
- }
-
- chooseView = [[UIView alloc] initWithFrame:kFrame];
- [chooseView setBackgroundColor:[UIColor colorWithWhite:.3 alpha:.3]];
- contantV = [[UIView alloc] initWithFrame:CGRectMake(0, 100, kSize.width, kSize.height-100-kSafeAreaBottomHeight)];
- [chooseView addSubview:contantV];
- [contantV setBackgroundColor:[UIColor whiteColor]];
-
- CGFloat x,y,wid,hei,bd;
-
- bd = 5;
- wid = hei = 40;
- x = kSize.width - wid - bd;
- y = bd;
- EXButton* btnn = [[EXButton alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
- [btnn addTarget:self action:@selector(hideChooseView) forControlEvents:UIControlEventTouchUpInside];
- [btnn setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor grayColor]] forState:UIControlStateNormal];
- [btnn setTitle:@"×" textColor:[UIColor whiteColor] font:30 fotState:UIControlStateNormal];
- [contantV addSubview:btnn];
-
- x = 20;
- wid = kSize.width-x-wid-bd-120;
- UITextField*tf = [[UITextField alloc]initWithFrame:CGRectMake(x, y, wid, hei)];
- searchTf = tf;
- tf.delegate = self;
- tf.layer.masksToBounds = YES;
- tf.layer.cornerRadius = 5;
- tf.layer.borderWidth = 1;
- tf.layer.borderColor = [UIColor lightGrayColor].CGColor;
- tf.placeholder = @"请输入题号";
- tf.textAlignment = NSTextAlignmentCenter;
- tf.keyboardType = UIKeyboardTypeNumberPad;
- tf.clearsOnBeginEditing = YES;
- [contantV addSubview:tf];
-
- x += wid;
- wid = 80;
- UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeSystem];
- sureBtn = searchBtn;
- searchBtn.frame = CGRectMake(x, y, wid, hei);
- [searchBtn setTitle:@"确定" textColor:defGreen font:NormalFont fotState:UIControlStateNormal];
- searchBtn.titleLabel.font = [UIFont systemFontOfSize:Font17];
- [searchBtn addTarget:self action:@selector(searchQuestion) forControlEvents:UIControlEventTouchUpInside];
- [contantV addSubview:searchBtn];
-
- x = 20;
- wid = 60;
- UILabel* label;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
- [label setText:@"text"];
- [label setTextColor:defGreen];
- [contantV addSubview:label];
- rigLbl = label;
-
- x += wid + bd;
- label = [[UILabel alloc] initWithFrame:CGRectMake(x, y, wid, hei)];
- [label setText:@"text"];
- [label setTextColor:[UIColor orangeColor]];
- [contantV addSubview:label];
- errorLbl = label;
-
- /**表示按钮的最小间距 可以做一个按钮的重用机制 不然 一千多个 很耗性能
- */
- y += hei + bd + bd;
- //用collection吧 自带缓存机制
- CGFloat width = (kSize.width - 60)/5.0;
-
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
-
- [layout setItemSize:CGSizeMake(width, width)];
- [layout setSectionInset:UIEdgeInsetsMake(0, 20, 20, 20)];
-
- UICollectionView *btnCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(0, y, kSize.width, contantV.height - y) collectionViewLayout:layout];
-
- btnCollection.backgroundColor = [UIColor whiteColor];
- btnCollection.delegate = self;
- btnCollection.dataSource = self;
- [contantV addSubview:btnCollection];
- [btnCollection registerClass:[BtnCollectionViewCell class] forCellWithReuseIdentifier:@"btn"];
- }
- -(void)goBackByNavigation{
- @weakify(self)
- if (myDelegate.type.intValue == QuestionTypeExam)
- {
- // UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" delegate:self cancelButtonTitle:@"退出" otherButtonTitles:@"取消", nil];
- // alert.tag = AlertTypeIsQuit;
- // [alert show];
-
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"退出后将不保存本次记录,是否继续退出?" confirmTitle:@"退出" cancelTitle:@"取消" confirmAction:^{
- @strongify(self)
- if (myDelegate.isUseriPhone) {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
-
- if (self.seconds < 60) {
- ShowMsg(@"学时未满一分钟不统计");
- return;
- }
- [self saveTrain];
- [self upLoadTrainRecord];
- }
-
- [self.view endEditing:1];
- [self.navigationController popToRootViewControllerAnimated:YES];
- } cancelAction:^{
-
- }];
- }else{
-
- if (myDelegate.timer) {
-
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"退出当前页面将结束理论计时,是否继续退出?" preferredStyle:UIAlertControllerStyleAlert];
-
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"退出" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- if (defUser.isycbd == 1) {
- [RQ_TIMING_VIEW stopTimingWithResultBlock:^(BOOL isSuccessed) {
- if (isSuccessed) {
- [RQ_TIMING_VIEW endTiming];
- }
- }];
- } else {
- [RQ_TIMING_VIEW stopTiming];
- }
- // [myDelegate.timer invalidate];
- // myDelegate.timer = nil;
- //
- //
- // if (self.seconds < 60) {
- // ShowMsg(@"学时未满一分钟不统计");
- // return;
- // }
- // [self saveTrain];
- // [self upLoadTrainRecord];
-
- [self.view endEditing:1];
- [self.navigationController popViewControllerAnimated:YES];
- }];
-
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
-
- [alert addAction:saveAction];
- [alert addAction:cancelAction];
-
- [self presentViewController:alert animated:YES completion:nil];
- }else {
- [self.view endEditing:1];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
- }
- - (void)initTrainView {
-
- UIView *view = [[UIView alloc] initWithFrame:CGRectMake(kSize.width - 50, kSize.height - 350 - kSafeAreaBottomHeight, 60, 100)];
- view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44];
- view.layer.masksToBounds = YES;
- view.layer.cornerRadius = 10;
- [self.view addSubview:view];
- rightView = view;
-
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 10, 50, 30)];
- label.backgroundColor = [UIColor clearColor];
- [label setText:@"00:00" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
- [rightView addSubview:label];
- timeLabel1 = label;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, 40, 50, 60)];
- label.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.5];
- [label setText:@"点击\n计时" Font:NormalFont TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
- label.numberOfLines = 0;
- [rightView addSubview:label];
- trainStateLabel = label;
- UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 60, 100)];
- btn.backgroundColor = [UIColor clearColor];
- [btn addTarget:self action:@selector(showOrHide:) forControlEvents:UIControlEventTouchUpInside];
- [rightView addSubview:btn];
-
-
- view = [[UIView alloc] initWithFrame:rightView.frame];
- view.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.44];
- view.layer.masksToBounds = YES;
- view.layer.cornerRadius = 10;
- view.hidden = YES;
- [self.view addSubview:view];
- show_hideView = view;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, kSize.width - 90, 23)];
- label.backgroundColor = [UIColor clearColor];
- [label setText:@"00:00:00" Font:FontTitle TextColor:[UIColor whiteColor] Alignment:NSTextAlignmentCenter];
-
- [show_hideView addSubview:label];
- timeLabel2 = label;
-
- label = [[UILabel alloc] initWithFrame:CGRectMake(15, 25, kSize.width - 120, 40)];
- label.backgroundColor = [UIColor clearColor];
- [label setText:@"注:退出当前页面将结束计时,学时详情在“个人-我的学时”查看" Font:NormalFont TextColor:[UIColor whiteColor]];
- label.numberOfLines = 0;
- [show_hideView addSubview:label];
-
- btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 65, kSize.width - 90, 35)];
- btn.backgroundColor = [UIColor colorWithRed:35/255.0 green:160/255.0 blue:227/255.0 alpha:.6];
- [btn setTitle:@"开始计时" textColor:[UIColor whiteColor] font:FontTitle fotState:UIControlStateNormal];
- [btn setTitle:@"结束计时" forState:UIControlStateSelected];
- [btn addTarget:self action:@selector(beginOrEndTrain) forControlEvents:UIControlEventTouchUpInside];
- [show_hideView addSubview:btn];
- begin_endBtn = btn;
- }
- - (void)showOrHide:(UIButton *)sender {
- sender.selected = !sender.selected;
-
- if (sender.selected) {
- [UIView animateWithDuration:.4 animations:^{
- show_hideView.hidden = NO;
- show_hideView.frame = CGRectMake(20, kSize.height - 300 - kSafeAreaBottomHeight, kSize.width - 90, 100);
-
- trainStateLabel.text = @"关闭\n弹窗";
- }];
- }else {
- [UIView animateWithDuration:.4 animations:^{
- show_hideView.frame = rightView.frame;
- } completion:^(BOOL finished) {
- show_hideView.hidden = YES;
-
- if (myDelegate.isUseriPhone) {
- trainStateLabel.text = @"计\n时\n中";
- }else {
- trainStateLabel.text = @"点击\n计时";
- }
- }];
- }
- }
- - (void)beginOrEndTrain {
- @weakify(self)
- if (!myDelegate.isLogin) {
- ShowMsg(@"请登录后再使用理论计时功能");
- return;
- }
-
- NSInteger isNeed = 1;
- for (NSDictionary * dic in defUser.userDict[@"params"]) {
- if ([dic[@"KEY"] isEqualToString:@"SP_VERIFY_IMEI"]) {
- isNeed = [dic[@"VALUE"] integerValue];
- }
- }
-
- NSString *IMEI = defUser.userDict[@"imei"];
- if (IMEI.length > 0) {
- if (isNeed == 1) {
- if ([Tools getIDFAWithType:GetIDFAType_Default]) {
- @strongify(self)
- if (![IMEI isEqualToString:[Tools getIDFAWithType:GetIDFAType_Default]]) {
- ShowMsg(@"您当前手机与绑定手机不一致, 无法计时");
- return;
- } else {
- if (!begin_endBtn.selected) {
- //开始计时
- if (defUser.isycbd == 1) {
- [self startTimingWithResultBlock:^(BOOL isSuccess) {
-
- }];
- } else {
- [self beginTime];
- }
- }else {//结束计时
- if (defUser.isycbd == 1) {
- [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
-
- }];
- } else {
- [self stopTiming];
- }
- begin_endBtn.selected = !begin_endBtn.selected;
- }
- }
- }
- } else {
- [Tools saveNotBindImeiLogWithType:@"2" block:^(BOOL isSuccess) {
- @strongify(self)
- if (isSuccess) {
- if (!begin_endBtn.selected) {
- //开始计时
- if (defUser.isycbd == 1) {
- [self startTimingWithResultBlock:^(BOOL isSuccess) {
-
- }];
- } else {
- [self beginTime];
- }
- }else {//结束计时
- if (defUser.isycbd == 1) {
- [self stopTimingWithResultBlock:^(BOOL isSuccessed) {
-
- }];
- } else {
- [self stopTiming];
- }
- begin_endBtn.selected = !begin_endBtn.selected;
- }
- }
- }];
- }
- } else {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"您的账号暂未与该手机绑定,不能进行此操作,请通过“考试界面左上角点击头像-弹出左边侧栏-绑定账号”进行绑定" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil completion:nil];
- }
- }
- -(void)stopTiming
- {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
-
- myDelegate.isUseriPhone = NO;
- myDelegate.isTrain = NO;
-
- timeLabel2.text = @"00:00:00";
- timeLabel1.text = @"00:00";
- // if (seconds < 60) {
- // ShowMsg(@"学时未满一分钟不统计");
- // }
- [self saveTrain];
- [self upLoadTrainRecord];
- }
- - (void)beginTime {
- @weakify(self)
- if (![Util connectedToNetWork])
- {
- ShowMsg(@"请检查网络连接。");
- return;
- }
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr property:defUser.userDict[@"outId"] forKey:@"outId"];
- [arr property:defUser.userDict[@"city"] forKey:@"dqbh"];
-
- NSString* method = @"isUsePhone";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
- @strongify(self)
- [MBProgressHUD hideHUDForView:self.view];
-
- if (!dict) {
- ShowMsgFailed();
- return;
- }
-
- if ([dict[@"code"] isEqualToString:@"90"]) {
- UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
-
- [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- @strongify(self)
- [LoginViewController loginFromVC:self];
- }]];
- [self presentViewController:alertFind animated:true completion:nil];
- return;
- }
-
- if ([dict[@"code"] isEqualToString:@"0"]) {
- myDelegate.begin_Time = dict[@"body"];
- [Tools playAudioWithString:@"操作成功,开始计时"];
-
- self.seconds = 0;
- myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
- myDelegate.isUseriPhone = YES;
- myDelegate.isTrain = YES;
-
- begin_endBtn.selected = YES;
-
- //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题
- [self saveTrain];
- } else {
- NSString *msg = dict[@"msg"];
- if (msg.length < 1) {
- msg = dict[@"body"];
- }
- ShowMsg(msg);
- [Tools playAudioWithString:msg];
- }
- }];
- }
- - (void)timeFireMethod {
- @weakify(self)
- self.seconds++;
- [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
-
- if (defUser.isycbd == 1) {
- NSString *pxkm = defUser.userDict[@"pxjd"];
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
- if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
- pxkm = @"4";
- }
- int remainder1 = (int)(self.seconds)%900;
- if (remainder1 == 0) {
- [self.timer setFireDate:[NSDate distantFuture]];
- SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow];
- alert.backgroundViewColor = backGroundColor;
- alert.customViewColor = RQ_MAIN_COLOR;
- [alert addButton:@"立即开始 " actionBlock:^(void) {
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, id dict) {
- @strongify(self)
- if (isSuccess) {
- NSString *timeStr = [self getTimes:self.seconds];
- /// 3.2上传过程照片
- if (dict) {
- NSDictionary *myDict = dict;
- NSString *imageUrlStr = myDict[@"body"];
- if (RQStringIsEmpty(imageUrlStr)) {
- ShowMsg(@"路径为空");
- }
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_Process resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- if (isSuccess) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"过程验证成功" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- @strongify(self)
- [self.timer setFireDate:[NSDate distantPast]];
- }];
- } else {
- self.seconds--;
- [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- self.seconds--;
- [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
- [self.timer setFireDate:[NSDate distantPast]];
- }
- } else {
- self.seconds--;
- [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- self.seconds--;
- [self setSecondString:[NSString stringWithFormat:@"%d",(int)self.seconds]];
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- });
- }];
- [alert addTimerToButtonIndex:0 reverse:YES];
- [alert showNotice:@"温馨提示" subTitle:@"即将开始活体检测,请做好准备" closeButtonTitle:nil duration:5.0f];
- }
- }
-
- int hour = 0;
- int min = 0;
- int second = 0;
- int remainder = (int)self.seconds%60;
- if (remainder == 0)
- {
- //每1分钟保存一次
- [self saveTrain];
- }
-
- hour = (int)self.seconds / 3600;
- min = (int)self.seconds % 3600 / 60;
- second = (int)self.seconds % 3600 % 60;
- NSString *min_s;
- NSString *second_s;
- if (min<10) {
- min_s=[NSString stringWithFormat:@"0%d",min];
- }else{
- min_s=[NSString stringWithFormat:@"%d",min];
- }
- if (second<10) {
- second_s=[NSString stringWithFormat:@"0%d",second];
- }else{
- second_s=[NSString stringWithFormat:@"%d",second];
- }
-
- //更新UI上的时间
- timeLabel2.text = [NSString stringWithFormat:@"0%d:%@:%@",hour,min_s,second_s];
- timeLabel1.text = [NSString stringWithFormat:@"0%d:%@",hour,min_s];
- }
- - (void)saveTrain {
- if (!formatter) {
- formatter = [NSDateFormatter rq_defaultDateFormatter];
- }
- TrainRecord *train = [[TrainRecord alloc] init];
-
- train.studentId = defUser.userStuId;
- train.beginTime = myDelegate.begin_Time;
-
- NSDate *date=[formatter dateFromString:myDelegate.begin_Time];
- date=[date dateByAddingTimeInterval:self.seconds];
- train.state = @"0";
- train.endTime=[formatter stringFromDate:date];
- NSInteger mins = self.seconds / 60;
- train.trainTime=[NSString stringWithFormat:@"%d",(int)mins];
- train.subject = myDelegate.subject;
- train.classid = (self.classIdStr && ![self.classIdStr isEqualToString:@""])? self.classIdStr : @"0";
- [DB_Helper saveTrain:train];
- }
- - (void)upLoadTrainRecord {
- NSString *pxkm = defUser.userDict[@"pxjd"];
-
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
-
- NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:myDelegate.subject];
- if (array.count < 1) {
- ShowMsg(@"本地无学时明细!");
- return;
- }
-
- //这里是对分段上传学时做的处理 如果学时上传有问题 查看这里
- [self uploadMoreTrainRecordWithArray:array];
- }
- - (void)uploadMoreTrainRecordWithArray:(NSArray *)trainArray {
- @weakify(self)
- if (![Util connectedToNetWork]) {
- showMsgUnconnect();
- return;
- }
-
- NSString* str = @"";
- for (TrainRecord *record in trainArray) {
- str = [str stringByAppendingString:[NSString stringWithFormat:@"%@,%@,%@,%@;",record.studentId,record.beginTime,record.endTime,record.trainTime]];
- }
-
- TrainRecord *record = [trainArray firstObject];
-
- NSMutableArray *arr=[NSMutableArray array];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"ios",@"trainType", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:[DES3Util encrypt:str ],@"trainRecord", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:record.subject,@"pxkm", nil]];
- [arr addObject:[NSDictionary dictionaryWithObjectsAndKeys:defUser.userDict[@"outId"],@"stuOutid", nil]];
-
- NSString* method = @"uploadMoreTrainRecord";
- [MBProgressHUD showLoadToView:self.view];
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *dict) {
- [MBProgressHUD hideHUDForView:self.view];
- @strongify(self)
- if (!dict) {
- ShowMsg(@"操作失败");
- return;
- }
- if ([dict[@"code"] isEqualToString:@"90"]) {
- UIAlertController *alertFind = [UIAlertController alertControllerWithTitle:nil message:dict[@"msg"] preferredStyle:UIAlertControllerStyleAlert];
-
- [alertFind addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
- @strongify(self)
- [LoginViewController loginFromVC:self];
- }]];
- [self presentViewController:alertFind animated:true completion:nil];
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"1"]) {
- ShowMsg(dict[@"body"]);
- return;
- }
- if ( [dict[@"code"] isEqualToString:@"0"]) {
- for (TrainRecord *record in trainArray) {
-
- [DB_Helper updateTrainState:record];
- }
-
- UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:@"上传学时成功!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
- [alert show];
- }
- }];
- }
- #pragma mark collection delegate
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return questions.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- BtnCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"btn" forIndexPath:indexPath];
-
- [cell.btn setTitle:[NSString stringWithFormat:@"%d",(int)indexPath.row + 1] textColor:contentTextColor font:22 fotState:UIControlStateNormal];
- [cell.btn addTarget:self action:@selector(chooseBtn:) forControlEvents:UIControlEventTouchUpInside];
- [cell.btn setTag:indexPath.row];
-
- return cell;
- }
- -(void)chooseBtn:(UIButton*)sender
- {
- if (searchTf.isFirstResponder) {
- [searchTf resignFirstResponder];
- return;
- }
- [self chooseQuestionWithQIndex:sender.tag];
- }
- -(void)chooseQuestionWithQIndex:(NSInteger)questionIndex{
-
- qIndex = questionIndex;
- [self setQueIndex];
- [self hideChooseView];
- //记录选择的位置
- //顺序模式
- if (QuestionTypeOrdered == myDelegate.type.intValue) {
- [self setIndexRecord];
- }
- //背题模式
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
- }
- -(void)setIndexRecord
- {
- if ([defUser.car_type isEqualToString:@"4"]) {
- defUser.coachIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- if ([defUser.car_type isEqualToString:@"1"]) {
- defUser.A1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- if ([defUser.car_type isEqualToString:@"2"]) {
- defUser.A2Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- if ([defUser.car_type isEqualToString:@"3"]) {
- defUser.dangerIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- if ([defUser.car_type isEqualToString:@"5"]) {
- defUser.texiIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- if ([defUser.car_type isEqualToString:@"6"]) {
- defUser.wycIndex = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
-
- if ([defUser.car_type isEqualToString:@"C1"]) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.userSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.userSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
-
- if ([defUser.car_type isEqualToString:@"A2"]) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.A2Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.A2Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
-
- if ([defUser.car_type isEqualToString:@"A1"]) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.A1Subj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.A1Subj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
-
- if ([defUser.car_type isEqualToString:@"D"]) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.DSubj1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.DSubj4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
- }
- -(void)hideChooseView
- {
- [chooseView removeFromSuperview];
- }
- -(void)showChooseView
- {
- if (myDelegate.type.intValue == QuestionTypeExam) {
-
- if (chooseView)
- {
- int rig = 0,fau =0;
-
- for (int i = 0; i< questions.count; i++)
- {
- if ( CorrectTypeFault == correct[i])
- {
- fau++;
-
- [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:[UIColor redColor]] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal];
- [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- }
- if ( CorrectTypeRignt == correct[i])
- {
- rig++;
-
- [choBtns[i] setImage:[[UIImage imageNamed:@"question_error.png"] tint:defGreen] withTitle:[NSString stringWithFormat:@"%d",i+1] Font:22 forState:UIControlStateNormal];
- [choBtns[i] setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
- }
- }
- //NSLog(@"对的-->%d错的-->%d",rig,fau);
- [rigLbl setText:[NSString stringWithFormat:@"正确 %d",rig]];
- [errorLbl setText:[NSString stringWithFormat:@"错误 %d",fau]];
- searchTf.hidden = YES;
- sureBtn.hidden = YES;
- }
- }else{
- [rigLbl setHidden:YES];
- [errorLbl setHidden:YES];
- }
- [[UIApplication sharedApplication].keyWindow addSubview:chooseView];
- }
- //-(void)addQue
- //{
- // Question *q=[questions objectAtIndex:qIndex];
- // [DB_Que_Helper addToStrengthenQue:[q._id intValue]];
- //}
- //-(void)removeQue
- //{
- // Question *q=[questions objectAtIndex:qIndex];
- // [DB_Que_Helper removeToStrengthenQue:[q._id intValue]];
- //}
- #pragma mark - 输入题号搜索
- -(void)searchQuestion{
- NSInteger qNum = [searchTf.text integerValue];
- if (qNum && qNum !=0 && qNum <= questions.count) {
- [self chooseQuestionWithQIndex:qNum-1];
- }else{
- ShowMsg(@"请输入正确题号");
- }
- }
- -(void)preExAction{
- if (questions.count < 1) {
- return;
- }
- qIndex --;
- if(qIndex<0){
- qIndex = 0;
- }
-
-
- //顺序模式
- if (QuestionTypeOrdered == myDelegate.type.intValue) {
- [self setIndexRecord];
- }
- //背题模式
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
- [self setQueIndex];
- }
- //错题
- -(void)faultExAction:(BOOL)isRight
- {
- /**
- 如果这次对 并且没有错的记录 可以不处理 若有错的记录 要将错改为对
- 如果这次错 并且没有错的记录 要标记错题 若有错的记录 可不做处理
- */
-
- Question* q = questions[qIndex];
- //这个地方直接从库里边查
- BOOL isOK;
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
- if (isRight) {
- [self deleteState:@"2"];
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"1"];
- if (isOK) {
- q.state = @"1";
- }else{
- q.state = @"0";
- }
-
- if (isRight == 1){
- //NSLog(@"删除错题");
- if (q.state.integerValue == 1)
- {
- q.state = @"0";
- [self deleteState:@"2"];
- if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) {
- RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"];
- }
- }
- }else{
- // NSLog(@"添加错题");
- if (q.state.integerValue == 0)
- {
- q.state = @"1";
- if ([DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"1" State:[q.state integerValue]]) {
- RQ_SHARE_FUNCTION.myErorNum = [DB_Que_Helper queryGZPZ_EXAM_CYRYMarkQuestionWithMarkType:@"1"];
- }
- }
- }
- } else {
- RQ_SHARE_FUNCTION.myErorNum = [RQ_YDTQuestion_Module getQuestionWithExerciseType:RQExerciseType_Wrong].count;
- if (isRight) {
- [self deleteState:@"2"];
- }
- // isOK = [DB_Que_Helper queryIsHaveWithQuestion:[q._id integerValue] Type:@"1"];//错题1
- }
- }
-
- }
- //排除
- -(void)moveExAction
- {
- if (questions.count<1) {
- return;
- }
- // Question* q = questions[qIndex];
- // if (q.move.intValue == 1) {
- // q.move = @"0";
- // [self deleteState:@"3"];
- // if ([defUser.car_type isEqualToString:@"2"]) {
- // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- // } else {
- // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- // }
- // }else{
- // q.move = @"1";
- // if ([defUser.car_type isEqualToString:@"2"]) {
- // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- // } else {
- // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- // }
- // }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- Question* q = questions[qIndex];
- if (q.move.intValue == 1) {
- q.move = @"0";
- [self deleteState:@"3"];
- [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- }else{
- q.move = @"1";
- [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"3" State:[q.state integerValue]];
- }
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [RQ_YDT_USER_Question_Module removeQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- if (![RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]) {
- [self deleteState:@"3"];
- }
- }
- }
-
-
-
-
-
- // NSLog(@"------%@",q.move);
-
- [self setMoveTitle];
- }
- //收藏
- -(void)favAction{
- // NSLog(@"收藏或取消收藏");
- if (questions.count<1) {
- return;
- }
- // Question* q = questions[qIndex];
- // if (q.favorite.intValue == 1) {
- // q.favorite = @"0";
- // [self deleteState:@"1"];
- // if ([defUser.car_type isEqualToString:@"2"]) {
- // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- // } else {
- // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- // }
- // }else{
- // q.favorite = @"1";
- // if ([defUser.car_type isEqualToString:@"2"]) {
- // [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- // } else {
- // [DB_Que_Helper setMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- // }
- // }
- UIButton* favBtn = navBtns[1];
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- if (favBtn.selected) {
- [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- } else {
- [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- }
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- Question* q = questions[qIndex];
- if (q.favorite.intValue == 1) {
- q.favorite = @"0";
- [self deleteState:@"1"];
- [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- }else{
- q.favorite = @"1";
- [DB_Que_Helper setGZPZ_EXAM_CYRYMarkQuestionWithQuestion:[q._id integerValue] Type:@"2" State:[q.state integerValue]];
- }
- } else {
- if (favBtn.selected) {
- [RQ_YDT_USER_Question_Module deleteCollectRecordWithQuestionId:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- [self deleteState:@"1"];
- } else {
- [RQ_YDT_USER_Question_Module collectQuestionWithID:ydtQuestionModel.ID carType:RQ_YDTQuestion_Module.carType subject:RQ_YDTQuestion_Module.subject];
- [self saveStateQuestion:@"1"];
- }
- }
- }
-
-
-
- [self setFavTitle];
- }
- //目前未发现调用 被弃用了吧 --markdanson
- //-(void)errorExAction
- //{
- // if (questions.count<1) {
- // return;
- // }
- // Question* q = questions[qIndex];
- // if (q.state.intValue > 0) {
- // q.state = @"0";
- // [self removeQue];
- // }else{
- // q.state = @"1";
- // [self addQue];
- // }
- // //[self setFaultTitle];
- //}
- /**
- 或者换个套路。每次滑动完毕。快速切换页面的内容和scroll的offset。
- 可以先切换中间的view的内容,然后修改offset,最后设置剩下2个的。
- 这样的话。在判断边界条件时值,只需要设置contenSize即可。
- 设置为一样的就可以了。给它弹提示框算了。
- */
- -(void)nextExAction
- {
- if (questions.count < 1) {
- return;
- }
-
- qIndex++;
- if(qIndex >= questions.count)
- {
- qIndex--;
- return;
- }
-
-
- if (QuestionTypeOrdered == myDelegate.type.intValue) {
- [self setIndexRecord];
- }
- //背题模式
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- if ( 1==myDelegate.subject.intValue) {
- defUser.user1Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }else{
- defUser.user4Index = [NSString stringWithFormat:@"%d",(int)qIndex];
- }
- }
- [self setQueIndex];
- }
- -(void)showAnswAction
- {
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- return;
- }
- STButton* btn = navBtns[3];
- btn.selected = !btn.selected;
- showAnsw[qIndex] = btn.selected;
-
- [self setShowAnsw];
- }
- - (void)pauseExamAction
- {
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- //关闭定时器
- [self.timer setFireDate:[NSDate distantFuture]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
- } else {
- //关闭定时器
- [self.timer setFireDate:[NSDate distantFuture]];
- }
- }
-
-
- [NSObject rq_showAlertViewWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" confirmTitle:@"继续考试" confirmAction:^{
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [self.timer setFireDate:[NSDate distantPast]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
-
- } else {
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }
- }];
-
- // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"暂停考试" message:@"已暂停考试,点击下面继续考试" delegate:self cancelButtonTitle:@"继续考试" otherButtonTitles: nil];
- // [alert setTag:AlertTypePause];
- // [alert show];
- }
- - (void)submitExam {
- // NSLog(@"提交考试答卷");
- @weakify(self)
- int undoCnt = 0;
- for (int i=0; i< questions.count; i++)
- {
- if (correct[i] == CorrectTypeUndo)
- {
- undoCnt ++ ;
- }
- }
- NSString* msg = [NSString stringWithFormat:@"还有%d道题没做,确定交卷?",undoCnt];
- QMUIAlertController *alert = [QMUIAlertController alertControllerWithTitle:@"提交试卷" message:msg preferredStyle:QMUIAlertControllerStyleAlert];
- [alert addAction:[QMUIAlertAction actionWithTitle:@"确定" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
- @strongify(self)
- [self isUploadGrade];
- }]];
-
- [alert addAction:[QMUIAlertAction actionWithTitle:@"查看未做的题" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController * _Nonnull aAlertController, QMUIAlertAction * _Nonnull action) {
- @strongify(self)
- qIndex = 1;
- //遍历corecct,找到第一个未做的题目
- for (int i = 0; i < questions.count; i++) {
- if (CorrectTypeUndo == correct[i]) {
- qIndex = i;
- break;
- }
- }
- [self setQueIndex];
- }]];
-
- [alert addAction:[QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:nil]];
- [alert showWithAnimated:YES];
- }
- #pragma mark setting功能
- /**专门给【设置】按钮。添加的函数
- */
- -(void)settingBtn:(STButton *)sender
- {
- //点击设置后 就要将模式改为夜间模式
- for (ExerView* v in exVs)
- {
- [v setNightMode:YES];
- }
- [self.view setBackgroundColor:nightColor];
- [contantV setBackgroundColor:nightColor];
- [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0];
-
- //sender.tag为3为考试模式 为4是其他模式
- NSMutableArray *setViewArray = [NSMutableArray array];
- if (setViewArray.count > 0)
- {
- for (int i = 0; i < setViewArray.count; i ++)
- {
- ExerciseSetting *set = setViewArray[i];
- [set removeFromSuperview];
- }
- }
- if (sender.tag == 3)
- {
- setView = [[ExerciseSetting alloc] initWithExamFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-180, kSize.width, 180)];
- isSkip = 1;
- isExplain = 0;
- }
- else
- {
- setView = [[ExerciseSetting alloc] initWithCustomFrame:CGRectMake(0, kSize.height-kNavOffSet-kSafeAreaBottomHeight-280, kSize.width, 280)];
- }
- [setView.skipSwitch setOn:isSkip];
- [setView.explainSwitch setOn:isExplain];
- [setView.nightSwitch setOn:myDelegate.isNightMode];
- [setView.voiceSwitch setOn:!myDelegate.isNotSoundMode];
-
- [self.view addSubview:setView];
- [setViewArray addObject:setView];
-
- //添加setting用的方法
- [setView.finishBtn addTarget:self action:@selector(setFinish) forControlEvents:UIControlEventTouchUpInside];
-
- [setView.smallBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside];
- setView.smallBtn.tag = 100;
- [setView.bigBtn addTarget:self action:@selector(setQuestionFont:) forControlEvents:UIControlEventTouchUpInside];
- setView.bigBtn.tag = 101;
-
- [setView.skipSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
- setView.skipSwitch.tag = 11;
- [setView.explainSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
- setView.explainSwitch.tag = 12;
- [setView.voiceSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
- setView.voiceSwitch.tag = 13;
- [setView.nightSwitch addTarget:self action:@selector(switchIsChanged:) forControlEvents:UIControlEventValueChanged];
- setView.nightSwitch.tag = 14;
-
- }
- -(void)switchIsChanged:(UISwitch *)aSwitch
- {
- switch (aSwitch.tag) {
- case 11:
- isSkip = aSwitch.on;
- break;
- case 12:
- isExplain = aSwitch.on;
- break;
- case 13:
- //是否无声模式 是否开启声音取反 默认开启声音
- myDelegate.isNotSoundMode = !aSwitch.on;
- break;
- case 14:
- myDelegate.isNightMode = aSwitch.on;
- break;
- default:
- break;
- }
- }
- -(void)setFinish
- {
- //根据设置 按钮状态
- [self checkIsNightMode];
- [setView removeFromSuperview];
- }
- -(void)setQuestionFont:(UIButton *)btn
- {
- //100小 101大
- if (btn.tag == 100) {
-
- if (myDelegate.optionFont == 14) {
- return;
- }
- myDelegate.optionFont -= 1;
- }
- if (btn.tag == 101) {
-
- if (myDelegate.optionFont == 28) {
- return;
- }
- myDelegate.optionFont += 1;
- }
-
- setView.fontLabel.text = [NSString stringWithFormat:@"%d",(int)myDelegate.optionFont];
-
- [exVs removeAllObjects];
-
- //重新构建题目
- [self configExerV:YES];
-
- //将原来在后面的还放到后面
- [self.view sendSubviewToBack:contantV];
-
- for (ExerView* v in exVs)
- {
- [v setNightMode:YES];
- }
- if (scroll) {
- [self.view sendSubviewToBack:scroll];
- }
- //[self setFinish];
- }
- //可以调用这个方法实现 夜间模式 只需要改myDelegate.isNightMode的值 然后调用checkIsNightMode即可
- -(void)checkIsNightMode
- {
- if(myDelegate.isNightMode)
- {
- for (ExerView* v in exVs)
- {
- [v setNightMode:YES];
- }
- [self.view setBackgroundColor:nightColor];
- [contantV setBackgroundColor:nightColor];
- [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"nightBg.png"] forBarMetrics:0];
- }else{
- for (ExerView* v in exVs)
- {
- [v setNightMode:NO];
- }
- [self.view setBackgroundColor:backGroundColor];
- [contantV setBackgroundColor:[UIColor whiteColor]];
- [self setNavBarNormalColor];
- }
- }
- -(void)setNavBarNormalColor
- {
- [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"normalBg.png"] forBarMetrics:0];
- }
- -(void)updateTime:(NSTimer*)tim
- {
- secCnt--;
- [self setFirstBbiTitle];
- if (secCnt < 1) {
- @weakify(self);
- [NSObject rq_showAlertViewWithTitle:@"提示" message:@"考试时间到了,现在交卷!" confirmTitle:@"确定" confirmAction:^{
- @strongify(self)
- [self isUploadGrade];
- }];
-
- // UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"考试时间到了,现在交卷!" delegate:self cancelButtonTitle:@"确定" otherButtonTitles: nil];
- // [alert setTag:AlertTypeTimeOut];
- // [alert show];
-
- [self.timer invalidate];
- self.timer = nil;
- }
- }
- - (void)isUploadGrade {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [self endExamAndGotoResult];
- } else {
- dispatch_async(dispatch_get_main_queue(), ^{
- @weakify(self)
- if (myDelegate.isLogin) {
- if ([defUser.car_type isEqualToString:@"2"]) {
- NSInteger score = correctMark;
- if (score >= 80) {
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核通过,成绩即将上传!" confirmTitle:@"确定" confirmAction:^{
- @strongify(self)
- grade.isUpdate = @"1";
- [self endExamAndGotoResult];
- }];
-
- } else {
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"考核失败,是否重新开始考核!" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{
- @strongify(self)
- [self.navigationController popViewControllerAnimated:NO];
- } cancelAction:^{
- @strongify(self)
- [self endExamAndGotoResult];
- }];
- }
- } else {
- grade.isUpdate = @"1";
- [self endExamAndGotoResult];
- // [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"是否允许上传本次成绩,成绩将在学霸排行榜中显示" confirmTitle:@"是" cancelTitle:@"否" confirmAction:^{
- // @strongify(self)
- // grade.isUpdate = @"1";
- // [self endExamAndGotoResult];
- // } cancelAction:^{
- // @strongify(self)
- // grade.isUpdate = @"0";
- // [self endExamAndGotoResult];
- // }];
- }
- } else {
- //没登录 就不上传成绩
- [NSObject rq_showAlertViewWithTitle:@"温馨提示" message:@"您还未登录,成绩暂无法同步云平台" confirmTitle:@"确定" confirmAction:^{
- @strongify(self)
- [self endExamAndGotoResult];
- }];
- }
- });
- }
-
-
-
- }
- - (void)endExamAndGotoResult {
- dispatch_async(dispatch_get_main_queue(), ^{
- if (!grade) {
- grade = [[Grade alloc] init];
- }
- if (!honors) {
- honors = @[@"马路杀手",@"驾考标兵",@"驾考牛人",@"驾考神人",@"外星人",@"幸运儿"];
- }
- NSInteger score = correctMark;
-
- NSInteger time = _testTime*60 - secCnt;
- NSDateFormatter *dateFormatter = [NSDateFormatter rq_defaultDateFormatter];
- // formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
- [dateFormatter setDateFormat: @"MM-dd"];
- grade.graDate = [dateFormatter stringFromDate:[NSDate date]];
-
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- //如果有开始时间 那就根据时长来计算结束时间 如果没有开始时间 就根据当前时间计算出开始时间 这样就修复了 更改本地时间取得更好成绩的漏洞
- grade.startDate = @"";
- if (grade.startDate.length > 10) {
- NSDate *beginDate = [dateFormatter dateFromString:grade.startDate];
- NSDate *endDte = [NSDate dateWithTimeInterval:time sinceDate:beginDate];
- grade.endDate = [dateFormatter stringFromDate:endDte];
- }else{
- grade.endDate = [dateFormatter stringFromDate:[NSDate date]];
- NSDate *beginDate = [NSDate dateWithTimeIntervalSinceNow:-time];
- grade.startDate = [dateFormatter stringFromDate:beginDate];
- }
-
- //NSLog(@"开始--><>%@---结束---><>%@---时长-><>%d",grade.startDate,grade.endDate,(int)time);
-
-
- if (score < 60) {
- grade.graHonor = honors[0];
- }else if (score < 90){
- grade.graHonor = honors[1];
- }else if (score < 93){
- grade.graHonor = honors[2];
- }else if (score < 96){
- grade.graHonor = honors[3];
- }else if (score < 98){
- grade.graHonor = honors[4];
- }else{
- grade.graHonor = honors[5];
- }
- //用min/sec获取占位符 确保时间格式为 00:00
- NSString *min = @"";
- NSString* sec = @"";
- if (time/60<10) {
- min= @"0";
- }
- if (time%60<10) {
- sec= @"0";
- }
-
- if (score > 100) {
- //如果成绩大于100 置为100
- score = 100;
- }
-
- grade.graTime = [NSString stringWithFormat:@"%@%d:%@%d",min,(int)time/60,sec,(int)time%60];
- grade.graScore = [NSString stringWithFormat:@"%d",(int)score];
-
- //NSLog(@"存入---><>%@--->%@----.%@----->%@--->%@----->%@",grade.graDate,grade.graHonor,grade.graScore,grade.graTime,grade.startDate,grade.endDate);
-
- [DB_Que_Helper insertGrade:grade];
-
- ExamResultVC* vc = [[ExamResultVC alloc] init];
- vc.grade = grade;
- vc.questions = questions;
- [self.navigationController qmui_pushViewController:vc animated:YES completion:nil];
- });
- }
- /**设置第一个导航栏按钮的标题。如果是普通练习。就显示题号。
- 否则显示时间。
- */
- - (void)setFirstBbiTitle {
- STButton* btn = navBtns[0];
- NSString* title ;
- if (QuestionTypeExam == myDelegate.type.intValue){
- int sec = secCnt%60;
- int min = secCnt/60;
- NSString* sec0,*min0;
- sec0 = sec<10 ? @"0" : @"";
- min0 = min<10 ? @"0" : @"";
- title = RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? [NSString stringWithFormat:@"%@%d:%@%d",min0,min,sec0,sec] : ([defUser.car_type isEqualToString:@"2"]? @"00:00" : [NSString stringWithFormat:@"%@%d:%@%d",min0,min,sec0,sec]);
- }else{
- title = [NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count];
- }
- [btn setTitle: title forState:UIControlStateNormal];
- }
- - (void)setQueIndex {
- if (questions.count < 1) {
- return;
- }
- [self setFirstBbiTitle];
- [self setMoveTitle];
- [self setFavTitle];
- [self setShowAnsw];
- [indexLbl setText:[NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]];
-
- NSInteger leeIndex = qIndex;
- if (questions.count>1) {
- if (qIndex == 0) {
- leeIndex += 1;
- }else if(qIndex == questions.count-1){
- leeIndex -= 1;
- }
- }
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[1] setQuestion:questions[leeIndex]];
- } else {
- [(ExerView*)exVs[1] setYdtQuestionModel:questions[leeIndex]];
- }
- }
-
-
-
- if (QuestionTypeRecite == myDelegate.type.intValue)
- {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue];
- [(ExerView*)exVs[1] setAnswer:myAnswer];
- [(ExerView*)exVs[1] setShowAnswer:YES];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[1] setAnswer:[[(Question*)questions[leeIndex] answer] intValue]];
- [(ExerView*)exVs[1] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
- } else {
- NSInteger myAnswer = [[(RQYDTQuestionModel*)questions[leeIndex] AnswerTrue] intValue];
- [(ExerView*)exVs[1] setAnswer:myAnswer];
- [(ExerView*)exVs[1] setShowAnswer:YES];
- }
- }
- }
- else
- {
- [(ExerView*)exVs[1] setAnswer:answers[leeIndex]];
- [(ExerView*)exVs[1] setShowAnswer:showAnsw[leeIndex]];
- }
-
- /**设置偏移
- */
- //这里记录一个问题,第一次记录训练到4396题,如果我进来选择了否,不继续练习,所以跑到了第一题,但是我没有切换上下题,然后我退出界面再次进来(这里依旧保留旧的记录4396题,而不是点了否之后的第一题,如果你切换了其它题则会刷新记录)
- if (qIndex==0) {
- [scroll setContentOffset:CGPointMake(0, 0)];
- lastOffset.x = 0;
- }else if(qIndex==questions.count-1){
- [scroll setContentOffset:CGPointMake(kSize.width*2, 0)];
- lastOffset.x = kSize.width*2;
- }else{
- [scroll setContentOffset:CGPointMake(kSize.width, 0)];
- lastOffset.x = kSize.width;
- }
-
- NSInteger qIndex0 = qIndex - 1;
- if (qIndex0 < 0) {
- qIndex0 = 0;
- }
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[0] setQuestion:questions[qIndex0]];
- } else {
- [(ExerView*)exVs[0] setYdtQuestionModel:questions[qIndex0]];
- }
- }
-
-
-
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]];
- [(ExerView*)exVs[0] setShowAnswer:YES];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[0] setAnswer:[[(Question*)questions[qIndex0] answer] intValue]];
- [(ExerView*)exVs[0] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
- } else {
- [(ExerView*)exVs[0] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex0] AnswerTrue] intValue]];
- [(ExerView*)exVs[0] setShowAnswer:YES];
- }
- }
-
- }else{
- [(ExerView*)exVs[0] setAnswer:answers[qIndex0]];
- [(ExerView*)exVs[0] setShowAnswer:showAnsw[qIndex0]];
- }
-
- NSInteger qIndex2 = qIndex + 1;
- if (qIndex2 >= questions.count) {
- qIndex2 = (int)questions.count -1;
- }
-
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[2] setQuestion:questions[qIndex2]];
- } else {
- [(ExerView*)exVs[2] setYdtQuestionModel:questions[qIndex2]];
- }
- }
-
-
-
- if (QuestionTypeRecite == myDelegate.type.intValue) {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]];
- [(ExerView*)exVs[2] setShowAnswer:YES];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- [(ExerView*)exVs[2] setAnswer:[[(Question*)questions[qIndex2] answer] intValue]];
- [(ExerView*)exVs[2] setShowAnswer:![defUser.car_type isEqualToString:@"2"]];
- } else {
- [(ExerView*)exVs[2] setAnswer:[[(RQYDTQuestionModel*)questions[qIndex2] AnswerTrue] intValue]];
- [(ExerView*)exVs[2] setShowAnswer:YES];
- }
- }
- } else {
- [(ExerView*)exVs[2] setAnswer:answers[qIndex2]];
- [(ExerView*)exVs[2] setShowAnswer:showAnsw[qIndex2]];
- }
-
- //这个操作是为了视频题的视频可以正常播放
- if (0 == qIndex) {
- [(ExerView*)exVs[0] playMovie];
- } else if (questions.count-1 == qIndex){
- [(ExerView*)exVs[2] playMovie];
- } else {
- [(ExerView*)exVs[1] playMovie];
- }
-
-
- [self.view bringSubviewToFront:rightView];
- [self.view bringSubviewToFront:show_hideView];
- }
- - (void)setShowAnsw {
- int vcInd = (int)(scroll.contentOffset.x / kSize.width);
- //先这样处理了,崩溃日志暗示这里等于3越界了@lee
- if (vcInd>=3) {
- vcInd = 2;
- }
- ExerView* v = exVs[vcInd];
- [v setShowAnswer:RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN? showAnsw[qIndex] : ([defUser.car_type isEqualToString:@"2"]? NO : showAnsw[qIndex])];
- //根据设置按钮的内容来定义这一题是否显示答案
- if (QuestionTypeRecite != myDelegate.type.intValue) {
- STButton* btn = navBtns[3];
- [btn setSelected:showAnsw[qIndex]];
- }
-
- }
- /**根据qIndex来设置是否收藏。
- */
- - (void)setFavTitle {
- UIButton* btn = navBtns[1];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- if (qIndex < questions.count) {
- Question* q = questions[qIndex];
- //这个地方直接从库里边查
- BOOL isOK;
- isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"2"];
- if (isOK) {
- q.favorite = @"1";
- }else{
- q.favorite = @"0";
- }
- [btn setSelected:q.favorite.intValue];
- //NSLog(@"favorite---><>%d",(int)q.favorite.integerValue);
- }
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [btn setSelected:[RQ_YDT_USER_Question_Module getCollectRecordWithQuestionId:ydtQuestionModel.ID]];
- }
- }
-
- }
- /**根据qIndex来设置是否排除。
- */
- - (void)setMoveTitle {
- UIButton* btn = navBtns[2];
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"]) {
- Question* q = questions.count > qIndex? questions[qIndex] : nil;
- if (q) {
- //这个地方直接从库里边查
- BOOL isOK;
- isOK = [DB_Que_Helper queryGZPZ_EXAM_CYRYIsHaveWithQuestion:[q._id integerValue] Type:@"3"];
- if (isOK) {
- q.move = @"1";
- }else{
- q.move = @"0";
- }
-
- [btn setSelected:q.move.intValue];
- //NSLog(@"move--><>%d",(int)q.move.integerValue);
- }
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [btn setSelected:[RQ_YDT_USER_Question_Module getRemoveRecordWithQuestionId:ydtQuestionModel.ID]];
- }
- }
- }
- /**type1是收藏,2是错题,3是排除的题。 废弃 dansonmark
- */
- - (void)saveStateQuestion:(NSString*)type {
- if (!myDelegate.isLogin) {
- return;
- }
- if (![Util connectedToNetWork]) {
- return;
- }
- if (defUser.sfzmhm.length == 0)
- {
- return;
- }
- NSString *subjectString = [myDelegate.subject intValue] == 4?@"4":@"1";
- NSMutableArray *arr=[NSMutableArray array];
- if ([defUser.car_type isEqualToString:@"2"]) {
- Question* ques = questions[qIndex];
- [arr addPro:@"qId" Value:ques._id];
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [arr addPro:@"qId" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]];
- }
- [arr addPro:@"userId" Value:defUser.userDict[@"id"]];
- [arr addPro:@"type" Value:type];
- [arr addPro:@"source" Value:@"2"];
- [arr addPro:@"subject" Value:subjectString];
- NSString* method = @"saveFavQuestion";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
- //NSLog(@"加入收排错---->%@---->%@",arr,root);
- if (!root || [root[@"code"] isEqualToString:@"1"])
- {
- [LoadingView showMsg:@"操作失败"];
- }
- }];
- }
- /**删除错题、收藏、排错
- */
- - (void)deleteState:(NSString*)type {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- if (!myDelegate.isLogin) {
- return;
- }
- if (![Util connectedToNetWork]) {
- return;
- }
- if ([defUser.userDict[@"id"] length] == 0){
- return;
- }
- NSMutableArray *arr=[NSMutableArray array];
- if ([defUser.car_type isEqualToString:@"2"]) {
- Question* ques = questions[qIndex];
- [arr addPro:@"id" Value:ques._id];
- } else {
- RQYDTQuestionModel *ydtQuestionModel = questions[qIndex];
- [arr addPro:@"id" Value:[NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:ydtQuestionModel.ID]]];
- }
- [arr addPro:@"user" Value:defUser.userDict[@"id"]];
- [arr addPro:@"outId" Value:defUser.userStuId];
- [arr addPro:@"type" Value:type];
- NSString* method = @"deleteFav";
- [jiaPeiManager requestAnythingWithURL:method array:arr data:nil completion:^(NSDictionary *root) {
- if (!root || [root[@"code"] isEqualToString:@"1"]) {
- ShowMsgFailed();
- }
- }];
- }
- }
- #pragma mark - 代理方法
- - (void)removeRandomAD {
- [self removeAd:nil];
- @weakify(adView)
- [UIView qmui_animateWithAnimated:YES duration:1 animations:^{
- @strongify(adView)
- adView.hidden = YES;
- }];
- }
- - (void)gotoAllCommentVC {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
-
- } else {
- AllCommentVC* vc = [[AllCommentVC alloc] init];
- if ([defUser.car_type isEqualToString:@"2"]) {
- vc.quest = questions[qIndex];
- } else {
- vc.ydtQuestionModel = questions[qIndex];
- }
- [self navPushHideTabbarToVC:vc];
- }
- }
- #pragma mark - alertViewDelegate
- - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
- @weakify(self)
- if (AlertTypePause == alertView.tag) {
- if (RQ_COMMON_MANAGER.YYXC_SERVICE_OPEN) {
- [self.timer setFireDate:[NSDate distantPast]];
- } else {
- if ([defUser.car_type isEqualToString:@"2"] && myDelegate.isLogin) {
- } else {
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }
-
- return;
- }
- if (AlertTypeTimeOut == alertView.tag) {
- [self isUploadGrade];
- return;
- }
- if (AlertTypeSubmit == alertView.tag) {
- switch (buttonIndex) {
- case 0:
- [self isUploadGrade];
- break;
- case 1:
- break;
- default:
- qIndex = 1;
- //遍历corecct,找到第一个未做的题目
- for (int i = 0; i<questions.count; i++) {
- if (CorrectTypeUndo == correct[i]) {
- qIndex = i;
- break;
- }
- }
- [self setQueIndex];
- break;
- }
- }
-
- if (AlertTypeIsLoad == alertView.tag) {
- if (buttonIndex == alertView.cancelButtonIndex){
- grade.isUpdate = @"0";
- }else{
- grade.isUpdate = @"1";
- }
- [self endExamAndGotoResult];
- }
-
- if (AlertTypeIsQuit == alertView.tag) {
- if (buttonIndex == 0) {
- if (myDelegate.isUseriPhone) {
- [myDelegate.timer invalidate];
- myDelegate.timer = nil;
- if (self.seconds < 60) {
- ShowMsg(@"学时未满一分钟不统计");
- return;
- }
- [self saveTrain];
- [self upLoadTrainRecord];
- }
- [self.view endEditing:1];
- [self.navigationController popViewControllerAnimated:YES];
- }
- }
-
- if (alertView.tag == 100) {
- if (buttonIndex == alertView.cancelButtonIndex){
- //是
- [indexLbl setText:[NSString stringWithFormat:@"%d/%d",(int)qIndex+1,(int)questions.count]];
- } else {
- //否
- qIndex = 0;
- [self configExerV:YES];
- }
-
- NSString *pxkm = defUser.userDict[@"pxjd"];
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
- NSArray* array = [DB_Helper quearyTrain:defUser.userStuId Subject:pxkm];
- if (array.count > 0 && defUser.isycbd != 1) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您本地有未上传学时,请确认上传!" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- @strongify(self)
- [self upLoadTrainRecord];
- }];
- [alert addAction:saveAction];
- [self presentViewController:alert animated:YES completion:nil];
- }
- }
- }
- - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
- if ([scrollView isMemberOfClass:[UICollectionView class]]) {
- if (searchTf.isFirstResponder) {
- [searchTf resignFirstResponder];
- }
- }
- }
- /**判断是否第一或最后一题
- */
- - (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
- if ([scrollView isKindOfClass:[UICollectionView class]]) {
- return;
- }
-
- CGPoint off = scrollView.contentOffset;
- /**要加上后面的判断,否则容易误判。
- */
- if (off.x <= 0 && 0 == qIndex) {
- [LoadingView showMsg:@"已经是第一道题了!"];
- } else if(off.x >= 2*kSize.width && questions.count-1 == qIndex){
- [LoadingView showMsg:@"已经是最后一道题了!"];
- }
- }
- - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
- // NSLog(@"TTTT--: %f",scrollView.contentOffset.x)
- //这里因为设置了按页滚动为yes,以及preExAction/preExAction ==》setQueIndex 里面对scrool。contentoffset。x和lastoffset的改动;
- //lastoffset和scroll.contentoffset.x 会有 0,kize.width,kize.width*2 三种值
- if (lastOffset.x > scroll.contentOffset.x) {
- [self preExAction];
- }else if (lastOffset.x < scroll.contentOffset.x) {
- [self nextExAction];
- }
- }
- #pragma mark - searchTf delegate
- - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
- NSString *newStr = [textField.text stringByReplacingCharactersInRange:range withString:string];
- if (newStr.length >4) {//限制输入至多4位
- return NO;
- }
- return YES;
- }
- #pragma mark - LazyLoad
- - (CGFloat)adWidth {
- return RQ_SCREEN_WIDTH;
- }
- - (CGFloat)adHeight {
- return self.adWidth * (100.f / 640.f);
- }
- - (UIView *)bannerView {
- if (!_bannerView) {
- CGRect rect = {CGPointZero, CGSizeMake(self.adWidth, self.adHeight)};
- _bannerView = [[UIView alloc]
- initWithFrame:rect];
- }
- return _bannerView;
- }
- #pragma mark - TimeModule
- - (void)startTimingWithResultBlock:(void (^)(BOOL isSuccess))resultBlock {
- @weakify(self)
- if (defUser.isycbd == 1) {
- [RQ_RemoteTheory_MANAGER getTheoryStatusWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull statusDict) {
- @strongify(self)
- if (isSuccess) {
- NSString *statusStr = statusDict[@"body"];
- if (!statusStr && [statusStr isEqualToString:@""]) {
- ShowMsg(@"获取学员状态异常!");
- !resultBlock? : resultBlock(NO);
- return;
- }
- BOOL statusIsSignIn = [statusStr isEqualToString:@"1"];
- NSString *pxkm = defUser.userDict[@"pxjd"];
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
- if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
- pxkm = @"4";
- }
-
-
- NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm];
- __block NSInteger trainTime = 0;
-
- [array.rac_sequence.signal subscribeNext:^(TrainRecord *record) {
- trainTime = trainTime + record.trainTime.integerValue;
- } completed:^{
- dispatch_async(dispatch_get_main_queue(), ^{
- @strongify(self)
- if (trainTime >= 30) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:statusIsSignIn? @"检测到上次未正常签退,请签退后再开始理论计时" : @"检测到学员已签退!本地存在异常学时,是否删除异常学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"取消" otherButtonTitles:@[statusIsSignIn? @"签退" : @"删除"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- @strongify(self)
- !resultBlock? : resultBlock(NO);
- if (selectedOtherButtonIndex == 0) {
- if (statusIsSignIn) {
- TrainRecord *lastRecord = [array lastObject];
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) {
- @strongify(self)
- if (isSuccess) {
- if (dict) {
- NSDictionary *myDict = dict;
- NSString *imageUrlStr = myDict[@"body"];
- if (RQStringIsEmpty(imageUrlStr)) {
- ShowMsg(@"路径为空");
- }
- /// 3.签退
- [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
- @strongify(self)
- if (success) {
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
- /// 4.2上传签退照片
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:lastRecord.classid timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- if (isSuccess) {
- NSLog(@"上传签退照片成功!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
- } else {
- NSLog(@"上传签退照片失败!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
- @strongify(self)
- [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:lastRecord.endTime actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut];
- }];
- }
- }];
- }
- !resultBlock? : resultBlock(NO);
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
-
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- } else {
- for (TrainRecord *record in array) {
- [DB_Helper deleteTrainRecord:record];
- }
- }
- }
- }];
- } else {
- if (statusIsSignIn) {
- [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:@[] resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
- @strongify(self)
- if (isSuccess) {
- [self signOutSuccessWithTrainArray:@[] signOutSuccess:YES uploadImageSuccess:NO completion:nil];
- }
- !resultBlock? : resultBlock(isSuccess);
- }];
- } else {
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, id dict) {
- @strongify(self)
- if (isSuccess) {
- if (dict) {
- NSDictionary *myDict = dict;
- NSString *imageUrlStr = myDict[@"body"];
- if (RQStringIsEmpty(imageUrlStr)) {
- ShowMsg(@"路径为空");
- }
- /// 3.获取线上时间
- [RQ_RemoteTheory_MANAGER getCurrentTimeWithResultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull timeDict) {
- @strongify(self)
- if (isSuccess) {
- // NSString *timeStr = @"2022-03-13 22:46:59";
- NSDate *date = [NSDate rq_dateWithTimestamp:timeDict[@"body"]];
- // NSDate *date = [NSDate rq_dateWithTimestamp:timeStr];
- NSInteger timeStamp = [[NSNumber numberWithDouble:[date timeIntervalSince1970]] integerValue];
- NSString *timeStampStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:timeStamp]];
-
- self.classIdStr = timeStampStr;
- if (self.classIdStr.length < 10) {
- /// 如果生成时间戳错误 用一个随机十位数代替
- self.classIdStr = [NSString stringWithFormat:@"%@",[NSNumber numberWithInteger:[NSString rq_randomNumberWithFrom:1647311377 to:9999999999]]];
- }
-
-
- /// 4.签到
- [RQ_RemoteTheory_MANAGER uploadEduSignInWithClassidStr:self.classIdStr resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signInDict) {
- if (isSuccess) {
- @strongify(self)
- NSString *timeStr = signInDict[@"body"];
- [self signInSuccessWithBeginTime:timeStr];
- /// 5.上传照片
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignIn resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- // @strongify(self)
- }];
-
- }
-
- !resultBlock? : resultBlock(isSuccess);
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
-
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- }
- }
- });
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- }
- }];
- } else {
- !resultBlock? : resultBlock(YES);
- [self beginTime];
- }
- }
- - (void)stopTimingWithResultBlock:(void (^)(BOOL isSuccessed))resultBlock {
- @weakify(self)
- [self.timer setFireDate:[NSDate distantFuture]];
- [self saveTrain];
- if (defUser.isycbd == 1) {
- /// 1.本地活体检测
- [RQ_CHECKBODY_MANAGER beginCheckBodyWithCheckNum:0 completeBlock:^(BOOL success, NSDictionary * _Nullable dic) {
- @strongify(self)
- if (success) {
- /// 2.线上活体检测
- [RQ_RemoteTheory_MANAGER edufaceTofaceWithPhotoStr:dic[@"normalImg"] loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, id dict) {
- @strongify(self)
- if (isSuccess) {
- if (dict) {
- NSDictionary *myDict = dict;
- NSString *imageUrlStr = myDict[@"body"];
- if (RQStringIsEmpty(imageUrlStr)) {
- ShowMsg(@"路径为空");
- }
- /// 3.签退
- NSString *pxkm = defUser.userDict[@"pxjd"];
- if (pxkm.length < 1) {
- pxkm = @"1";
- }
- if (([pxkm isEqualToString:@"2"] || [pxkm isEqualToString:@"3"])) {
- pxkm = @"4";
- }
-
- NSArray* array = [DB_Helper quearyTrain:RQStringIsNotEmpty(defUser.userStuId)? defUser.userStuId : @"" Subject:pxkm];
- if (array.count < 1) {
- !resultBlock? : resultBlock(YES);
- ShowMsg(@"本地无学时明细!");
- return;
- }
- [RQ_RemoteTheory_MANAGER uploadEduSignOutWithArray:array resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull signOutDict) {
- @strongify(self)
- if (isSuccess) {
- !resultBlock? : resultBlock(YES);
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:nil];
- /// 4.2上传签退照片
- NSString *timeStr = [self getTimes:self.seconds];
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- @strongify(self)
- if (isSuccess) {
- NSLog(@"上传签退照片成功!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:YES completion:nil];
- } else {
- NSLog(@"上传签退照片失败!");
- [self signOutSuccessWithTrainArray:array signOutSuccess:YES uploadImageSuccess:NO completion:^{
- [self reUploadPhotoWithClassidStr:self.classIdStr timeStr:timeStr actionPhotoStr:imageUrlStr loginFlagType:LoginFlagType_SignOut];
- }];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- !resultBlock? : resultBlock(NO);
- [self.timer setFireDate:[NSDate distantPast]];
- }
- }];
- } else {
- !resultBlock? : resultBlock(YES);
- [self setSecondString:@"0"];
-
- [self.timer setFireDate:[NSDate distantFuture]];
- [self.timer invalidate];
- self.timer = nil;
- myDelegate.timer = nil;
- // myDelegate.tPeriodVC = nil;
- myDelegate.isTrain = NO;
- timeLabel1.text = @"00:00";
- timeLabel2.text = @"00:00:00";
- // if (self.seconds < 60) {
- // ShowMsg(@"学时未满一分钟不统计");
- // return;
- // }
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"结束计时,是否上传学时?" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"暂不上传" otherButtonTitles:@[@"确定"] otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- @strongify(self)
- if (selectedOtherButtonIndex == 0) {
- [self upLoadTrainRecord];
- }else if (selectedOtherButtonIndex == NSNotFound){
- ShowMsg(@"学时已保存在本地");
- }
- }];
- }
- }
- //远程理论签到成功
- - (void)signInSuccessWithBeginTime:(NSString *)beginTime {
- myDelegate.begin_Time = beginTime;
- [Tools playAudioWithString:@"操作成功,开始计时"];
- self.seconds = 0;
- // [self.on_offBtn setTitle:@"结束计时" forState:UIControlStateNormal];
- myDelegate.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
- myDelegate.isUseriPhone = YES;
- myDelegate.isTrain = YES;
- self.timer = myDelegate.timer;
- begin_endBtn.selected = YES;
- //防止前五分钟内退出软件 造成理论无本地学时 无法签退的问题
- [self saveTrain];
- // myDelegate.tPeriodVC = self;
- ShowMsgSuc();
-
- [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:YES];
- }
- //远程理论签退成功
- - (void)signOutSuccessWithTrainArray:(NSArray *)trainArray signOutSuccess:(BOOL)signOutSuccess uploadImageSuccess:(BOOL)uploadImageSuccess completion:(void (^)(void))completion {
- for (TrainRecord *record in trainArray) {
- [DB_Helper updateTrainState:record];
- }
- if (trainArray.count > 0) {
- if (signOutSuccess) {
- if (![_secondString isEqualToString:@"0"]) {
- [self setSecondString:@"0"];
- }
- if (self.timer.isValid) {
- [self.timer invalidate];
- }
- if (self.timer) {
- self.timer = nil;
- }
- if (myDelegate.timer) {
- myDelegate.timer = nil;
- }
- // if (myDelegate.tPeriodVC) {
- // myDelegate.tPeriodVC = nil;
- // }
- if (myDelegate.isTrain) {
- myDelegate.isTrain = NO;
- }
- if (![timeLabel1.text isEqualToString:@"00:00"]) {
- timeLabel1.text = @"00:00";
- }
- if (![timeLabel2.text isEqualToString:@"00:00:00"]) {
- timeLabel2.text = @"00:00:00";
- }
- }
-
- if (signOutSuccess && uploadImageSuccess) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"签退成功!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"确定" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:nil];
- } else if (signOutSuccess && !uploadImageSuccess && completion) {
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- completion();
- }];
- }
-
-
- } else {
- // 强制签退后再去调签到
- [self startTimingWithResultBlock:nil];
- }
- [RQ_COMMON_MANAGER keepIdleTimerDisabledisOpen:NO];
- }
- - (void)reUploadPhotoWithClassidStr:(NSString *)classidStr timeStr:(NSString *)timeStr actionPhotoStr:(NSString *)actionPhotoStr loginFlagType:(LoginFlagType)loginFlagType {
- __block BOOL reUploadSuccess = YES;
- __block BOOL isUploading = NO;
- int i = 0;
- do {
- if (i == 0) {
- if (!isUploading) {
- isUploading = YES;
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- if (isSuccess) {
- ShowMsg(@"重新上传照片成功!");
- reUploadSuccess = YES;
- } else {
- reUploadSuccess = NO;
- }
- isUploading = NO;
- }];
- }
- } else {
- if (!isUploading) {
- isUploading = YES;
- [RQ_SHARE_FUNCTION showAlertWithTitle:@"温馨提示" message:@"上传照片失败!" alertControllerStyle:UIAlertControllerStyleAlert cancelButtonTitle:@"重新上传" otherButtonTitles:nil otherButtonStyles:nil showInWindow:NO completion:^(NSUInteger selectedOtherButtonIndex) {
- [RQ_RemoteTheory_MANAGER uploadEduPicWithClassidStr:classidStr timeStr:timeStr actionPhotoStr:actionPhotoStr loginFlagType:loginFlagType resultBlock:^(BOOL isSuccess, NSDictionary * _Nonnull uploadEduPicDict) {
- if (isSuccess) {
- ShowMsg(@"重新上传照片成功!");
- reUploadSuccess = YES;
- } else {
- reUploadSuccess = NO;
- }
- isUploading = NO;
- }];
- }];
- }
- }
- i ++;
- } while (reUploadSuccess == NO);
- }
- - (NSString *)getTimes:(int)second {
-
- NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
- [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
-
- NSString *beginTimeStr = myDelegate.begin_Time;
- [formatter setLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"]];
- NSDate *beginDate = [formatter dateFromString:beginTimeStr];
- NSDate *newDate = [NSDate dateWithTimeInterval:second sinceDate:beginDate];
- NSString *nowString = [formatter stringFromDate:newDate];
- return nowString;
- }
- @end
|