//
|
// PBCheckTableViewCell.m
|
// IphoneBIMe
|
//
|
// Created by zjf on 2020/8/19.
|
// Copyright © 2020 ProBIM. All rights reserved.
|
//
|
|
#import "PBCheckTableViewCell.h"
|
#import "PBImageCollectionViewCell.h"
|
#import "PBVideoCollectionViewCell.h"
|
#import "PBExamineAddModel.h"
|
static NSString *const ImageCellID = @"ImageCellID";
|
static NSString *const VideoCellID = @"VideoCellID";
|
@interface PBCheckTableViewCell()<UICollectionViewDataSource, UICollectionViewDelegate, SDPhotoBrowserDelegate>
|
@property (nonatomic, weak) UILabel *descL;
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
@end
|
@implementation PBCheckTableViewCell
|
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
|
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
|
[self setupUI];
|
}
|
return self;
|
}
|
- (void)setupUI {
|
UILabel *descL = [UILabel z_labelWithText:@"" Color:TitleColor isBold:NO Font:16];
|
descL.numberOfLines = 0;
|
[self.contentView addSubview:descL];
|
[descL mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(self.contentView).offset(10);
|
make.left.equalTo(self.contentView).offset(16);
|
make.right.equalTo(self.contentView).offset(-16);
|
}];
|
UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout.alloc init];
|
layout.itemSize = CGSizeMake(80, 80);
|
layout.minimumLineSpacing = 10;
|
layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
|
self.collectionView = [UICollectionView.alloc initWithFrame:CGRectZero collectionViewLayout:layout];
|
[self.collectionView registerClass:[PBImageCollectionViewCell class] forCellWithReuseIdentifier:ImageCellID];
|
[self.collectionView registerClass:[PBVideoCollectionViewCell class] forCellWithReuseIdentifier:VideoCellID];
|
self.collectionView.delegate = self;
|
self.collectionView.dataSource = self;
|
self.collectionView.bounces = NO;
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
self.collectionView.backgroundColor = [UIColor whiteColor];
|
[self.contentView addSubview:self.collectionView];
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
make.top.equalTo(descL.mas_bottom).offset(10);
|
make.left.equalTo(self.contentView).offset(20);
|
make.right.equalTo(self.contentView).offset(-20);
|
make.height.equalTo(@80);
|
make.bottom.equalTo(self.contentView).offset(-10);
|
}];
|
self.descL = descL;
|
}
|
#pragma mark - UICollectionViewDataSource
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
return self.examineAddModel.dataArr.count;
|
}
|
|
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
NSDictionary *dict = self.examineAddModel.dataArr[indexPath.row];
|
if ([[dict valueForKey:@"AttachmentType"] isEqualToString:@".mp4"]) {
|
PBVideoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:VideoCellID forIndexPath:indexPath];
|
NSString *url = [NSString stringWithFormat:@"%@%@",BaseUrl,[dict valueForKey:@"AttachmentUrl"]];
|
cell.videoUrl = url;
|
cell.PlayVideoBlock = ^{
|
if (self.PlayVideoBlock) {
|
self.PlayVideoBlock(url);
|
}
|
};
|
return cell;
|
}else {
|
PBImageCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ImageCellID forIndexPath:indexPath];
|
NSString *url = [NSString stringWithFormat:@"%@%@",BaseUrl,[dict valueForKey:@"AttachmentUrl"]];
|
cell.roleType = PARTICIPANT;
|
cell.imageUrl = url;
|
return cell;
|
}
|
}
|
|
#pragma mark - UICollectionViewDelegate
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
NSDictionary *dict = self.examineAddModel.dataArr[indexPath.row];
|
if ([[dict valueForKey:@"AttachmentType"] isEqualToString:@".mp4"]) {
|
if (self.PlayVideoBlock) {
|
self.PlayVideoBlock([NSString stringWithFormat:@"%@%@",BaseUrl, [dict valueForKey:@"AttachmentUrl"]]);
|
}
|
}else {
|
SDPhotoBrowser *photoBrowser = [SDPhotoBrowser new];
|
photoBrowser.delegate = self;
|
photoBrowser.currentImageIndex = indexPath.item;
|
photoBrowser.imageCount = self.examineAddModel.dataArr.count;
|
photoBrowser.sourceImagesContainerView = self.collectionView;
|
[photoBrowser show];
|
}
|
}
|
|
#pragma mark SDPhotoBrowserDelegate
|
// 返回临时占位图片(即原来的小图)
|
- (UIImage *)photoBrowser:(SDPhotoBrowser *)browser placeholderImageForIndex:(NSInteger)index
|
{
|
// 不建议用此种方式获取小图,这里只是为了简单实现展示而已
|
PBImageCollectionViewCell *cell = (PBImageCollectionViewCell *)[self collectionView:self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
|
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:cell.imageUrl]];
|
UIImage *image = [UIImage imageWithData:data];;
|
return image;
|
}
|
- (void)setExamineAddModel:(PBExamineAddModel *)examineAddModel {
|
_examineAddModel = examineAddModel;
|
self.descL.text = examineAddModel.dataStr;
|
[self.collectionView reloadData];
|
}
|
|
|
@end
|