JLBubbleViewController.m 9.4 KB

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