JXShowLabelVc.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. //
  2. // JXShowLabelVc.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/6/10.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JXShowLabelVc.h"
  9. #import "JXLabelObject.h"
  10. #import "JXNewLabelVC.h"
  11. @interface JXShowLabelVc ()
  12. @property (nonatomic,strong) NSMutableArray *array;
  13. @property (nonatomic,weak) UIScrollView *scrollView;
  14. @property (nonatomic,strong) NSMutableArray *dataArr;
  15. @end
  16. @implementation JXShowLabelVc
  17. - (IBAction)gobackBtn:(id)sender {
  18. [g_navigation dismissViewController:self animated:YES];
  19. }
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. _dataArr=[NSMutableArray array];
  23. _array=[NSMutableArray array];
  24. UIScrollView *scrollView=[[UIScrollView alloc]init];
  25. scrollView.frame=CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP);
  26. [self.view addSubview:scrollView];
  27. self.scrollView=scrollView;
  28. }
  29. - (void)viewWillAppear:(BOOL)animated{
  30. [super viewWillAppear:animated];
  31. //获取所有标签
  32. [g_server friendGroupListToView:self];
  33. }
  34. /*
  35. URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D
  36. URL http://47.57.16.13:8092/friendGroup/add?groupName=yupYY&language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780359147&secret=PtEHqzeOt6d3FjgNIFRUag%3D%3D
  37. URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D
  38. */
  39. //服务器返回数据
  40. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  41. //更新本地好友
  42. if ([aDownload.action isEqualToString:act_AttentionList]) {
  43. }
  44. // 同步标签
  45. if ([aDownload.action isEqualToString:act_FriendGroupList]) {
  46. [self createButonUI:array1.mutableCopy];
  47. //[_dataArr addObjectsFromArray:array1];
  48. for (NSInteger i = 0; i < array1.count; i ++) {
  49. NSDictionary *dict = array1[i];
  50. JXLabelObject *labelObj = [[JXLabelObject alloc] init];
  51. labelObj.groupId = dict[@"groupId"];
  52. labelObj.groupName = dict[@"groupName"];
  53. labelObj.userId = dict[@"userId"];
  54. NSArray *userIdList = dict[@"userIdList"];
  55. NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
  56. if (userIdListStr.length > 0) {
  57. labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
  58. }
  59. [labelObj insert];
  60. }
  61. // 删除服务器上已经删除的
  62. NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  63. [_dataArr addObjectsFromArray:arr];
  64. for (NSInteger i = 0; i < arr.count; i ++) {
  65. JXLabelObject *locLabel = arr[i];
  66. BOOL flag = NO;
  67. for (NSInteger j = 0; j < array1.count; j ++) {
  68. NSDictionary * dict = array1[j];
  69. if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
  70. flag = YES;
  71. break;
  72. }
  73. }
  74. if (!flag) {
  75. [locLabel delete];
  76. }
  77. }
  78. _array = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  79. for (JXLabelObject *labelObj in _array) {
  80. NSString *userIdStr = labelObj.userIdList;
  81. NSArray *userIds = [userIdStr componentsSeparatedByString:@","];
  82. if (userIdStr.length <= 0) {
  83. userIds = nil;
  84. }
  85. NSMutableArray *newUserIds = [userIds mutableCopy];
  86. for (NSInteger i = 0; i < userIds.count; i ++) {
  87. NSString *userId = userIds[i];
  88. NSString *userName = [JXUserObject getUserNameWithUserId:userId];
  89. if (!userName || userName.length <= 0) {
  90. [newUserIds removeObject:userId];
  91. }
  92. }
  93. NSString *string = [newUserIds componentsJoinedByString:@","];
  94. labelObj.userIdList = string;
  95. [labelObj update];
  96. }
  97. }
  98. if ([aDownload.action isEqualToString:act_customerLinkList]){
  99. }
  100. }
  101. - (void)createButonUI:(NSMutableArray *)array{
  102. NSDictionary *tempDict=@{@"createTime":@"1589277624",@"groupId":@"5eba73b882e8f762eccdf702",@"groupName":@"+",@"userId":@"10000757",@"userIdList":@[]};
  103. [array addObject:tempDict];
  104. /*
  105. {
  106. "currentTime": 1591781851716,
  107. "data": [{
  108. "createTime": 1589277624,
  109. "groupId": "5eba73b882e8f762eccdf702",
  110. "groupName": "家人",
  111. "userId": 10000757,
  112. "userIdList": [10000777]
  113. }, {
  114. "createTime": 1591781851,
  115. "groupId": "5ee0a9db82e8f728a6ce24c5",
  116. "groupName": "uuu",
  117. "userId": 10000757,
  118. "userIdList": []
  119. }],
  120. "resultCode": 1
  121. }
  122. */
  123. for (int i=0; i<array.count;i++) {
  124. NSDictionary *dict=array[i];
  125. CGFloat btnW=(JX_SCREEN_WIDTH-60)/3;
  126. UIButton *biaoBtn=[[UIButton alloc]init];
  127. biaoBtn.layer.cornerRadius=5;
  128. biaoBtn.layer.masksToBounds=YES;
  129. biaoBtn.layer.borderColor=[UIColor greenColor].CGColor;
  130. biaoBtn.layer.borderWidth=1;
  131. biaoBtn.tag=i;
  132. biaoBtn.titleLabel.font=[UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
  133. [biaoBtn setTitle:dict[@"groupName"] forState:UIControlStateNormal];
  134. [biaoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  135. biaoBtn.frame=CGRectMake(20+i%3*(btnW+10), 30+i/3*(44+10), btnW, 44);
  136. [_scrollView addSubview:biaoBtn];
  137. if (i==array.count-1) {
  138. [biaoBtn addTarget:self action:@selector(gotoAddNewBiaBtn:) forControlEvents:UIControlEventTouchUpInside];
  139. }else{
  140. [biaoBtn addTarget:self action:@selector(gotoUpdateBiaoqBtn:) forControlEvents:UIControlEventTouchUpInside];
  141. }
  142. }
  143. }
  144. //添加新的标签
  145. - (void)gotoAddNewBiaBtn:(UIButton *)btn{
  146. JXNewLabelVC *vc = [[JXNewLabelVC alloc] init];
  147. vc.title = Localized(@"JX_NewLabel");
  148. [g_navigation pushViewController:vc animated:YES];
  149. }
  150. // 更新标签
  151. - (void)gotoUpdateBiaoqBtn:(UIButton *)sender{
  152. JXLabelObject *labelObj=_dataArr[sender.tag];
  153. JXNewLabelVC *vc = [[JXNewLabelVC alloc] init];
  154. vc.labelObj=labelObj;
  155. vc.title = @"设置标签";
  156. [g_navigation pushViewController:vc animated:YES];
  157. }
  158. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  159. return hide_error;
  160. }
  161. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  162. return hide_error;
  163. }
  164. @end