QMPickedAudioViewController.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. //
  2. // QMPickedAudioViewController.m
  3. // IMSDK-OC
  4. //
  5. // Created by HCF on 16/8/10.
  6. // Copyright © 2016年 HCF. All rights reserved.
  7. //
  8. #import "QMPickedAudioViewController.h"
  9. #import "QMFileManager.h"
  10. #import "QMFileTabbarView.h"
  11. #import "QMProfileManager.h"
  12. #import "QMFileTableCell.h"
  13. #import "QMFileModel.h"
  14. #import "QMChatRoomViewController.h"
  15. @interface QMPickedAudioViewController ()<UITableViewDelegate, UITableViewDataSource> {
  16. UITableView *_tableView;
  17. QMFileTabbarView *_tabbarView;
  18. NSArray *_audioArray;
  19. CGFloat _navHeight;
  20. }
  21. @property (nonatomic, strong) NSMutableSet *pickedAudioSet;
  22. @end
  23. @implementation QMPickedAudioViewController
  24. - (void)viewDidLoad {
  25. [super viewDidLoad];
  26. // Do any additional setup after loading the view.
  27. CGRect StatusRect = [[UIApplication sharedApplication] statusBarFrame];
  28. CGRect NavRect = self.navigationController.navigationBar.frame;
  29. _navHeight = StatusRect.size.height + NavRect.size.height;
  30. self.view.backgroundColor = [UIColor whiteColor];
  31. self.pickedAudioSet = [[NSMutableSet alloc] initWithCapacity:10];
  32. _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight-_navHeight-44) style:UITableViewStylePlain];
  33. _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
  34. _tableView.backgroundColor = [UIColor whiteColor];
  35. _tableView.delegate = self;
  36. _tableView.dataSource = self;
  37. [self.view addSubview:_tableView];
  38. _tabbarView = [[QMFileTabbarView alloc] init];
  39. _tabbarView.frame = CGRectMake(0, kScreenHeight-44-_navHeight, kScreenWidth, 44);
  40. [self.view addSubview:_tabbarView];
  41. [_tableView registerClass:[QMFileTableCell class] forCellReuseIdentifier:NSStringFromClass(QMFileTableCell.self)];
  42. __weak QMPickedAudioViewController *strongSelf = self;
  43. _tabbarView.selectAction = ^{
  44. QMChatRoomViewController * tagViewController = nil;
  45. for (UIViewController *viewController in strongSelf.navigationController.viewControllers) {
  46. if ([viewController isKindOfClass:[QMChatRoomViewController class]]) {
  47. tagViewController = (QMChatRoomViewController *)viewController;
  48. [strongSelf.navigationController popToViewController:tagViewController animated:true];
  49. for (QMFileModel *model in strongSelf.pickedAudioSet) {
  50. [tagViewController sendFileMessageWithName:model.fileName AndSize:model.fileSize AndPath:model.fileName];
  51. }
  52. }
  53. }
  54. };
  55. [self getData];
  56. }
  57. - (void)dealloc {
  58. }
  59. - (void)getData {
  60. QMProfileManager * manager = [QMProfileManager sharedInstance];
  61. _audioArray = [manager getFilesAttributes:AUDIO];
  62. [_tableView reloadData];
  63. }
  64. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  65. return 80;
  66. }
  67. - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  68. return 0.1;
  69. }
  70. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  71. return 0.1;
  72. }
  73. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  74. return _audioArray.count;
  75. }
  76. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  77. QMFileTableCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(QMFileTableCell.self) forIndexPath:indexPath];
  78. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  79. return cell;
  80. }
  81. - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  82. QMFileModel *model = _audioArray[indexPath.row];
  83. if ([cell isKindOfClass:[QMFileTableCell class]]) {
  84. QMFileTableCell *displayCell = (QMFileTableCell *)cell;
  85. [displayCell configureWithModel:model];
  86. displayCell.pickedItemImageView.hidden = ![self.pickedAudioSet containsObject:model];
  87. }
  88. }
  89. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  90. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  91. QMFileModel *model = _audioArray[indexPath.row];
  92. if ([self.pickedAudioSet containsObject:model]) {
  93. [self.pickedAudioSet removeObject:model];
  94. }else {
  95. if ([self.pickedAudioSet count]>0) {
  96. }else {
  97. [self.pickedAudioSet addObject:model];
  98. }
  99. }
  100. QMFileTableCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  101. cell.pickedItemImageView.hidden = ![self.pickedAudioSet containsObject:model];
  102. if ([self.pickedAudioSet count]>0) {
  103. _tabbarView.doneButton.selected = YES;
  104. }else {
  105. _tabbarView.doneButton.selected = NO;
  106. }
  107. }
  108. - (void)didReceiveMemoryWarning {
  109. [super didReceiveMemoryWarning];
  110. // Dispose of any resources that can be recreated.
  111. }
  112. @end