|
//
// bindThirdAccountController.m
// ThePaperHD
//
// Created by scar1900 on 15/3/27.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "bindThirdAccountController.h"
#import "MLNavigationController.h"
#import "KGModal.h"
#import "TPCustomButton.h"
#define thirdButtonTag 1200
#define thirdButtonLabelTag 4200
@interface bindThirdAccountController ()
@property(nonatomic, strong)UIButton *closeBtn;
@property(nonatomic, strong)UILabel *titleLabel;
@property(nonatomic, strong)UITextField *phoneTextField;
@property(nonatomic, strong)UITextField *inviteCodeField;
@property(nonatomic, strong)UIButton *getInviteCodeBtn;
@property(nonatomic, strong)TPCustomButton *confirmBtn;
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)NSMutableArray *thirdSocietyBtnList;
@end
@implementation bindThirdAccountController
@synthesize thirdSocietyBtnList;
@synthesize socialMap = _socialMap;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, 0, loginPopUpSize.width, loginPopUpSize.height);
[self.view addSubview:self.closeBtn];
[self.view addSubview:self.titleLabel];
self.closeBtn.frame = CGRectMake(0, 0, 50, 80);
[self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)];
self.titleLabel.frame = CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
80);
[self.view addSubview:self.backView];
[self initThirdSocietyBtnList];
[self addShareBtnInContent];
}
- (void)initThirdSocietyBtnList {
CGFloat padding = (loginPopUpSize.width-40*4)/5;
self.thirdSocietyBtnList = [NSMutableArray arrayWithCapacity:10];
for (int i=0;i<7;i++) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.tag = thirdButtonTag + i;
if (i<4) {
button.frame = CGRectMake(padding+i*(40+padding), 114/2, 40, 40);
}else if (i<7) {
button.frame = CGRectMake(padding+(i-4)*(40+padding), 290/2, 40, 40);
}
[self setShareBtn:button tagNum:i];
[self setButtonHiligthAndNormalColor:button];
button.layer.cornerRadius = 2.0f;
button.clipsToBounds = YES;
[self.thirdSocietyBtnList addObject:button];
}
}
- (void)addShareBtnInContent {
if (self.thirdSocietyBtnList.count > 0) {
[self.thirdSocietyBtnList enumerateObjectsUsingBlock:^(UIButton* btn, NSUInteger idx, BOOL *stop) {
[self.backView addSubview:btn];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(btn.center.x-117/4, CGRectGetMaxY(btn.frame)+13/2, 117/2, 16)];
label.font = appFont(11, NO);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithHexString:TextBlack];
label.textAlignment = NSTextAlignmentCenter;
if (btn.selected) {
label.text = @"解除绑定";
}else {
label.text = @"点击绑定";
}
if (!btn.enabled) {
label.text = @"无法绑定";
}
label.tag = thirdButtonLabelTag+idx;
[self.backView addSubview:label];
}];
}
}
- (void)setSocialMap:(NSDictionary *)map {
_socialMap = map;
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
[KGModal sharedInstance].tapOutsideToDismiss = NO;
}
- (UIButton*)closeBtn {
if (!_closeBtn) {
_closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_closeBtn setImage:Image(@"login/popUpBack.png") forState:UIControlStateNormal];
[_closeBtn setImage:Image(@"login/popUpBack_h.png") forState:UIControlStateHighlighted];
[_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside];
}
return _closeBtn;
}
- (UILabel*)titleLabel {
if (!_titleLabel) {
_titleLabel = [[UILabel alloc]initWithFrame:CGRectZero];
_titleLabel.backgroundColor = [UIColor clearColor];
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.text = @"社交账号绑定";
_titleLabel.textColor = [UIColor whiteColor];
_titleLabel.font = appFont(30, NO);
}
return _titleLabel;
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), loginPopUpSize.width, loginPopUpSize.height-80)];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
#pragma mark - btn event
- (void)closeEvent:(UIButton*)btn {
[(MLNavigationController*)self.navigationController popViewControllerWithFlip];
}
#pragma mark - bindbutton
- (void)setShareBtn:(UIButton*)button tagNum:(int)num{
UIImageView *btnImageView = [[UIImageView alloc]init];
switch (num) {
case 0:
btnImageView.image = Image(@"login/weChatBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b14d"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(weChatBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"WEIXIN"]) {
button.selected = YES;
}else {
button.selected = NO;
if (![shareUtil isHaveWeChatClient]) {
button.enabled = NO;
}else {
button.enabled = YES;
}
}
break;
case 1:
btnImageView.image = Image(@"login/QQBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x5da3e9"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(qqBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"TENCENT"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
case 2:
btnImageView.image = Image(@"login/sinaBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xcf803d"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(sinaBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"SINA"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
case 3:
// btnImageView.image = Image(@"login/renrenBind.png");
btnImageView.image = Image(@"login/doubanBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x77b24d"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(doubanBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"DOUBAN"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
case 4:
btnImageView.image = Image(@"login/evernoteBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x75b249"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(evernoteBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"YINXIANG"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
case 5:
btnImageView.image = Image(@"login/youdaoBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x83b6d3"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(youdaoBind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"YOUDAO"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
case 6:
btnImageView.image = Image(@"login/pocketBind.png");
[button setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0xca4055"])
forState:UIControlStateSelected];
[button addTarget:self action:@selector(pocketbind:) forControlEvents:UIControlEventTouchUpInside];
if (self.socialMap[@"POCKET"]) {
button.selected = YES;
}else {
button.selected = NO;
}
break;
default:
break;
}
CGSize size = btnImageView.image.size;
btnImageView.frame = CGRectMake(CGRectGetWidth(button.frame)/2-size.width/2,
CGRectGetHeight(button.frame)/2-size.height/2, size.width, size.height);
[button addSubview:btnImageView];
}
- (void)setButtonHiligthAndNormalColor:(UIButton*)btn {
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK])
forState:UIControlStateHighlighted];
[btn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONDISABLEBACK])
forState:UIControlStateNormal];
}
- (void)bindSocietyWithType:(shareAndLoginType)type withButton:(UIButton*)btn{
UILabel *label = (UILabel*)[self.view viewWithTag:btn.tag-thirdButtonTag+thirdButtonLabelTag];
[shareUtil bindSocietyAccountWithType:type completion:^(BOOL isSuccess) {
if (isSuccess) {
btn.selected = YES;
label.text = @"解除绑定";
ShowMessage(@"绑定成功", YES);
}else {
ShowMessage(@"绑定失败", NO);
}
}];
}
- (void)bindOutSocietyWithType:(shareAndLoginType)type withButton:(UIButton*)btn {
if ([self checkIfIsLoginType:type]) {
return;
}
UILabel *label = (UILabel*)[self.view viewWithTag:btn.tag-thirdButtonTag+thirdButtonLabelTag];
[shareUtil bindOutWithType:type completion:^(BOOL isSuccess) {
if (isSuccess) {
btn.selected = NO;
label.text = @"点击绑定";
if (![shareUtil isHaveWeChatClient] && type == weChatLoginType) {
btn.enabled = NO;
}else {
btn.enabled = YES;
}
ShowMessage(@"解绑成功", YES);
}
}];
}
- (void)weChatBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:weChatLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:weChatLoginType withButton:btn];
}
}
- (void)qqBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:QQLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:QQLoginType withButton:btn];
}
}
- (void)sinaBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:sinaWeiBoLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:sinaWeiBoLoginType withButton:btn];
}
}
- (void)renrenBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:renrenLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:renrenLoginType withButton:btn];
}
}
- (void)doubanBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:doubanLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:doubanLoginType withButton:btn];
}
}
- (void)evernoteBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:evernoteLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:evernoteLoginType withButton:btn];
}
}
- (void)youdaoBind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:youdaoLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:youdaoLoginType withButton:btn];
}
}
- (void)pocketbind:(UIButton*)btn {
if (!btn.selected) {
[self bindSocietyWithType:pocketLoginType withButton:btn];
}else {
[self bindOutSocietyWithType:pocketLoginType withButton:btn];
}
}
- (BOOL)checkIfIsLoginType:(shareAndLoginType)type {
userBO *user = [TPUserDefault instance].userBO;
if ([user.loginType intValue] == type) {
ShowTextMessage(@"登录账号无法解除绑定");
return YES;
}else {
return NO;
}
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
|