NewGroupController.m 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. //
  2. // NewGroupController.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/4/21.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "NewGroupController.h"
  9. #import "config.h"
  10. #import "GroupNetApi.h"
  11. #import <SDWebImage/UIImageView+WebCache.h>
  12. @interface NewGroupController()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
  13. @property (weak, nonatomic) IBOutlet UIImageView *avatar;
  14. @property (weak, nonatomic) IBOutlet UITextField *inputName;
  15. @property (weak, nonatomic) IBOutlet UITableViewCell *yaoqingCell;
  16. @property (weak, nonatomic) IBOutlet UILabel *titleLb;
  17. @property (weak, nonatomic) IBOutlet UITableViewCell *shenheCell;
  18. @property (weak, nonatomic) IBOutlet UITableViewCell *jinyanCell;
  19. @property (weak, nonatomic) IBOutlet UITableViewCell *jiahaoyCell;
  20. @property (weak, nonatomic) IBOutlet UIButton *saveBt;
  21. @property (weak, nonatomic) IBOutlet UISwitch *yaoqingS;
  22. @property (weak, nonatomic) IBOutlet UISwitch *shenheS;
  23. @property (weak, nonatomic) IBOutlet UISwitch *jinyanS;
  24. @property (weak, nonatomic) IBOutlet UISwitch *jinjiaS;
  25. @property (nonatomic,strong) NSString *avatarStr;
  26. @property (nonatomic,strong) NSString *yaoqing;
  27. @property (nonatomic,strong) NSString *jinyan;
  28. @property (nonatomic,strong) NSString *jinjia;
  29. @property (nonatomic,strong) NSString *shenhe;
  30. @end
  31. @implementation NewGroupController
  32. -(void)viewDidLoad{
  33. [super viewDidLoad];
  34. [self.navigationController setNavigationBarHidden:YES animated:NO];
  35. _titleLb.text = NSLocalizedString(@"group-addNew", @"");
  36. // 创建一个点击手势
  37. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  38. // 将手势添加到主视图上
  39. [self.view addGestureRecognizer:tap];
  40. _yaoqing=@"1";
  41. _jinyan=@"0";
  42. _jinjia=@"0";
  43. _shenhe=@"1";
  44. [self initSubview];
  45. [self initGData];
  46. }
  47. -(void)dismissKeyboard{
  48. NSLog(@"dismissKeyboard");
  49. [self.view endEditing:YES];
  50. }
  51. - (IBAction)gotoback:(id)sender {
  52. [self dismissViewControllerAnimated:YES completion:nil];
  53. }
  54. - (IBAction)yaoqingC:(id)sender {
  55. UISwitch *switchButton = (UISwitch*)sender;
  56. BOOL isButtonOn = [switchButton isOn];
  57. if(isButtonOn){
  58. _yaoqing = @"1";
  59. }
  60. else{
  61. _yaoqing = @"0";
  62. }
  63. }
  64. - (IBAction)shenheC:(id)sender {
  65. UISwitch *switchButton = (UISwitch*)sender;
  66. BOOL isButtonOn = [switchButton isOn];
  67. if(isButtonOn){
  68. _shenhe = @"1";
  69. }
  70. else{
  71. _shenhe = @"0";
  72. }
  73. }
  74. - (IBAction)jinyanC:(id)sender {
  75. UISwitch *switchButton = (UISwitch*)sender;
  76. BOOL isButtonOn = [switchButton isOn];
  77. if(isButtonOn){
  78. _jinyan = @"1";
  79. }
  80. else{
  81. _jinyan = @"0";
  82. }
  83. }
  84. - (IBAction)jinjiaC:(id)sender {
  85. UISwitch *switchButton = (UISwitch*)sender;
  86. BOOL isButtonOn = [switchButton isOn];
  87. if(isButtonOn){
  88. _jinjia = @"1";
  89. }
  90. else{
  91. _jinjia = @"0";
  92. }
  93. }
  94. - (IBAction)selectImg:(id)sender {
  95. [self openImagePicker];
  96. }
  97. - (IBAction)saveAct:(id)sender {
  98. [self addnewGroup];
  99. }
  100. -(void)initSubview{
  101. _yaoqingCell.contentView.layer.borderWidth = 0.5f;
  102. _yaoqingCell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  103. _yaoqingCell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  104. _yaoqingCell.textLabel.text =NSLocalizedString(@"NGroupCtr-kaiqiyaoq", @"开启邀请");
  105. _yaoqingCell.textLabel.textColor = [UIColor whiteColor];
  106. [_yaoqingS setOn:YES];
  107. [_saveBt setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  108. [_saveBt setBackgroundColor:globalColor(GCTypeGreen)];
  109. _saveBt.layer.cornerRadius = 8;
  110. _saveBt.layer.masksToBounds = YES; // 防止子视图超出圆角边界
  111. _shenheCell.contentView.layer.borderWidth = 0.5f;
  112. _shenheCell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor;
  113. _shenheCell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  114. _shenheCell.textLabel.text =NSLocalizedString(@"NGroupCtr-ruqunxsh", @"入群需审核");
  115. _shenheCell.textLabel.textColor = [UIColor whiteColor];
  116. [_shenheS setOn:YES];
  117. _jinyanCell.contentView.layer.borderWidth = 0.5f;
  118. _jinyanCell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  119. _jinyanCell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  120. _jinyanCell.textLabel.text =NSLocalizedString(@"NGroupCtr-quantijy", @"全体禁言");
  121. _jinyanCell.textLabel.textColor = [UIColor whiteColor];
  122. [_jinyanS setOn:NO];
  123. _jiahaoyCell.contentView.layer.borderWidth = 0.5f;
  124. _jiahaoyCell.contentView.layer.borderColor = [UIColor lightGrayColor].CGColor; //globalColor(GCTypeGreen);
  125. _jiahaoyCell.contentView.layer.cornerRadius = 8.0f; // 可选,设置圆角
  126. _jiahaoyCell.textLabel.text =NSLocalizedString(@"NGroupCtr-jinjiahy", @"禁加好友");
  127. _jiahaoyCell.textLabel.textColor = [UIColor whiteColor];
  128. [_jinjiaS setOn:NO];
  129. }
  130. -(void)initGData{
  131. _avatarStr = @"";
  132. if(self.groupMsg){
  133. _avatarStr = self.groupMsg[@"avatar"];
  134. NSString *temp = self.groupMsg[@"name"];
  135. _inputName.text = temp;
  136. temp = self.groupMsg[@"openInvite"];
  137. _yaoqing=temp;
  138. if(temp.intValue ==1){
  139. [_yaoqingS setOn:YES];
  140. }
  141. else{
  142. [_yaoqingS setOn:NO];
  143. }
  144. temp = self.groupMsg[@"inviteCheck"];
  145. _shenhe=temp;
  146. if(temp.intValue ==1){
  147. [_shenheS setOn:YES];
  148. }
  149. else{
  150. [_shenheS setOn:NO];
  151. }
  152. temp = self.groupMsg[@"prohibition"];
  153. _jinyan=temp;
  154. if(temp.intValue ==1){
  155. [_jinyanS setOn:YES];
  156. }
  157. else{
  158. [_jinyanS setOn:NO];
  159. }
  160. temp = self.groupMsg[@"prohibitFriend"];
  161. _jinjia=temp;
  162. if(temp.intValue ==1){
  163. [_jinjiaS setOn:YES];
  164. }
  165. else{
  166. [_jinjiaS setOn:NO];
  167. }
  168. }
  169. [_avatar sd_setImageWithURL:[NSURL URLWithString:_avatarStr] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  170. }
  171. /*
  172. * 添加群组
  173. * @param name 群名称
  174. * @param avatar 群头像
  175. * @param openInvite 是否开放邀请
  176. * @param inviteCheck 加群是否需要审核
  177. * @param prohibition 禁言
  178. * @param prohibitFriend 是否允许加好友
  179. * @param announcement 群公告
  180. */
  181. -(void)addnewGroup{
  182. if(self.groupMsg){
  183. NSString *groupId = self.groupMsg[@"id"];
  184. NSDictionary *dic = @{
  185. @"name":_inputName.text,
  186. @"avatar":_avatarStr,
  187. @"openInvite":_yaoqing,
  188. @"inviteCheck":_shenhe,
  189. @"prohibition":_jinyan,
  190. @"prohibitFriend":_jinjia,
  191. };
  192. [GroupNetApi updateGroup:dic groupId:groupId succ:^(int code, NSDictionary * res) {
  193. NSLog(@"res updateGroup:%@",res);
  194. NSString *codestr = res[@"code"];
  195. if(codestr.intValue==200){
  196. [self dismissViewControllerAnimated:YES completion:nil];
  197. }
  198. } fail:^(NSError * _Nonnull error) {
  199. }];
  200. }
  201. else{
  202. if(_inputName.text.length>0){
  203. NSDictionary *dic = @{
  204. @"name":_inputName.text,
  205. @"avatar":_avatarStr,
  206. @"openInvite":_yaoqing,
  207. @"inviteCheck":_shenhe,
  208. @"prohibition":_jinyan,
  209. @"prohibitFriend":_jinjia,
  210. @"announcement":@"",
  211. };
  212. [GroupNetApi addNewGroup:dic succ:^(int code, NSDictionary * res) {
  213. NSLog(@"res addNewGroup:%@",res);
  214. NSString *codestr = res[@"code"];
  215. if(codestr.intValue==200){
  216. [self dismissViewControllerAnimated:YES completion:nil];
  217. }
  218. } fail:^(NSError * _Nonnull error) {
  219. }];
  220. }
  221. else{
  222. }
  223. }
  224. }
  225. #pragma mark imagePicker
  226. - (void)openImagePicker {
  227. UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  228. imagePicker.delegate = self;
  229. imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // 或者使用UIImagePickerControllerSourceTypeCamera
  230. [self presentViewController:imagePicker animated:YES completion:nil];
  231. }
  232. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {
  233. UIImage *chosenImage = info[UIImagePickerControllerEditedImage]; // 如果你设置了允许编辑,则使用这个键;否则使用UIImagePickerControllerOriginalImage
  234. if (!chosenImage) {
  235. chosenImage = info[UIImagePickerControllerOriginalImage];
  236. }
  237. // 裁剪图片,例如裁剪成一个圆形头像
  238. chosenImage = [self imageWithImage:chosenImage scaledToFillSize:CGSizeMake(100, 100)]; // 假设我们想要一个100x100的圆形头像
  239. [self dismissViewControllerAnimated:YES completion:nil];
  240. // 现在你可以调用上传图片的方法了
  241. [self uploadProfilePicture:chosenImage];
  242. }
  243. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
  244. [self dismissViewControllerAnimated:YES completion:nil];
  245. }
  246. - (UIImage *)imageWithImage:(UIImage *)image scaledToFillSize:(CGSize)size {
  247. UIGraphicsBeginImageContextWithOptions(size, NO, image.scale);
  248. UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, size.width, size.height)];
  249. [path addClip];
  250. [image drawInRect:CGRectMake(0, 0, size.width, size.height)];
  251. UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  252. UIGraphicsEndImageContext();
  253. return newImage;
  254. }
  255. - (void)uploadProfilePicture:(UIImage *)image {
  256. NSDate *now = [NSDate date];
  257. NSTimeInterval trt = [now timeIntervalSince1970];
  258. NSInteger time = trt*1000;
  259. NSString *fileName = [NSString stringWithFormat:@"%ld.png",(long)time];
  260. NSData *imageData = UIImagePNGRepresentation(image);
  261. [GroupNetApi upLoaddataWToken:imageData fileName:fileName succ:^(int code, NSDictionary * res) {
  262. NSLog(@"res:%@",res);
  263. self->_avatarStr = res[@"url"];
  264. [self->_avatar sd_setImageWithURL:[NSURL URLWithString:self->_avatarStr] placeholderImage:[UIImage imageNamed:@"Avatar"]];
  265. } fail:^(NSError * _Nonnull error) {
  266. ;
  267. }];
  268. }
  269. #pragma mark statusBar
  270. - (UIStatusBarStyle)preferredStatusBarStyle{
  271. return UIStatusBarStyleLightContent;
  272. }
  273. @end