|
@@ -0,0 +1,279 @@
|
|
|
+//
|
|
|
+// ASGiftCardListViewController.m
|
|
|
+// Asteria
|
|
|
+//
|
|
|
+// Created by iOS on 2023/11/2.
|
|
|
+//
|
|
|
+
|
|
|
+#import "ASGiftCardListViewController.h"
|
|
|
+#import "ASGiftCardTableView.h"
|
|
|
+
|
|
|
+@interface ASGiftCardListViewController ()<UIScrollViewDelegate>
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIView *topBgV;
|
|
|
+@property (nonatomic, strong) UIView *bottomBgV;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIButton *availabelBt;
|
|
|
+@property (nonatomic, strong) UIButton *usedBt;
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIScrollView *scrollV;
|
|
|
+
|
|
|
+@property (nonatomic, strong) ASGiftCardTableView *allTableV;
|
|
|
+@property (nonatomic, strong) ASGiftCardTableView *usedTableV;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation ASGiftCardListViewController
|
|
|
+
|
|
|
+- (void)viewDidLoad {
|
|
|
+ [super viewDidLoad];
|
|
|
+ [self loadSubVs];
|
|
|
+ [self configSubVs];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)viewWillAppear:(BOOL)animated {
|
|
|
+ [super viewWillAppear:animated];
|
|
|
+ [self loadData];
|
|
|
+ [self checkEmpty];
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (void)loadData {
|
|
|
+ NSMutableArray *allArr = [NSMutableArray array];
|
|
|
+ NSMutableArray *usedArr = [NSMutableArray array];
|
|
|
+ if (arc4random()%2 == 1) {
|
|
|
+ for (int i=0;i<(arc4random()%100+3);i++) {
|
|
|
+ [allArr addObject:[ASGiftCardModel demoData]];
|
|
|
+ }
|
|
|
+ for (int i=0;i<(arc4random()%200+5);i++) {
|
|
|
+ ASGiftCardModel *m = [ASGiftCardModel demoData];
|
|
|
+ m.state = arc4random()%3;// == 1 ? ASGiftCardStateUsed : ASGiftCardStateExpired;
|
|
|
+ [usedArr addObject:m];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ self.allTableV.dataArr = allArr;
|
|
|
+ self.usedTableV.dataArr = usedArr;
|
|
|
+ [self setEmptyTip:@"No Giftcard Yet"];
|
|
|
+ [self.allTableV reloadData];
|
|
|
+ [self.usedTableV reloadData];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (void)checkEmpty {
|
|
|
+ if (_allTableV.dataArr.count == 0 && self.availabelBt.isSelected) {
|
|
|
+ [self showEmptyV: self.allTableV];
|
|
|
+ } else if (_usedTableV.dataArr.count == 0 && self.usedBt.isSelected) {
|
|
|
+ [self showEmptyV: self.usedTableV];
|
|
|
+ } else {
|
|
|
+ [self hiddenEmpty];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - loadSubVs
|
|
|
+- (void)configSubVs {
|
|
|
+ self.view.backgroundColor = _E0FFF5;
|
|
|
+ self.customNavBar.backgroundColor = _F0FFFA;
|
|
|
+ self.titleStr = @"My Giftcard";
|
|
|
+ [self setNavRightSearch:^{
|
|
|
+
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)loadSubVs {
|
|
|
+ [self.view addSubview:self.topBgV];
|
|
|
+ [self.view addSubview:self.bottomBgV];
|
|
|
+
|
|
|
+ [self.topBgV addSubview:self.availabelBt];
|
|
|
+ [self.topBgV addSubview:self.usedBt];
|
|
|
+
|
|
|
+ [self.bottomBgV addSubview:self.scrollV];
|
|
|
+ [self.scrollV addSubview:self.allTableV];
|
|
|
+ [self.scrollV addSubview:self.usedTableV];
|
|
|
+
|
|
|
+
|
|
|
+ [self.topBgV mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(self.customNavBar.mas_bottom);
|
|
|
+ make.leading.trailing.equalTo(self.view);
|
|
|
+ make.height.equalTo(@60);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.availabelBt mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerY.equalTo(self.topBgV);
|
|
|
+ make.height.equalTo(@40);
|
|
|
+ make.leading.equalTo(self.topBgV).offset(10);
|
|
|
+ }];
|
|
|
+ [self.usedBt mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.centerY.equalTo(self.availabelBt);
|
|
|
+ make.height.equalTo(@40);
|
|
|
+ make.leading.equalTo(self.availabelBt.mas_trailing).offset(10);
|
|
|
+ make.trailing.equalTo(self.topBgV).offset(-10);
|
|
|
+ make.width.equalTo(self.availabelBt);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.bottomBgV mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(self.topBgV.mas_bottom);
|
|
|
+ make.leading.trailing.bottom.equalTo(self.view);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollV mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(self.bottomBgV).offset(10);
|
|
|
+ make.leading.trailing.bottom.equalTo(self.bottomBgV);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.allTableV mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.leading.bottom.equalTo(self.scrollV);
|
|
|
+ make.width.equalTo(self.bottomBgV);
|
|
|
+ make.height.equalTo(self.bottomBgV).offset(-10);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.usedTableV mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.leading.equalTo(self.allTableV.mas_trailing);
|
|
|
+ make.top.trailing.bottom.equalTo(self.scrollV);
|
|
|
+ make.width.equalTo(self.bottomBgV);
|
|
|
+ make.height.equalTo(self.bottomBgV).offset(-10);
|
|
|
+ }];
|
|
|
+
|
|
|
+ dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
+ [UIView viewAddHorColorBg:self.bottomBgV colorArr:@[
|
|
|
+ (id)_E0FFF5.CGColor,
|
|
|
+ (id)Col_FFF.CGColor
|
|
|
+ ] startP:CGPointMake(0.5, 0) endP:CGPointMake(0.5, 1)];
|
|
|
+ [self.bottomBgV bringSubviewToFront:self.scrollV];
|
|
|
+
|
|
|
+ });
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// MARK: - bt Actions
|
|
|
+
|
|
|
+- (void)topBtAction:(UIButton *)bt {
|
|
|
+ if (bt == self.usedBt) {
|
|
|
+ self.availabelBt.selected = false;
|
|
|
+ self.usedBt.selected = true;
|
|
|
+ [self.scrollV setContentOffset:CGPointMake(KScreenWidth, 0) animated:true];
|
|
|
+ } else {
|
|
|
+ self.availabelBt.selected = true;
|
|
|
+ self.usedBt.selected = false;
|
|
|
+ [self.scrollV setContentOffset:CGPointMake(0, 0) animated:true];
|
|
|
+ }
|
|
|
+ [self setBtStatus:self.availabelBt];
|
|
|
+ [self setBtStatus:self.usedBt];
|
|
|
+ [self checkEmpty];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setBtStatus:(UIButton *)bt {
|
|
|
+ bt.backgroundColor = bt.isSelected ? _113632 : Col_FFF;
|
|
|
+ bt.titleLabel.font = [UIFont fontWithName:bt.isSelected ? Rob_Bold : Rob_Regular size:16];
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+// MARK: - subvs
|
|
|
+
|
|
|
+
|
|
|
+- (UIView *)topBgV {
|
|
|
+ if (!_topBgV) {
|
|
|
+ UIView *v = [UIView baseV];
|
|
|
+ v.backgroundColor = _E0FFF5;
|
|
|
+ _topBgV = v;
|
|
|
+ }
|
|
|
+ return _topBgV;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView *)bottomBgV{
|
|
|
+ if (!_bottomBgV) {
|
|
|
+ UIView *v = [UIView baseV];
|
|
|
+ v.frame = CGRectMake(0, 0, KScreenWidth, KScreenHeight);
|
|
|
+ v.backgroundColor = UIColor.clearColor;
|
|
|
+
|
|
|
+ _bottomBgV = v;
|
|
|
+ }
|
|
|
+ return _bottomBgV;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIButton *)availabelBt {
|
|
|
+ if (!_availabelBt) {
|
|
|
+ UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ bt.selected = true;
|
|
|
+ bt.backgroundColor = _113632;
|
|
|
+ bt.titleLabel.font = [UIFont fontWithName:Rob_Bold size:16];
|
|
|
+ [bt setTitleColor:Col_000 forState:UIControlStateNormal];
|
|
|
+ bt.layer.cornerRadius = 4;
|
|
|
+ bt.layer.masksToBounds = true;
|
|
|
+ [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
|
|
|
+ [bt setTitle:@"AVAILABLE" forState:UIControlStateNormal];
|
|
|
+ _availabelBt = bt;
|
|
|
+ }
|
|
|
+ return _availabelBt;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIButton *)usedBt {
|
|
|
+ if (!_usedBt) {
|
|
|
+ UIButton *bt = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ [bt addTarget:self action:@selector(topBtAction:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ bt.backgroundColor = Col_FFF;
|
|
|
+ bt.titleLabel.font = [UIFont fontWithName:Rob_Regular size:16];
|
|
|
+ [bt setTitleColor:Col_000 forState:UIControlStateNormal];
|
|
|
+ bt.layer.cornerRadius = 4;
|
|
|
+ bt.layer.masksToBounds = true;
|
|
|
+ [bt setTitleColor:Col_FFF forState:UIControlStateSelected];
|
|
|
+ [bt setTitle:@"EXPIRED/USED" forState:UIControlStateNormal];
|
|
|
+ _usedBt = bt;
|
|
|
+ }
|
|
|
+ return _usedBt;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (UIScrollView *)scrollV {
|
|
|
+ if (!_scrollV) {
|
|
|
+ UIScrollView *v = [[UIScrollView alloc] init];
|
|
|
+ v.showsVerticalScrollIndicator = false;
|
|
|
+ v.showsHorizontalScrollIndicator = false;
|
|
|
+ v.delegate = self;
|
|
|
+ v.pagingEnabled = true;
|
|
|
+ v.backgroundColor = UIColor.clearColor;
|
|
|
+ v.alwaysBounceHorizontal = true;
|
|
|
+ _scrollV = v;
|
|
|
+ }
|
|
|
+ return _scrollV;
|
|
|
+}
|
|
|
+
|
|
|
+- (ASGiftCardTableView *)allTableV {
|
|
|
+ if (!_allTableV) {
|
|
|
+ ASGiftCardTableView *v = [[ASGiftCardTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
+ _allTableV = v;
|
|
|
+ }
|
|
|
+ return _allTableV;
|
|
|
+}
|
|
|
+
|
|
|
+- (ASGiftCardTableView *)usedTableV {
|
|
|
+ if (!_usedTableV) {
|
|
|
+ ASGiftCardTableView *v = [[ASGiftCardTableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
|
|
|
+ _usedTableV = v;
|
|
|
+ }
|
|
|
+ return _usedTableV;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// MARK: - scrollview delegate
|
|
|
+- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
|
|
+ NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
|
|
|
+ self.availabelBt.selected = index == 0;
|
|
|
+ self.usedBt.selected = index == 1;
|
|
|
+ [self checkEmpty];
|
|
|
+ [self setBtStatus:self.availabelBt];
|
|
|
+ [self setBtStatus:self.usedBt];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
|
|
|
+ NSInteger index = (NSInteger)(scrollView.contentOffset.x/KScreenWidth);
|
|
|
+ self.availabelBt.selected = index == 0;
|
|
|
+ self.usedBt.selected = index == 1;
|
|
|
+ [self checkEmpty];
|
|
|
+ [self setBtStatus:self.availabelBt];
|
|
|
+ [self setBtStatus:self.usedBt];
|
|
|
+}
|
|
|
+
|
|
|
+@end
|