123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // JXShowLabelVc.m
- // shiku_im
- //
- // Created by 123 on 2020/6/10.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JXShowLabelVc.h"
- #import "JXLabelObject.h"
- #import "JXNewLabelVC.h"
- @interface JXShowLabelVc ()
- @property (nonatomic,strong) NSMutableArray *array;
- @property (nonatomic,weak) UIScrollView *scrollView;
- @property (nonatomic,strong) NSMutableArray *dataArr;
- @end
- @implementation JXShowLabelVc
- - (IBAction)gobackBtn:(id)sender {
- [g_navigation dismissViewController:self animated:YES];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- _dataArr=[NSMutableArray array];
- _array=[NSMutableArray array];
-
- UIScrollView *scrollView=[[UIScrollView alloc]init];
- scrollView.frame=CGRectMake(0, JX_SCREEN_TOP, JX_SCREEN_WIDTH, JX_SCREEN_HEIGHT-JX_SCREEN_TOP);
- [self.view addSubview:scrollView];
- self.scrollView=scrollView;
- }
- - (void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
-
-
- //获取所有标签
- [g_server friendGroupListToView:self];
- }
- /*
- URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D
-
- URL http://47.57.16.13:8092/friendGroup/add?groupName=yupYY&language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780359147&secret=PtEHqzeOt6d3FjgNIFRUag%3D%3D
-
- URL http://47.57.16.13:8092/friendGroup/list?language=zh&access_token=209d8948cf0e4d26b04a5c119041e085&salt=1591780308306&secret=6iQuBmisSNhnA%2Bov5fmStg%3D%3D
- */
- //服务器返回数据
- -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
-
- //更新本地好友
- if ([aDownload.action isEqualToString:act_AttentionList]) {
-
- }
- // 同步标签
- if ([aDownload.action isEqualToString:act_FriendGroupList]) {
-
- [self createButonUI:array1.mutableCopy];
- //[_dataArr addObjectsFromArray:array1];
- for (NSInteger i = 0; i < array1.count; i ++) {
- NSDictionary *dict = array1[i];
- JXLabelObject *labelObj = [[JXLabelObject alloc] init];
- labelObj.groupId = dict[@"groupId"];
- labelObj.groupName = dict[@"groupName"];
- labelObj.userId = dict[@"userId"];
-
- NSArray *userIdList = dict[@"userIdList"];
- NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
- if (userIdListStr.length > 0) {
- labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
- }
- [labelObj insert];
- }
-
- // 删除服务器上已经删除的
- NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
- [_dataArr addObjectsFromArray:arr];
-
-
- for (NSInteger i = 0; i < arr.count; i ++) {
- JXLabelObject *locLabel = arr[i];
- BOOL flag = NO;
- for (NSInteger j = 0; j < array1.count; j ++) {
- NSDictionary * dict = array1[j];
-
- if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
- flag = YES;
- break;
- }
- }
-
- if (!flag) {
- [locLabel delete];
- }
- }
-
- _array = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
- for (JXLabelObject *labelObj in _array) {
- NSString *userIdStr = labelObj.userIdList;
- NSArray *userIds = [userIdStr componentsSeparatedByString:@","];
- if (userIdStr.length <= 0) {
- userIds = nil;
- }
-
- NSMutableArray *newUserIds = [userIds mutableCopy];
- for (NSInteger i = 0; i < userIds.count; i ++) {
- NSString *userId = userIds[i];
- NSString *userName = [JXUserObject getUserNameWithUserId:userId];
-
- if (!userName || userName.length <= 0) {
- [newUserIds removeObject:userId];
- }
-
- }
-
- NSString *string = [newUserIds componentsJoinedByString:@","];
-
- labelObj.userIdList = string;
-
- [labelObj update];
- }
- }
-
- if ([aDownload.action isEqualToString:act_customerLinkList]){
-
-
-
- }
- }
- - (void)createButonUI:(NSMutableArray *)array{
- NSDictionary *tempDict=@{@"createTime":@"1589277624",@"groupId":@"5eba73b882e8f762eccdf702",@"groupName":@"+",@"userId":@"10000757",@"userIdList":@[]};
- [array addObject:tempDict];
- /*
- {
- "currentTime": 1591781851716,
- "data": [{
- "createTime": 1589277624,
- "groupId": "5eba73b882e8f762eccdf702",
- "groupName": "家人",
- "userId": 10000757,
- "userIdList": [10000777]
- }, {
- "createTime": 1591781851,
- "groupId": "5ee0a9db82e8f728a6ce24c5",
- "groupName": "uuu",
- "userId": 10000757,
- "userIdList": []
- }],
- "resultCode": 1
- }
- */
-
- for (int i=0; i<array.count;i++) {
- NSDictionary *dict=array[i];
- CGFloat btnW=(JX_SCREEN_WIDTH-60)/3;
- UIButton *biaoBtn=[[UIButton alloc]init];
- biaoBtn.layer.cornerRadius=5;
- biaoBtn.layer.masksToBounds=YES;
- biaoBtn.layer.borderColor=[UIColor greenColor].CGColor;
- biaoBtn.layer.borderWidth=1;
- biaoBtn.tag=i;
- biaoBtn.titleLabel.font=[UIFont systemFontOfSize:13 weight:UIFontWeightRegular];
- [biaoBtn setTitle:dict[@"groupName"] forState:UIControlStateNormal];
- [biaoBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
- biaoBtn.frame=CGRectMake(20+i%3*(btnW+10), 30+i/3*(44+10), btnW, 44);
- [_scrollView addSubview:biaoBtn];
- if (i==array.count-1) {
- [biaoBtn addTarget:self action:@selector(gotoAddNewBiaBtn:) forControlEvents:UIControlEventTouchUpInside];
- }else{
- [biaoBtn addTarget:self action:@selector(gotoUpdateBiaoqBtn:) forControlEvents:UIControlEventTouchUpInside];
- }
-
- }
-
- }
- //添加新的标签
- - (void)gotoAddNewBiaBtn:(UIButton *)btn{
-
- JXNewLabelVC *vc = [[JXNewLabelVC alloc] init];
- vc.title = Localized(@"JX_NewLabel");
- [g_navigation pushViewController:vc animated:YES];
- }
- // 更新标签
- - (void)gotoUpdateBiaoqBtn:(UIButton *)sender{
- JXLabelObject *labelObj=_dataArr[sender.tag];
-
-
- JXNewLabelVC *vc = [[JXNewLabelVC alloc] init];
- vc.labelObj=labelObj;
- vc.title = @"设置标签";
- [g_navigation pushViewController:vc animated:YES];
-
- }
- -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
-
-
- return hide_error;
- }
- -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
-
- return hide_error;
- }
- @end
|