| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052 |
- //
- // DetailPageViewController.m
- // Apex Mobile
- //
- // Created by Ray on 14-3-8.
- // Copyright (c) 2014年 United Software Applications, Inc. All rights reserved.
- //
- #import "DetailPageViewController.h"
- #import "AMShipMap.h"
- #define DEF_CELL_HEIGHT 44
- #define DEF_TABLE_HEIGHT 44
- #define LINE_WIDTH 0
- #define CELL_MARGIN 15
- #define LABEL_MARGIN 0
- #define NEW_MAPCELL_MARGIN 8
- #import "TabBarController.h"
- #import "DetailCellTracking.h"
- #import <QuickLook/QuickLook.h>
- #import "DetailCellKVNew.h"
- #import "MyQLPreviewController.h"
- #import "LPShareActivity.h"
- #import "AMCommEditCell.h"
- #import "AMCommHeadCell.h"
- #import "AMCommContentCell.h"
- #import <Contacts/Contacts.h>
- #import <ContactsUI/ContactsUI.h>
- #define COMM_ID_HEAD @"COMM_ID_HEAD"
- #define COMM_ID_CONTENT @"COMM_ID_CONTENT"
- #define COMM_ID_EDIT @"COMM_ID_EDIT"
- @interface DetailHUD : UIView
- @property (nonatomic,strong) UILabel *msgLb;
- @end
- @implementation DetailHUD
- + (void)show:(NSString *)msg inView:(UIView *)view {
-
- if (!msg) {
- return;
- }
-
- DetailHUD *hud = [[DetailHUD alloc] initWithFrame:CGRectZero];
- hud.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.9];
- hud.msgLb.text = msg;
- [hud layoutSize];
- for (UIView *sub in view.subviews) {
- if ([sub isKindOfClass:self]) {
- sub.hidden = YES;
- }
- }
- [view addSubview:hud];
-
- [hud performSelector:@selector(hide) withObject:nil afterDelay:3.0f];
- }
- - (UILabel *)msgLb {
- if (!_msgLb) {
- _msgLb = [[UILabel alloc] initWithFrame:CGRectZero];
- _msgLb.textColor = [UIColor whiteColor];
- _msgLb.font = [UIFont systemFontOfSize:14.0f];
-
- [self addSubview:_msgLb];
- }
- return _msgLb;
- }
- - (void)layoutSize {
- [self.msgLb sizeToFit];
- CGSize size = self.msgLb.bounds.size;
-
- CGFloat height = size.height + 20;
- CGFloat width = size.width + 20;
- if (height < 30) {
- height = 30;
- }
- if (width < 30) {
- width = 30;
- }
-
- self.msgLb.center = CGPointMake(width * 0.5, height * 0.5);
- self.bounds = CGRectMake(0, 0, width, height);
-
- self.layer.cornerRadius = 5.0f;
- self.layer.masksToBounds = YES;
-
- }
- - (void)willMoveToSuperview:(UIView *)newSuperview {
- [super willMoveToSuperview:newSuperview];
-
- if (newSuperview) {
- self.center = CGPointMake(newSuperview.bounds.size.width * 0.5, newSuperview.bounds.size.height * 0.5);
- }
- }
- - (void)layoutSubviews {
- [super layoutSubviews];
-
- if (self.superview) {
- self.center = CGPointMake(self.superview.bounds.size.width * 0.5, self.superview.bounds.size.height * 0.5);
- }
- }
- - (void)hide {
- [self removeFromSuperview];
- }
- @end
- @interface DetailPageViewController () <QLPreviewControllerDataSource,QLPreviewControllerDelegate,DetailKVCellTapDelegate,AMCommHeadCellDelegate,AMCommContentCellDelegate,AMCommEditCellDelegate,CNContactPickerDelegate,AMShipMapDelegate>
- @property (nonatomic,strong) MyQLPreviewController *quickLook;
- @property (nonatomic,copy) NSString *documentPath;
- @property (nonatomic,copy) NSString *email;
- @property (nonatomic,copy) NSString *email_subject;
- @property (nonatomic,copy) NSString *email_content;
- @property (nonatomic,strong) IBOutlet AMShipMap *shipMap;
- @property (nonatomic,weak) UITableViewCell *editingCell;
- @property (nonatomic,strong) NSIndexPath *editingIndexPath;
- @property (nonatomic,strong) NSIndexPath *contactSelectIndexPath;
- @property (nonatomic,weak) UITapGestureRecognizer *tap;
- @property (nonatomic,assign) BOOL showKeyboard;
- @property (nonatomic,strong) NSIndexPath *containerSelectedIndexPath;
- @end
- @implementation DetailPageViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- -(void)changeCell
- {
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
- reF.attributedTitle = [[NSAttributedString alloc]initWithString:@"refreshing"];
- [self performSelector:@selector(ReloadData) withObject:nil afterDelay:1];
- DebugLog(@"refresh!!!!!!!!");
-
- }
- -(void)ReloadData
- {
-
- // Count ++ ;
- // [mytabelview reloadData];
- [self loadpage];
- UIRefreshControl *reF = (UIRefreshControl *)[self.view viewWithTag:200];
-
- [reF endRefreshing];
-
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // self.webviewoprationQueue = [[NSOperationQueue alloc] init];
- // self.webviewoprationQueue.maxConcurrentOperationCount = 1;
-
- UIRefreshControl *ref = [[UIRefreshControl alloc]init];
- ref.tag = 200 ;
- ref.attributedTitle = [[NSAttributedString alloc]initWithString:@"drag to refresh"];
- ref.tintColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // ref.hidden = true;
- [ref addTarget:self action:@selector(changeCell) forControlEvents:UIControlEventValueChanged];
-
- [self.table addSubview:ref];
- if(self.tabBarController.tabBar.hidden==true)
- {
- CGRect frame = self.table.frame;
- frame.size.height +=40;
- self.table.frame=frame;
- }
- // self.view.backgroundColor= [UIColor whiteColor];
- [self loadpage];
- // Do any additional setup after loading the view.
-
- UIBarButtonItem *previewMenuBtn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"ic_menu"] style:UIBarButtonItemStylePlain target:self action:@selector(quickLookMenuClick:)];
- self.quickLook.navigationItem.rightBarButtonItem = previewMenuBtn;
-
- [self configureMap];
- [self configureTableView];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- NSString *action_type = [self.params objectForKey:@"action_type"];
- if ([action_type isEqualToString:@"Detail"]) { // 避免Tap与Tacking中Cell点击冲突
- [self startListenKeyboard];
- }
-
- if (self.shipMap) {
- [self.shipMap shipMapWillAppear];
- }
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [self stopListenKeyboard];
-
- if (self.shipMap) {
- [self.shipMap shipMapWillDisappear];
- }
- }
- - (void)configureTableView {
-
- [self.table registerNib:[UINib nibWithNibName:@"AMCommHeadCell" bundle:nil] forCellReuseIdentifier:COMM_ID_HEAD];
- [self.table registerNib:[UINib nibWithNibName:@"AMCommContentCell" bundle:nil] forCellReuseIdentifier:COMM_ID_CONTENT];
- [self.table registerNib:[UINib nibWithNibName:@"AMCommEditCell" bundle:nil] forCellReuseIdentifier:COMM_ID_EDIT];
-
- }
- - (void)configureMap {
-
- if (!self.showMap) {
-
- NSArray *constraints = [[self.view constraints] mutableCopy];
- // 删除Table与Map相关约束
- for (NSLayoutConstraint *constaint in constraints) {
- if ([constaint.identifier isEqualToString:@"top_constraint"]) {
- [self.view removeConstraint:constaint];
- } else if ([constaint.identifier isEqualToString:@"ratio_constraint"]) {
- [self.view removeConstraint:constaint];
- }
- }
-
- // 移除地图
- [self.shipMap removeFromSuperview];
- self.shipMap = nil;
-
- // 设置新约束
- NSLayoutConstraint *top = [NSLayoutConstraint constraintWithItem:self.table
- attribute:NSLayoutAttributeTop
- relatedBy:NSLayoutRelationEqual
- toItem:self.topLayoutGuide
- attribute:NSLayoutAttributeBottom
- multiplier:1.0
- constant:0];
- [self.view addConstraint:top];
-
-
-
- [self.view layoutIfNeeded];
- } else {
- self.shipMap.showCurrent = YES;
- self.shipMap.showPoe = YES;
- self.shipMap.showPol = YES;
- self.shipMap.showPod = YES;
- self.shipMap.showPor = YES;
- self.shipMap.showOrigin = YES;
- self.shipMap.showDestination = YES;
-
- self.shipMap.delegate = self;
- }
-
- }
- - (void)saveDocumentClick:(id)sender {
-
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
-
- NSError *err;
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
- [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
- }
- [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
-
- UIAlertController *alertVC;
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- if (err) {
- alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
- } else {
- alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert];
- }
- [alertVC addAction:action];
-
- [self presentViewController:alertVC animated:YES completion:nil];
-
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- -(void) loadpage
- {
-
- // [self.params setValue:[NSString stringWithFormat:@"%d",self.offset] forKey:@"offset"];
- // self.prepageButton.enabled=false;
- // self.nextpageButton.enabled=false;
- self.mum.center = self.view.center;
- __weak typeof(self) weakSelf = self;
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@"ResizeView" context:nil];
- [UIView setAnimationDuration:animationDuration];
-
- self.mum.hidden = false;
- self.table.hidden = true;
-
- [UIView commitAnimations];
-
- if (self.showMap) {
- [self.params setObject:@(YES) forKey:@"request_location"];
- }
- if ([[self.params objectForKey:@"action_type"] isEqualToString:@"Detail"]) {
- [self.params setObject:@(YES) forKey:@"request_communication"];
- }
-
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
- self.content=[RANetwork get_detailcontent:self.params];
-
-
- // PageData* pageData=nil;
- // if(self.recordCount==-1)
- // self.recordCount=[RANetwork get_recordcount: self.params ];
- // if(self.recordCount>0)
- // {
- // self.pageData=[RANetwork get_pagedata:self.params];
- // // self.pageData=[RANetwork]
- // }
- //
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- NSTimeInterval animationDuration = 0.30f;
- [UIView beginAnimations:@"ResizeView" context:nil];
- [UIView setAnimationDuration:animationDuration];
-
-
- self.mum.hidden = true;
- if(self.content.result_code!=RESULT_TRUE)
- {
- self.table.hidden =false;
- [self.table reloadData];
-
- }
- else
- if([self.content get_segmentcount]==0)
- {
-
-
- self.table.hidden =true;
- self.norecordLabel.hidden=false;
-
- if(self.tabBarController.childViewControllers.count==1)
- {
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
- message: @"No Search Result."
- preferredStyle: UIAlertControllerStyleAlert];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"Back" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf.navigationController popViewControllerAnimated:false];
- }];
- [alertVC addAction:action];
- [weakSelf presentViewController:alertVC animated:YES completion:nil];
-
- }
-
-
- }
- else
- {
- self.table.hidden =false;
- [self.table reloadData];
-
- self.email = [self.content.originContent objectForKey:@"email"];
- self.email_subject = [self.content.originContent objectForKey:@"email_subject"];
- self.email_content = [self.content.originContent objectForKey:@"email_content"];
- }
- [UIView commitAnimations];
-
- NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
- bool autologin =[defaults boolForKey:@"autologin"];
- if(!autologin)
- {
- TabBarController * viewController =[[UIStoryboard storyboardWithName:@"Main" bundle:nil] instantiateViewControllerWithIdentifier:@"LoginTabBar"];
- [self presentViewController:viewController animated:YES completion:^{
-
- }];
- }
- // 设置默认选中第一个Container
- for (NSInteger i = 0; i < self.content.segments.count; i++) {
-
- NSMutableDictionary* segment = [self.content.segments[i] mutableCopy];
- NSString* type =[segment valueForKey:@"_type"];
-
- if([type isEqualToString:@"tracking"]) {
- NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:i];
- [self.table selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
- [self tableView:self.table didSelectRowAtIndexPath:indexPath];
- break;
- }
- }
-
- // [self.table setNeedsDisplay];
- // if(self.recordCount<2000)
- // self.countView.title = [NSString stringWithFormat:@"%d records",self.recordCount];
- // else
- // self.countView.title = @"2000+ records";
- //
- // if(self.offset<self.pageData.get_count)
- // self.prepageButton.enabled=false;
- // else
- // self.prepageButton.enabled=true;
- // if(self.offset+self.pageData.get_count>=self.recordCount)
- // self.nextpageButton.enabled=false;
- // else
- // self.nextpageButton.enabled=true;
- // [self.grid initgrid :self.pageData];
-
-
- });
- });
- }
- //- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
- //{
- //// [self.table beginUpdates];
- // [self.table reloadData];
- //// [self.table endUpdates];
- //
- //}
- - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
-
- __weak typeof(self) weakSelf = self;
- [coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
-
- // 动画前
- } completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
-
- // 动画后
- [weakSelf.table reloadData];
- }];
-
- [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
- }
- //// 是否支持屏幕旋转
- //- (BOOL)shouldAutorotate {
- //
- //
- // return YES;
- //}
- //// 支持的旋转方向
- //- (NSUInteger)supportedInterfaceOrientations {
- // return UIInterfaceOrientationLandscapeRight;//UIInterfaceOrientationMaskAllButUpsideDown;
- //}
- //// 一开始的屏幕旋转方向
- //- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
- // return UIInterfaceOrientationLandscapeRight;
- //}
- - (void)showDocument:(NSString *)url {
-
- __weak typeof(self) weakSelf = self;
-
- // show alert
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle: nil
- message: @"loading..."
- preferredStyle: UIAlertControllerStyleAlert];
-
-
-
- UIViewController *customVC = [[UIViewController alloc] init];
-
-
- UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
- spinner.color = [UIColor darkGrayColor];
- [spinner startAnimating];
- [customVC.view addSubview:spinner];
-
- [customVC.view addConstraint:[NSLayoutConstraint
- constraintWithItem: spinner
- attribute:NSLayoutAttributeCenterX
- relatedBy:NSLayoutRelationEqual
- toItem:customVC.view
- attribute:NSLayoutAttributeCenterX
- multiplier:1.0f
- constant:0.0f]];
-
-
-
- [customVC.view addConstraint:[NSLayoutConstraint
- constraintWithItem: spinner
- attribute:NSLayoutAttributeCenterY
- relatedBy:NSLayoutRelationEqual
- toItem:customVC.view
- attribute:NSLayoutAttributeCenterY
- multiplier:1.0f
- constant:0.0f]];
-
-
- [alertController setValue:customVC forKey:@"contentViewController"];
-
- [self presentViewController: alertController animated: YES completion: nil];
-
- // download
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
-
- // NSArray *paths = NSSearchPathForDirectoriesInDomains(nstem, NSUserDomainMask, YES);
- // NSString *documents = [paths objectAtIndex:0];
- // NSString *cacheDir = [documents stringByAppendingPathComponent:[module_name stringByAppendingString:@"_download"]];
-
- NSString *cacheDir = NSTemporaryDirectory();
-
- if (![[NSFileManager defaultManager] fileExistsAtPath:cacheDir]) {
- [[NSFileManager defaultManager] createDirectoryAtPath:cacheDir withIntermediateDirectories:NO attributes:nil error:nil];
- }
-
- // NSString *path = [cacheDir stringByAppendingPathComponent:[NSUUID UUID].UUIDString];
-
-
-
- [RANetwork download_file:nil url:url toCachePath:cacheDir progressHandler:^(NSURLSessionTask *task, double progress) {
-
- DebugLog(@"download progress %f",progress);
- } completionHandler:^(NSMutableDictionary *result) {
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
- weakSelf.documentPath = nil;
- [alertController dismissViewControllerAnimated:YES completion:^{
-
-
- if ([[result objectForKey:@"result"] intValue] == RESULT_TRUE) {
-
- NSString *cachePath = [result objectForKey:@"path"];
- weakSelf.documentPath = cachePath;
-
- if (cachePath) { // push 必须在completion中
- [weakSelf.navigationController pushViewController:weakSelf.quickLook animated:YES];
- }
-
- } else {
-
- NSString *msg = [result objectForKey:@"msg"];
-
- UIAlertController *alertVC = [UIAlertController alertControllerWithTitle: @"Warning"
- message: msg
- preferredStyle: UIAlertControllerStyleAlert];
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alertVC addAction:action];
- [weakSelf presentViewController:alertVC animated:YES completion:nil];
- }
-
- }];
-
-
- });
-
- DebugLog(@"download result %@",result);
-
- }];
-
-
- });
-
- }
- #pragma mark - WKNavigationDelegate
- - (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation
- {
- NSLog(@"webview didFinishNavigation");
- UITableViewCell *cell = (UITableViewCell *)[[webView superview] superview];
-
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- if(indexPath==nil)
- {//for ios7
- cell = (UITableViewCell *) webView.superview.superview.superview;
- indexPath = [self.table indexPathForCell:cell];
- }
-
-
-
- float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
-
- if(height>0)
- return;
-
-
-
- [webView evaluateJavaScript:@"document.body.scrollHeight;" completionHandler:^(id _Nullable fitHeight,NSError * _Nullable error) {
- CGRect frame = webView.frame;
- frame.size.height = [fitHeight floatValue];
- //webView.frame = frame;
-
- [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",frame.size.height/*webView.scrollView.contentSize.height*/] forKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]];
-
- DebugLog(@"webViewDidFinishLoad ^^^^^^^^^^^^^^^^^reloadRowsAtIndexPaths");
- if (![[self.table indexPathsForVisibleRows] containsObject:indexPath])
- {
- //cell 已无法显示。
- return;
- }
-
- dispatch_async(dispatch_get_main_queue(), ^{
-
-
- NSLog(@"reload tableview!!! %f",frame.size.height);
- // UI更新代码
- // [self.table reloadData];
- // [self.detailTable reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
- [self.table reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
- //[self.editorTable reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationNone];
- });
-
-
- }];
-
-
- }
- //禁止链接跳转
- - (void)webView:(WKWebView *)webView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
-
- NSLog(@"%s",__func__);
- NSLog(@"navigationAction = %@, \r!!!!!!!!!!!!!!!!!!!!!!\n request = %@",navigationAction,navigationAction.request.URL);
-
-
-
-
-
- if(navigationAction.navigationType != WKNavigationTypeLinkActivated)
-
- return decisionHandler(WKNavigationActionPolicyAllow);
- // NSString *currentURL =[webView.request.URL lastPathComponent];// [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
- NSString* str = navigationAction.request.URL.absoluteString;
- if([str isEqualToString:@"about:blank"])
- return decisionHandler(WKNavigationActionPolicyAllow);;
-
- [self showDocument:navigationAction.request.URL.absoluteString];
-
- return decisionHandler(WKNavigationActionPolicyCancel);;
-
-
- }
- #pragma mark - Section Switch
- - (void)sectionSwitchClick:(UIButton *)sender {
- NSInteger section = sender.tag - 1020;
-
- NSMutableArray *segments = [self.content.segments mutableCopy];
- NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
- NSString* type =[segment valueForKey:@"_type"];
- if([type isEqualToString:@"tracking"])
- {
- BOOL close = [[segment objectForKey:@"close"] boolValue];
-
- if (!close) {
- close = YES;
- } else {
- close = NO;
- }
- [segment setValue:@(close) forKey:@"close"];
- segments[section] = segment;
- self.content.segments = segments;
- // [self.table reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:UITableViewRowAnimationNone];
- [self.table reloadData];
- }
- }
- - (void)copyTap:(UITapGestureRecognizer *)tap {
- UILabel *lb = (UILabel *)tap.view;
-
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = lb.text;
- [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",lb.text] inView:self.view];
- }
- #pragma mark - Table view data source
- //
- //- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- //{
- // return 40;
- //}
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- {
- DebugLog(@"heightForRowAtIndexPath");
-
- // float height = [self.content itemHeightAtIndexPath:indexPath];
- NSString* type = [self.content get_segmenttype:indexPath.section];
-
-
-
- if([type isEqualToString:@"table"])
- {
- // [self.content.webviewHeight setObject:[NSString stringWithFormat:@"%f",webView.frame.size.height] forKey:[NSString stringWithFormat:@"%d",webView.tag]];
-
- float height= [[self.content.webviewHeight valueForKey:[NSString stringWithFormat:@"%ld",(long)indexPath.section]] floatValue];
- if(height==0)
- height=DEF_TABLE_HEIGHT;
-
-
- // DebugLog(@"heightForRowAtIndexPath...............webview,hight = %f section=%ld",height,indexPath.section);
- //wait(1000);
- return height;
-
- }
- else if([type isEqualToString:@"tracking"])
- {
- return 64;
- }
- else if([type isEqualToString:@"mapping"])
- {
-
-
- // NSString *CellIdentifier = @"detail_item_kvnew";
- // DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* key =[item allKeys][0];
- // [cell.keyLabel sizeToFit];
- NSString* val=[item valueForKey:key];
- if([val isEqual:[NSNull null]])
- val=@"";
- // cell.keyLabel.text = key;
- // cell.valLabel.htmlText = val;
-
- // UILabel* l = [UILabel new];
- // l.text =@"Place_Of_Receipt";
-
- // CGSize size= [l sizeThatFits:CGSizeMake(116,MAXFLOAT)];
-
- float width = tableView.frame.size.width;
- // width-=CELL_MARGIN*2;
- CGSize constraintkey = CGSizeMake(width*0.4-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//key label width is 40% cell width;
- CGSize constraintval = CGSizeMake(width*0.6-2*NEW_MAPCELL_MARGIN, MAXFLOAT);//val label width is 60% cell width;
-
- /*
- NSLineBreakByWordWrapping = 0, // Wrap at word boundaries, default
- NSLineBreakByCharWrapping, // Wrap at character boundaries
- NSLineBreakByClipping, // Simply clip
- NSLineBreakByTruncatingHead, // Truncate at head of line: "...wxyz"
- NSLineBreakByTruncatingTail,
- */
-
- UIFont * F1=[UIFont systemFontOfSize:13];
- UIFont * F2=[UIFont fontWithName:@".SFUIText-Bold" size:13];//[UIFont boldSystemFontOfSize:13];
- // [UILabel setFont:];
- MDHTMLLabel* keylabel = [MDHTMLLabel new];
- keylabel.font = F2;
- keylabel.numberOfLines = 0;
- keylabel.lineBreakMode = NSLineBreakByTruncatingTail;
- keylabel.frame = CGRectMake(0, 0, constraintkey.width, constraintkey.height);
- keylabel.text=key;
- CGSize calkeysize= [keylabel sizeThatFits:constraintkey];
- if([key isEqualToString:@"Place_Of_Delivery"])
- {
- // int abc=0;
- }
- // [keylabel sizeToFit];
- // CGRect r = keylabel.frame;
-
-
- MDHTMLLabel* vallabel = [MDHTMLLabel new];
- vallabel.font = F1;
- vallabel.numberOfLines = 0;
- vallabel.lineBreakMode = NSLineBreakByWordWrapping;
- vallabel.htmlText=val;
- vallabel.frame = CGRectMake(0, 0, constraintval.width, constraintval.height);
- CGSize calvalsize= [vallabel sizeThatFits:constraintval];
-
- float height = MAX(calkeysize.height,calvalsize.height)+NEW_MAPCELL_MARGIN*2;
- height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
-
- return height;
- //
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- // NSString* key =[item allKeys][0];
- // // [cell.keyLabel sizeToFit];
- // NSString* val=[item valueForKey:key];
- // if([val isEqual:[NSNull null]])
- // val=@"";
- // if(val==nil)
- // val=@"";
- // if([val isEqualToString:@"null"])
- // val=@"";
- //
- //
- //
- // CGRect frame;
- // frame.size = constraintval;
- // frame.origin.x=0;
- // frame.origin.y=0;
- // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // // rtlabel.lineSpacing = 20.0;
- // [rtlabel setText: val];
- // CGSize sizeval=rtlabel.optimumSize;
- //
- //
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- // float height = MAX(sizekey.height,sizeval.height);
- // height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
- //
- // /*
- // NSString *text = [items objectAtIndex:[indexPath row]];
- //
- // CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
- //
- // CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
- //
- // CGFloat height = MAX(size.height, 44.0f);
- //
- // return height + (CELL_CONTENT_MARGIN * 2);
- // */
- // // NSString *CellIdentifier = @"detail_item_kv";
- // // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- // // cell.keyLabel.text=[item allKeys][0];
- // // [cell.keyLabel sizeToFit];
- // // cell.valLabel.text= [item valueForKey:cell.keyLabel.text];
- // // [cell.valLabel sizeToFit];
- // //
- // // return MAX(cell.keyLabel.frame.size.height,cell.valLabel.frame.size.height);
- // return height;
- }
- else if ([type isEqualToString:@"communication"]) {
- NSInteger rowCount = [self tableView:tableView numberOfRowsInSection:indexPath.section];
- if (indexPath.row == 0) {
- return 118.0f;
- } else if (indexPath.row == rowCount - 1) {
-
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- NSString *edit_content = [segment objectForKey:@"edit_content"];
-
- CGFloat h = 40.0f; // 输入框高度,最小40
- if (edit_content && edit_content.length > 0) {
-
- AMCommEditCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"AMCommEditCell" owner:nil options:nil] objectAtIndex:0];
-
- h = [cell heightForContent:edit_content withTableWidth:CGRectGetWidth(tableView.bounds)];
-
- if (h < 40.0f) {
- h = 40.0f;
- } else if (h > 100.0f) { // 输入框高度,最大100
- h = 100.0f;
- }
-
-
- } else {
- h = 40.0f;
- }
-
- return 50.0f + h;
- } else {
-
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- NSString *itemKey = [NSString stringWithFormat:@"item%ld",indexPath.row - 1];
- NSDictionary *item = [[segment objectForKey:itemKey] mutableCopy];
-
- CGFloat height = [[item objectForKey:@"content_height"] floatValue];
- if (height <= 0) {
-
- NSString *content = [item objectForKey:@"msg"];
-
- if (content && content.length > 0) {
- NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:14.0f]};
-
- CGSize resSize = [content boundingRectWithSize:CGSizeMake(CGRectGetWidth(tableView.bounds) - 11, MAXFLOAT)
- options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
- attributes:attribute
- context:nil].size;
- height = resSize.height;
- } else {
- height = 0;
- }
-
- [item setValue:@(height) forKey:@"content_height"];
- [segment setObject:item forKey:itemKey];
-
- NSMutableArray *arr = [self.content.segments mutableCopy];
- [arr replaceObjectAtIndex:indexPath.section withObject:segment];
- self.content.segments = arr;
- }
- return 71.5 + height;
- }
- }
- else
- {
- DebugLog(@"cellForRowAtIndexPath =====> list");
-
- float width = tableView.frame.size.width;
- width-=CELL_MARGIN*2;
-
- CGSize constraintval = CGSizeMake(width, 20000.0f);//val label width is 60% cell width;
-
- NSDictionary* item = self.content.segments[indexPath.section];
-
- NSString* text=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
-
-
-
- if([text isEqual:[NSNull null]])
- text=@"";
- if(text==nil)
- text=@"";
- if([text isEqualToString:@"null"])
- text=@"";
-
-
-
- // CGRect frame;
- // frame.size = constraintval;
- // frame.origin.x=0;
- // frame.origin.y=0;
-
-
- // CGSize sizeText = [text sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizeText = [text boundingRectWithSize:constraintval options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
- float height = sizeText.height;
- height = MAX(height+LINE_WIDTH, DEF_CELL_HEIGHT);
- return height;
-
- }
-
-
- // return height;
- }
- //- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
- // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- // UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
- // titleLabel.textColor=[UIColor whiteColor];
- // titleLabel.backgroundColor = [UIColor clearColor];
- // titleLabel.text =[self.content get_segmentname:section];
- // [titleLabel sizeToFit];
- // [myView addSubview:titleLabel];
- //
- // return myView;
- //}
- //- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
- //{
- // UIView* myView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
- // myView.backgroundColor = [UIColor colorWithRed:0.10 green:0.68 blue:0.94 alpha:0.7];
- //// UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 90, 22)];
- //// titleLabel.textColor=[UIColor whiteColor];
- //// titleLabel.backgroundColor = [UIColor grayColor];
- //// titleLabel.text =[self.content get_segmentname:section];
- //// [titleLabel sizeToFit];
- //// [myView addSubview:titleLabel];
- //
- // return myView;
- //}
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
-
- DebugLog(@"numberOfSectionsInTableView=%ld",[self.content get_segmentcount]);
- return [self.content get_segmentcount];
-
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- DebugLog(@"numberOfRowsInSection=%d",[self.content get_itemcount:section]);
- NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
- NSString* type =[segment valueForKey:@"_type"];
-
- if ([type isEqualToString:@"communication"]) {
- return [self.content get_itemcount:section] + 2;
- } else {
- return [self.content get_itemcount:section];
- }
-
-
- }
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
- DebugLog(@"titleForHeaderInSection=%@",[self.content get_segmentname:section]);
- return [self.content get_segmentname:section];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
-
- NSMutableDictionary* segment = [self.content.segments[section] mutableCopy];
- NSString* type =[segment valueForKey:@"_type"];
- CGFloat w = tableView.frame.size.width;
- UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, w, 30)];
-
- UILabel *titleLb = [[UILabel alloc] initWithFrame:CGRectMake(5, 0, w - 100, 30)];
- titleLb.font = [UIFont systemFontOfSize:15.0f];
- titleLb.textColor = APGRAYCOLOR;
- titleLb.text = [self tableView:tableView titleForHeaderInSection:section];
-
- [header addSubview:titleLb];
-
- if([type isEqualToString:@"tracking"])
- {
- BOOL close = [[segment objectForKey:@"close"] boolValue];
- NSString *title = @"Show";
- if (!close) {
- title = @"Hide";
- } else {
- title = @"Show";
- }
-
- UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
- btn.frame = CGRectMake(w - 70, 0, 60, 30);
- btn.tag = 1020 + section;
- [btn setTitle:title forState:UIControlStateNormal];
- [btn setTitleColor:APGRAYCOLOR forState:UIControlStateNormal];
- [btn addTarget:self action:@selector(sectionSwitchClick:) forControlEvents:UIControlEventTouchUpInside];
-
- [header addSubview:btn];
-
- // Tap Copy
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(copyTap:)];
- tapGesture.numberOfTapsRequired = 2;
- [titleLb addGestureRecognizer:tapGesture];
- titleLb.userInteractionEnabled = YES;
- }
-
- return header;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- return 30;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- {
- return 0.0001;
- }
- //- (UIImage *) imageWithTintColor:(UIImage*)source Color:(UIColor *)tintColor blendMode:(CGBlendMode)blendMode {
- // //We want to keep alpha, set opaque to NO; Use 0.0f for scale to use the scale factor of the device’s main screen.
- // UIGraphicsBeginImageContextWithOptions(source.size, NO, 0.0f); [tintColor setFill];
- // CGRect bounds = CGRectMake(0, 0, source.size.width, source.size.height); UIRectFill(bounds);
- // //Draw the tinted image in context
- // [source drawInRect:bounds blendMode:blendMode alpha:1.0f];
- // if (blendMode != kCGBlendModeDestinationIn)
- // {
- // [source drawInRect:bounds blendMode:kCGBlendModeDestinationIn alpha:1.0f];
- // }
- // UIImage *tintedImage = UIGraphicsGetImageFromCurrentImageContext();
- // UIGraphicsEndImageContext();
- // return tintedImage;
- //}
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
-
-
-
- // NSString *CellIdentifier = @"testcell";
- // return [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
-
- NSString* type = [self.content get_segmenttype:indexPath.section];
-
-
-
- if([type isEqualToString:@"table"])
- {
- DebugLog(@"cellForRowAtIndexPath =====> table");
-
- static NSString *CellIdentifier = @"detail_item_web";
-
- DetailCellWeb *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* tablecontent = [item valueForKey:@"content"];
- cell.webView.tag = indexPath.section;
- // cell.webView.scrollView.contentSize.height = 0;
- cell.webView.scrollView.bounces=NO;
- cell.webView.scrollView.directionalLockEnabled = true;
- CGSize size= cell.webView.scrollView.contentSize;
- size.height=10;
- cell.webView.scrollView.contentSize=size;
- cell.webView.navigationDelegate=self;
- // nsstring* c = [NSString stringwith]
- // NSString *filePath = [[NSBundle mainBundle]pathForResource:@"about" ofType:@"htm"];
- // NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
-
-
- [cell.webView loadHTMLString:tablecontent baseURL:nil];
- // dispatch_async(dispatch_get_main_queue(), ^{
- //
- // wait(5000);
- // DebugLog(@"!!!!!!!!!!!!!!!!!!!!!!!!!!!webview section=%ld height=%f",indexPath.section,cell.webView.scrollView.contentSize.height);
- //
- //// DebugLog(@"url:%@", [self.webView stringByEvaluatingJavaScriptFromString:@"window.location.href;"]); // shows google.com instead of about:blank
- // });
-
-
-
- // CGRect rect = cell.webView.frame;
- // [self.content set_itemheight:cell.webView.frame.size.height AtIndexPath:indexPath];
- // [cell.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
- return cell;
- }
- else if([type isEqualToString:@"tracking"])
- {
- DebugLog(@"cellForRowAtIndexPath =====> table");
-
- static NSString *CellIdentifier = @"detail_item_tracking";
-
- DetailCellTracking *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
-
- if(indexPath.row==0)
- {
- cell.trackingIcon.tintColor=UIColorFromRGB(0x1e7ffb);
- cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
- }
- else
- {
- cell.trackingIcon.tintColor=[UIColor grayColor];
- cell.trackingIcon.image = [[UIImage imageNamed:item[@"icon"]] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
- }
-
-
- cell.trackingMsg.text=item[@"msg"];
- // NSString* tablecontent = [item valueForKey:@"content"];
- // cell.webView.tag = indexPath.section;
- // // cell.webView.scrollView.contentSize.height = 0;
- // cell.webView.scrollView.bounces=NO;
- // cell.webView.scrollView.directionalLockEnabled = true;
- // CGSize size= cell.webView.scrollView.contentSize;
- // size.height=10;
- // cell.webView.scrollView.contentSize=size;
- //
- //
- // [cell.webView loadHTMLString:tablecontent baseURL:nil];
-
- return cell;
- }
- else if([type isEqualToString:@"mapping"])
- {
-
-
- NSString *CellIdentifier = @"detail_item_kvnew";
- DetailCellKVNew *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- NSString* key =[item allKeys][0];
- // [cell.keyLabel sizeToFit];
- NSString* val=[item valueForKey:key];
-
- // if([val isEqual:[NSNull null]])
- // val=@"";
- cell.keyLabel.text = key;
- cell.valLabel.htmlText = val;
-
- if([key isEqualToString:@"Place_Of_Delivery"])
- {
- // int abc=0;
- }
-
- NSLog(@"key %@ val %@",key,val);
-
- cell.tapDelegate = self;
-
- // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
- // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
- // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
- // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
- return cell;
- // float width = tableView.frame.size.width;
- //
- // width-=CELL_MARGIN*2;
- // CGSize constraintkey = CGSizeMake(width*0.4-2*LABEL_MARGIN, 20000.0f);//key label width is 40% cell width;
- // CGSize constraintval = CGSizeMake(width*0.6-2*LABEL_MARGIN, 20000.0f);//val label width is 60% cell width;
- // NSDictionary* item = [self.content get_item_seg:indexPath.section row:indexPath.row];
- // NSString* key =[item allKeys][0];
- // // [cell.keyLabel sizeToFit];
- // NSString* val=[item valueForKey:key];
- // if([val isEqual:[NSNull null]])
- // val=@"";
- // if(val==nil)
- // val=@"";
- // if([val isEqualToString:@"null"])
- // val=@"";
- //
- //
- //
- //
- // CGRect frame;
- // frame.size = constraintval;
- // frame.origin.x=0;
- // frame.origin.y=0;
- // RTLabel* rtlabel = [[RTLabel alloc] initWithFrame:frame];
- // [rtlabel setLineBreakMode: RTTextLineBreakModeWordWrapping];
- // // rtlabel.lineSpacing = 20.0;
- // [rtlabel setText: val];
- // CGSize sizeval=rtlabel.optimumSize;
- // CGSize sizekey = [key sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
- // // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:17.0] constrainedToSize:constraintval lineBreakMode:NSLineBreakByWordWrapping];
- //// DebugLog(@"tableView width:%f",width);
- ////
- //// DebugLog(@"key width= %f val width = %f",constraintkey.width,constraintval.width);
- //// DebugLog(@"key = %@ val = %@",key,val);
- // float height = MAX(sizekey.height,sizeval.height);
- // height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
- // sizekey.height = height;
- // sizekey.width = constraintkey.width;
- // // sizeval.height = height;
- // sizeval.width =constraintval.width;
- //
- // NSString *CellIdentifier = @"detail_item_kv";
- // DetailCellKV *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- // if(cell==nil)
- // DebugLog(@"cell is nil.........................");
- //
- //
- // // CGRect framekey ;
- // // framekey.origin.x=CELL_MARGIN;
- // // framekey.origin.y=LINE_WIDTH;
- // // framekey.size = sizekey;
- // // UILabel* keyLabel = [[UILabel alloc]initWithFrame:framekey];
- // // keyLabel.lineBreakMode = NSLineBreakByWordWrapping;
- // // keyLabel.backgroundColor = [UIColor grayColor];
- // // keyLabel.text = key;
- // //
- // // CGRect frameval;
- // // frameval.origin.x=constraintkey.width+CELL_MARGIN;
- // // frameval.origin.y=LINE_WIDTH;
- // // frameval.size = sizeval;
- // //
- // // UILabel* valLabel = [[UILabel alloc]initWithFrame:frameval];
- // // valLabel.lineBreakMode = NSLineBreakByWordWrapping;
- // // valLabel.text = val;
- // //
- // // for(UIView* v in cell.contentView.subviews)
- // // {
- // // [v removeFromSuperview];
- // //
- // // }
- // //
- // // [cell.contentView addSubview:keyLabel];
- // // [cell.contentView addSubview:valLabel];
- //
- //
- // CGRect framekey = cell.keyLabel.frame;
- // framekey.origin.x=CELL_MARGIN+LABEL_MARGIN;
- // framekey.origin.y=LINE_WIDTH;
- // framekey.size = sizekey;
- // cell.keyLabel.frame = framekey;
- // cell.keyLabel.text=key;
- // CGRect frameval = cell.valLabel.frame;
- // frameval.origin.x=constraintkey.width+CELL_MARGIN+3*LABEL_MARGIN; //2 margin for key 1 margin for value self
- // frameval.origin.y=LINE_WIDTH;
- // frameval.size = sizeval;
- // cell.valLabel.frame = frameval;
- // // [cell.valLabel setTextAlignment:RTTextAlignmentCenter];
- // cell.valLabel.text= val;
- // CGPoint rcenter;
- // rcenter.x = width * 0.4+width * 0.6/2;
- // rcenter.y = height /2;
- // cell.valLabel.center=rcenter;
- //// cell.valLabel.backgroundColor =[UIColor redColor];
- //
- //// cell.contentView.superview.backgroundColor = [UIColor clearColor];
- //// cell.backgroundColor = [UIColor whiteColor];
- // UIView * lineview = [[LineView alloc] initWithFrame:cell.contentView.frame];
- // lineview.userInteractionEnabled = NO;// 不设为NO会屏蔽cell的点击事件
- // lineview.backgroundColor = [UIColor clearColor];// 设为透明从而使得cell.backgroundColor有效.
- // lineview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
- // [cell.contentView addSubview:lineview];// cell.contentView是个readonly属性,所以别想着替换contentView了.
- //
- //
- //
- // // [cell.valLabel sizeToFit];
- // // cell.anameLabel.text = [field valueForKey:@"aname"];
- // // [cell.anameLabel sizeToFit];
- // // DebugLog(@"cellForRowAtIndexPath%@",[field valueForKey:@"aname"]);
- // // Configure the cell...
- // // CGRect rect = cell.frame;
- // // [self.content set_itemheight:100 AtIndexPath:indexPath];
- // return cell;
- }
- else if ([type isEqualToString:@"communication"]) {
-
- NSInteger rowCount = [tableView numberOfRowsInSection:indexPath.section];
-
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
-
- if (indexPath.row == 0) { // head
-
- AMCommHeadCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_HEAD forIndexPath:indexPath];
-
- NSString *to = [segment objectForKey:@"receipt"];
- NSString *cc = [segment objectForKey:@"cc"];
-
- [cell setTo:to];
- [cell setCc:cc];
-
- cell.delegate = self;
-
- return cell;
-
- } else if (indexPath.row == rowCount - 1) { // edit
-
- AMCommEditCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_EDIT forIndexPath:indexPath];
-
- NSString *editContent = [segment objectForKey:@"edit_content"];
- [cell setEmail:editContent];
- cell.delegate = self;
-
- return cell;
-
- } else { // content
-
- AMCommContentCell *cell = [tableView dequeueReusableCellWithIdentifier:COMM_ID_CONTENT forIndexPath:indexPath];
-
- NSDictionary *item = [segment objectForKey:[NSString stringWithFormat:@"item%ld",indexPath.row - 1]];
-
- NSString *sender = [item objectForKey:@"Sender"];
- NSString *content = [item objectForKey:@"msg"];
- NSString *time = [item objectForKey:@"mst_time"];
- NSString *email = [item objectForKey:@"email_url"];
-
-
- [cell setSender:sender];
- [cell setContent:content];
- [cell setTime:time];
- [cell setEmail:email];
-
- cell.delegate = self;
-
- return cell;
-
- }
- }
- else
- {
- DebugLog(@"cellForRowAtIndexPath =====> list");
-
- static NSString *CellIdentifier = @"detail_item_list";
-
-
-
- float width = tableView.frame.size.width;
-
- width-=CELL_MARGIN*2;
- CGSize constraintkey = CGSizeMake(width, 20000.0f);//key label width is 40% cell width;
-
- NSDictionary* item = self.content.segments[indexPath.section];
-
- NSString* val=[item valueForKey:[NSString stringWithFormat:@"line%ld",(long)indexPath.row]];
-
- if([val isEqual:[NSNull null]])
- val=@"";
- if(val==nil)
- val=@"";
- if([val isEqualToString:@"null"])
- val=@"";
-
-
-
-
-
- // CGSize sizeval = [val sizeWithFont:[UIFont systemFontOfSize:13.0] constrainedToSize:constraintkey lineBreakMode:NSLineBreakByWordWrapping];
-
- CGSize sizeval = [val boundingRectWithSize:constraintkey options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes: @{NSFontAttributeName: [UIFont systemFontOfSize:13.0]} context:nil].size;
-
- float height = sizeval.height;
- height = MAX(height, DEF_CELL_HEIGHT-LINE_WIDTH);
- sizeval.height = height;
- sizeval.width = constraintkey.width;
-
-
-
-
-
-
-
-
- //创建cell
- DetailCellList *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
- CGRect framekey = cell.listLabel.frame;
- framekey.origin.x=CELL_MARGIN;
- framekey.origin.y=LINE_WIDTH;
- framekey.size = sizeval;
- cell.listLabel.frame = framekey;
- cell.listLabel.text= val;
-
-
-
- return cell;
-
- }
- return nil;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
-
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- NSString* type =[segment valueForKey:@"_type"];
-
- NSString* port = self.content.originContent[@"backup_port"];
-
- if([type isEqualToString:@"tracking"]) {
- NSDictionary *location = [segment objectForKey:@"location"];
- [self.shipMap showShipAnnotaion:location backupLocation:port];
- self.containerSelectedIndexPath = indexPath;
- }
-
-
- }
- #pragma mark - Quick Look
- - (MyQLPreviewController *)quickLook {
- if (!_quickLook)
- {
- _quickLook = [[MyQLPreviewController alloc] init];
- _quickLook.delegate = self;
- _quickLook.dataSource = self;
- }
- else
- {
- [_quickLook reloadData];
- }
- return _quickLook;
- }
- #pragma mark - QuickLook Data Source
- - (NSInteger)numberOfPreviewItemsInPreviewController:(QLPreviewController *)controller {
- return 1;
- }
- - (id <QLPreviewItem>) previewController:(QLPreviewController *)controller previewItemAtIndex:(NSInteger)index {
-
- return [NSURL fileURLWithPath:self.documentPath];
- }
- #pragma mark - QuickLook Delegate
- - (void) previewControllerDidDismiss:(QLPreviewController *)controller {
-
- }
- /**
- * 文件内部链接点击不进行外部跳转
- */
- - (BOOL) previewController:(QLPreviewController *)controller shouldOpenURL:(NSURL *)url forPreviewItem:(id<QLPreviewItem>)item {
- return NO;
- }
- #pragma mark - KVDetail Tap Delegate
- - (void)detailCell:(DetailCellKVNew *)cell doubleTapedForValue:(NSString *)value {
-
- // NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
- pasteboard.string = value;
- [DetailHUD show:[NSString stringWithFormat:@"%@ Copied",cell.keyLabel.text] inView:self.view];
-
- }
- #pragma mark - Quick Look Menu Action
- - (void)saveDocument {
-
- NSMutableDictionary *emailInfo = [NSMutableDictionary new];
- if (self.email.length==0) {
- self.email=@"";
-
- }
- if (self.email_subject.length==0) {
- self.email_subject=@"";
-
- }
- if (self.email_content.length==0) {
- self.email_content=@"";
-
- }
- [emailInfo setValue:self.email forKey:@"reciptions"];
- [emailInfo setValue:self.email_subject forKey:@"subject"];
- [emailInfo setValue:self.email_content forKey:@"content"];
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
- NSString *emailPath = [path stringByAppendingPathComponent:[NSString stringWithFormat:@".%@",[[self.documentPath stringByDeletingPathExtension] lastPathComponent]]];
-
- NSError *err;
-
- if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
- [[NSFileManager defaultManager] removeItemAtPath:filePath error:nil];
- }
- [[NSFileManager defaultManager] moveItemAtPath:self.documentPath toPath:filePath error:&err];
-
- NSData* saved_email_data = [RAConvertor dict2data:emailInfo];
-
- [saved_email_data writeToFile:emailPath atomically:NO];
-
-
-
-
-
- UIAlertController *alertVC;
- UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- if (err) {
- alertVC = [UIAlertController alertControllerWithTitle:@"Warning" message:[NSString stringWithFormat:@"save document failed:\n%@",err.localizedDescription] preferredStyle:UIAlertControllerStyleAlert];
- } else {
- alertVC = [UIAlertController alertControllerWithTitle:nil message:@"Document Saved" preferredStyle:UIAlertControllerStyleAlert];
- }
- [alertVC addAction:action];
-
- [self presentViewController:alertVC animated:YES completion:nil];
- }
- - (void)shareDocument {
-
- return [self share_activity];
- }
- -(void) share_activity
- {
- // 设置分享内容
- // NSString *text = @"分享内容";
- NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
- NSString *path = [paths objectAtIndex:0];
- NSString *filePath = [path stringByAppendingPathComponent:[self.documentPath lastPathComponent]];
-
- // 没有保存的情况
- if ([[NSFileManager defaultManager] fileExistsAtPath:self.documentPath]) {
- filePath = self.documentPath;
- }
-
- NSURL *url = [NSURL fileURLWithPath:filePath];
-
- NSArray *activityItems = @[url];
-
- LPShareActivity *share = [[LPShareActivity alloc] init];
- share.to = [self.email componentsSeparatedByString:@","];//@[@"676767@qq.com"];
- share.subject = self.email_subject;//@"test subject";
- share.body = self.email_content;// @"body";
- share.filePath = filePath;
- share.handle = ^(UIViewController *vc) {
- [self presentViewController:vc animated:YES completion:^{
- // [share activityDidFinish:YES];
- // ...
- }];
- };
-
- // 服务类型控制器
- UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[share]];
- // _activityViewController = activityViewController;
- // activityViewController.excludedActivityTypes = @[UIActivityTypeMail];
- activityViewController.modalInPopover = true;
- [self presentViewController:activityViewController animated:YES completion:nil];
-
- // 选中分享类型
- [activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
-
- // 显示选中的分享类型
- NSLog(@"act type %@",activityType);
-
- if (completed) {
- NSLog(@"ok");
- }else {
- NSLog(@"not ok");
- }
-
- }];
- }
- - (void)quickLookMenuClick:(id)sender {
-
- UIAlertController *menuAlert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
-
- __weak typeof(self) weakSelf = self;
- UIAlertAction *saveAction = [UIAlertAction actionWithTitle:@"Save Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf saveDocument];
- }];
- UIAlertAction *shareAction = [UIAlertAction actionWithTitle:@"Share Document" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf shareDocument];
- }];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
-
- }];
-
- [menuAlert addAction:saveAction];
- [menuAlert addAction:shareAction];
- [menuAlert addAction:cancelAction];
-
- [self presentViewController:menuAlert animated:YES completion:nil];
- }
- #pragma mark - Keyboard
- - (void)startListenKeyboard {
- NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
- // 键盘通知
- [notificationCenter addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
- [notificationCenter addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
- [notificationCenter addObserver:self selector:@selector(keyboardChangeFrame:) name:UIKeyboardDidChangeFrameNotification object:nil];
-
- UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToHideKeyboard:)];
- [self.view addGestureRecognizer:tap];
- self.tap = tap;
- }
- - (void)stopListenKeyboard {
- NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
- [notificationCenter removeObserver:self];
-
- [self.view removeGestureRecognizer:self.tap];
- }
- - (void)tapToHideKeyboard:(UITapGestureRecognizer *)tap {
- [self.view endEditing:YES];
- }
- /**键盘隐藏*/
- - (void)keyboardWillHide:(NSNotification *)notification {
- NSLog(@"keyboard hide");
- self.showKeyboard = NO;
- }
- /**键盘显示*/
- - (void)keyboardWillShow:(NSNotification *)notification {
-
- // NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
- // CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
- //
- // if (duration == 0) {
- // duration = 0.25;
- // }
- NSLog(@"keyboard show");
- self.showKeyboard = YES;
- }
- /**在使用过程中切换键盘*/
- - (void)keyboardChangeFrame:(NSNotification *)notification {
-
- NSLog(@"keyboard change frame");
-
- NSTimeInterval duration = [[[notification userInfo] objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
- // CGRect begin = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue];
- CGRect end = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
-
- if (duration == 0) {
- duration = 0.25;
- }
-
- NSLayoutConstraint *bottom_constraint = nil;
- for (NSLayoutConstraint *constraint in self.view.constraints) {
- if ([constraint.identifier isEqualToString:@"table_bottom_constraint"]) {
- bottom_constraint = constraint;
- break;
- }
- }
-
- CGFloat tabBarY = CGRectGetMinY(self.tabBarController.tabBar.frame);
-
- CGFloat offset = tabBarY - CGRectGetMinY(end);
- if (offset < 0) {
- offset = 0;
- }
-
- if (bottom_constraint) {
- bottom_constraint.constant = offset;
- [self.view layoutIfNeeded];
-
- if (self.editingIndexPath) {
- [self.table scrollToRowAtIndexPath:self.editingIndexPath atScrollPosition:UITableViewScrollPositionNone animated:UITableViewRowAnimationNone];
- }
- }
-
- CGSize contentSize = self.table.contentSize;
- CGPoint contentOffset = self.table.contentOffset;
- offset = contentOffset.y - (contentSize.height - CGRectGetHeight(self.table.bounds));
- if (offset > 0) {
- contentOffset.y -= offset;
- self.table.contentOffset = contentOffset;
- }
-
- }
- #pragma mark - COMM Head Delegate
- - (void)commHeadCell:(AMCommHeadCell *)cell didChangeCC:(NSString *)cc {
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
-
- [self cc:cc changedForIndexPath:indexPath];
- }
- - (void)commHeadCell:(AMCommHeadCell *)cell didBeginEditing:(UITextField *)textField {
- self.editingCell = cell;
- self.editingIndexPath = [self.table indexPathForCell:cell];
- }
- - (void)commHeadCell:(AMCommHeadCell *)cell didEndEditing:(UITextField *)textField {
- self.editingCell = nil;
- self.editingIndexPath = nil;
- }
- - (void)commHeadCell:(AMCommHeadCell *)cell didClickContactButton:(UIButton *)button {
-
- self.contactSelectIndexPath = [self.table indexPathForCell:cell];
-
- CNContactPickerViewController *contactVC = [[CNContactPickerViewController alloc] init];
- contactVC.delegate = self;
-
-
- [self presentViewController:contactVC animated:YES completion:nil];
- }
- #pragma mark - COMM Content Delegate
- - (void)commContentCell:(AMCommContentCell *)cell sendEmail:(NSString *)email {
-
- // MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
- // if (!emailVC) {
- //
- // return;
- // }
- // [emailVC setMessageBody:[NSString stringWithFormat:@"<a>%@</a>",email] isHTML:YES];
- //
- // [self presentViewController:emailVC animated:YES completion:nil];
-
- NSURL *url = [NSURL URLWithString:email];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- [[UIApplication sharedApplication] openURL:url];
- }
-
- }
- #pragma mark - COMM Edit Delegate
- - (void)commEditCell:(AMCommEditCell *)cell clickToSendEmail:(NSString *)email {
-
- // 检查Email内容是否为空
- if (!email || email.length == 0) {
-
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication message that will be sent is blank" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:okAction];
- [self presentViewController:alert animated:YES completion:nil];
- return;
- }
-
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- NSString *cc = [segment objectForKey:@"cc"];
- if (cc && cc.length > 0) {
-
- // 校验邮箱地址格式是否有效
- NSArray *ccArr = [cc componentsSeparatedByString:@";"];
- for (NSString *ccStr in ccArr) {
- if (ccStr.length > 0) {
- BOOL isEmail = [self validateEmail:ccStr];
- if (!isEmail) {
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Warning" message:@"The communication cc is not right" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:okAction];
- [self presentViewController:alert animated:YES completion:nil];
- return;
- }
- }
- }
-
- // 校验通过
-
- }
-
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"send email" preferredStyle:UIAlertControllerStyleAlert];
- [self presentViewController:alert animated:YES completion:nil];
-
- NSString *serialNo = [segment objectForKey:@"serial_no"];
-
- __weak typeof(self) weakSelf = self;
- dispatch_async(dispatch_get_global_queue(0, 0), ^{
- NSDictionary *sendResponse = [RANetwork sendEmail:email CC:cc SerialNo:serialNo];
- dispatch_async(dispatch_get_main_queue(), ^{
-
- [alert dismissViewControllerAnimated:YES completion:^{
-
- if (weakSelf) {
- __strong typeof(weakSelf) strongSelf = weakSelf;
- int result = [[sendResponse objectForKey:@"result"] intValue];
-
- if (result == RESULT_TRUE) {
-
- } else {
- NSString *msg = [sendResponse objectForKey:@"err_msg"];
- if (msg == nil) {
- msg = @"Sorry,something wrong";
- }
- UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:msg preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
-
- }];
- [alert addAction:okAction];
- [strongSelf presentViewController:alert animated:YES completion:nil];
- }
-
- }
-
- }];
-
- });
- });
-
-
- }
- - (void)commEditCell:(AMCommEditCell *)cell didChangeEmail:(NSString *)email {
- // 保存数据
- NSIndexPath *indexPath = [self.table indexPathForCell:cell];
-
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- if (email && email.length > 0) {
- [segment setValue:email forKey:@"edit_content"];
- } else {
- [segment removeObjectForKey:@"edit_content"];
- }
-
- NSMutableArray *arr = [self.content.segments mutableCopy];
- [arr replaceObjectAtIndex:indexPath.section withObject:segment];
- self.content.segments = arr;
-
- // 调用 tableView 的 beginUpdates 和 endUpdates,重新计算 cell 的高度
- [self.table beginUpdates];
- [self.table endUpdates];
-
- // 防止在输入的时候超出屏幕区域
- CGRect frame = cell.frame;
- if (CGRectGetMaxY(frame) > CGRectGetMaxY(self.table.bounds)) {
- [self.table scrollRectToVisible:frame animated:NO];
- }
- }
- - (void)commEditCell:(AMCommEditCell *)cell didBeginEditing:(UITextView *)textView {
- self.editingCell = cell;
- self.editingIndexPath = [self.table indexPathForCell:cell];
- }
- - (void)commEditCell:(AMCommEditCell *)cell didEndEditing:(UITextView *)textView {
- self.editingCell = nil;
- self.editingIndexPath = nil;
- }
- #pragma mark - Contact Picker Delegate
- - (void)contactPickerDidCancel:(CNContactPickerViewController *)picker {
- self.contactSelectIndexPath = nil;
- }
- - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContact:(CNContact *)contact {
-
- [self handleSelectContact:contact];
-
- self.contactSelectIndexPath = nil;
- }
- - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContacts:(NSArray<CNContact *> *)contacts {
-
- for (CNContact *contact in contacts) {
- [self handleSelectContact:contact];
- }
-
- self.contactSelectIndexPath = nil;
- }
- - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperty:(CNContactProperty *)contactProperty {
- self.contactSelectIndexPath = nil;
- }
- - (void)contactPicker:(CNContactPickerViewController *)picker didSelectContactProperties:(NSArray<CNContactProperty *> *)contactProperties {
-
- self.contactSelectIndexPath = nil;
- }
- #pragma mark - Utils
- - (BOOL)validateEmail:(NSString *)email {
-
- NSString *emailRegex =@"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
-
- NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
-
- return [emailTest evaluateWithObject:email];
- }
- - (void)handleSelectContact:(CNContact *)contact {
-
- NSArray *emailArr = [contact emailAddresses];
- for (CNLabeledValue *value in emailArr) {
- if ([value.label isEqualToString:CNLabelWork]) {
- [self appendCC:[NSString stringWithFormat:@"%@;",value.value] forIndexPath:self.contactSelectIndexPath];
- [self.table reloadRowsAtIndexPaths:@[self.contactSelectIndexPath] withRowAnimation:UITableViewRowAnimationNone];
- AMCommHeadCell *cell = [self.table cellForRowAtIndexPath:self.contactSelectIndexPath];
- [cell beginEditing];
- break;
- }
- }
-
- }
- - (void)appendCC:(NSString *)cc forIndexPath:(NSIndexPath *)indexPath {
- if (indexPath == nil || cc == nil || cc.length == 0) {
- return;
- }
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- NSString *oldCC = [segment objectForKey:@"cc"];
- if (oldCC == nil || oldCC.length == 0) {
- oldCC = cc;
- } else {
- if ([[oldCC substringFromIndex:oldCC.length - 1] isEqualToString:@";"]) {
- oldCC = [oldCC stringByAppendingString:cc];
- } else {
- oldCC = [oldCC stringByAppendingString:[NSString stringWithFormat:@";%@",cc]];
- }
- }
-
- [self cc:oldCC changedForIndexPath:indexPath];
- }
- - (void)cc:(NSString *)cc changedForIndexPath:(NSIndexPath *)indexPath {
- if (indexPath == nil) {
- return;
- }
- NSMutableDictionary* segment = [self.content.segments[indexPath.section] mutableCopy];
- if (cc && cc.length > 0) {
- [segment setValue:cc forKey:@"cc"];
- } else {
- [segment removeObjectForKey:@"cc"];
- }
-
- NSMutableArray *arr = [self.content.segments mutableCopy];
- [arr replaceObjectAtIndex:indexPath.section withObject:segment];
- self.content.segments = arr;
- }
- #pragma mark - ShipMap Delegate
- - (void)shipMap:(AMShipMap *)shipMap tryToZoomIn:(BOOL)zoomIn {
-
- if (zoomIn) {
-
- NSArray *constraints = self.view.constraints;
- NSLayoutConstraint *h_ratio_constraint = nil;
-
- for (NSLayoutConstraint *constraint in constraints) {
- if (constraint.identifier && [constraint.identifier isEqualToString:@"ratio_constraint"]) {
- h_ratio_constraint = constraint;
- }
- }
-
- if (h_ratio_constraint) {
- [self.view removeConstraint:h_ratio_constraint];
- }
-
- NSLayoutConstraint *table_h_constraint = [NSLayoutConstraint constraintWithItem:self.table
- attribute:NSLayoutAttributeHeight
- relatedBy:NSLayoutRelationEqual
- toItem:nil
- attribute:NSLayoutAttributeNotAnAttribute
- multiplier:0
- constant:0];
- table_h_constraint.identifier = @"table_height";
- [self.view addConstraint:table_h_constraint];
-
- } else {
-
- NSArray *constraints = self.view.constraints;
- NSLayoutConstraint *h_constraint = nil;
-
- for (NSLayoutConstraint *constraint in constraints) {
- if (constraint.identifier && [constraint.identifier isEqualToString:@"table_height"]) {
- h_constraint = constraint;
- }
- }
-
- if (h_constraint) {
- [self.view removeConstraint:h_constraint];
- }
-
- float h_ratio = 0.5;
- NSLayoutConstraint *h_ratio_constraint = [NSLayoutConstraint constraintWithItem:shipMap
- attribute:NSLayoutAttributeHeight
- relatedBy:NSLayoutRelationEqual
- toItem:self.table
- attribute:NSLayoutAttributeHeight
- multiplier:h_ratio
- constant:0];
- h_ratio_constraint.identifier = @"ratio_constraint";
-
- [self.view addConstraint:h_ratio_constraint];
- }
-
-
- [self.view layoutIfNeeded];
- }
- @end
|