XMGMainViewController.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // XMGMainViewController.m
  3. // 备课-百思不得姐
  4. //
  5. // Created by MJ Lee on 15/6/15.
  6. // Copyright © 2015年 小码哥. All rights reserved.
  7. //
  8. #import "XMGMainViewController.h"
  9. #import "JXMsgViewController.h"
  10. #import "CYWebAddPointVC.h"
  11. #import "XMGNavigationViewController.h"
  12. #import "MJTabBar.h"
  13. #import "JXXMGMyVc.h"
  14. #import "JXBigReelVc.h"
  15. #import "JXWellBeingVc.h"
  16. #import "JXTabMenuView.h"
  17. #import "JXMsgViewController.h"
  18. #import "JXFriendViewController.h"
  19. #import "AppDelegate.h"
  20. #import "JXNewFriendViewController.h"
  21. #import "JXFriendObject.h"
  22. #import "PSMyViewController.h"
  23. #ifdef Live_Version
  24. #import "JXLiveViewController.h"
  25. #endif
  26. #import "JXProgressVC.h"
  27. #import "JXGroupViewController.h"
  28. #import "OrganizTreeViewController.h"
  29. #import "JXLabelObject.h"
  30. #import "JXBlogRemind.h"
  31. #import "JXRoomPool.h"
  32. #import "JXDeviceAuthController.h"
  33. #import "UIColor+Util.h"
  34. #import "UIColor+XQColor.h"
  35. #import "JXLabelObject.h"
  36. #import "JXDeviceAuthController.h"
  37. #import "JXProgressVC.h"
  38. #import "JXBlogRemind.h"
  39. #import "JXBigReelVc.h"
  40. #import "JXShowMainView.h"
  41. #import "JXNewRegisterVc.h"
  42. @interface XMGMainViewController ()
  43. @end
  44. @implementation XMGMainViewController
  45. -(instancetype)init{
  46. if (self=[super init]) {
  47. [g_notify addObserver:self selector:@selector(loginSynchronizeFriends:) name:kXmppClickLoginNotifaction object:nil];
  48. [g_notify addObserver:self selector:@selector(appDidEnterForeground) name:kApplicationWillEnterForeground object:nil];
  49. [g_notify addObserver:self selector:@selector(getUserInfo:) name:kXMPPMessageUpadteUserInfoNotification object:nil];
  50. [g_notify addObserver:self selector:@selector(getRoomSet:) name:kXMPPMessageUpadteGroupNotification object:nil];
  51. [g_notify addObserver:self selector:@selector(onXmppLoginChanged:) name:kXmppLoginNotifaction object:nil];
  52. [g_notify addObserver:self selector:@selector(hasLoginOther:) name:kXMPPLoginOtherNotification object:nil];
  53. [g_notify addObserver:self selector:@selector(showDeviceAuth:) name:kDeviceAuthNotification object:nil];
  54. }
  55. return self;
  56. }
  57. - (void)viewDidLoad {
  58. [super viewDidLoad];
  59. [self initViewControllers];
  60. self.tabBar.backgroundColor = [UIColor whiteColor];
  61. }
  62. - (void)viewDidAppear:(BOOL)animated {
  63. }
  64. - (void)didReceiveMemoryWarning {
  65. [super didReceiveMemoryWarning];
  66. }
  67. - (void)initViewControllers {
  68. JXMsgViewController *controller1 = [[JXMsgViewController alloc] init];
  69. XMGOpenGLNavVc *nav1 = [[XMGOpenGLNavVc alloc] initWithRootViewController:controller1];
  70. nav1.yp_tabItemTitle = @"主页";
  71. JXWellBeingVc *controller2 = [[JXWellBeingVc alloc] init];
  72. controller2.yp_tabItemTitle = @"福利";
  73. JXXMGMyVc *controller3 = [[JXXMGMyVc alloc] init];
  74. controller3.yp_tabItemTitle = @"我";
  75. self.viewControllers = [NSMutableArray arrayWithObjects:nav1, controller2, controller3, nil];
  76. }
  77. - (void)appEnterForegroundNotif:(NSNotification *)noti {
  78. [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  79. }
  80. - (void)getUserInfo:(NSNotification *)noti {
  81. JXMessageObject *msg = noti.object;
  82. [g_server getUser:msg.toUserId toView:self];
  83. }
  84. - (void)getRoomSet:(NSNotification *)noti {
  85. JXMessageObject *msg = noti.object;
  86. [g_server getRoom:msg.toUserId toView:self];
  87. }
  88. -(void)dealloc{
  89. // [_psMyviewVC.view release];
  90. // [_msgVc.view release];
  91. [g_notify removeObserver:self name:kXmppLoginNotifaction object:nil];
  92. [g_notify removeObserver:self name:kSystemLoginNotifaction object:nil];
  93. [g_notify removeObserver:self name:kXmppClickLoginNotifaction object:nil];
  94. [g_notify removeObserver:self name:kXMPPLoginOtherNotification object:nil];
  95. [g_notify removeObserver:self name:kApplicationWillEnterForeground object:nil];
  96. [g_notify removeObserver:self name:kXMPPMessageUpadteUserInfoNotification object:nil];
  97. [g_notify removeObserver:self name:kDeviceAuthNotification object:nil];
  98. // [super dealloc];
  99. }
  100. - (void)appDidEnterForeground {
  101. // 获取服务器时间
  102. [g_server getCurrentTimeToView:self];
  103. }
  104. - (void)loginSynchronizeFriends:(NSNotification*)notification{
  105. //判断服务器好友数量是否与本地一致
  106. // _friendArray = [g_server.myself fetchAllFriendsOrNotFromLocal];
  107. // og(@"%d -------%ld",[g_server.myself.friendCount intValue] , [_friendArray count]);
  108. // if ([g_server.myself.friendCount intValue] > [_friendArray count] && [g_server.myself.friendCount intValue] >0) {
  109. // [g_App showAlert:Localized(@"JXAlert_SynchFirendOK") delegate:self];
  110. if (self.isLoadFriendAndGroup) {
  111. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  112. }else{
  113. [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  114. }
  115. [[JXXMPP sharedInstance] performSelector:@selector(login) withObject:nil afterDelay:2];//2秒后执行xmpp登录
  116. // }
  117. }
  118. - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
  119. if (alertView.tag == 10002) {
  120. [g_server performSelector:@selector(showLogin) withObject:nil afterDelay:0.5];
  121. return;
  122. }else if (buttonIndex == 1) {
  123. [g_server listAttention:0 userId:MY_USER_ID toView:self];
  124. }
  125. }
  126. -(void)buildTop{
  127. ///NSMutableArray *remindArray = [[JXBlogRemind sharedInstance] doFetchUnread];
  128. }
  129. -(void)actionSegment:(UIButton*)sender{
  130. //[self doSelected:(int)sender.tag];
  131. }
  132. -(void)onXmppLoginChanged:(NSNumber*)isLogin{
  133. if([JXXMPP sharedInstance].isLogined == login_status_yes){
  134. // 获取离线调用接口列表
  135. [g_server offlineOperation:(g_server.lastOfflineTime *1000 + g_server.timeDifference)/1000 toView:self];
  136. [self onAfterLogin];
  137. }
  138. }
  139. -(void)onAfterLogin{
  140. // [_msgVc scrollToPageUp];
  141. }
  142. -(void)hasLoginOther:(NSNotification *)notifcation{
  143. [g_App showAlert:Localized(@"JXXMPP_Other") delegate:self tag:10002 onlyConfirm:YES];
  144. }
  145. - (void)showDeviceAuth:(NSNotification *)notification{
  146. JXMessageObject *msg = notification.object;
  147. JXDeviceAuthController *authCon = [[JXDeviceAuthController alloc] initWithMsg:msg];
  148. UIViewController *lastVC = (UIViewController *)g_navigation.subViews.lastObject;
  149. [lastVC presentViewController:authCon animated:YES completion:nil];
  150. }
  151. -(void) didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  152. //更新本地好友
  153. if ([aDownload.action isEqualToString:act_AttentionList]) {
  154. JXProgressVC * pv = [JXProgressVC alloc];
  155. pv.dataArray = array1;
  156. pv = [pv init];
  157. if (array1.count > 300) {
  158. [g_navigation pushViewController:pv animated:YES];
  159. }
  160. // [self.view addSubview:pv.view];
  161. }
  162. // 同步标签
  163. if ([aDownload.action isEqualToString:act_FriendGroupList]) {
  164. for (NSInteger i = 0; i < array1.count; i ++) {
  165. NSDictionary *dict = array1[i];
  166. JXLabelObject *labelObj = [[JXLabelObject alloc] init];
  167. labelObj.groupId = dict[@"groupId"];
  168. labelObj.groupName = dict[@"groupName"];
  169. labelObj.userId = dict[@"userId"];
  170. NSArray *userIdList = dict[@"userIdList"];
  171. NSString *userIdListStr = [userIdList componentsJoinedByString:@","];
  172. if (userIdListStr.length > 0) {
  173. labelObj.userIdList = [NSString stringWithFormat:@"%@", userIdListStr];
  174. }
  175. [labelObj insert];
  176. }
  177. // 删除服务器上已经删除的
  178. NSArray *arr = [[JXLabelObject sharedInstance] fetchAllLabelsFromLocal];
  179. for (NSInteger i = 0; i < arr.count; i ++) {
  180. JXLabelObject *locLabel = arr[i];
  181. BOOL flag = NO;
  182. for (NSInteger j = 0; j < array1.count; j ++) {
  183. NSDictionary * dict = array1[j];
  184. if ([locLabel.groupId isEqualToString:dict[@"groupId"]]) {
  185. flag = YES;
  186. break;
  187. }
  188. }
  189. if (!flag) {
  190. [locLabel delete];
  191. }
  192. }
  193. }
  194. if ([aDownload.action isEqualToString:act_offlineOperation]) {
  195. for (NSDictionary *dict in array1) {
  196. if ([[dict objectForKey:@"tag"] isEqualToString:@"label"]) {
  197. [g_notify postNotificationName:kOfflineOperationUpdateLabelList object:nil];
  198. }
  199. else if ([[dict objectForKey:@"tag"] isEqualToString:@"friend"]) {
  200. [g_server getUser:[dict objectForKey:@"friendId"] toView:self];
  201. }
  202. else if ([[dict objectForKey:@"tag"] isEqualToString:@"room"]) {
  203. [g_server getRoom:[dict objectForKey:@"friendId"] toView:self];
  204. }
  205. }
  206. }
  207. if ([aDownload.action isEqualToString:act_UserGet]) {
  208. JXUserObject *user = [[JXUserObject alloc] init];
  209. [user getDataFromDict:dict];
  210. NSString *gradeIndexcc= dict[@"gradeIndex"];
  211. [[NSUserDefaults standardUserDefaults] setObject:gradeIndexcc forKey:@"gradeIndexcc"];
  212. [[NSUserDefaults standardUserDefaults] synchronize];
  213. if ([user.userId intValue] == [MY_USER_ID intValue]) {
  214. [g_server doSaveUser:dict];
  215. user.bubbleFontId = [dict objectForKey:@"bubbleFontId"];
  216. user.gradeIndex = [dict objectForKey:@"gradeIndex"];
  217. // 保存自己
  218. [user insert];
  219. [user update];
  220. }else {
  221. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:user.userId];
  222. user.content = user1.content;
  223. user.timeSend = user1.timeSend;
  224. [user update];
  225. }
  226. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  227. }
  228. if ([aDownload.action isEqualToString:act_roomGet]) {
  229. JXUserObject *user = [[JXUserObject alloc] init];
  230. [user getDataFromDict:dict];
  231. user.userId = [dict objectForKey:@"jid"];
  232. user.roomId = [dict objectForKey:@"id"];
  233. user.userNickname = [dict objectForKey:@"name"];
  234. if(![g_xmpp.roomPool getRoom:user.userId] || ![user haveTheUser]){
  235. user.userDescription = [dict objectForKey:@"desc"];
  236. user.showRead = [dict objectForKey:@"showRead"];
  237. user.showMember = [dict objectForKey:@"showMember"];
  238. user.allowSendCard = [dict objectForKey:@"allowSendCard"];
  239. user.chatRecordTimeOut = [dict objectForKey:@"chatRecordTimeOut"];
  240. user.talkTime = [dict objectForKey:@"talkTime"];
  241. user.allowInviteFriend = [dict objectForKey:@"allowInviteFriend"];
  242. user.allowUploadFile = [dict objectForKey:@"allowUploadFile"];
  243. user.allowConference = [dict objectForKey:@"allowConference"];
  244. user.allowSpeakCourse = [dict objectForKey:@"allowSpeakCourse"];
  245. user.offlineNoPushMsg = [(NSDictionary *)[dict objectForKey:@"member"] objectForKey:@"offlineNoPushMsg"];
  246. user.isNeedVerify = [dict objectForKey:@"isNeedVerify"];
  247. user.createUserId = [dict objectForKey:@"userId"];
  248. user.content = @" ";
  249. user.topTime = nil;
  250. [user insertRoom];
  251. // [g_xmpp.roomPool joinRoom:user.userId title:user.userNickname lastDate:nil isNew:NO];
  252. }else {
  253. NSDictionary * groupDict = [user toDictionary];
  254. roomData * roomdata = [[roomData alloc] init];
  255. [roomdata getDataFromDict:groupDict];
  256. [roomdata getDataFromDict:dict];
  257. JXUserObject *user1 = [[JXUserObject sharedInstance] getUserById:roomdata.roomJid];
  258. user.content = user1.content;
  259. user.status = user1.status;
  260. user.offlineNoPushMsg = [NSNumber numberWithBool:roomdata.offlineNoPushMsg];
  261. user.msgsNew = user1.msgsNew;
  262. [user update];
  263. }
  264. [g_notify postNotificationName:kOfflineOperationUpdateUserSet object:user];
  265. }
  266. }
  267. -(int) didServerResultFailed:(JXConnection*)aDownload dict:(NSDictionary*)dict{
  268. return hide_error;
  269. }
  270. -(int) didServerConnectError:(JXConnection*)aDownload error:(NSError *)error{//error为空时,代表超时
  271. return hide_error;
  272. }
  273. @end