123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- //
- // JLBubbleViewController.m
- // shiku_im
- //
- // Created by JayLuo on 2020/4/7.
- // Copyright © 2020 Reese. All rights reserved.
- //
- #import "JLBubbleViewController.h"
- #import "JLFacePackgeViewCell.h"
- #import "JLFacePackgeViewHeader.h"
- #import "JLFacePackgeModel.h"
- #import "JLFacePackgeDetailViewController.h"
- #import "JLRecommendFacePackgeViewController.h"
- #import "JLMyFacePackgeViewController.h"
- #import "JLBubbleViewCell.h"
- #import "JXSetChatTextFontVC.h"
- #import "JLBubbleModel.h"
- #define cellID @"JLBubbleViewCell"
- @interface JLBubbleViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
- @property (nonatomic, strong) UICollectionView *collectionView;
- @property (nonatomic, strong) NSMutableArray *bubbleArray;
- @property (nonatomic, strong) NSMutableArray *dataArray;
- @end
- @implementation JLBubbleViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.isGotoBack = YES;
- self.title = @"气泡";
- self.heightFooter = 0;
- self.heightHeader = JX_SCREEN_TOP;
- [self createHeadAndFoot];
- _bubbleArray = [NSMutableArray array];
- [self setupUI];
- [self getServerData];
- }
- - (void)getServerData {
- // [g_server getAllBubbleFontListToView:self];
- [g_server getbubbleFontByUserId:nil ToView:self];
- }
- - (void)setupUI {
- UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
- label.text = @"字体大小";
- label.font = [UIFont systemFontOfSize:13];
- UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:label];
- [label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rightButtonClick)]];
- label.userInteractionEnabled = YES;
- [self setRightBarButtonItem:item];
- [self collectionView];
- }
- - (void)rightButtonClick {
- JXSetChatTextFontVC *vc = [[JXSetChatTextFontVC alloc] init];
- [g_navigation pushViewController:vc animated:YES];
-
- }
- - (void)didServerResultSucces:(JXConnection*)aDownload dict:(NSDictionary*)dict array:(NSArray*)array1{
- if([aDownload.action isEqualToString:act_UserGet]){
- JXUserObject* user = [[JXUserObject alloc]init];
- [user getDataFromDict:dict];
- [user userFromDictionary:user dict:dict];
- [user insert];
- }
- if([aDownload.action isEqualToString:act_getbubbleFontByUserId]){
- // _bubbleArray = [JLBubbleModel mj_objectArrayWithKeyValuesArray:array1];
- [_bubbleArray removeAllObjects];
- // for (NSDictionary *modelDict in array1) {
- // JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:modelDict];
- // [_bubbleArray addObject:model];
- // }
- // 更新数据库
- // 保存到数据库
- JLBubbleManager *manager = [JLBubbleManager sharedManager];
- FMDatabase* db = [manager openResouceDb];
- BOOL result = [manager checkBubbleFontTableCreatedInDb:db];
- if (result) {
- // self.id, self.iosLeftUrl, self.iosRightUrl, self.name, self.code, self.color
- for (NSDictionary *tempDict in array1) {
- JLBubbleModel *model = [JLBubbleModel mj_objectWithKeyValues:tempDict];
- manager.id = model.id;
- manager.iosLeftUrl = model.bubble.iosLeftUrl;
- manager.iosRightUrl = model.bubble.iosRightUrl;
- manager.name = model.bubble.name;
- manager.code = [NSString stringWithFormat:@"%d", model.font.code];
- manager.color = model.font.color;
- [manager insertBubbleFontTable];
- [_bubbleArray addObject:model];
- }
- }
- [self.collectionView reloadData];
- }
- if([aDownload.action isEqualToString:act_changeUserDefaultBubbleFont]){
- [g_App showAlert:@"修改成功"];
-
-
- //更新自己
- [g_server getUser:MY_USER_ID toView:self];
- [self getServerData];
- }
-
- }
- - (UICollectionView *)collectionView {
- if (_collectionView == nil) {
- UICollectionViewFlowLayout *layout = ({
-
- UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
-
- // 设置尺寸
- CGFloat width = (self_width - 4 * 5)/3;
- layout.itemSize = CGSizeMake(width, width * 6 / 4);
-
- //估算的尺寸(一般不需要设置)
- // layout.estimatedItemSize = CGSizeMake(120, 130);
-
- //头部的参考尺寸(就是尺寸)
- // layout.headerReferenceSize = CGSizeMake(self_width, 50);
- //尾部的参考尺寸
- layout.footerReferenceSize = CGSizeMake(100, 100);
- layout.sectionFootersPinToVisibleBounds = YES;
- layout.sectionHeadersPinToVisibleBounds = YES;
- layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
- layout.scrollDirection = UICollectionViewScrollDirectionVertical;
- layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
- layout.minimumInteritemSpacing = 5;
- layout.minimumLineSpacing = 5;
-
- layout;
-
- });
-
- _collectionView = ({
- UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
-
- collectionView.bounds = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
-
- collectionView.backgroundColor = OVERALL_LIGHT_GRAY;
-
- collectionView.frame = CGRectMake(0, JX_SCREEN_TOP, self.view.bounds.size.width, self.view.bounds.size.height-JX_SCREEN_TOP);
-
- collectionView.dataSource = self;
-
- collectionView.delegate = self;
- [collectionView registerNib:[UINib nibWithNibName:@"JLBubbleViewCell" bundle:nil] forCellWithReuseIdentifier:cellID];
-
- //设置滚动条
- collectionView.showsHorizontalScrollIndicator = NO;
- collectionView.showsVerticalScrollIndicator = YES;
-
- //设置是否需要弹簧效果
- collectionView.bounces = NO;
- collectionView.allowsSelection = YES;
- collectionView.allowsMultipleSelection = NO;
- collectionView;
-
- });
-
- [self.view addSubview:_collectionView];
-
- }
- return _collectionView;
- }
- - (NSMutableArray *)dataArray {
- if (!_dataArray) {
- _dataArray = [NSMutableArray array];
- }
- return _dataArray;
- }
- #pragma mark - UICollectionViewDataSource
- - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
- return 1;
- }
- - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
- return _bubbleArray.count;
- }
- - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
- JLBubbleViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellID forIndexPath:indexPath];
- JLBubbleModel *model = _bubbleArray[indexPath.row];
- // 获取本地
- NSBundle *bundle = [NSBundle mainBundle];
- NSString *plistPath = [bundle pathForResource:@"FontNameList" ofType:@"plist"];
- //获取本地文件列表 NSArray
- NSDictionary *fontNameList = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
- NSString *fontName = [fontNameList valueForKeyPath:[NSString stringWithFormat:@"%d",model.font.code]];
- cell.titleLabel.font = [UIFont fontWithName:fontName size:12];
- cell.titleLabel.text = model.bubble.name;
- // cell.titleLabel.textColor = [[JLBubbleManager sharedManager] getBubbleFontColor:model.font.color];
- [cell.bubbleImageView sd_setImageWithURL:[NSURL URLWithString:model.homeUrl]];
- [cell setIsBeSelected:model.defaultItem];
- // [cell setIsBeSelected:[self.dataArray[indexPath.row] boolValue]];
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section {
- return UIEdgeInsetsMake(10, 5, 5, 5);
- }
- - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section {
- return CGSizeZero;
- }
- - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
-
-
- // 取出对应模型的文字字体/气泡图片/
- JLBubbleModel *model = _bubbleArray[indexPath.row];
-
-
- // 获取本地
- NSBundle *bundle = [NSBundle mainBundle];
- NSString *plistPath = [bundle pathForResource:@"FontNameList" ofType:@"plist"];
- //获取本地文件列表 NSArray
- NSDictionary *fontNameList = [[NSDictionary alloc] initWithContentsOfFile:plistPath];
- NSString *fontName = [fontNameList valueForKeyPath:[NSString stringWithFormat:@"%d",model.font.code]];
-
-
- [g_default setObject:fontName forKey:kChatFontName];
- [g_default synchronize];
- for (NSInteger a = 0; a<_bubbleArray.count; a++) {
- JLBubbleModel *tempModel = _bubbleArray[a];
- if (a == indexPath.row) {
- tempModel.defaultItem = !tempModel.defaultItem;
- }else {
- tempModel.defaultItem = NO;
- }
- }
- // [g_App showAlert:[NSString stringWithFormat:@"您选择了[%@]气泡",model.bubble.name]];
- [g_server changeUserDefaultBubbleFont:model.id ToView:self];
- [collectionView reloadData];
- }
- @end
|