2
0

DNAlbumTableViewController.m 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. //
  2. // DNAlbumTableViewController.m
  3. // ImagePicker
  4. //
  5. // Created by DingXiao on 15/2/10.
  6. // Copyright (c) 2015年 Dennis. All rights reserved.
  7. //
  8. #import "DNAlbumTableViewController.h"
  9. #import "DNImagePickerController.h"
  10. #import "DNImageFlowViewController.h"
  11. #import "DNAlbumCell.h"
  12. #import "DNUnAuthorizedTipsView.h"
  13. #import "DNImagePickerHelper.h"
  14. #import "DNAlbum.h"
  15. #import "WFCUImage.h"
  16. static NSString* const dnalbumTableViewCellReuseIdentifier = @"dnalbumTableViewCellReuseIdentifier";
  17. @interface DNAlbumTableViewController ()
  18. @property (nonatomic, strong) NSArray *albumArray;
  19. @end
  20. @implementation DNAlbumTableViewController
  21. #pragma mark - life cycle
  22. - (void)viewDidLoad {
  23. [super viewDidLoad];
  24. [self setupView];
  25. [self reloadTableView];
  26. }
  27. #pragma mark - public
  28. - (void)reloadTableView {
  29. [DNImagePickerHelper requestAlbumListWithCompleteHandler:^(NSArray<DNAlbum *> * _Nonnull anblumList) {
  30. if (anblumList) {
  31. self.albumArray = [anblumList copy];
  32. [self.tableView reloadData];
  33. }
  34. }];
  35. }
  36. #pragma mark - mark setup Data and View
  37. - (void)setupView {
  38. self.title = WFCString(@"albumTitle");
  39. self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:WFCString(@"cancel") style:UIBarButtonItemStyleDone target:self action:@selector(cancelAction:)];
  40. [self.tableView registerClass:[DNAlbumCell class] forCellReuseIdentifier:dnalbumTableViewCellReuseIdentifier];
  41. UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
  42. self.tableView.tableFooterView = view;
  43. }
  44. #pragma mark - ui actions
  45. - (void)cancelAction:(id)sender {
  46. DNImagePickerController *navController = [self dnImagePickerController];
  47. if (navController && [navController.imagePickerDelegate respondsToSelector:@selector(dnImagePickerControllerDidCancel:)]) {
  48. [navController.imagePickerDelegate dnImagePickerControllerDidCancel:navController];
  49. }
  50. }
  51. #pragma mark - getter/setter
  52. - (DNImagePickerController *)dnImagePickerController {
  53. if (!self.navigationController
  54. ||
  55. ![self.navigationController isKindOfClass:[DNImagePickerController class]])
  56. {
  57. NSAssert(false, @"check the navigation controller");
  58. }
  59. return (DNImagePickerController *)self.navigationController;
  60. }
  61. - (void)showUnAuthorizedTipsView {
  62. DNUnAuthorizedTipsView *view = [[DNUnAuthorizedTipsView alloc] initWithFrame:self.tableView.frame];
  63. self.tableView.backgroundView = view;
  64. }
  65. #pragma mark - Table view data source
  66. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  67. return self.albumArray.count;
  68. }
  69. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  70. DNAlbumCell *cell = [tableView dequeueReusableCellWithIdentifier:dnalbumTableViewCellReuseIdentifier forIndexPath:indexPath];
  71. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  72. DNAlbum *album = self.albumArray[indexPath.row];
  73. cell.titleLabel.attributedText = album.albumAttributedString;
  74. [album fetchPostImageWithSize:CGSizeMake(60, 60) imageResutHandler:^(UIImage * _Nullable postImage) {
  75. if (postImage) {
  76. cell.postImageView.image = postImage;
  77. } else {
  78. cell.postImageView.image = [WFCUImage imageNamed:@"assets_placeholder_picture"];
  79. }
  80. }];
  81. return cell;
  82. }
  83. - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
  84. return 64;
  85. }
  86. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  87. return 64;
  88. }
  89. #pragma mark - tableView delegate
  90. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  91. DNAlbum *album = self.albumArray[indexPath.row];
  92. DNImageFlowViewController *imageFlowViewController = [[DNImageFlowViewController alloc] initWithAblum:album];
  93. [self.navigationController pushViewController:imageFlowViewController animated:YES];
  94. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  95. }
  96. @end