JXChatSettingVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. //
  2. // JXChatSettingVC.m
  3. // shiku_im
  4. //
  5. // Created by p on 2018/5/19.
  6. // Copyright © 2018年 Reese. All rights reserved.
  7. //
  8. #import "JXChatSettingVC.h"
  9. #import "JXUserInfoVC.h"
  10. #import "JXSelFriendVC.h"
  11. #import "JXSetChatBackgroundVC.h"
  12. #import "JXInputValueVC.h"
  13. #import "JXSearchChatLogVC.h"
  14. #import "JXLabelObject.h"
  15. #import "JXSetLabelVC.h"
  16. #import "JXSelectFriendsVC.h"
  17. #import "JXTransferRecordTableVC.h"
  18. #import "JXSetNoteAndLabelVC.h"
  19. @interface JXChatSettingVC () <UIPickerViewDelegate,UIAlertViewDelegate>
  20. @property (nonatomic, strong) JXImageView *head;
  21. @property (nonatomic, strong) UILabel *userName;
  22. @property (nonatomic, strong) UILabel *userDesc;
  23. @property (nonatomic, strong) JXLabel *remarksLabel;
  24. @property (nonatomic, strong) JXLabel *chatRecordTimeOutLabel;
  25. @property (nonatomic, strong) JXLabel *labelLabel;
  26. @property (nonatomic, strong) UISwitch *messageFreeSwitch;
  27. @property (nonatomic, strong) UISwitch *chatTopSwitch;
  28. @property (nonatomic, strong) UISwitch *readDeleteSwitch;
  29. @property (nonatomic, assign) BOOL isMsgFree;
  30. @property (nonatomic, assign) BOOL isChatTop;
  31. @property (nonatomic, assign) BOOL isReadDel;
  32. @property (nonatomic, strong) UIView *selectView;
  33. @property (nonatomic, strong) UIPickerView *pickerView;
  34. @property (nonatomic, strong) NSArray *pickerArr;
  35. @property (nonatomic, strong) UILabel *describe;
  36. @property (nonatomic, assign) BOOL isOtherUpdate;
  37. @end
  38. #define HEIGHT 55
  39. @implementation JXChatSettingVC
  40. - (void)viewDidLoad {
  41. [super viewDidLoad];
  42. // Do any additional setup after loading the view.
  43. self.heightHeader = JX_SCREEN_TOP;
  44. self.heightFooter = 0;
  45. self.isGotoBack = YES;
  46. [self createHeadAndFoot];
  47. self.tableBody.backgroundColor = HEXCOLOR(0xF2F2F2);
  48. self.title = Localized(@"JX_ChatSettings");
  49. // _pickerArr = @[Localized(@"JX_Forever"), Localized(@"JX_OneHour"), Localized(@"JX_OneDay"), Localized(@"JX_OneWeeks"), Localized(@"JX_OneMonth"), Localized(@"JX_OneQuarter"), Localized(@"JX_OneYear")];
  50. int h=0;
  51. int w=JX_SCREEN_WIDTH;
  52. [g_notify addObserver:self selector:@selector(actionQuitChatVC:) name:kActionRelayQuitVC object:nil];
  53. [g_notify addObserver:self selector:@selector(updateChatSetting) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  54. [g_notify addObserver:self selector:@selector(updateChatSetting) name:kOfflineOperationUpdateUserSet object:nil];
  55. UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, JX_SCREEN_WIDTH, 0)];
  56. baseView.backgroundColor = HEXCOLOR(0xF2F2F2);
  57. [self.tableBody addSubview:baseView];
  58. float marginHei = 10;
  59. JXImageView* iv;
  60. iv = [self createHeadButtonclick:nil];
  61. iv.frame = CGRectMake(0, h, w, 90);
  62. h+=iv.frame.size.height + marginHei;
  63. // iv = [self createRoomButtonClick:@selector(createRoom)];
  64. // iv.frame = CGRectMake(0, h, w, HEIGHT);
  65. // h += iv.frame.size.height + marginHei;
  66. if ([self.user.userId intValue]>10100 || [self.user.userId intValue]<10000) {
  67. // iv = [self createButton:_user.describe.length > 0 ? Localized(@"JX_UserInfoDescribe") : Localized(@"JX_MemoName") drawTop:NO drawBottom:YES icon:nil click:@selector(setLabel)];
  68. // iv.frame = CGRectMake(0,h, w, HEIGHT);
  69. // h+=iv.frame.size.height;
  70. // _remarksLabel = [self createLabel:iv default:_user.describe.length > 0 ? _user.describe : _user.remarkName isClick:YES];
  71. }
  72. //Localized(@"JX_Label")
  73. iv = [self createButton:@"备注和标签" drawTop:NO drawBottom:NO icon:nil click:@selector(setLabel)];
  74. iv.frame = CGRectMake(0,h, w, HEIGHT);
  75. h+=iv.frame.size.height + marginHei;
  76. NSMutableArray *array = [[JXLabelObject sharedInstance] fetchLabelsWithUserId:self.user.userId];
  77. NSMutableString *labelsName = [NSMutableString string];
  78. for (NSInteger i = 0; i < array.count; i ++) {
  79. JXLabelObject *labelObj = array[i];
  80. if (i == 0) {
  81. [labelsName appendString:labelObj.groupName];
  82. }else {
  83. [labelsName appendFormat:@",%@",labelObj.groupName];
  84. }
  85. }
  86. _labelLabel = [self createLabel:iv default:labelsName isClick:YES];
  87. _labelLabel.textColor = HEXCOLOR(0x999999);
  88. // iv = [self createButton:Localized(@"JX_LookupChatRecords") drawTop:NO drawBottom:NO icon:nil click:@selector(searchChatLog)];
  89. // iv.frame = CGRectMake(0,h, w, HEIGHT);
  90. if ([g_config.enablePayModule boolValue]) {
  91. // h+=iv.frame.size.height;
  92. // iv = [self createButton:Localized(@"JX_ViewTransferRecords") drawTop:YES drawBottom:NO icon:nil click:@selector(checkTransfer)];
  93. // iv.frame = CGRectMake(0,h, w, HEIGHT);
  94. }
  95. // h+=iv.frame.size.height + marginHei;
  96. // iv = [self createButton:Localized(@"JX_ReadDelete") drawTop:NO drawBottom:NO icon:nil click:nil];
  97. // iv.frame = CGRectMake(0,h, w, HEIGHT);
  98. // h+=iv.frame.size.height;
  99. // _readDeleteSwitch = [self createSwitch:iv defaule:[self.user.isOpenReadDel intValue] == 1 click:@selector(readDelAction:)];
  100. // if (_room.roomJid) {
  101. iv = [self createButton:Localized(@"JX_ChatAtTheTop") drawTop:YES drawBottom:NO icon:nil click:nil];
  102. iv.frame = CGRectMake(0,h, w, HEIGHT);
  103. h+=iv.frame.size.height;
  104. _chatTopSwitch = [self createSwitch:iv defaule:[self.user.topTime timeIntervalSince1970] > 0 click:@selector(topChatAction:)];
  105. iv = [self createButton:Localized(@"JX_MessageFree") drawTop:YES drawBottom:NO icon:nil click:nil];
  106. iv.frame = CGRectMake(0,h, w, HEIGHT);
  107. h+=iv.frame.size.height + marginHei;
  108. _messageFreeSwitch = [self createSwitch:iv defaule:[self.user.offlineNoPushMsg intValue] == 1 click:@selector(messageFreeAction:)];
  109. // }
  110. /*
  111. iv = [self createButton:Localized(@"JX_ChatBackground") drawTop:NO drawBottom:NO icon:nil click:@selector(chatBackGroundImage)];
  112. iv.frame = CGRectMake(0,h, w, HEIGHT);
  113. h+=iv.frame.size.height + marginHei;
  114. iv = [self createButton:Localized(@"JX_MessageAutoDestroyed") drawTop:NO drawBottom:YES icon:nil click:@selector(chatRecordTimeOutAction)];
  115. iv.frame = CGRectMake(0,h, w, HEIGHT);
  116. h+=iv.frame.size.height;
  117. */
  118. _chatRecordTimeOutLabel = [self createLabel:iv default:[self setChatRecordTimeOutLabelText] isClick:YES];
  119. iv = [self createButton:Localized(@"JX_EmptyChatRecords") drawTop:NO drawBottom:YES icon:nil click:@selector(cleanMessageLog)];
  120. iv.frame = CGRectMake(0,h, w, HEIGHT);
  121. h+=iv.frame.size.height;
  122. if (_room.roomJid) {
  123. iv = [self createButton:Localized(@"JX_DelMsgTwoSides") drawTop:NO drawBottom:NO icon:nil click:@selector(cleanTwoSidesMessageLog)];
  124. iv.frame = CGRectMake(0,h, w, HEIGHT);
  125. h+=iv.frame.size.height;
  126. }
  127. CGRect frame = baseView.frame;
  128. frame.size.height = h;
  129. baseView.frame = frame;
  130. if ((h + HEIGHT + 20) > self.tableBody.frame.size.height) {
  131. self.tableBody.contentSize = CGSizeMake(self_width, h + HEIGHT + 20);
  132. }
  133. [g_server getUser:self.user.userId toView:self];
  134. [self createPickerView];
  135. }
  136. - (NSString *)setChatRecordTimeOutLabelText {
  137. double outTime = [self.user.chatRecordTimeOut doubleValue];
  138. NSString *str;
  139. if (outTime <= 0) {
  140. str = _pickerArr[0];
  141. }else if (outTime == 0.04) {
  142. str = _pickerArr[1];
  143. }else if (outTime == 1) {
  144. str = _pickerArr[2];
  145. }else if (outTime == 7) {
  146. str = _pickerArr[3];
  147. }else if (outTime == 30) {
  148. str = _pickerArr[4];
  149. }else if (outTime == 90) {
  150. str = _pickerArr[5];
  151. }else{
  152. str = _pickerArr[6];
  153. }
  154. return str;
  155. }
  156. - (void)updateChatSetting {
  157. self.isOtherUpdate = YES;
  158. [g_server getUser:self.user.userId toView:self];
  159. }
  160. - (void)createPickerView {
  161. _selectView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height - 220, JX_SCREEN_WIDTH, 220)];
  162. _selectView.backgroundColor = HEXCOLOR(0xF2F2F2);
  163. _selectView.hidden = YES;
  164. [self.view addSubview:_selectView];
  165. UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(_selectView.frame.size.width - 80, 20, 60, 20)];
  166. [btn setTitle:Localized(@"JX_Confirm") forState:UIControlStateNormal];
  167. btn.titleLabel.font = [UIFont systemFontOfSize:16.0];
  168. [btn setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  169. [btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
  170. [_selectView addSubview:btn];
  171. btn = [[UIButton alloc] initWithFrame:CGRectMake(20, 20, 50, 20)];
  172. [btn setTitle:Localized(@"JX_Cencal") forState:UIControlStateNormal];
  173. btn.titleLabel.font = [UIFont systemFontOfSize:16.0];
  174. [btn setTitleColor:THEMECOLOR forState:UIControlStateNormal];
  175. [btn addTarget:self action:@selector(cancelBtnAction:) forControlEvents:UIControlEventTouchUpInside];
  176. [_selectView addSubview:btn];
  177. _pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, _selectView.frame.size.width, _selectView.frame.size.height - 40)];
  178. _pickerView.delegate = self;
  179. double outTime = [self.user.chatRecordTimeOut doubleValue];
  180. NSInteger index = 0;
  181. if (outTime <= 0) {
  182. index = 0;
  183. }else if (outTime == 0.04) {
  184. index = 1;
  185. }else if (outTime == 1) {
  186. index = 2;
  187. }else if (outTime == 7) {
  188. index = 3;
  189. }else if (outTime == 30) {
  190. index = 4;
  191. }else if (outTime == 90) {
  192. index = 5;
  193. }else{
  194. index = 6;
  195. }
  196. [_pickerView selectRow:index inComponent:0 animated:NO];
  197. [_selectView addSubview:_pickerView];
  198. }
  199. - (void)btnAction:(UIButton *)btn {
  200. _selectView.hidden = YES;
  201. NSInteger row = [_pickerView selectedRowInComponent:0];
  202. _chatRecordTimeOutLabel.text = _pickerArr[row];
  203. NSString *str = [NSString stringWithFormat:@"%ld",row];
  204. switch (row) {
  205. case 0:
  206. str = @"-1";
  207. break;
  208. case 1:
  209. str = @"0.04";
  210. break;
  211. case 2:
  212. str = @"1";
  213. break;
  214. case 3:
  215. str = @"7";
  216. break;
  217. case 4:
  218. str = @"30";
  219. break;
  220. case 5:
  221. str = @"90";
  222. break;
  223. case 6:
  224. str = @"365";
  225. break;
  226. default:
  227. break;
  228. }
  229. self.user.chatRecordTimeOut = str;
  230. [self.user updateUserChatRecordTimeOut];
  231. [g_server friendsUpdate:self.user.userId chatRecordTimeOut:str toView:self];
  232. }
  233. - (void)cancelBtnAction:(UIButton *)btn {
  234. _selectView.hidden = YES;
  235. }
  236. - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
  237. {
  238. return 1;
  239. }
  240. - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
  241. {
  242. return _pickerArr.count;
  243. }
  244. - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
  245. {
  246. return _pickerArr[row];
  247. }
  248. - (void)dealloc {
  249. [g_notify removeObserver:self];
  250. }
  251. - (void)checkTransfer {
  252. JXTransferRecordTableVC *vc = [[JXTransferRecordTableVC alloc] init];
  253. vc.userId = self.user.userId;
  254. [g_navigation pushViewController:vc animated:YES];
  255. }
  256. // 发起群聊
  257. - (JXImageView *)createRoomButtonClick:(SEL)click {
  258. JXImageView* btn = [[JXImageView alloc] init];
  259. btn.backgroundColor = [UIColor whiteColor];
  260. btn.userInteractionEnabled = YES;
  261. btn.didTouch = click;
  262. btn.delegate = self;
  263. [self.tableBody addSubview:btn];
  264. JXImageView *add = [[JXImageView alloc] initWithFrame:CGRectMake(20, 15, 20, 20)];
  265. add.image = [UIImage imageNamed:@"person_add"];
  266. [btn addSubview:add];
  267. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(add.frame) + 20, 0, 200, HEIGHT)];
  268. label.font = [UIFont systemFontOfSize:15.0];
  269. label.textColor = HEXCOLOR(0xff3db4ff);
  270. label.text = Localized(@"JX_LaunchGroupChat");
  271. [btn addSubview:label];
  272. return btn;
  273. }
  274. - (void)remarkAction {
  275. JXInputValueVC* vc = [JXInputValueVC alloc];
  276. vc.value = self.user.remarkName.length > 0 ? self.user.remarkName : self.user.userNickname;
  277. vc.title = Localized(@"JXUserInfoVC_SetName");
  278. vc.delegate = self;
  279. vc.isLimit = YES;
  280. vc.didSelect = @selector(onSaveNickName:);
  281. vc = [vc init];
  282. // [g_window addSubview:vc.view];
  283. [g_navigation pushViewController:vc animated:YES];
  284. }
  285. -(void)onSaveNickName:(JXInputValueVC*)vc{
  286. _remarksLabel.text = vc.value;
  287. self.user.remarkName = vc.value;
  288. [g_server setFriendName:self.user.userId noteName:vc.value describe:nil toView:self];
  289. }
  290. // 标签
  291. - (void)setLabel {
  292. JXSetNoteAndLabelVC *vc = [[JXSetNoteAndLabelVC alloc] init];
  293. vc.title = @"设置备注和标签";// Localized(@"JX_SetNotesAndLabels");
  294. vc.delegate = self;
  295. vc.didSelect = @selector(refreshLabel:);
  296. vc.user = self.user;
  297. [g_navigation pushViewController:vc animated:YES];
  298. }
  299. - (void)refreshLabel:(JXUserObject *)user {
  300. NSMutableArray *array = [[JXLabelObject sharedInstance] fetchLabelsWithUserId:self.user.userId];
  301. NSMutableString *labelsName = [NSMutableString string];
  302. for (NSInteger i = 0; i < array.count; i ++) {
  303. JXLabelObject *labelObj = array[i];
  304. if (i == 0) {
  305. [labelsName appendString:labelObj.groupName];
  306. }else {
  307. [labelsName appendFormat:@",%@",labelObj.groupName];
  308. }
  309. }
  310. _labelLabel.text = labelsName;
  311. if (user.describe.length > 0) {
  312. _describe.text = Localized(@"JX_UserInfoDescribe");
  313. _remarksLabel.text = user.describe;
  314. }else {
  315. _describe.text = Localized(@"JX_MemoName");
  316. _remarksLabel.text = user.remarkName;
  317. }
  318. self.user.remarkName = user.remarkName;
  319. self.user.describe = user.describe;
  320. [g_server setFriendName:self.user.userId noteName:user.remarkName describe:user.describe toView:self];
  321. }
  322. // 查找聊天内容
  323. - (void)searchChatLog {
  324. JXSearchChatLogVC *vc = [[JXSearchChatLogVC alloc] init];
  325. vc.user = self.user;
  326. [g_navigation pushViewController:vc animated:YES];
  327. }
  328. // 阅后即焚
  329. - (void)readDelAction:(UISwitch *)switchView {
  330. int readDel = switchView.isOn;
  331. self.isReadDel = YES;
  332. [g_server friendsUpdateOfflineNoPushMsgUserId:g_myself.userId toUserId:self.user.userId offlineNoPushMsg:readDel type:1 toView:self];
  333. }
  334. // 置顶聊天
  335. - (void)topChatAction:(UISwitch *)switchView {
  336. int topChat = switchView.isOn;
  337. self.isChatTop = YES;
  338. [g_server friendsUpdateOfflineNoPushMsgUserId:g_myself.userId toUserId:self.user.userId offlineNoPushMsg:topChat type:2 toView:self];
  339. }
  340. // 消息免打扰
  341. - (void)messageFreeAction:(UISwitch *)switchView {
  342. int offlineNoPushMsg = switchView.isOn;
  343. self.isMsgFree = YES;
  344. [g_server friendsUpdateOfflineNoPushMsgUserId:g_myself.userId toUserId:self.user.userId offlineNoPushMsg:offlineNoPushMsg type:0 toView:self];
  345. }
  346. - (void)chatRecordTimeOutAction {
  347. double outTime = [self.user.chatRecordTimeOut doubleValue];
  348. NSInteger index = 0;
  349. if (outTime <= 0) {
  350. index = 0;
  351. }else if (outTime == 0.04) {
  352. index = 1;
  353. }else if (outTime == 1) {
  354. index = 2;
  355. }else if (outTime == 7) {
  356. index = 3;
  357. }else if (outTime == 30) {
  358. index = 4;
  359. }else if (outTime == 90) {
  360. index = 5;
  361. }else{
  362. index = 6;
  363. }
  364. [_pickerView selectRow:index inComponent:0 animated:NO];
  365. _selectView.hidden = NO;
  366. }
  367. // 清除聊天记录
  368. - (void)cleanMessageLog {
  369. [g_App showAlert:Localized(@"JX_ConfirmDeleteChat") delegate:self tag:1111 onlyConfirm:NO];
  370. }
  371. //清空双方的聊天记录
  372. - (void)cleanTwoSidesMessageLog {
  373. [g_App showAlert:Localized(@"JX_ConfirmDelMsgTwoSides?") delegate:self tag:2222 onlyConfirm:NO];
  374. }
  375. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
  376. if (buttonIndex == 1 && (alertView.tag == 1111 || alertView.tag == 2222)) {
  377. if (alertView.tag == 2222) {
  378. JXMessageObject *msg = [[JXMessageObject alloc] init];
  379. msg.timeSend = [NSDate date];
  380. msg.type = [NSNumber numberWithInt:kWCMessageTypeDelMsgTwoSides];
  381. msg.fromUserId = MY_USER_ID;
  382. msg.toUserId = self.user.userId;
  383. [g_xmpp sendMessage:msg roomName:nil];
  384. }
  385. JXMessageObject *msg = [[JXMessageObject alloc] init];
  386. msg.toUserId = self.user.userId;
  387. [msg deleteAll];
  388. msg.type = [NSNumber numberWithInt:1];
  389. msg.content = @" ";
  390. [msg updateLastSend:UpdateLastSendType_None];
  391. [msg notifyMyLastSend];
  392. [g_server emptyMsgWithTouserId:self.user.userId type:[NSNumber numberWithInt:0] toView:self];
  393. [g_notify postNotificationName:kRefreshChatLogNotif object:nil];
  394. }
  395. }
  396. -(JXImageView*)createHeadButtonclick:(SEL)click{
  397. JXImageView* btn = [[JXImageView alloc] init];
  398. btn.backgroundColor = [UIColor whiteColor];
  399. btn.userInteractionEnabled = YES;
  400. btn.didTouch = click;
  401. btn.delegate = self;
  402. [self.tableBody addSubview:btn];
  403. _head = [[JXImageView alloc]initWithFrame:CGRectMake(20, 10, 50, 50)];
  404. _head.layer.cornerRadius = 50 / 2;
  405. _head.layer.masksToBounds = YES;
  406. // _head.didTouch = @selector(onHeadImage);
  407. _head.delegate = self;
  408. _head.didTouch = @selector(onResume);
  409. [g_server getHeadImageLarge:self.user.userId userName:self.user.userNickname imageView:_head];
  410. [btn addSubview:_head];
  411. // [_head release];
  412. if ([self.user.userType intValue] != 2) {
  413. JXImageView *add = [[JXImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_head.frame) + 20, _head.frame.origin.y, _head.frame.size.width, _head.frame.size.height)];
  414. add.delegate = self;
  415. add.didTouch = @selector(createRoom);
  416. add.image = [UIImage imageNamed:@"add"];
  417. [btn addSubview:add];
  418. }
  419. //名字Label
  420. UILabel* p = [[UILabel alloc]initWithFrame:CGRectMake(_head.frame.origin.x, CGRectGetMaxY(_head.frame), _head.frame.size.width, 20)];
  421. p.font = g_factory.font13;
  422. p.text = g_server.myself.userNickname;
  423. p.textAlignment = NSTextAlignmentCenter;
  424. p.backgroundColor = [UIColor clearColor];
  425. [btn addSubview:p];
  426. _userName = p;
  427. _userName.text = self.user.remarkName.length > 0 ? self.user.remarkName : self.user.userNickname;
  428. if(click){
  429. UIImageView* iv;
  430. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  431. iv.image = [UIImage imageNamed:@"new_icon_>"];
  432. iv.center = CGPointMake(iv.center.x, CGRectGetMidY(_head.frame));
  433. [btn addSubview:iv];
  434. }
  435. // UIView* line = [[UIView alloc] initWithFrame:CGRectMake(0,90-0.5,JX_SCREEN_WIDTH,0.5)];
  436. // line.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
  437. // [btn addSubview:line];
  438. return btn;
  439. }
  440. -(JXImageView*)createButton:(NSString*)title drawTop:(BOOL)drawTop drawBottom:(BOOL)drawBottom icon:(NSString*)icon click:(SEL)click{
  441. JXImageView* btn = [[JXImageView alloc] init];
  442. btn.backgroundColor = [UIColor whiteColor];
  443. btn.userInteractionEnabled = YES;
  444. btn.didTouch = click;
  445. btn.delegate = self;
  446. [self.tableBody addSubview:btn];
  447. JXLabel* p = [[JXLabel alloc] initWithFrame:CGRectMake(15, 0, JX_SCREEN_WIDTH-100, HEIGHT)];
  448. p.text = title;
  449. p.font = g_factory.font15;
  450. p.backgroundColor = [UIColor clearColor];
  451. p.textColor = [UIColor blackColor];
  452. p.delegate = self;
  453. p.didTouch = click;
  454. [btn addSubview:p];
  455. if ([title isEqualToString:Localized(@"JX_UserInfoDescribe")] || [title isEqualToString:Localized(@"JX_MemoName")]) {
  456. _describe = p;
  457. }
  458. if(icon){
  459. UIImageView* iv = [[UIImageView alloc] initWithFrame:CGRectMake(10, (HEIGHT-20)/2, 20, 20)];
  460. iv.image = [UIImage imageNamed:icon];
  461. [btn addSubview:iv];
  462. }
  463. if(drawTop){
  464. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,0,JX_SCREEN_WIDTH-15,LINE_WH)];
  465. line.backgroundColor = THE_LINE_COLOR;
  466. [btn addSubview:line];
  467. }
  468. if(drawBottom){
  469. UIView* line = [[UIView alloc] initWithFrame:CGRectMake(15,HEIGHT-LINE_WH,JX_SCREEN_WIDTH,LINE_WH)];
  470. line.backgroundColor = THE_LINE_COLOR;
  471. [btn addSubview:line];
  472. }
  473. if(click){
  474. UIImageView* iv;
  475. iv = [[UIImageView alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH-15-7, (HEIGHT-13)/2, 7, 13)];
  476. iv.image = [UIImage imageNamed:@"new_icon_>"];
  477. [btn addSubview:iv];
  478. }
  479. return btn;
  480. }
  481. -(JXLabel*)createLabel:(UIView*)parent default:(NSString*)s isClick:(BOOL) boo{
  482. JXLabel * p;
  483. if (boo) {
  484. p = [[JXLabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2 - 23 -INSETS,INSETS,JX_SCREEN_WIDTH/2 - INSETS,HEIGHT-INSETS*2)];
  485. }else{
  486. p = [[JXLabel alloc] initWithFrame:CGRectMake(JX_SCREEN_WIDTH/2 ,INSETS,JX_SCREEN_WIDTH/2 - INSETS,HEIGHT-INSETS*2)];
  487. }
  488. p.userInteractionEnabled = NO;
  489. p.text = s;
  490. p.textColor = [UIColor lightGrayColor];
  491. p.font = g_factory.font15;
  492. p.textAlignment = NSTextAlignmentRight;
  493. [parent addSubview:p];
  494. // [p release];
  495. return p;
  496. }
  497. - (UISwitch *)createSwitch:(UIView *)parent defaule:(BOOL)isOn click:(SEL)click {
  498. UISwitch *switchView = [[UISwitch alloc] init];
  499. switchView.frame = CGRectMake(JX_SCREEN_WIDTH -INSETS - 51, 6, 0, 0);
  500. [switchView addTarget:self action:click forControlEvents:UIControlEventValueChanged];
  501. switchView.onTintColor = THEMECOLOR;
  502. [switchView setOn:isOn];
  503. [parent addSubview:switchView];
  504. return switchView;
  505. }
  506. - (void)onResume {
  507. // [g_server getUser:self.user.userId toView:self];
  508. JXUserInfoVC* vc = [JXUserInfoVC alloc];
  509. vc.userId = self.user.userId;
  510. vc.user = self.user;
  511. vc.fromAddType = 6;
  512. vc = [vc init];
  513. [g_navigation pushViewController:vc animated:YES];
  514. }
  515. - (void)createRoom {
  516. if ([g_config.isCommonCreateGroup intValue] == 1) {
  517. [g_App showAlert:Localized(@"JX_NotCreateNewRoom")];
  518. return;
  519. }
  520. memberData *member = [[memberData alloc] init];
  521. member.userId = [g_myself.userId longLongValue];
  522. member.userNickName = MY_USER_NAME;
  523. member.role = @1;
  524. [_room.members addObject:member];
  525. JXSelectFriendsVC* vc = [JXSelectFriendsVC alloc];
  526. // vc.chatRoom = _chatRoom;
  527. vc.room = _room;
  528. vc.isNewRoom = YES;
  529. vc.isForRoom = YES;
  530. vc.forRoomUser = self.user;
  531. vc = [vc init];
  532. // [g_window addSubview:vc.view];
  533. [g_navigation pushViewController:vc animated:YES];
  534. }
  535. - (void)actionQuitChatVC:(NSNotification *)notif {
  536. [self actionQuit];
  537. }
  538. - (void)chatBackGroundImage {
  539. JXSetChatBackgroundVC *vc = [[JXSetChatBackgroundVC alloc] init];
  540. vc.userId = self.user.userId;
  541. [g_navigation pushViewController:vc animated:YES];
  542. }
  543. //服务端返回数据
  544. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  545. [_wait hide];
  546. // if( [aDownload.action isEqualToString:act_UserGet] ){
  547. // JXUserObject* user = [[JXUserObject alloc]init];
  548. // [user getDataFromDict:dict];
  549. //
  550. // JXUserInfoVC* vc = [JXUserInfoVC alloc];
  551. // vc.user = user;
  552. // vc = [vc init];
  553. // // [g_window addSubview:vc.view];
  554. // [g_navigation pushViewController:vc animated:YES];
  555. // }
  556. if( [aDownload.action isEqualToString:act_UploadFile] ){
  557. NSDictionary* p = nil;
  558. if([(NSArray *)[dict objectForKey:@"audios"] count]>0)
  559. p = [[dict objectForKey:@"audios"] objectAtIndex:0];
  560. if([(NSArray *)[dict objectForKey:@"images"] count]>0)
  561. p = [[dict objectForKey:@"images"] objectAtIndex:0];
  562. if([(NSArray *)[dict objectForKey:@"videos"] count]>0)
  563. p = [[dict objectForKey:@"videos"] objectAtIndex:0];
  564. if(p==nil)
  565. p = [(NSArray *)[dict objectForKey:@"others"] objectAtIndex:0];
  566. NSString* url = [p objectForKey:@"oUrl"];
  567. [g_constant.userBackGroundImage setObject:url forKey:self.user.userId];
  568. BOOL isSuccess = [g_constant.userBackGroundImage writeToFile:backImage atomically:YES];
  569. if (isSuccess) {
  570. [g_App showAlert:Localized(@"JX_SetUpSuccess")];
  571. }else {
  572. [g_App showAlert:Localized(@"JX_SettingFailure")];
  573. }
  574. }
  575. if([aDownload.action isEqualToString:act_FriendRemark]){
  576. [_wait stop];
  577. _userName.text = self.user.remarkName.length > 0 ? self.user.remarkName : self.user.userNickname;
  578. JXUserObject* user1 = [[JXUserObject sharedInstance] getUserById:self.user.userId];
  579. user1.remarkName = self.user.remarkName;
  580. user1.describe = self.user.describe;
  581. // 修改备注后实时刷新
  582. [g_notify postNotificationName:kFriendRemark object:user1];
  583. [user1 update];
  584. [g_App showAlert:Localized(@"JXAlert_SetOK")];
  585. }
  586. if([aDownload.action isEqualToString:act_friendsUpdateOfflineNoPushMsg]){
  587. [_wait stop];
  588. if (self.isMsgFree) {
  589. self.isMsgFree = NO;
  590. self.user.offlineNoPushMsg = [NSNumber numberWithBool:_messageFreeSwitch.isOn];
  591. [self.user updateOfflineNoPushMsg];
  592. [g_App showAlert:Localized(@"JXAlert_SetOK")];
  593. }
  594. else if (self.isChatTop) {
  595. self.isChatTop = NO;
  596. long long time = [[dict objectForKey:@"openTopChatTime"] longLongValue];
  597. self.user.topTime = [NSDate dateWithTimeIntervalSince1970:time];
  598. if (!_chatTopSwitch.isOn) {
  599. self.user.topTime = nil;
  600. }
  601. [self.user updateTopTime];
  602. [g_notify postNotificationName:kFriendListRefresh object:nil];
  603. [g_notify postNotificationName:kChatViewDisappear object:nil];
  604. }
  605. else if (self.isReadDel) {
  606. self.isReadDel = NO;
  607. if (_readDeleteSwitch.isOn) {
  608. [g_App showAlert:Localized(@"JX_ReadDeleteTip")];
  609. }
  610. self.user.isOpenReadDel = [NSNumber numberWithBool:_readDeleteSwitch.isOn];
  611. [self.user updateIsOpenReadDel];
  612. [g_notify postNotificationName:kOpenReadDelNotif object:self.user.isOpenReadDel];
  613. }
  614. }
  615. if( [aDownload.action isEqualToString:act_UserGet] ){
  616. JXUserObject* user = [[JXUserObject alloc]init];
  617. [user getDataFromDict:dict];
  618. self.user = user;
  619. _remarksLabel.text = _user.describe.length > 0 ? _user.describe : _user.remarkName;
  620. [_readDeleteSwitch setOn:[user.isOpenReadDel boolValue]];
  621. [_chatTopSwitch setOn:[user.topTime timeIntervalSince1970] > 0];
  622. [_messageFreeSwitch setOn:[user.offlineNoPushMsg intValue] == 1];
  623. _chatRecordTimeOutLabel.text = [self setChatRecordTimeOutLabelText];
  624. [g_notify postNotificationName:kOpenReadDelNotif object:self.user.isOpenReadDel];
  625. }
  626. if( [aDownload.action isEqualToString:act_EmptyMsg] ){
  627. // 清除聊天记
  628. JXMessageObject *msg = [[JXMessageObject alloc] init];
  629. msg.isGroup = YES;
  630. msg.toUserId = self.user.userId;
  631. [msg deleteAll];
  632. msg.type = [NSNumber numberWithInt:1];
  633. msg.content = @" ";
  634. [msg updateLastSend:UpdateLastSendType_None];
  635. [msg notifyMyLastSend];
  636. // [g_notify postNotificationName:kRefreshChatLogNotif object:nil];
  637. [g_notify postNotificationName:kChatVCReloadNotif object:nil];
  638. [g_App showAlert:Localized(@"JXAlert_DeleteOK")];
  639. }
  640. }
  641. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  642. [_wait hide];
  643. return show_error;
  644. }
  645. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  646. [_wait hide];
  647. return show_error;
  648. }
  649. -(void) didServerConnectStart:(JXConnection*)aDownload{
  650. [_wait start];
  651. }
  652. - (void)didReceiveMemoryWarning {
  653. [super didReceiveMemoryWarning];
  654. // Dispose of any resources that can be recreated.
  655. }
  656. /*
  657. #pragma mark - Navigation
  658. // In a storyboard-based application, you will often want to do a little preparation before navigation
  659. - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  660. // Get the new view controller using [segue destinationViewController].
  661. // Pass the selected object to the new view controller.
  662. }
  663. */
  664. @end