TUIGroupNoticeController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. //
  2. // TUIGroupNoticeController.m
  3. // TUIGroup
  4. //
  5. // Created by harvy on 2022/1/11.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. //
  8. #import "TUIGroupNoticeController.h"
  9. #import <TUICore/TUIThemeManager.h>
  10. #import "TUIGroupNoticeDataProvider.h"
  11. @interface TUIGroupNoticeController ()
  12. @property(nonatomic, strong) UITextView *textView;
  13. @property(nonatomic, weak) UIButton *rightButton;
  14. @property(nonatomic, strong) TUIGroupNoticeDataProvider *dataProvider;
  15. @end
  16. @implementation TUIGroupNoticeController
  17. - (void)viewDidLoad {
  18. [super viewDidLoad];
  19. self.view.backgroundColor = TIMCommonDynamicColor(@"controller_bg_color", @"#F2F3F5");
  20. [self.view addSubview:self.textView];
  21. UIButton *rightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  22. [rightBtn setTitleColor:TIMCommonDynamicColor(@"nav_title_text_color", @"#000000") forState:UIControlStateNormal];
  23. [rightBtn setTitleColor:TIMCommonDynamicColor(@"nav_title_text_color", @"#000000") forState:UIControlStateSelected];
  24. [rightBtn setTitle:TIMCommonLocalizableString(Edit) forState:UIControlStateNormal];
  25. [rightBtn setTitle:TIMCommonLocalizableString(Done) forState:UIControlStateSelected];
  26. [rightBtn sizeToFit];
  27. [rightBtn addTarget:self action:@selector(onClickRight:) forControlEvents:UIControlEventTouchUpInside];
  28. self.rightButton = rightBtn;
  29. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
  30. self.rightButton.hidden = YES;
  31. UILabel *titleLabel = [[UILabel alloc] init];
  32. titleLabel.text = TIMCommonLocalizableString(TUIKitGroupNotice);
  33. titleLabel.font = [UIFont boldSystemFontOfSize:17.0];
  34. titleLabel.textColor = TIMCommonDynamicColor(@"nav_title_text_color", @"#000000");
  35. [titleLabel sizeToFit];
  36. self.navigationItem.titleView = titleLabel;
  37. __weak typeof(self) weakSelf = self;
  38. self.dataProvider.groupID = self.groupID;
  39. [self.dataProvider getGroupInfo:^{
  40. weakSelf.textView.text = weakSelf.dataProvider.groupInfo.notification;
  41. weakSelf.textView.editable = NO;
  42. weakSelf.rightButton.hidden = !weakSelf.dataProvider.canEditNotice;
  43. }];
  44. }
  45. - (void)viewWillLayoutSubviews {
  46. [super viewWillLayoutSubviews];
  47. self.textView.frame = self.view.bounds;
  48. }
  49. - (void)viewDidAppear:(BOOL)animated {
  50. [super viewDidAppear:animated];
  51. if (self.dataProvider.canEditNotice && self.textView.text.length == 0) {
  52. [self onClickRight:self.rightButton];
  53. }
  54. }
  55. - (void)onClickRight:(UIButton *)button {
  56. if (button.isSelected) {
  57. self.textView.editable = NO;
  58. [self.textView resignFirstResponder];
  59. [self updateNotice];
  60. } else {
  61. self.textView.editable = YES;
  62. [self.textView becomeFirstResponder];
  63. }
  64. button.selected = !button.isSelected;
  65. }
  66. - (void)updateNotice {
  67. __weak typeof(self) weakSelf = self;
  68. [self.dataProvider updateNotice:self.textView.text
  69. callback:^(int code, NSString *desc) {
  70. if (code != 0) {
  71. [TUITool makeToastError:code msg:desc];
  72. return;
  73. }
  74. if (weakSelf.onNoticeChanged) {
  75. weakSelf.onNoticeChanged();
  76. }
  77. }];
  78. }
  79. - (UITextView *)textView {
  80. if (_textView == nil) {
  81. _textView = [[UITextView alloc] init];
  82. _textView.textAlignment = isRTL()?NSTextAlignmentRight:NSTextAlignmentLeft;
  83. _textView.backgroundColor = TIMCommonDynamicColor(@"controller_bg_color", @"#F2F3F5");
  84. _textView.textColor = TIMCommonDynamicColor(@"form_title_color", @"#000000");
  85. _textView.font = [UIFont systemFontOfSize:17];
  86. }
  87. return _textView;
  88. }
  89. - (TUIGroupNoticeDataProvider *)dataProvider {
  90. if (_dataProvider == nil) {
  91. _dataProvider = [[TUIGroupNoticeDataProvider alloc] init];
  92. }
  93. return _dataProvider;
  94. }
  95. @end