362 lines
14 KiB
Objective-C
362 lines
14 KiB
Objective-C
//
|
|
// QXUserPhotosView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/5/29.
|
|
//
|
|
|
|
#import "QXUserPhotosView.h"
|
|
#import "QXCreatPhotosViewController.h"
|
|
#import "QXPhotoPasswordView.h"
|
|
#import "QXMineNetwork.h"
|
|
#import "QXPhotosDetailVC.h"
|
|
|
|
@interface QXUserPhotosView()<UICollectionViewDelegate,UICollectionViewDataSource,QXPhotoPasswordViewDelegate>
|
|
@property (nonatomic, copy) void(^scrollCallback)(UIScrollView *scrollView);
|
|
@property (nonatomic, strong) NSMutableArray *dataArray;
|
|
@property (nonatomic, assign) NSInteger page;
|
|
@property (nonatomic, assign) BOOL isMe;
|
|
@end
|
|
@implementation QXUserPhotosView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
self.page = 1;
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(photosListReload) name:noticePhotosStatusChange object:nil];
|
|
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
|
|
layout.itemSize = CGSizeMake((SCREEN_WIDTH-16*2-13)/2, (SCREEN_WIDTH-16*2-13)/2+46);
|
|
layout.minimumLineSpacing = 13;
|
|
layout.minimumInteritemSpacing = 13;
|
|
layout.sectionInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
|
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
|
|
self.collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
|
|
[self.collectionView registerClass:[QXUserPhotosCell class] forCellWithReuseIdentifier:@"QXUserPhotosCell"];
|
|
self.collectionView.delegate = self;
|
|
self.collectionView.dataSource = self;
|
|
self.collectionView.showsHorizontalScrollIndicator = NO;
|
|
self.collectionView.backgroundColor = RGB16(0xf6f6f6);
|
|
[self addSubview:self.collectionView];
|
|
[self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.mas_equalTo(12);
|
|
make.top.mas_equalTo(12);
|
|
make.height.mas_equalTo(ScaleWidth(76));
|
|
make.right.mas_equalTo(-12);
|
|
}];
|
|
MJWeakSelf
|
|
_collectionView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
|
|
weakSelf.page++;
|
|
[weakSelf getPhotos];
|
|
}];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithOffsetY:(CGFloat)offsety {
|
|
self = [self initWithFrame:CGRectZero];
|
|
self.collectionView.contentOffset = CGPointMake(0, offsety);
|
|
|
|
return self;
|
|
}
|
|
|
|
- (void)layoutSubviews {
|
|
[super layoutSubviews];
|
|
|
|
self.collectionView.frame = self.bounds;
|
|
}
|
|
|
|
-(void)setUser_id:(NSString *)user_id{
|
|
_user_id = user_id;
|
|
if ([user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) {
|
|
self.isMe = YES;
|
|
}else{
|
|
self.isMe = NO;
|
|
}
|
|
[self getPhotos];
|
|
}
|
|
|
|
-(void)photosListReload{
|
|
self.page = 1;
|
|
[self getPhotos];
|
|
}
|
|
|
|
-(void)getPhotos{
|
|
MJWeakSelf
|
|
[QXMineNetwork photosListWithUserId:self.user_id
|
|
page:self.page
|
|
successBlock:^(NSArray<QXPhotoModel *> * _Nonnull hotos) {
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
if (weakSelf.page == 1) {
|
|
[weakSelf.dataArray removeAllObjects];
|
|
}
|
|
[weakSelf.dataArray addObjectsFromArray:hotos];
|
|
if (hotos.count == 0) {
|
|
weakSelf.collectionView.mj_footer.state = MJRefreshStateNoMoreData;
|
|
}else{
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}
|
|
[weakSelf.collectionView reloadData];
|
|
} failBlock:^(NSError * _Nonnull error, NSString * _Nonnull msg) {
|
|
[weakSelf.collectionView.mj_footer endRefreshing];
|
|
}];
|
|
}
|
|
|
|
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
if (self.isMe) {
|
|
return self.dataArray.count+1;
|
|
}else{
|
|
return self.dataArray.count;
|
|
}
|
|
|
|
}
|
|
-(__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
QXUserPhotosCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QXUserPhotosCell" forIndexPath:indexPath];
|
|
if (self.isMe) {
|
|
if (indexPath.row == 0) {
|
|
cell.photoImageView.image = [UIImage imageNamed:@"user_photos_add"];
|
|
cell.titleLabel.text = @"";
|
|
cell.countLabel.text = @"";
|
|
cell.isLock = NO;
|
|
}else{
|
|
QXPhotoModel *model = self.dataArray[indexPath.row-1];
|
|
[cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
|
|
cell.titleLabel.text = model.name;
|
|
cell.countLabel.text = [NSString stringWithFormat:@"浏览 %@",model.read_num];
|
|
if (model.is_pwd.integerValue == 0) {
|
|
cell.isLock = NO;
|
|
}else{
|
|
cell.isLock = YES;
|
|
}
|
|
}
|
|
}else{
|
|
QXPhotoModel *model = self.dataArray[indexPath.row];
|
|
[cell.photoImageView sd_setImageWithURL:[NSURL URLWithString:model.image]];
|
|
cell.titleLabel.text = model.name;
|
|
cell.countLabel.text = [NSString stringWithFormat:@"浏览 %@",model.read_num];
|
|
if (model.is_pwd.integerValue == 0) {
|
|
cell.isLock = NO;
|
|
}else{
|
|
cell.isLock = YES;
|
|
}
|
|
}
|
|
return cell;
|
|
}
|
|
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
MJWeakSelf
|
|
if (self.isMe) {
|
|
if (indexPath.row == 0) {
|
|
QXCreatPhotosViewController *vc = [[QXCreatPhotosViewController alloc] init];
|
|
vc.createSuccessBlock = ^{
|
|
[weakSelf getPhotos];
|
|
};
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
QXPhotoModel *model = self.dataArray[indexPath.row-1];
|
|
if (model.is_pwd.integerValue == 0) {
|
|
QXPhotosDetailVC *vc = [[QXPhotosDetailVC alloc] init];
|
|
vc.albumId = model.id;
|
|
vc.name = model.name;
|
|
vc.photoList = self.dataArray;
|
|
vc.userId = self.user_id;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
if ([self.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) {
|
|
QXPhotosDetailVC *vc = [[QXPhotosDetailVC alloc] init];
|
|
vc.albumId = model.id;
|
|
vc.name = model.name;
|
|
vc.photoList = self.dataArray;
|
|
vc.userId = self.user_id;
|
|
vc.pwd = model.pwd;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
QXPhotoPasswordView *passwordView = [[QXPhotoPasswordView alloc] init];
|
|
passwordView.model = model;
|
|
passwordView.delegate = self;
|
|
[[QXGlobal shareGlobal] showView:passwordView popType:(PopViewTypePopFromCenter) tapDismiss:NO finishBlock:^{
|
|
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
}else{
|
|
QXPhotoModel *model = self.dataArray[indexPath.row];
|
|
if (model.is_pwd.integerValue == 0) {
|
|
QXPhotosDetailVC *vc = [[QXPhotosDetailVC alloc] init];
|
|
vc.albumId = model.id;
|
|
vc.name = model.name;
|
|
vc.photoList = self.dataArray;
|
|
vc.userId = self.user_id;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
if ([self.user_id isEqualToString:[QXGlobal shareGlobal].loginModel.user_id]) {
|
|
QXPhotosDetailVC *vc = [[QXPhotosDetailVC alloc] init];
|
|
vc.albumId = model.id;
|
|
vc.name = model.name;
|
|
vc.photoList = self.dataArray;
|
|
vc.userId = self.user_id;
|
|
vc.pwd = model.pwd;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
QXPhotoPasswordView *passwordView = [[QXPhotoPasswordView alloc] init];
|
|
passwordView.model = model;
|
|
passwordView.delegate = self;
|
|
[[QXGlobal shareGlobal] showView:passwordView popType:(PopViewTypePopFromCenter) tapDismiss:NO finishBlock:^{
|
|
|
|
}];
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
-(void)didClickCommitWithPassword:(NSString *)password model:(nonnull QXPhotoModel *)model{
|
|
QXLOG(@"相册密码为%@",password);
|
|
if ([password isEqualToString:model.pwd]) {
|
|
QXPhotosDetailVC *vc = [[QXPhotosDetailVC alloc] init];
|
|
vc.albumId = model.id;
|
|
vc.name = model.name;
|
|
vc.photoList = self.dataArray;
|
|
vc.userId = self.user_id;
|
|
vc.pwd = password;
|
|
[self.navigationController pushViewController:vc animated:YES];
|
|
}else{
|
|
showToast(@"密码错误");
|
|
}
|
|
|
|
}
|
|
|
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
if (self.scrollCallback != nil) {
|
|
self.scrollCallback(scrollView);
|
|
}
|
|
if (self.listScrollCallback != nil) {
|
|
self.listScrollCallback(scrollView);
|
|
}
|
|
}
|
|
#pragma mark - JXPagingViewListViewDelegate
|
|
|
|
- (UIScrollView *)listScrollView {
|
|
return self.collectionView;
|
|
}
|
|
|
|
- (void)listViewDidScrollCallback:(void (^)(UIScrollView *))callback {
|
|
self.scrollCallback = callback;
|
|
}
|
|
|
|
- (UIView *)listView {
|
|
return self;
|
|
}
|
|
|
|
-(NSMutableArray *)dataArray{
|
|
if (!_dataArray) {
|
|
_dataArray = [NSMutableArray arrayWithCapacity:1];
|
|
}
|
|
return _dataArray;
|
|
}
|
|
|
|
@end
|
|
|
|
@implementation QXUserPhotosCell
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame
|
|
{
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
-(void)setIsLock:(BOOL)isLock{
|
|
_isLock = isLock;
|
|
self.lockImageView.hidden = !isLock;
|
|
self.blurView.hidden = !isLock;
|
|
}
|
|
|
|
-(void)setSelectedState:(BOOL)selectedState{
|
|
_selectedState = selectedState;
|
|
self.selectedBtn.hidden = !selectedState;
|
|
self.selectedBgView.hidden = !selectedState;
|
|
}
|
|
|
|
-(void)initSubviews{
|
|
// user_photos_add
|
|
self.photoImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
self.photoImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
self.photoImageView.clipsToBounds = YES;
|
|
[self.photoImageView addRoundedCornersWithRadius:6];
|
|
[self.contentView addSubview:self.photoImageView];
|
|
[self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.equalTo(self.contentView);
|
|
make.height.equalTo(self.photoImageView.mas_width).multipliedBy(1);
|
|
}];
|
|
|
|
self.titleLabel = [[UILabel alloc] init];
|
|
self.titleLabel.font = [UIFont systemFontOfSize:14];
|
|
self.titleLabel.textColor = QXConfig.textColor;
|
|
|
|
[self.contentView addSubview:self.titleLabel];
|
|
|
|
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self.contentView);
|
|
make.top.equalTo(self.photoImageView.mas_bottom).offset(6);
|
|
make.height.mas_equalTo(22);
|
|
}];
|
|
|
|
self.countLabel = [[UILabel alloc] init];
|
|
self.countLabel.font = [UIFont systemFontOfSize:14];
|
|
self.countLabel.textColor = RGB16(0x999999);
|
|
[self.contentView addSubview:self.countLabel];
|
|
|
|
[self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.equalTo(self.contentView);
|
|
make.top.equalTo(self.titleLabel.mas_bottom);
|
|
make.height.mas_equalTo(18);
|
|
}];
|
|
|
|
self.lockImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_photos_lock"]];
|
|
self.lockImageView.hidden = YES;
|
|
[self.contentView addSubview:self.lockImageView];
|
|
[self.lockImageView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.centerX.centerY.equalTo(self.photoImageView);
|
|
make.size.mas_equalTo(CGSizeMake(ScaleWidth(22), ScaleWidth(22)));
|
|
}];
|
|
|
|
self.selectedBgView = [[UIView alloc] init];
|
|
self.selectedBgView.backgroundColor = RGB16A(0xffffff, 0.2);
|
|
[self.selectedBgView addRoundedCornersWithRadius:10];
|
|
self.selectedBgView.hidden = YES;
|
|
[self.contentView addSubview:self.selectedBgView];
|
|
[self.selectedBgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.top.bottom.left.right.equalTo(self.contentView);
|
|
}];
|
|
|
|
self.selectedBtn = [[UIButton alloc] init];
|
|
self.selectedBtn.userInteractionEnabled = NO;
|
|
self.selectedBtn.hidden = YES;
|
|
// [self.selectedBtn addTarget:self action:@selector(selectedAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.selectedBtn setImage:[UIImage imageNamed:@"login_agreement_sel"] forState:(UIControlStateSelected)];
|
|
[self.selectedBtn setImage:[UIImage imageNamed:@"login_agreement_nor"] forState:(UIControlStateNormal)];
|
|
[self.contentView addSubview:self.selectedBtn];
|
|
[self.selectedBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.right.top.equalTo(self);
|
|
make.size.mas_equalTo(CGSizeMake(25, 25));
|
|
}];
|
|
|
|
UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
|
|
UIVisualEffectView *blurView = [[UIVisualEffectView alloc] initWithEffect:effect];
|
|
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:effect];
|
|
UIVisualEffectView *vibrancyView = [[UIVisualEffectView alloc] initWithEffect:vibrancyEffect];
|
|
[blurView.contentView addSubview:vibrancyView];
|
|
self.blurView = blurView;
|
|
self.blurView.hidden = YES;
|
|
[self.photoImageView addSubview:blurView];
|
|
[blurView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.bottom.equalTo(self.photoImageView);
|
|
}];
|
|
[vibrancyView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.left.right.top.bottom.equalTo(blurView);
|
|
}];
|
|
}
|
|
@end
|