CommentListTableViewCell.m 4.34 KB
Newer Older
曹云霄's avatar
曹云霄 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
//
//  CommentListTableViewCell.m
//  Lighting
//
//  Created by 曹云霄 on 2016/12/12.
//  Copyright © 2016年 上海勾芒科技有限公司. All rights reserved.
//

#import "CommentListTableViewCell.h"
#import "MWPhotoBrowser.h"
@interface CommentListTableViewCell ()<MWPhotoBrowserDelegate>
@property (nonatomic,strong) NSMutableArray *browserArray;
@end
@implementation CommentListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.bestView = [[BestReplyView alloc] init];
    [self.contentView addSubview:self.bestView];
    [self.bestView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.optionButton.mas_left).offset(-5);
        make.size.mas_equalTo(CGSizeMake(0, 30));
        make.centerY.equalTo(self.optionButton);
    }];
    
    for (UIImageView  *obj in self.attachmentView.subviews) {
        if ([obj isKindOfClass:[UIImageView class]]) {
            obj.userInteractionEnabled = YES;
            UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)];
            [obj addGestureRecognizer:tap];
        }
    }
}

- (void)tapImage:(UIGestureRecognizer *)tap {
    if (tap.view.tag + 1 > self.replyEntity.attachments.count) {
        return;
    }
    
    [self.browserArray removeAllObjects];
    for (TOAttachmentEntity *att in self.replyEntity.attachments) {
        MWPhoto *photo = [MWPhoto photoWithURL:[NSURL URLWithString:att.fileUrl]];
        [self.browserArray addObject:photo];
    }
    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];
    [browser setCurrentPhotoIndex:tap.view.tag];
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:browser];
曹云霄's avatar
曹云霄 committed
49
    [self.viewController.navigationController presentViewController:nav animated:YES completion:nil];
曹云霄's avatar
曹云霄 committed
50 51 52 53 54 55 56 57 58 59 60
}

#pragma mark - <MWPhotoBrowserDelegate>
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser
{
    return self.browserArray.count;
}

- (id<MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index
{
    if (index < self.browserArray.count) {
曹云霄's avatar
曹云霄 committed
61
        return [self.browserArray objectAtIndex_opple:index];
曹云霄's avatar
曹云霄 committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
    }
    return nil;
}

- (NSString *)photoBrowser:(MWPhotoBrowser *)photoBrowser titleForPhotoAtIndex:(NSUInteger)index
{
    return [NSString stringWithFormat:@"%ld/%ld", index + 1, self.browserArray.count];
}
#pragma mark - 选项按钮
- (IBAction)extensionButtonClickAction:(UIButton *)sender {
    if (self.bestView.width != 0) {
        [UIView animateWithDuration:0.2 animations:^{
            self.bestView.width = 0;
            self.bestView.x = self.optionButton.x;
        }];
    }else {
        [UIView animateWithDuration:0.2 animations:^{
            self.bestView.width = 90;
            self.bestView.x -= 100;
        }];
    }
}

#pragma mark - 赋值
- (void)setReplyEntity:(CustomTOForumReplyEntity *)replyEntity
{
    _replyEntity = replyEntity;
    self.bestView.replyId = _replyEntity.fid;
    if (_replyEntity.isAdminReply) {
        self.issuerNameLabel.customText = @"管理员";
        self.issuerImageView.image = [UIImage imageNamed:@"manager"];
    }else {
        self.issuerNameLabel.customText = [NSString stringWithFormat:@"%@: %@",_replyEntity.replyerPosition,_replyEntity.replyerRealName];
        [self.issuerImageView sd_setImageWithURL:[NSURL URLWithString:_replyEntity.replyerPicture] placeholderImage:ReplaceImage];
    }
    self.issuerDateLabel.text = [BaseViewController formateDate:_replyEntity.replyTime];
    self.commentContentLabel.text = _replyEntity.replyContent;
    self.bestView.isBest = _replyEntity.best;
    self.bestView.indexPath = self.indexPath;
    self.baseImageView.hidden = !_replyEntity.best;
    if (replyEntity.attachments.count > 0) {
        self.layoutAttHeight.constant = 164;
    }else{
        self.layoutAttHeight.constant = 0;
    }
    
    for (NSInteger i = 0; i < replyEntity.attachments.count; i++) {
        TOAttachmentEntity *att = replyEntity.attachments[i];
        UIImageView *imgView = (UIImageView *)[self.attachmentView viewWithTag:i];
        [imgView sd_setImageWithURL:[NSURL URLWithString:att.fileUrl] placeholderImage:REPLACEIMAGE];
    }
    
}

#pragma mark - lazy
- (NSMutableArray *)browserArray
{
    if (!_browserArray) {
        _browserArray = [NSMutableArray array];
    }
    return _browserArray;
}

@end