JLMyBubbleVC.m 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. //
  2. // JLMyBubbleVC.m
  3. // shiku_im
  4. //
  5. // Created by 123 on 2020/5/30.
  6. // Copyright © 2020 Reese. All rights reserved.
  7. //
  8. #import "JLMyBubbleVC.h"
  9. #import "JLBubbleViewController.h"
  10. #import "JLFacePackgeViewCell.h"
  11. #import "JLFacePackgeViewHeader.h"
  12. #import "JLFacePackgeModel.h"
  13. #import "JLFacePackgeDetailViewController.h"
  14. #import "JLRecommendFacePackgeViewController.h"
  15. #import "JLMyFacePackgeViewController.h"
  16. #import "JLBubbleViewCell.h"
  17. #import "JXSetChatTextFontVC.h"
  18. #import "JLBubbleModel.h"
  19. #define cellID @"JLBubbleViewCell"
  20. @interface JLMyBubbleVC ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
  21. @property (nonatomic, strong) UICollectionView *collectionView;
  22. @property (nonatomic, strong) NSMutableArray *bubbleArray;
  23. @property (nonatomic, strong) NSMutableArray *dataArray;
  24. @end
  25. @implementation JLMyBubbleVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. self.isGotoBack = YES;
  29. self.title = @"气泡";
  30. self.heightFooter = 0;
  31. self.heightHeader = JX_SCREEN_TOP;
  32. [self createHeadAndFoot];
  33. _bubbleArray = [NSMutableArray array];
  34. [self setupUI];
  35. [self getServerData];
  36. }
  37. - (void)getServerData {
  38. // [g_server getAllBubbleFontListToView:self];
  39. [g_server getbubbleFontByUserId:nil ToView:self];
  40. }
  41. - (void)setupUI {
  42. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
  43. label.text = @"字体大小";
  44. label.font = [UIFont systemFontOfSize:13];
  45. UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
  46. [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightButtonClick)]];
  47. label.userInteractionEnabled = YES;
  48. [self setRightBarButtonItem:item];
  49. [self collectionView];
  50. }
  51. - (void)rightButtonClick {
  52. JXSetChatTextFontVC *vc = [[JXSetChatTextFontVC alloc] init];
  53. [g_navigation pushViewController:vc animated:YES];
  54. }
  55. - (void)didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
  56. if([aDownload.action isEqualToString:act_UserGet]){
  57. JXUserObject* user = [[JXUserObject alloc]init];
  58. [user getDataFromDict:dict];
  59. [user userFromDictionary:user dict:dict];
  60. [user insert];
  61. }
  62. if([aDownload.action isEqualToString:act_getbubbleFontByUserId]){
  63. // _bubbleArray = [JLBubbleModel mj_objectArrayWithKeyValuesArray:array1];
  64. [_bubbleArray removeAllObjects];
  65. // for (NSDictionary *modelDict in array1) {
  66. // JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:modelDict];
  67. // [_bubbleArray addObject:model];
  68. // }
  69. // 更新数据库
  70. // 保存到数据库
  71. JLBubbleManager *manager = [JLBubbleManager sharedManager];
  72. FMDatabase* db = [manager openResouceDb];
  73. BOOL result = [manager checkBubbleFontTableCreatedInDb:db];
  74. if (result) {
  75. // self.id, self.iosLeftUrl, self.iosRightUrl, self.name, self.code, self.color
  76. for (NSDictionary *tempDict in array1) {
  77. JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:tempDict];
  78. manager.id = model.id;
  79. manager.iosLeftUrl = model.bubble.iosLeftUrl;
  80. manager.iosRightUrl = model.bubble.iosRightUrl;
  81. manager.name = model.bubble.name;
  82. manager.code = [NSString stringWithFormat:@"%d", model.font.code];
  83. manager.color = model.font.color;
  84. [manager insertBubbleFontTable];
  85. [_bubbleArray addObject:model];
  86. }
  87. }
  88. [self.collectionView reloadData];
  89. }
  90. if([aDownload.action isEqualToString:act_changeUserDefaultBubbleFont]){
  91. [g_App showAlert:@"修改成功"];
  92. //更新自己
  93. [g_server getUser:MY_USER_ID toView:self];
  94. [self getServerData];
  95. }
  96. }
  97. - (UICollectionView *)collectionView {
  98. if (_collectionView == nil) {
  99. UICollectionViewFlowLayout *layout = ({
  100. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  101. // 设置尺寸
  102. CGFloat width = (self_width - 4 * 5)/3;
  103. layout.itemSize = CGSizeMake(width, width * 6 / 4);
  104. //估算的尺寸(一般不需要设置)
  105. // layout.estimatedItemSize = CGSizeMake(120, 130);
  106. //头部的参考尺寸(就是尺寸)
  107. // layout.headerReferenceSize = CGSizeMake(self_width, 50);
  108. //尾部的参考尺寸
  109. layout.footerReferenceSize = CGSizeMake(100, 100);
  110. layout.sectionFootersPinToVisibleBounds = YES;
  111. layout.sectionHeadersPinToVisibleBounds = YES;
  112. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  113. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  114. layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
  115. layout.minimumInteritemSpacing = 5;
  116. layout.minimumLineSpacing = 5;
  117. layout;
  118. });
  119. _collectionView = ({
  120. UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  121. collectionView.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
  122. collectionView.backgroundColor = OVERALL_LIGHT_GRAY;
  123. collectionView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
  124. collectionView.dataSource = self;
  125. collectionView.delegate = self;
  126. [collectionView registerNib:[UINib nibWithNibName:@"JLBubbleViewCell" bundle:nil] forCellWithReuseIdentifier:cellID];
  127. //设置滚动条
  128. collectionView.showsHorizontalScrollIndicator = NO;
  129. collectionView.showsVerticalScrollIndicator = YES;
  130. //设置是否需要弹簧效果
  131. collectionView.bounces = NO;
  132. collectionView.allowsSelection = YES;
  133. collectionView.allowsMultipleSelection = NO;
  134. collectionView;
  135. });
  136. [self.view addSubview:_collectionView];
  137. }
  138. return _collectionView;
  139. }
  140. - (NSMutableArray *)dataArray {
  141. if (!_dataArray) {
  142. _dataArray = [NSMutableArray array];
  143. }
  144. return _dataArray;
  145. }
  146. #pragma mark - UICollectionViewDataSource
  147. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
  148. return 1;
  149. }
  150. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  151. return _bubbleArray.count;
  152. }
  153. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  154. JLBubbleViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
  155. JLBubbleModel *model = _bubbleArray[indexPath.row];
  156. // 获取本地
  157. NSBundle *bundle = [NSBundle mainBundle];
  158. NSString *plistPath = [bundle pathForResource:@"FontNameList" ofType:@"plist"];
  159. //获取本地文件列表 NSArray
  160. NSDictionary *fontNameList = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
  161. NSString *fontName = [fontNameList valueForKeyPath:[NSString stringWithFormat:@"%d",model.font.code]];
  162. cell.titleLabel.font = [UIFont fontWithName:fontName size:12];
  163. cell.titleLabel.text = model.bubble.name;
  164. // cell.titleLabel.textColor = [[JLBubbleManager sharedManager] getBubbleFontColor:model.font.color];
  165. [cell.bubbleImageView sd_setImageWithURL:[NSURL URLWithString:model.homeUrl]];
  166. [cell setIsBeSelected:model.defaultItem];
  167. // [cell setIsBeSelected:[self.dataArray[indexPath.row] boolValue]];
  168. return cell;
  169. }
  170. - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
  171. return UIEdgeInsetsMake(10, 5, 5, 5);
  172. }
  173. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
  174. return CGSizeZero;
  175. }
  176. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
  177. // 取出对应模型的文字字体/气泡图片/
  178. JLBubbleModel *model = _bubbleArray[indexPath.row];
  179. // 获取本地
  180. NSBundle *bundle = [NSBundle mainBundle];
  181. NSString *plistPath = [bundle pathForResource:@"FontNameList" ofType:@"plist"];
  182. //获取本地文件列表 NSArray
  183. NSDictionary *fontNameList = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
  184. NSString *fontName = [fontNameList valueForKeyPath:[NSString stringWithFormat:@"%d",model.font.code]];
  185. [g_default setObject:fontName forKey:kChatFontName];
  186. [g_default synchronize];
  187. for (NSInteger a = 0; a<_bubbleArray.count; a++) {
  188. JLBubbleModel *tempModel = _bubbleArray[a];
  189. if (a == indexPath.row) {
  190. tempModel.defaultItem = !tempModel.defaultItem;
  191. }else {
  192. tempModel.defaultItem = NO;
  193. }
  194. }
  195. // [g_App showAlert:[NSString stringWithFormat:@"您选择了[%@]气泡",model.bubble.name]];
  196. [g_server changeUserDefaultBubbleFont:model.id ToView:self];
  197. [collectionView reloadData];
  198. }
  199. @end