Files
peko-ios/YuMi/Modules/YMMine/View/Cell/MineInfo/XPMineDataClanTableViewCell.m
2023-08-10 18:44:46 +08:00

448 lines
17 KiB
Objective-C

//
// XPMineDataClanTableViewCell.m
// xplan-ios
//
// Created by 冯硕 on 2022/4/14.
//
#import "XPMineDataClanTableViewCell.h"
///Third
#import <Masonry/Masonry.h>
#import <YYText/YYText.h>
///Tool
#import "NetImageView.h"
#import "UIButton+EnlargeTouchArea.h"
///Model
#import "ClanDetailInfoModel.h"
@interface XPMineDataClanTableViewCell ()
/////背景
@property (nonatomic,strong) UIView *backView;
/////显示标题
@property (nonatomic,strong) UILabel *titleLabel;
///星座
@property (nonatomic,strong) UILabel *starView;
///星座背景图片
@property (nonatomic,strong) UIImageView *starIconView;
///星座
@property (nonatomic,strong) UILabel *starTitleView;
///生日
@property (nonatomic,strong) UILabel *birthdayHeadView;
@property (nonatomic,strong) UILabel *birthdayView;
///地区
@property (nonatomic,strong) UILabel *areaHeadView;
@property (nonatomic,strong) UILabel *areaView;
@property (nonatomic,strong) UIButton *areaMornBnt;
@property (nonatomic,strong) UIButton *areaIconView;
///房间
@property (nonatomic,strong) UILabel *roomHeadView;
@property (nonatomic,strong) UILabel *roomView;
@property (nonatomic,strong) UIButton *roomIconView;
///公会
@property (nonatomic,strong) UILabel *clanHeadView;
@property (nonatomic,strong) UILabel *clanView;
@property (nonatomic,strong) UIButton *clanIconView;
@end
@implementation XPMineDataClanTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
#pragma mark - Private Method
- (void)initSubViews {
self.backgroundColor = [UIColor clearColor];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addSubview:self.backView];
[self.backView addSubview:self.titleLabel];
[self.backView addSubview:self.starView];
[self.backView addSubview:self.starIconView];
[self.starIconView addSubview:self.starTitleView];
[self.backView addSubview:self.birthdayHeadView];
[self.backView addSubview:self.birthdayView];
[self.backView addSubview:self.areaHeadView];
[self.backView addSubview:self.areaView];
[self.backView addSubview:self.areaMornBnt];
[self.backView addSubview:self.areaIconView];
[self.backView addSubview:self.roomHeadView];
[self.backView addSubview:self.roomView];
[self.backView addSubview:self.roomIconView];
[self.backView addSubview:self.clanHeadView];
[self.backView addSubview:self.clanView];
[self.backView addSubview:self.clanIconView];
}
- (void)initSubViewConstraints {
[self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.right.mas_equalTo(self.contentView).inset(kGetScaleWidth(15));
make.top.mas_equalTo(self.contentView);
make.bottom.mas_equalTo(self.contentView).mas_offset(-kGetScaleWidth(12));
}];
[self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.backView).offset(kGetScaleWidth(12));
make.top.mas_equalTo(self.backView).offset(kGetScaleWidth(10));
make.height.mas_equalTo(kGetScaleWidth(17));
}];
[self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.height.equalTo(self.titleLabel);
make.top.equalTo(self.titleLabel.mas_bottom).mas_offset(kGetScaleWidth(12));
}];
[self.starIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kGetScaleWidth(13));
make.width.mas_equalTo(kGetScaleWidth(38));
make.centerY.equalTo(self.starView);
make.left.equalTo(self.starView.mas_right).mas_offset(kGetScaleWidth(10));
}];
[self.starTitleView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(kGetScaleWidth(5));
make.right.mas_equalTo(-kGetScaleWidth(5));
make.top.bottom.equalTo(self.starIconView);
}];
[self.birthdayHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.height.equalTo(self.titleLabel);
make.top.equalTo(self.starView.mas_bottom).mas_offset(kGetScaleWidth(5));
}];
[self.birthdayView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.birthdayHeadView);
make.left.equalTo(self.starIconView);
}];
[self.areaHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.height.equalTo(self.titleLabel);
make.top.mas_equalTo(kGetScaleWidth(84));
}];
[self.areaView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.centerY.equalTo(self.areaHeadView);
make.left.equalTo(self.starIconView);
}];
[self.areaMornBnt mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.mas_equalTo(kGetScaleWidth(25));
make.height.mas_equalTo(kGetScaleWidth(17));
make.left.equalTo(self.areaView.mas_right).mas_offset(kGetScaleWidth(8));
make.centerY.equalTo(self.areaView);
}];
[self.areaIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(20));
make.centerY.equalTo(self.areaView);
make.left.equalTo(self.areaMornBnt.mas_right);
}];
[self.roomHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.height.equalTo(self.titleLabel);
make.top.mas_equalTo(kGetScaleWidth(106));
}];
[self.roomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.centerY.equalTo(self.roomHeadView);
make.left.equalTo(self.starIconView);
}];
[self.roomIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(20));
make.centerY.equalTo(self.roomHeadView);
make.left.equalTo(self.roomView.mas_right);
}];
[self.clanHeadView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.height.equalTo(self.titleLabel);
make.top.mas_equalTo(kGetScaleWidth(130));
}];
[self.clanView mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.clanHeadView);
make.left.equalTo(self.starIconView);
}];
[self.clanIconView mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(kGetScaleWidth(20));
make.centerY.equalTo(self.clanHeadView);
make.left.equalTo(self.clanView.mas_right);
}];
}
#pragma mark - Event Response
- (void)enterButtonAction:(UIButton *)sender {
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataClanTableViewCell:didClickEnter:)]) {
[self.delegate xPMineDataClanTableViewCell:self didClickEnter:self.clanInfo];
}
}
- (void)foldButtonAction:(UIButton *)sender{
sender.selected = !sender.selected;
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataClanTableViewCell:didClickFold:)]) {
[self.delegate xPMineDataClanTableViewCell:self didClickFold:sender];
}
}
- (void)didTapClanView {
if (_clanInfo.clan.elderUid.length <= 0) return;
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataClanTableViewCell:didClickClanView:)]) {
[self.delegate xPMineDataClanTableViewCell:self didClickClanView:self.clanInfo];
}
}
- (void)didTapHallView {
if(_clanInfo.hall.hallName.length <= 0)return;
if (self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataClanTableViewCell:didClickHallView:)]) {
[self.delegate xPMineDataClanTableViewCell:self didClickHallView:self.clanInfo];
}
}
- (void)didTapAreaView {
if(self.delegate && [self.delegate respondsToSelector:@selector(xPMineDataClanTableViewCell:didClickOpen:)]){
[self.delegate xPMineDataClanTableViewCell:self didClickOpen:self.clanInfo];
}
}
#pragma mark - Getters And Setters
- (void)setClanInfo:(ClanDetailInfoModel *)clanInfo {
_clanInfo = clanInfo;
if (_clanInfo) {
_clanView.text = _clanInfo.clan.name;
_roomView.text = _clanInfo.hall.hallName.length > 0 ? _clanInfo.hall.hallName :([[AccountInfoStorage instance] getUid].integerValue == self.userInfo.uid ? YMLocalizedString(@"XPMineDataClanTableViewCell12") : YMLocalizedString(@"XPMineDataClanTableViewCell11")) ;
_roomIconView.hidden = !(_clanInfo.hall.hallName.length > 0);
_roomView.textColor = _clanInfo.hall.hallName.length > 0 ? UIColorFromRGB(0xFFBC51):[DJDKMIMOMColor inputTextColor];
if(self.isOpne == YES){
self.areaMornBnt.hidden = YES;
self.areaIconView.hidden = YES;
self.roomHeadView.hidden = NO;
self.roomView.hidden = NO;
self.clanView.hidden = YES;
self.clanHeadView.hidden = YES;
self.clanIconView.hidden = YES;
if (self.clanInfo.clan.elderUid.length > 0) {
self.clanView.hidden = NO;
self.clanHeadView.hidden = NO;
self.clanIconView.hidden = NO;
}
}else{
self.roomHeadView.hidden = YES;
self.roomView.hidden = YES;
self.roomIconView.hidden = YES;
self.clanView.hidden = YES;
self.clanHeadView.hidden = YES;
self.clanIconView.hidden = YES;
self.areaMornBnt.hidden = NO;
self.areaIconView.hidden = NO;
}
}
}
-(void)setUserInfo:(UserInfoModel *)userInfo{
_userInfo = userInfo;
_starIconView.hidden = NO;
NSString *dateStr = [NSString stringWithFormat:@"%@",[self calculateConstellationWithMonth:_userInfo.birth]];
_starTitleView.text = dateStr;
_birthdayView.text = [NSDate timestampSwitchTime:_userInfo.birth / 1000 andFormatter:@"yyyy-MM-dd"];
_areaView.text = _userInfo.region;
}
- (NSString *)calculateConstellationWithMonth:(long)time
{
NSString *astroString = YMLocalizedString(@"XPMineHeadView0");
NSString *astroFormat = @"102123444543";
NSString *result;
NSInteger month = [self getMonth:time];
NSInteger day = [self getDay:time];
if (month<1 || month>12 || day<1 || day>31){
return YMLocalizedString(@"XPMineHeadView1");
}
if(month==2 && day>29)
{
return YMLocalizedString(@"XPMineHeadView2");
}else if(month==4 || month==6 || month==9 || month==11) {
if (day>30) {
return YMLocalizedString(@"XPMineHeadView3");
}
}
result=[NSString stringWithFormat:@"%@",[astroString substringWithRange:NSMakeRange(month*2-(day < [[astroFormat substringWithRange:NSMakeRange((month-1), 1)] intValue] - (-19))*2,2)]];
return [NSString stringWithFormat:YMLocalizedString(@"XPMineHeadView6"),result];
}
-(NSInteger) getMonth:(long )time
{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSCalendarUnitMonth fromDate:date];
NSInteger month = components.month;
return month;
}
- (NSInteger) getDay:(long) time
{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:time/1000];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSCalendarUnitDay fromDate:date];
NSInteger day = components.day;
return day;
}
- (void)setIsShowEnterHall:(BOOL)isShowEnterHall {
_isShowEnterHall = isShowEnterHall;
}
- (UIView *)backView {
if (!_backView) {
_backView = [[UIView alloc] init];
_backView.userInteractionEnabled = YES;
_backView.layer.cornerRadius = kGetScaleWidth(8);
_backView.backgroundColor =[UIColor whiteColor];
}
return _backView;
}
- (UILabel *)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.text = YMLocalizedString(@"XPMineDataClanTableViewCell6");
_titleLabel.font = kFontMedium(15);
_titleLabel.textColor = UIColorFromRGB(0x1F1A4E);
}
return _titleLabel;
}
-(UILabel *)starView{
if (!_starView){
_starView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataClanTableViewCell7") font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
}
return _starView;
}
-(UIImageView *)starIconView{
if (!_starIconView){
_starIconView = [[UIImageView alloc]init];
UIImage *image = [UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xA486FF),UIColorFromRGB(0xD3ACFE)] gradientType:GradientTypeLeftToRight imgSize:CGSizeMake(kGetScaleWidth(38), kGetScaleWidth(13))];
_starIconView.layer.cornerRadius = kGetScaleWidth(6.5);
_starIconView.layer.masksToBounds = YES;
_starIconView.image = image;
_starIconView.hidden = YES;
}
return _starIconView;
}
-(UILabel *)starTitleView{
if (!_starTitleView){
_starTitleView = [UILabel labelInitWithText:@"" font:kFontRegular(8.5) textColor:[UIColor whiteColor]];
_starTitleView.textAlignment = NSTextAlignmentCenter;
}
return _starTitleView;
}
- (UILabel *)birthdayHeadView{
if (!_birthdayHeadView){
_birthdayHeadView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataClanTableViewCell8") font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
}
return _birthdayHeadView;
}
- (UILabel *)birthdayView{
if (!_birthdayView){
_birthdayView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
}
return _birthdayView;
}
-(UILabel *)areaHeadView{
if (!_areaHeadView){
_areaHeadView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataClanTableViewCell13") font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
}
return _areaHeadView;
}
-(UILabel *)areaView{
if (!_areaView){
_areaView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
}
return _areaView;
}
-(UIButton *)areaMornBnt{
if (!_areaMornBnt){
_areaMornBnt = [UIButton new];
[_areaMornBnt setTitle:YMLocalizedString(@"XPMineDataClanTableViewCell14") forState:UIControlStateNormal];
[_areaMornBnt setTitleColor:UIColorFromRGB(0xFFBC51) forState:UIControlStateNormal];
_areaMornBnt.titleLabel.font = kFontRegular(11);
[_areaMornBnt addTarget:self action:@selector(didTapAreaView) forControlEvents:UIControlEventTouchUpInside];
}
return _areaMornBnt;
}
-(UIButton *)areaIconView{
if (!_areaIconView){
_areaIconView = [UIButton new];
[_areaIconView setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_areaIconView addTarget:self action:@selector(didTapAreaView) forControlEvents:UIControlEventTouchUpInside];
[_areaIconView setBackgroundImage:kImage(@"mine_clan_arrow") forState:UIControlStateNormal];
}
return _areaIconView;
}
-(UILabel *)roomHeadView{
if (!_roomHeadView){
_roomHeadView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataClanTableViewCell9") font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
_roomHeadView.hidden = YES;
}
return _roomHeadView;
}
- (UILabel *)roomView{
if (!_roomView){
_roomView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0xFFBC51)];
_roomView.userInteractionEnabled = YES;
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapHallView)];
[_roomView addGestureRecognizer:tap];
_roomView.hidden = YES;
}
return _roomView;
}
-(UIButton *)roomIconView{
if (!_roomIconView){
_roomIconView = [UIButton new];
[_roomIconView setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_roomIconView addTarget:self action:@selector(didTapHallView) forControlEvents:UIControlEventTouchUpInside];
[_roomIconView setBackgroundImage:kImage(@"mine_clan_arrow") forState:UIControlStateNormal];
_roomIconView.hidden = YES;
}
return _roomIconView;
}
- (UILabel *)clanHeadView{
if (!_clanHeadView){
_clanHeadView = [UILabel labelInitWithText:YMLocalizedString(@"XPMineDataClanTableViewCell10") font:kFontRegular(12) textColor:[DJDKMIMOMColor inputTextColor]];
_clanHeadView.hidden = YES;
}
return _clanHeadView;
}
-(UILabel *)clanView{
if (!_clanView){
_clanView = [UILabel labelInitWithText:@"" font:kFontRegular(12) textColor:UIColorFromRGB(0xFFBC51)];
_clanView.userInteractionEnabled = YES;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(didTapClanView)];
[_clanView addGestureRecognizer:tap];
_clanView.hidden = YES;
}
return _clanView;
}
-(UIButton *)clanIconView{
if (!_clanIconView){
_clanIconView = [UIButton new];
[_clanIconView setEnlargeEdgeWithTop:10 right:10 bottom:10 left:10];
[_clanIconView addTarget:self action:@selector(didTapClanView) forControlEvents:UIControlEventTouchUpInside];
[_clanIconView setBackgroundImage:kImage(@"mine_clan_arrow") forState:UIControlStateNormal];
_clanIconView.hidden = YES;
}
return _clanIconView;
}
@end