123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404 |
- //
- // KBSignInViewController.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/9/27.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "KBSignInViewController.h"
- #import "KBSignInView.h"
- #import "KBSignInModel.h"
- #import "KBSignTypeModel.h"
- #import "KBSignPopView.h"
- #import "KBSignSuccView.h"
- #import "CCAlertShowView.h"
- #import "KBSignInClickView.h"
- #import "KBRollingCollectionViewCell.h"
- #import "KBPopRouleView.h"
- #import <AlibcTradeSDK/AlibcTradeSDK.h>
- #import <AlibabaAuthSDK/ALBBSession.h>
- #import <AlibabaAuthSDK/ALBBSDK.h>
- @interface KBSignInViewController ()<KBSignInClickViewDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
- {
- UIButton *signBtn;
- UILabel *tipLb;
- CGFloat collectionViewWidth;
- }
- @property (nonatomic ,strong) UICollectionView *userCollectionView;
- @property (nonatomic ,strong) NSMutableArray *userArray;
- @property (nonatomic ,strong) NSMutableArray *collectionCellWithArry;
- @property (nonatomic ,strong) NSTimer *usertimer;
- @property (nonatomic, strong) KBSignInView *signView;
- @property (nonatomic, strong) KBSignInModel *signInModel;
- //@property (nonatomic, strong) KBSignTypeModel *signTypeModel;
- @property (nonatomic, strong) KBSignInClickView *signTableView;
- @property (nonatomic, strong) UIImageView *contentImgView;
- @property (nonatomic, strong) UIImageView *topImgView;
- @property (nonatomic, strong) UIImageView *middleImgView;
- @end
- @implementation KBSignInViewController
- - (void)dealloc {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
- [self getSignAction];
- [self signUserRollingAction];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.userArray = [NSMutableArray arrayWithCapacity:0];
- self.collectionCellWithArry = [NSMutableArray arrayWithCapacity:0];
- [self configNavigationBar];
- [self initSubViews];
- [self addObserverForApp];
- }
- - (void)addObserverForApp {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(getSignAction)
- name:UIApplicationDidBecomeActiveNotification object:nil];
- }
- - (void)initSubViews {
- UIImageView *bgImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, NavBarHeight, SCREEN_WIDTH, SCREEN_HEIGHT-NavBarHeight)];
- bgImgView.image = [UIImage imageNamed:@"signIn_bg"];
- [self.view addSubview:bgImgView];
-
- self.contentImgView = [[UIImageView alloc] init];
- self.contentImgView.image = [UIImage imageNamed:@"signInContent_bg"];
- [self.view addSubview:self.contentImgView];
- [self.contentImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(NavBarHeight+87);
- make.width.mas_equalTo(FITSIZE(323));
- make.height.mas_equalTo(FITSIZE(472));
- make.centerX.mas_equalTo(self.view);
- }];
-
- self.topImgView = [[UIImageView alloc] init];
- [self.view addSubview: self.topImgView];
- [self.topImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(NavBarHeight+52);
- make.width.mas_equalTo(FITSIZE(266));
- make.height.mas_equalTo(FITSIZE(72));
- make.centerX.mas_equalTo(self.view);
- }];
-
- self.middleImgView = [[UIImageView alloc] init];
- [self.view addSubview: self.middleImgView];
- [self.middleImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.topImgView.mas_bottom).offset(24);
- make.width.mas_equalTo(FITSIZE(314));
- make.height.mas_equalTo(FITSIZE(38));
- make.centerX.mas_equalTo(self.view);
- }];
-
- self.signView = [[KBSignInView alloc] init];
- self.signView.backgroundColor = [UIColor clearColor];
- [self.view addSubview:self.signView];
-
- [self.signView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.middleImgView.mas_bottom).offset(23);
- make.width.mas_equalTo(self.contentImgView);
- make.height.mas_equalTo(20);
- make.centerX.mas_equalTo(self.view);
- }];
-
- [self.view addSubview:self.signTableView];
-
- [self.signTableView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.signView.mas_bottom).offset(10);
- make.width.mas_equalTo(self.contentImgView);
- make.height.mas_equalTo(FITSIZE(72*4));
- make.left.mas_equalTo(self.contentImgView.mas_left);
- }];
-
- [self.view addSubview:self.userCollectionView];
-
- UIButton *ruleBtn=[UIButton buttonWithType:UIButtonTypeCustom];
- [ruleBtn setTitle:@"红包规则" forState:UIControlStateNormal];
- [ruleBtn setTitleColor:[UIColor YHColorWithHex:0x8B7117] forState:UIControlStateNormal];
- ruleBtn.backgroundColor=[UIColor clearColor];
- ruleBtn.titleLabel.font=[UIFont systemFontOfSize:12];
- [self.view addSubview:ruleBtn];
- [ruleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.mas_equalTo(self.contentImgView.mas_bottom).offset(23);
- make.centerX.mas_equalTo(self.view);
- make.width.mas_equalTo(SCREEN_WIDTH-FITSIZE(320));
- make.height.mas_equalTo(FITSIZE(22));
- }];
- [[ruleBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
- KBPopRouleView *popView = [[KBPopRouleView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(283), Fitsize(290)) text:self.signInModel.red_roule];
- CCAlertShowView *showView = [CCAlertShowView alertViewWithView:popView];
- [showView show];
- }];
- }
- - (void)getSignAction {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/getUserActiveNew",BaseURL];
- [KBHttp get:url params:nil success:^(id json) {
- self.signInModel = [KBSignInModel yy_modelWithJSON:json[@"data"]];
- if (self.signInModel.sign == 1) {
- [self refreshUI];
- }else {
- [self refreshUI];
- KBSignPopView *popView = [[KBSignPopView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(283), Fitsize(382)) text:self.signInModel.red_message];
- popView.clickBtn.hidden = NO;
-
- CCAlertShowView *showView = [CCAlertShowView showAlertViewWithView:popView backgroundDismissEnable:NO];
- [showView show];
- [[popView.clickBtn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
- [self signAction];
- [showView dismiss];
- }];
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)signAction {
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/complateActive",BaseURL];
- [KBHttp get:url params:nil success:^(id json) {
- [self getSignAction];
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)refreshUI {
- [self.topImgView sd_setImageWithURL:[NSURL URLWithString:self.signInModel.sign_img] placeholderImage:nil];
- [self.middleImgView sd_setImageWithURL:[NSURL URLWithString:self.signInModel.describe_img] placeholderImage:nil];
- [self.signView setSignModelArr:self.signInModel.days];
- [self.signTableView refreshTableViewWithArry:self.signInModel.detail];
- }
- - (void)configNavigationBar {
- [self.navigationBar setNavTitle:@"签到领红包"];
- self.navigationBar.navTitleLabel.textColor = [UIColor blackColor];
- self.navigationBar.backgroundColor = [UIColor whiteColor];
- UIButton *leftBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 40)];
- [leftBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
- [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
- [self.navigationBar setCustomLeftButtons:@[leftBtn]];
- }
- //- (void)showSuccessView {
- // KBSignSuccView *succView = [[KBSignSuccView alloc] initWithFrame:CGRectMake(0, 0, Fitsize(283), Fitsize(290)) text:self.signTypeModel.red_message];
- // CCAlertShowView *showView = [CCAlertShowView alertViewWithView:succView];
- // succView.sureClick = ^{
- // [showView dismiss];
- // };
- // [showView show];
- //
- //}
- - (void)clickViewIndexPath:(NSIndexPath *)index {
-
- [self changeBtnTypeWhenClick:index];
- KBSignDetailModel *model = [KBSignDetailModel yy_modelWithJSON:self.signInModel.detail[index.row]];
- NSString *tbUrl = model.ot_url;
-
- if (tbUrl.length > 0) {
- [self jumpToTaobaoWithUrl:tbUrl parentVc:self];
- UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
- pasteBoard.string = model.red_url==nil?@"":model.red_url;
- return;
- }
-
- NSURL *url = [NSURL URLWithString:@"taobao://"];
- if ([[UIApplication sharedApplication] canOpenURL:url]) {
- KBSignDetailModel *model = [KBSignDetailModel yy_modelWithJSON:self.signInModel.detail[index.row]];
- UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
- pasteBoard.string = model.red_url==nil?@"":model.red_url;
- [[UIApplication sharedApplication] openURL:url];
- }else{
- [MBProgressHUD showMessage:self.signInModel.uninstall_taobao];
- }
- }
- - (void)changeBtnTypeWhenClick:(NSIndexPath *)index {
- KBSignDetailModel *model = [KBSignDetailModel yy_modelWithJSON:self.signInModel.detail[index.row]];
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/ButtonChange",BaseURL];
- NSString *nowDay = self.signInModel.now_days==nil?@"":self.signInModel.now_days;
- NSString *Id = model.btn==nil?@"":model.btn;
- NSDictionary *para = @{@"days":nowDay,
- @"red":Id
- };
- [KBHttp get:url params:para success:^(id json) {
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (KBSignInClickView *)signTableView {
- if (!_signTableView) {
- _signTableView = [[KBSignInClickView alloc] init];
- _signTableView.clickViewDelegate = self;
- }
- return _signTableView;
- }
- #pragma mark UICollectionView滚动
- - (void)signUserRollingAction {
-
- NSString *url = [NSString stringWithFormat:@"%@/api/v2/users/getRollscreen",BaseURL];
- [KBHttp get:url params:nil success:^(id json) {
- [self.userArray removeAllObjects];
- [self.collectionCellWithArry removeAllObjects];
- NSArray *jsonArry = [NSArray arrayWithArray:json[@"data"]];
- for (NSDictionary *userDic in jsonArry) {
- [self.userArray addObject:[KBSignInRollingUser yy_modelWithJSON:userDic]];
- }
- for (KBSignInRollingUser *userModel in self.userArray) {
- CGFloat cellWidth = 20+[self getWidhWithString:userModel.res withFontSize:12]+10;
- [self.collectionCellWithArry addObject:[NSNumber numberWithFloat:cellWidth]];
- collectionViewWidth+=cellWidth;
- }
- [self makeTime];
-
- [self.userCollectionView reloadData];
-
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)makeTime {
- if (collectionViewWidth>SCREEN_WIDTH) {
- if(!self.usertimer){
- self.usertimer=[NSTimer timerWithTimeInterval:0.05 target:self selector:@selector(clicknetxt) userInfo:nil repeats:YES];
- [[NSRunLoop mainRunLoop] addTimer:self.usertimer forMode:NSRunLoopCommonModes];
- }
- }
- }
- -(void)clicknetxt
- {
- self.userCollectionView.contentOffset=CGPointMake(self.userCollectionView.contentOffset.x+1, self.userCollectionView.contentOffset.y);
-
- }
- - (UICollectionView *)userCollectionView {
- if (!_userCollectionView) {
- UICollectionViewFlowLayout *layout1=[[UICollectionViewFlowLayout alloc]init];
- layout1.scrollDirection=UICollectionViewScrollDirectionHorizontal;
- _userCollectionView =[[UICollectionView alloc]initWithFrame:CGRectMake(0,NavBarHeight, SCREEN_WIDTH,27+9*2) collectionViewLayout:layout1];
- _userCollectionView.indicatorStyle=UIScrollViewIndicatorStyleWhite;
- [_userCollectionView registerClass:[KBRollingCollectionViewCell class] forCellWithReuseIdentifier:@"KBRollingCollectionViewCell"];
- _userCollectionView.delegate=self;
- _userCollectionView.dataSource=self;
- _userCollectionView.backgroundColor = [UIColor clearColor];
- _userCollectionView.showsHorizontalScrollIndicator=NO;
- }
- return _userCollectionView;
- }
- #pragma mark collection代理
- -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
- {
- return self.userArray.count;
-
- }
- -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- KBRollingCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"KBRollingCollectionViewCell" forIndexPath:indexPath];
- KBSignInRollingUser *model=self.userArray[indexPath.item];
- cell.model=model;
- return cell;
- }
- - (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
- {
- return UIEdgeInsetsMake(0, 10, 0, 0);
-
- }
- -(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
- {
- CGFloat cellWidth = [self.collectionCellWithArry[indexPath.row] floatValue];
- return CGSizeMake(cellWidth, self.userCollectionView.frame.size.height);
- }
- - (CGFloat)getWidhWithString:(NSString *)string withFontSize:(CGFloat)fontSize {
- NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]};
- CGSize textSize = [string boundingRectWithSize:CGSizeMake(MAXFLOAT, 20) options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;
- return textSize.width;
-
- }
- - (void)scrollViewDidScroll:(UIScrollView *)scrollView
- {
-
- if([scrollView isEqual:self.userCollectionView]) {
- if(scrollView.contentSize.width>SCREEN_WIDTH){
- if(scrollView.contentOffset.x>=scrollView.contentSize.width){
-
- [scrollView setContentOffset:CGPointMake(-SCREEN_WIDTH, 0)];
- }
- }
- }
- }
- - (void)backAction {
-
- [self.navigationController popViewControllerAnimated:YES];
- }
- -(void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- if (self.usertimer) {
- [self.usertimer invalidate];
- self.usertimer=nil;
- }
- }
- - (void)jumpToTaobaoWithUrl:(NSString *)url parentVc:(UIViewController *)parentVc{
-
- id<AlibcTradePage> page = [AlibcTradePageFactory page:url];
- //淘客信息
- AlibcTradeTaokeParams *taoKeParams=[[AlibcTradeTaokeParams alloc] init];
- taoKeParams.pid= ALTK_PID;
- //打开方式
- AlibcTradeShowParams* showParam = [[AlibcTradeShowParams alloc] init];
-
- showParam.openType = AlibcOpenTypeNative;
-
-
- [[AlibcTradeSDK sharedInstance].tradeService show:parentVc page:page showParams:showParam taoKeParams:taoKeParams trackParam:nil tradeProcessSuccessCallback:^(AlibcTradeResult * _Nullable result) {
-
- } tradeProcessFailedCallback:^(NSError * _Nullable error) {
-
- }];
- }
- /*
- #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
|