JXProgressVC.m 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. //
  2. // JXProgressVC.m
  3. // shiku_im
  4. //
  5. // Created by Apple on 16/10/10.
  6. // Copyright © 2016年 Reese. All rights reserved.
  7. //
  8. #import "JXProgressVC.h"
  9. @interface JXProgressVC ()
  10. @end
  11. @implementation JXProgressVC
  12. - (instancetype)init
  13. {
  14. self = [super init];
  15. if (self) {
  16. //self.view.frame = CGRectMake(JX_SCREEN_WIDTH, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  17. self.title = Localized(@"JXProgressVC_SnyFriend");
  18. self.isGotoBack = YES;
  19. self.heightHeader = JX_SCREEN_TOP;
  20. self.heightFooter = 0;
  21. [self createHeadAndFoot];
  22. [self createProgressView];
  23. [self customView];
  24. if (self.dataArray.count <= 1000) {
  25. [self dealWithFriendData:_dataArray];
  26. }
  27. // dispatch_async(dispatch_get_global_queue(1, 0), ^{
  28. // });
  29. }
  30. return self;
  31. }
  32. - (void)viewDidLoad {
  33. [super viewDidLoad];
  34. // Do any additional setup after loading the view.
  35. }
  36. -(void)viewDidAppear:(BOOL)animated{
  37. [super viewDidAppear:animated];
  38. [self dealWithFriendData:_dataArray];
  39. // [UIView animateWithDuration:0.3 animations:^{
  40. // self.view.frame = CGRectMake(0, 0, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT);
  41. // }];
  42. }
  43. - (void)customView{
  44. //按钮
  45. // _comBtn = [[UIButton alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2 - 50, 300, 100, 30)];
  46. // _comBtn.layer.cornerRadius = 5;
  47. // _comBtn.clipsToBounds = YES;
  48. // [_comBtn setTitle:Localized(@"JXProgressVC_SnyNow") forState:UIControlStateNormal];
  49. // [_comBtn setBackgroundImage:[UIImage imageNamed:@"feaBtn_backImg_sel"] forState:UIControlStateNormal];
  50. // _comBtn.titleLabel.font = g_factory.font15;
  51. // [_comBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  52. // [_comBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  53. // _comBtn.tag = 1;
  54. // [self.tableBody addSubview:_comBtn];
  55. // [_comBtn release];
  56. //本地与服务器好友数量
  57. // _dbCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2 - 100, 160, 200, 30)];
  58. // _dbCountLabel.text = [NSString stringWithFormat:@"%@%ld",Localized(@"JXProgressVC_LFriendCount"),_dbFriends];
  59. // _dbCountLabel.font = [UIFont systemFontOfSize:13];
  60. // _dbCountLabel.textAlignment = NSTextAlignmentCenter;
  61. // [self.tableBody addSubview:_dbCountLabel];
  62. // [_dbCountLabel release];
  63. _sysCountLabel = [[UILabel alloc]initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2 - 100, 200, 200, 30)];
  64. _sysCountLabel.text = [NSString stringWithFormat:@"%@%lu",Localized(@"JXProgressVC_SFriendCount"),(unsigned long)[_dataArray count]];
  65. _sysCountLabel.font = [UIFont systemFontOfSize:13];
  66. _sysCountLabel.textAlignment = NSTextAlignmentCenter;
  67. [self.tableBody addSubview:_sysCountLabel];
  68. // [_sysCountLabel release];
  69. }
  70. -(void)btnClick:(UIButton *)btn{
  71. if (btn.tag == 1) {
  72. [self dealWithFriendData:_dataArray];
  73. }else if (btn.tag == 2){
  74. [self actionQuit];
  75. }
  76. }
  77. -(void)createProgressView{
  78. //ProgressView
  79. UIView * centerView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, JX_SCREEN_WIDTH - 100, 80)];
  80. centerView.backgroundColor = [UIColor whiteColor];
  81. centerView.layer.cornerRadius = 10;
  82. [self.tableBody addSubview:centerView];
  83. // [centerView release];
  84. // _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 5, JX_SCREEN_WIDTH - 100, 25)];
  85. // _titleLabel.text = @"是否同步好友";
  86. // _titleLabel.textAlignment = NSTextAlignmentCenter;
  87. // _titleLabel.font = [UIFont systemFontOfSize:13];
  88. // [centerView addSubview:_titleLabel];
  89. // [_titleLabel release];
  90. //
  91. _progressView = [[UIProgressView alloc]initWithFrame:CGRectMake(5, 40, JX_SCREEN_WIDTH - 110, 5)];
  92. [centerView addSubview:_progressView];
  93. // [_progressView release];
  94. _progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 50, JX_SCREEN_WIDTH - 100, 20)];
  95. _progressLabel.font = [UIFont systemFontOfSize:12];
  96. _progressLabel.text = @"";
  97. _progressLabel.textAlignment = NSTextAlignmentCenter;
  98. [centerView addSubview:_progressLabel];
  99. // [_progressLabel release];
  100. }
  101. -(void)dealWithFriendData:(NSArray *)array1{
  102. // if (_dbFriends == [array1 count]) {
  103. //// [g_App showAlert:Localized(@"JXAlert_SynchFirend")];
  104. //// [JXMyTools showTipView:Localized(@"JXAlert_SynchFirend")];
  105. // [_comBtn setTitle:Localized(@"JX_Finish") forState:UIControlStateNormal];
  106. // _comBtn.tag = 2;
  107. // [self actionQuit];
  108. // return;
  109. // }
  110. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  111. // [_wait start:Localized(@"JXProgressVC_SnyFriend")];
  112. // });
  113. // _titleLabel.text = @"正在同步好友";
  114. // 删除本地数据库好友 重新插入
  115. // [[JXUserObject sharedInstance] deleteAllUser];
  116. //遍历服务器返回的好友
  117. _progressView.progress = 0.0;
  118. NSMutableArray *userIds = [NSMutableArray array];
  119. for (int i = 0; i< [array1 count]; i++) {
  120. NSDictionary * dict = array1[i];
  121. JXUserObject * user = [[JXUserObject alloc]init];
  122. //数据转为一个好友对象
  123. [user getDataFromDictSmall:dict];
  124. //访问数据库是否存在改好友,没有则写入数据库
  125. if (user.userId.length > 5) {
  126. [userIds addObject:user.userId];
  127. [user insertFriend];
  128. [user updateUserNickname];
  129. [user updateRemarkName];
  130. [user updateTelephone];
  131. }
  132. // [user release];
  133. [_progressView setProgress:((i+1)*1.0)/([array1 count]*1.0) animated:YES];
  134. _progressLabel.text = [NSString stringWithFormat:@"%d/%lu",i+1,(unsigned long)[array1 count]];
  135. NSLog(@"%@",_progressLabel.text);
  136. [[NSRunLoop currentRunLoop]runUntilDate:[NSDate distantPast]];//重要
  137. }
  138. [_wait start:Localized(@"JXProgressVC_SnyFriend")];
  139. // 删除服务器上已经删除的
  140. NSArray *arr = [g_server.myself fetchAllFriendsOrNotFromLocal];
  141. for (NSInteger i = 0; i < arr.count; i ++) {
  142. JXUserObject *locUser = arr[i];
  143. // BOOL flag = NO;
  144. // for (NSInteger j = 0; j < array1.count; j ++) {
  145. // NSDictionary * dict = array1[j];
  146. // JXUserObject * serverUser = [[JXUserObject alloc]init];
  147. // //数据转为一个好友对象
  148. // [serverUser getDataFromDictSmall:dict];
  149. // if ([locUser.userId isEqualToString:serverUser.userId]) {
  150. // flag = YES;
  151. // break;
  152. // }
  153. // }
  154. //
  155. // if (!flag) {
  156. // [locUser delete];
  157. // }
  158. if (![userIds containsObject:locUser.userId] && [locUser.status intValue] == friend_status_friend) {
  159. [locUser delete];
  160. }
  161. }
  162. // _dbFriends = [array1 count];
  163. //// _titleLabel.text = @"同步完成";
  164. // _dbCountLabel.text = _dbCountLabel.text = [NSString stringWithFormat:@"%@%ld",Localized(@"JXProgressVC_LFriendCount"),[array1 count]];
  165. // _sysCountLabel.text = [NSString stringWithFormat:@"%@%ld",Localized(@"JXProgressVC_SFriendCount"),[array1 count]];
  166. // [_comBtn setTitle:Localized(@"JX_Finish") forState:UIControlStateNormal];
  167. // _comBtn.tag = 2;
  168. [[JXXMPP sharedInstance] login];
  169. // [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:1];//1秒后执行xmpp登录
  170. [g_notify postNotificationName:kXMPPNewFriendNotifaction object:nil];
  171. [g_notify postNotificationName:kChatViewDisappear object:nil];
  172. // dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  173. [_wait stop];
  174. [self actionQuit];
  175. // });
  176. }
  177. - (void)didReceiveMemoryWarning {
  178. [super didReceiveMemoryWarning];
  179. // Dispose of any resources that can be recreated.
  180. }
  181. /*
  182. #pragma mark - Navigation
  183. // In a storyboard-based application, you will often want to do a little preparation before navigation
  184. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  185. // Get the new view controller using [segue destinationViewController].
  186. // Pass the selected object to the new view controller.
  187. }
  188. */
  189. @end