// // settingListCell.m // ThePaperHD // // Created by liyuan on 15/4/10. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "settingListCell.h" #import "Util.h" #include #include @interface settingListCell () @property(nonatomic, strong)UIView *selectView; @property(nonatomic, strong)UILabel *titleLabel; @property(nonatomic, strong)UILabel *closeLabel; @property(nonatomic, strong)UILabel *pushCloseLabel; @property(nonatomic, strong)UISwitch *propellingSwitch; @property(nonatomic, strong)UIImageView *nextBtn; @property(nonatomic, strong)UILabel *fragmentLabel; @property(nonatomic, strong)UIView *line; @end @implementation settingListCell @synthesize indexPath; @synthesize isShowClearStatus = _isShowClearStatus; @synthesize isPushOpen = _isPushOpen; - (void)awakeFromNib { // Initialization code } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; // Configure the view for the selected state } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{ self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectedBackgroundView = self.selectView; [self.contentView addSubview:self.titleLabel]; [self.contentView addSubview:self.propellingSwitch]; [self.contentView addSubview:self.nextBtn]; [self.contentView addSubview:self.fragmentLabel]; [self.contentView addSubview:self.line]; } return self; } #pragma mark -- set VIEW - (UIView *)selectView { if (!_selectView) { _selectView = [[UIView alloc]initWithFrame:CGRectZero]; _selectView.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _selectView; } -(UILabel *)titleLabel{ if (!_titleLabel) { _titleLabel = [[UILabel alloc] init]; _titleLabel.font = appFont(TEXT_TWO_LEVELSIZE, NO); _titleLabel.backgroundColor = [UIColor clearColor]; _titleLabel.textColor = [UIColor colorWithHexString:TextBlack]; _titleLabel.textAlignment = NSTextAlignmentCenter; } return _titleLabel; } -(UILabel *)closeLabel{ if (!_closeLabel) { _closeLabel = [UILabel new]; _closeLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _closeLabel.text = @"已关闭"; _closeLabel.font = appFont(14, NO); _closeLabel.hidden = YES;//设置页:打开和关闭推送页面展示有问题(bug:6043) _closeLabel.backgroundColor = [UIColor clearColor]; } return _closeLabel; } -(UILabel *)pushCloseLabel{ if (!_pushCloseLabel) { _pushCloseLabel = [UILabel new]; _pushCloseLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _pushCloseLabel.text = @"您没有在系统中打开澎湃新闻客户端消息推送,请在系统“设置”-“通知中心”中,找到应用程序“澎湃新闻”打开新消息通知"; _pushCloseLabel.font = appFont(TEXT_FOUR_LEVELSIZE, NO); _pushCloseLabel.numberOfLines = 0; _pushCloseLabel.hidden = YES;//设置页:打开和关闭推送页面展示有问题(bug:6043) _pushCloseLabel.backgroundColor = [UIColor clearColor]; } return _pushCloseLabel; } -(UISwitch *)propellingSwitch{ if (!_propellingSwitch) { _propellingSwitch = [[UISwitch alloc]init]; [_propellingSwitch addTarget:self action:@selector(switchSelector:) forControlEvents:UIControlEventValueChanged]; if ([[TPUserDefault instance].isOpenPush intValue] == 1) { _propellingSwitch.on = YES; }else { _propellingSwitch.on = NO; } } return _propellingSwitch; } -(UIImageView *)nextBtn{ if (!_nextBtn) { _nextBtn = [[UIImageView alloc] init]; _nextBtn.userInteractionEnabled = NO; } return _nextBtn; } -(UILabel *)fragmentLabel{ if (!_fragmentLabel) { _fragmentLabel = [[UILabel alloc] init]; _fragmentLabel.font = appFont(12, NO); _fragmentLabel.textColor = [UIColor colorWithHexString:TextLightGray]; _fragmentLabel.hidden = YES; _fragmentLabel.backgroundColor = [UIColor clearColor]; } return _fragmentLabel; } -(UIView *)line{ if (!_line) { _line = [[UIView alloc] init]; _line.backgroundColor = [UIColor colorWithHexString:LINECOLOR]; } return _line; } #pragma mark -- set Data -(void)setIndexPath:(NSIndexPath *)_indexPath{ indexPath = _indexPath; // self.contentView.backgroundColor = [UIColor colorWithHexString:BackGroundColor]; switch (indexPath.section) { case 0: switch (indexPath.row) { case 0: self.titleLabel.text = @"推送设置"; self.nextBtn.hidden = YES; self.propellingSwitch.hidden = NO; self.fragmentLabel.hidden = YES; //设置页:打开和关闭推送页面展示有问题(bug:6043) self.pushCloseLabel.hidden = NO; self.closeLabel.hidden = NO; self.selectionStyle = UITableViewCellSelectionStyleNone; break; default: break; } break; case 1: switch (indexPath.row) { case 0: self.titleLabel.text = @"给我评分"; self.propellingSwitch.hidden = YES; self.nextBtn.hidden = NO; self.fragmentLabel.hidden = YES; self.pushCloseLabel.hidden = YES; self.closeLabel.hidden = YES; self.nextBtn.image = Image(@"setting/message_notificationcell_arrow.png");//【需求】视觉优化(bug:4569 7) self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectedBackgroundView = self.selectView; break; case 1: self.titleLabel.text = @"用户反馈"; self.propellingSwitch.hidden = YES; self.nextBtn.hidden = NO; self.fragmentLabel.hidden = YES; self.pushCloseLabel.hidden = YES; self.closeLabel.hidden = YES; // nextBtn.image = Image(@"setting/setting_listCell_arrow.png"); self.nextBtn.image = Image(@"setting/message_notificationcell_arrow.png");//【需求】视觉优化(bug:4569 7) self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectedBackgroundView = self.selectView; break; case 2: self.titleLabel.text = @"关于澎湃"; self.propellingSwitch.hidden = YES; self.nextBtn.hidden = NO; self.fragmentLabel.hidden = YES; self.pushCloseLabel.hidden = YES; self.closeLabel.hidden = YES; self.nextBtn.image = Image(@"setting/message_notificationcell_arrow.png");//【需求】视觉优化(bug:4569) self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectedBackgroundView = self.selectView; break; case 3: self.titleLabel.text = @"清理缓存"; self.propellingSwitch.hidden = YES; self.nextBtn.hidden = NO; self.fragmentLabel.hidden = NO; self.pushCloseLabel.hidden = YES; self.closeLabel.hidden = YES; self.nextBtn.image = Image(@"setting/setting_listCell_clear.png"); self.selectionStyle = UITableViewCellSelectionStyleGray; self.selectedBackgroundView = self.selectView; break; default: break; } break; default: break; } } -(void)setIsPushOpen:(BOOL)isOpen{ _isPushOpen = isOpen; if (!_isPushOpen) { [self.contentView addSubview:self.closeLabel]; [self.contentView addSubview:self.pushCloseLabel]; [self.propellingSwitch removeFromSuperview]; } } - (void)setIsShowClearStatus:(BOOL)isShow { _isShowClearStatus = isShow; if (self.indexPath.section == 1 && self.indexPath.row == 3) { if (!isShow) { NSString *cachePath = CachePath(@""); float folderSize = [self folderSizeAtPath:cachePath]; self.fragmentLabel.text = [NSString stringWithFormat:@"碎片文件:%.2fM",folderSize]; }else { self.fragmentLabel.text = @"正在清理"; } } } #pragma mark -- set HANDLER -(void) switchSelector:(UISwitch *) proSwitch{ AppDelegate *delegate=(AppDelegate*)[[UIApplication sharedApplication]delegate]; if (proSwitch.isOn) { [delegate registUmentRemotePush]; ShowTextMessage(@"开启推送"); }else{ [delegate unRegistUmentRemotePush]; ShowTextMessage(@"关闭推送"); [MobClick event:@"17"]; } } -(void) nightModeSelector:(UISwitch*) nightSwitch{//夜间模式 if ([self.settingListCellDelegate respondsToSelector:@selector(gotoNightMode:)]) { [self.settingListCellDelegate gotoNightMode:nightSwitch.isOn]; } } //缓存文件的大小 - (float) folderSizeAtPath:(NSString*) folderPath { long long folderSize = [Util folderSizeAtPath3:folderPath]; float folderMBSize = folderSize/(1024.0*1024.0); return folderMBSize; } -(void)layoutSubviews{ [super layoutSubviews]; if ([self.titleLabel.text isEqualToString:@"清理缓存"]) { self.nextBtn.frame = CGRectMake(self.contentView.frame.size.width-40, 10, 30, 30); self.titleLabel.frame = CGRectMake(20, 13, widthForString(self.titleLabel.text, self.titleLabel.font, 19, NSLineBreakByWordWrapping), 19); }else{ self.nextBtn.frame = CGRectMake(self.contentView.frame.size.width-24, CGRectGetHeight(self.contentView.bounds)/2 - 9/2, 9, 16); self.titleLabel.frame = CGRectMake(20, 21, widthForString(self.titleLabel.text, self.titleLabel.font, 19, NSLineBreakByWordWrapping), 19); } self.fragmentLabel.frame = CGRectMake(20, 35, 300, 12); self.line.frame = CGRectMake(10, 54, self.contentView.frame.size.width-20, 1); //【需求】iOS推送设置优化iPad(bug:5937) if(0 == self.indexPath.section ){ if (isNotIOS7) { self.propellingSwitch.frame = CGRectMake(self.contentView.frame.size.width-80, 10, 50, 29); self.closeLabel.frame = CGRectMake(self.contentView.frame.size.width-80, 23, 50, 19); }else{ self.propellingSwitch.frame = CGRectMake(self.contentView.frame.size.width-60, 10, 50, 29); self.closeLabel.frame = CGRectMake(self.contentView.frame.size.width-60, 23, 50, 19); } self.pushCloseLabel.frame = CGRectMake(20, 65, CGRectGetWidth(self.contentView.bounds)-40, 55); } } @end