QMPickedDocViewController.m 4.8 KB

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