PCSessionViewController.m 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. //
  2. // PCSessionViewController.m
  3. // WildFireChat
  4. //
  5. // Created by heavyrain lee on 2019/3/2.
  6. // Copyright © 2019 WildFireChat. All rights reserved.
  7. //
  8. #import "PCSessionViewController.h"
  9. #import <WFChatClient/WFCChatClient.h>
  10. #import <WFChatUIKit/WFChatUIKit.h>
  11. #import "MBProgressHUD.h"
  12. #import "AppService.h"
  13. @interface PCSessionViewController ()
  14. @property(nonatomic, strong)UIButton *muteBtn;
  15. @end
  16. @implementation PCSessionViewController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. [self.view setBackgroundColor:[UIColor whiteColor]];
  20. CGFloat width = [UIScreen mainScreen].bounds.size.width;
  21. CGFloat height = [UIScreen mainScreen].bounds.size.height;
  22. UIImageView *pcView = [[UIImageView alloc] initWithFrame:CGRectMake((width - 200)/2, 100, 200, 200)];
  23. pcView.image = [UIImage imageNamed:@"pc"];
  24. [self.view addSubview:pcView];
  25. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake((width - 200)/2, 300, 200, 16)];
  26. [label setText:@"电脑已登录"];
  27. [label setTextAlignment:NSTextAlignmentCenter];
  28. [self.view addSubview:label];
  29. self.muteBtn = [[UIButton alloc] initWithFrame:CGRectMake((width-width/3)/2-35, 336, 70, 70)];
  30. [self.muteBtn setImage:[UIImage imageNamed:@"mute_notification"] forState:UIControlStateNormal];
  31. [self.muteBtn setImage:[UIImage imageNamed:@"mute_notification_hover"] forState:UIControlStateSelected];
  32. self.muteBtn.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.f];
  33. self.muteBtn.layer.cornerRadius = 35;
  34. self.muteBtn.layer.masksToBounds = YES;
  35. if ([[WFCCIMService sharedWFCIMService] isMuteNotificationWhenPcOnline]) {
  36. [self.muteBtn setSelected:YES];
  37. self.muteBtn.backgroundColor = [UIColor colorWithRed:62.f/255 green:100.f/255 blue:228.f/255 alpha:1.f];
  38. }
  39. [self.muteBtn addTarget:self action:@selector(onMuteBtn:) forControlEvents:UIControlEventTouchUpInside];
  40. [self.view addSubview:self.muteBtn];
  41. UILabel *muteLabel = [[UILabel alloc] initWithFrame:CGRectMake((width-width/3)/2-35, 410, 70, 15)];
  42. [muteLabel setText:@"手机静音"];
  43. [muteLabel setFont:[UIFont systemFontOfSize:12]];
  44. [muteLabel setTextColor:[UIColor grayColor]];
  45. [muteLabel setTextAlignment:NSTextAlignmentCenter];
  46. [self.view addSubview:muteLabel];
  47. UIButton *fileBtn = [[UIButton alloc] initWithFrame:CGRectMake((width+width/3)/2-35, 336, 70, 70)];
  48. [fileBtn setImage:[UIImage imageNamed:@"pc_file_transfer"] forState:UIControlStateNormal];
  49. [fileBtn setImage:[UIImage imageNamed:@"pc_file_transfer"] forState:UIControlStateSelected];
  50. fileBtn.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.f];
  51. fileBtn.layer.cornerRadius = 35;
  52. fileBtn.layer.masksToBounds = YES;
  53. [fileBtn addTarget:self action:@selector(onFileBtn:) forControlEvents:UIControlEventTouchUpInside];
  54. [self.view addSubview:fileBtn];
  55. UILabel *fileLabel = [[UILabel alloc] initWithFrame:CGRectMake((width+width/3)/2-35, 410, 70, 15)];
  56. [fileLabel setText:@"传输文件"];
  57. [fileLabel setFont:[UIFont systemFontOfSize:12]];
  58. [fileLabel setTextColor:[UIColor grayColor]];
  59. [fileLabel setTextAlignment:NSTextAlignmentCenter];
  60. [self.view addSubview:fileLabel];
  61. UIButton *logoutBtn = [[UIButton alloc] initWithFrame:CGRectMake(90, height - 120, width - 180, 36)];
  62. [logoutBtn setBackgroundColor:[UIColor redColor]];
  63. [logoutBtn setTitle:@"退出电脑登录" forState:UIControlStateNormal];
  64. logoutBtn.layer.masksToBounds = YES;
  65. logoutBtn.layer.cornerRadius = 5.f;
  66. [logoutBtn addTarget:self action:@selector(onLogoutBtn:) forControlEvents:UIControlEventTouchUpInside];
  67. NSArray<WFCCPCOnlineInfo *> *infos = [[WFCCIMService sharedWFCIMService] getPCOnlineInfos];
  68. if (infos.count) {
  69. if (infos[0].platform == PlatformType_Windows) {
  70. [logoutBtn setTitle:@"退出 Windows 登录" forState:UIControlStateNormal];
  71. [label setText:@"Windows 已登录"];
  72. } else if(infos[0].platform == PlatformType_OSX) {
  73. [logoutBtn setTitle:@"退出 Mac 登录" forState:UIControlStateNormal];
  74. [label setText:@"Mac 已登录"];
  75. } else if(infos[0].platform == PlatformType_Linux) {
  76. [logoutBtn setTitle:@"退出 Linux 登录" forState:UIControlStateNormal];
  77. [label setText:@"Linux 已登录"];
  78. } else if(infos[0].platform == PlatformType_WEB) {
  79. [logoutBtn setTitle:@"退出 Web 登录" forState:UIControlStateNormal];
  80. [label setText:@"Web 已登录"];
  81. } else if(infos[0].platform == PlatformType_WX) {
  82. [logoutBtn setTitle:@"退出小程序登录" forState:UIControlStateNormal];
  83. [label setText:@"小程序已登录"];
  84. } else if(infos[0].platform == PlatformType_iPad) {
  85. [logoutBtn setTitle:@"退出 iPad 登录" forState:UIControlStateNormal];
  86. [label setText:@"iPad 已登录"];
  87. } else if(infos[0].platform == PlatformType_Android) {
  88. [logoutBtn setTitle:@"退出 Android 平板登录" forState:UIControlStateNormal];
  89. [label setText:@"Android 平板已登录"];
  90. }
  91. }
  92. [self.view addSubview:logoutBtn];
  93. }
  94. - (void)onLogoutBtn:(id)sender {
  95. __weak typeof(self)ws = self;
  96. [[WFCCIMService sharedWFCIMService] kickoffPCClient:self.pcClientInfo.clientId success:^{
  97. [ws sendLogoutDone:YES isLogin:YES];
  98. } error:^(int error_code) {
  99. [ws sendLogoutDone:NO isLogin:YES];
  100. }];
  101. }
  102. - (void)sendLogoutDone:(BOOL)result isLogin:(BOOL)isLogin {
  103. if (!result) {
  104. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  105. hud.mode = MBProgressHUDModeText;
  106. hud.label.text = @"网络错误";
  107. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  108. [hud hideAnimated:YES afterDelay:1.f];
  109. } else if(isLogin) {
  110. MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
  111. hud.mode = MBProgressHUDModeText;
  112. hud.label.text = @"成功";
  113. hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
  114. __weak typeof(self)ws = self;
  115. [hud setCompletionBlock:^{
  116. [ws.navigationController popViewControllerAnimated:YES];
  117. }];
  118. [hud hideAnimated:YES afterDelay:1.f];
  119. }
  120. }
  121. - (void)onMuteBtn:(id)sender {
  122. BOOL pre = [[WFCCIMService sharedWFCIMService] isMuteNotificationWhenPcOnline];
  123. __weak typeof(self)ws = self;
  124. [[WFCCIMService sharedWFCIMService] muteNotificationWhenPcOnline:!pre success:^{
  125. if ([[WFCCIMService sharedWFCIMService] isMuteNotificationWhenPcOnline]) {
  126. ws.muteBtn.selected = YES;
  127. ws.muteBtn.backgroundColor = [UIColor colorWithRed:62.f/255 green:100.f/255 blue:228.f/255 alpha:1.f];
  128. } else {
  129. ws.muteBtn.selected = NO;
  130. ws.muteBtn.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.f];
  131. }
  132. } error:^(int error_code) {
  133. }];
  134. }
  135. - (void)onFileBtn:(id)sender {
  136. if ([WFCUConfigManager globalManager].fileTransferId) {
  137. WFCUMessageListViewController *mvc = [[WFCUMessageListViewController alloc] init];
  138. mvc.conversation = [WFCCConversation conversationWithType:Single_Type target:[WFCUConfigManager globalManager].fileTransferId line:0];
  139. mvc.hidesBottomBarWhenPushed = YES;
  140. [self.navigationController pushViewController:mvc animated:YES];
  141. }
  142. }
  143. @end