|
| 1 | +// |
| 2 | +// SendRewardManager.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 15/12/2. |
| 6 | +// Copyright © 2015年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "SendRewardManager.h" |
| 10 | +#import "Coding_NetAPIManager.h" |
| 11 | +#import "Login.h" |
| 12 | + |
| 13 | +@interface SendRewardManager () |
| 14 | +@property (strong, nonatomic) Tweet *curTweet; |
| 15 | +@property (copy, nonatomic) void(^completion)(Tweet *curTweet, BOOL sendSucess); |
| 16 | +@property (strong, nonatomic) NSArray *tipStrList; |
| 17 | + |
| 18 | + |
| 19 | +@property (strong, nonatomic) UIView *bgView, *contentView, *tipBgView; |
| 20 | +@property (strong, nonatomic) UIButton *closeBtn, *submitBtn; |
| 21 | +@property (strong, nonatomic) UILabel *titleL, *tipL, *bottomL; |
| 22 | +@property (strong, nonatomic) UITextField *passwordF; |
| 23 | +@end |
| 24 | + |
| 25 | +@implementation SendRewardManager |
| 26 | ++ (instancetype)shareManager{ |
| 27 | + static SendRewardManager *shared_manager = nil; |
| 28 | + static dispatch_once_t pred; |
| 29 | + dispatch_once(&pred, ^{ |
| 30 | + shared_manager = [[self alloc] init]; |
| 31 | + }); |
| 32 | + return shared_manager; |
| 33 | +} |
| 34 | + |
| 35 | ++ (instancetype)handleTweet:(Tweet *)curTweet completion:(void(^)(Tweet *curTweet, BOOL sendSucess))block{ |
| 36 | + SendRewardManager *manager = [self shareManager]; |
| 37 | + if (manager.curTweet) {//有正在处理的冒泡,此次调用无效 |
| 38 | + return nil; |
| 39 | + } |
| 40 | + manager.curTweet = curTweet; |
| 41 | + manager.completion = block; |
| 42 | + [[Coding_NetAPIManager sharedManager] request_Preparereward:curTweet.id.stringValue andBlock:^(id data, NSError *error) { |
| 43 | + manager.tipStrList = data; |
| 44 | + [manager p_show]; |
| 45 | + }]; |
| 46 | + return manager; |
| 47 | +} |
| 48 | + |
| 49 | +- (instancetype)init |
| 50 | +{ |
| 51 | + self = [super init]; |
| 52 | + if (self) { |
| 53 | + CGFloat buttonHeight = 44; |
| 54 | + |
| 55 | + //层级关系 |
| 56 | + _bgView = [UIView new]; |
| 57 | + _contentView = [UIView new]; |
| 58 | + _closeBtn = [UIButton new]; |
| 59 | + _titleL = [UILabel new]; |
| 60 | + _passwordF = [UITextField new]; |
| 61 | + _submitBtn = [UIButton buttonWithStyle:StrapSuccessStyle andTitle:@"确认打赏" andFrame:CGRectMake(0, 0, buttonHeight, buttonHeight) target:self action:@selector(submitBtnClicked)]; |
| 62 | + _bottomL = [UILabel new]; |
| 63 | + _tipBgView = [UIView new]; |
| 64 | + _tipL = [UILabel new]; |
| 65 | + [_contentView addSubview:_closeBtn]; |
| 66 | + [_contentView addSubview:_titleL]; |
| 67 | + [_contentView addSubview:_passwordF]; |
| 68 | + [_contentView addSubview:_submitBtn]; |
| 69 | + [_contentView addSubview:_bottomL]; |
| 70 | + [_contentView addSubview:_tipBgView]; |
| 71 | + [_contentView addSubview:_tipL]; |
| 72 | + |
| 73 | + [_bgView addSubview:_contentView]; |
| 74 | + |
| 75 | + //属性设置 |
| 76 | + _contentView.backgroundColor = [UIColor colorWithHexString:@"0xF8F8F8"]; |
| 77 | + _contentView.layer.masksToBounds = YES; |
| 78 | + _contentView.layer.cornerRadius = 6; |
| 79 | + [_closeBtn setImage:[UIImage imageNamed:@"button_close"] forState:UIControlStateNormal]; |
| 80 | + [_closeBtn addTarget:self action:@selector(p_dismiss) forControlEvents:UIControlEventTouchUpInside]; |
| 81 | + _titleL.font = [UIFont systemFontOfSize:18]; |
| 82 | + _titleL.textColor = [UIColor colorWithHexString:@"0x222222"]; |
| 83 | + _titleL.textAlignment = NSTextAlignmentCenter; |
| 84 | + _titleL.attributedText = [self p_titleStr]; |
| 85 | + _passwordF.font = [UIFont systemFontOfSize:15]; |
| 86 | + _passwordF.textColor = [UIColor colorWithHexString:@"0x222222"]; |
| 87 | + _passwordF.secureTextEntry = YES; |
| 88 | + _passwordF.textAlignment = NSTextAlignmentCenter; |
| 89 | + [_passwordF doBorderWidth:1.0 color:[UIColor colorWithHexString:@"0xCCCCCC"] cornerRadius:2.0]; |
| 90 | + _passwordF.placeholder = @" 请输入密码"; |
| 91 | + _bottomL.font = [UIFont systemFontOfSize:12]; |
| 92 | + _bottomL.textColor = [UIColor colorWithHexString:@"0x999999"]; |
| 93 | + _bottomL.textAlignment = NSTextAlignmentCenter; |
| 94 | + _bottomL.attributedText = [self p_bottomStr]; |
| 95 | + _tipBgView.backgroundColor = [UIColor colorWithHexString:@"0xF2DEDE"]; |
| 96 | + _tipBgView.layer.masksToBounds = YES; |
| 97 | + _tipBgView.layer.cornerRadius = 3; |
| 98 | + _tipL.font = [UIFont systemFontOfSize:15]; |
| 99 | + _tipL.textColor = [UIColor colorWithHexString:@"0xC55351"]; |
| 100 | + _tipL.textAlignment = NSTextAlignmentCenter; |
| 101 | + _tipL.numberOfLines = 0; |
| 102 | + |
| 103 | + //位置大小 |
| 104 | + [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
| 105 | + make.left.top.equalTo(_contentView); |
| 106 | + make.width.height.mas_equalTo(buttonHeight); |
| 107 | + }]; |
| 108 | + [_titleL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 109 | + make.left.right.equalTo(_contentView); |
| 110 | + make.top.equalTo(_contentView).offset(35); |
| 111 | + }]; |
| 112 | + [_passwordF mas_makeConstraints:^(MASConstraintMaker *make) { |
| 113 | + make.top.equalTo(_titleL.mas_bottom).offset(20); |
| 114 | + make.left.equalTo(_contentView).offset(25); |
| 115 | + make.right.equalTo(_contentView).offset(-25); |
| 116 | + make.height.mas_equalTo(35); |
| 117 | + }]; |
| 118 | + [_submitBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
| 119 | + make.top.equalTo(_passwordF.mas_bottom).offset(25); |
| 120 | + make.left.equalTo(_contentView).offset(50); |
| 121 | + make.right.equalTo(_contentView).offset(-50); |
| 122 | + make.height.mas_equalTo(buttonHeight); |
| 123 | + }]; |
| 124 | + [_tipBgView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 125 | + make.top.equalTo(_titleL.mas_bottom).offset(20); |
| 126 | + make.left.equalTo(_contentView).offset(25); |
| 127 | + make.right.equalTo(_contentView).offset(-25); |
| 128 | + make.height.mas_equalTo(60); |
| 129 | + }]; |
| 130 | + [_tipL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 131 | + make.edges.equalTo(_tipBgView).insets(UIEdgeInsetsMake(10, 15, 10, 15)); |
| 132 | + }]; |
| 133 | +// [_bgView bk_whenTapped:^{ |
| 134 | +// [self p_dismiss]; |
| 135 | +// }]; |
| 136 | + |
| 137 | + |
| 138 | + [_bottomL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 139 | + make.left.right.equalTo(_contentView); |
| 140 | + make.bottom.equalTo(_contentView).offset(-15); |
| 141 | + make.height.mas_equalTo(15); |
| 142 | + }]; |
| 143 | + |
| 144 | + |
| 145 | + //初始状态 |
| 146 | + _bgView.backgroundColor = [UIColor clearColor]; |
| 147 | + _contentView.alpha = 0; |
| 148 | + } |
| 149 | + return self; |
| 150 | +} |
| 151 | + |
| 152 | +- (NSAttributedString *)p_titleStr{ |
| 153 | + NSString *tempStr = @"打赏给该用户 0.01 码币"; |
| 154 | + NSMutableAttributedString *titleStr = [[NSMutableAttributedString alloc] initWithString:tempStr]; |
| 155 | + [titleStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"0xF5A623"] range:[tempStr rangeOfString:@"0.01"]]; |
| 156 | + return titleStr; |
| 157 | +} |
| 158 | + |
| 159 | + |
| 160 | +- (NSAttributedString *)p_bottomStr{ |
| 161 | + NSString *tempStr = [NSString stringWithFormat:@"我的码币余额:%@ ", [Login curLoginUser].points_left.stringValue]; |
| 162 | + NSMutableAttributedString *bottomStr = [[NSMutableAttributedString alloc] initWithString:tempStr]; |
| 163 | + [bottomStr addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithHexString:@"0xF5A623"] range:[tempStr rangeOfString:[Login curLoginUser].points_left.stringValue]]; |
| 164 | + return bottomStr; |
| 165 | +} |
| 166 | + |
| 167 | +- (void)setTipStrList:(NSArray *)tipStrList{ |
| 168 | + _tipStrList = tipStrList; |
| 169 | + _tipL.text = tipStrList.firstObject; |
| 170 | + |
| 171 | + BOOL hasTip = _tipStrList.count > 0; |
| 172 | + CGFloat contentHeight = hasTip? 185: 229; |
| 173 | + CGFloat centerYOffset = hasTip? 0: -60; |
| 174 | + _passwordF.hidden = hasTip; |
| 175 | + _submitBtn.hidden = hasTip; |
| 176 | + _tipBgView.hidden = !hasTip; |
| 177 | + _tipL.hidden = !hasTip; |
| 178 | + |
| 179 | + [_contentView mas_remakeConstraints:^(MASConstraintMaker *make) { |
| 180 | + make.left.equalTo(_bgView).offset(kPaddingLeftWidth); |
| 181 | + make.height.mas_equalTo(contentHeight); |
| 182 | + make.centerX.equalTo(_bgView); |
| 183 | + make.centerY.equalTo(_bgView).offset(centerYOffset); |
| 184 | + }]; |
| 185 | +} |
| 186 | + |
| 187 | +- (void)submitBtnClicked{ |
| 188 | +#warning submitBtnClicked reward |
| 189 | + [NSObject showHudTipStr:@"稍等~"]; |
| 190 | +} |
| 191 | + |
| 192 | +- (void)p_show{ |
| 193 | + _bgView.frame = kScreen_Bounds; |
| 194 | + [kKeyWindow addSubview:_bgView]; |
| 195 | + [UIView animateWithDuration:0.3 animations:^{ |
| 196 | + _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; |
| 197 | + _contentView.alpha = 1; |
| 198 | + } completion:^(BOOL finished) { |
| 199 | + if (!_passwordF.hidden) { |
| 200 | + [_passwordF becomeFirstResponder]; |
| 201 | + } |
| 202 | + }]; |
| 203 | +} |
| 204 | + |
| 205 | +- (void)p_dismiss{ |
| 206 | + _curTweet = nil; |
| 207 | + _completion = nil; |
| 208 | + |
| 209 | + [UIView animateWithDuration:0.3 animations:^{ |
| 210 | + _bgView.backgroundColor = [UIColor clearColor]; |
| 211 | + _contentView.alpha = 0; |
| 212 | + } completion:^(BOOL finished) { |
| 213 | + [_bgView removeFromSuperview]; |
| 214 | + }]; |
| 215 | +} |
| 216 | + |
| 217 | +@end |
0 commit comments