Skip to content

Instantly share code, notes, and snippets.

@thuycom205
Created June 22, 2018 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thuycom205/85646c130458fe4e8946ea17d4dba5d8 to your computer and use it in GitHub Desktop.
Save thuycom205/85646c130458fe4e8946ea17d4dba5d8 to your computer and use it in GitHub Desktop.
//
// MNCartShippingCellExtension.m
// OpenShop
//
// Created by Thuy Luu on 2/26/18.
// Copyright © 2018 Business-Factory. All rights reserved.
//
#import "MNCartShippingCellExtension.h"
#import "MNCartViewController.h"
#import "MNShippingCellCollectionViewCell.h"
@implementation MNCartShippingCellExtension
- (instancetype)initWithCollectionViewController:(BFCollectionViewController *)viewController {
self = [super initWithCollectionViewController:viewController];
if (self) {
self.collectionView = viewController.collectionView;
}
return self;
}
#pragma mark - UICollectionViewDataSource
- (NSUInteger)getNumberOfItems
{
return 1;
}
- (UICollectionViewCell *)getCellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionView *collectiveView = self.collectionView;
MNShippingCellCollectionViewCell *cell = (MNShippingCellCollectionViewCell *)[collectiveView dequeueReusableCellWithReuseIdentifier:@"shippingMethodCell" forIndexPath:indexPath];
MNCartViewController *cartController = (MNCartViewController*) self.collectionViewController;
if (self.mode == 0) {
cell.CellLegendLabel.text = @"Shipping Address";
cell.cellType = @"shipping";
} else if (self.mode == 1) {
cell.CellLegendLabel.text = @"Billing Address";
cell.cellType = @"billing";
}
if (self.mode == 0) {
if (cartController.selectedShippingAddress.firstname ) {
[cell.fullNameLabel setHidden:NO];
cell.fullNameLabel.text = [NSString stringWithFormat:@"%@ %@", cartController.selectedShippingAddress.firstname ,cartController.selectedShippingAddress.lastname ];
} else {
[cell.fullNameLabel setHidden:YES];
}
if ([cartController.selectedShippingAddress.street count] > 0) {
[cell.streetLabel setHidden:NO];
NSInteger cnt = [cartController.selectedShippingAddress.street count];
if (cnt == 1) {
cell.streetLabel.text = [cartController.selectedShippingAddress.street firstObject];
} else if (cnt == 2) {
NSString *street1= [cartController.selectedShippingAddress.street firstObject];
NSString *street2= [cartController.selectedShippingAddress.street objectAtIndex:1];
NSString *fullStreet = [NSString stringWithFormat:@"%@ %@" , street1,street2];
cell.streetLabel.text = fullStreet;
}
} else {
[cell.streetLabel setHidden:YES];
}
if (cartController.selectedShippingAddress.city) {
[cell.cityLabel setHidden:NO];
cell.cityLabel.text = cartController.selectedShippingAddress.city;
} else {
[cell.cityLabel setHidden:YES];
}
if (cartController.selectedShippingAddress.region.region ) {
[cell.regionLabel setHidden:NO];
cell.regionLabel.text = cartController.selectedShippingAddress.region.region ;
} else {
[cell.regionLabel setHidden:YES];
}
if (cartController.selectedShippingAddress.country_name) {
[cell.countryLabel setHidden:NO];
cell.countryLabel.text = cartController.selectedShippingAddress.country_name;
} else {
[cell.countryLabel setHidden:YES];
}
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectShippingAddressBtnClick:)];
UIView *contenCell = [cell.subviews firstObject];
// [contenCell addGestureRecognizer:gesture];
for ( UIView *uiview in cell.subviews) {
for (UIView *element in uiview.subviews) {
if ([element.restorationIdentifier isEqualToString:@"shippingAddrSelect"]) {
UIButton *leftBtn = (UIButton*) element;
[leftBtn addTarget:self action:@selector(selectShippingAddressBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
}
[cell.sameAsBillingContainer setHidden:NO];
if (cartController.isBillingAddressNOTSameAsShippingAddress) {
[cell.bemCb setOn:NO];
} else {
[cell.bemCb setOn:YES];
}
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
cell.nsLayoutWidth.constant = width-30;
[cell setNeedsLayout];
[cell layoutIfNeeded];
cell.delegate = cartController;
return cell;
} else {
if (cartController.selectedBillingAddress.firstname ) {
[cell.fullNameLabel setHidden:NO];
cell.fullNameLabel.text = [NSString stringWithFormat:@"%@ %@", cartController.selectedBillingAddress.firstname ,cartController.selectedBillingAddress.lastname ];
} else {
[cell.fullNameLabel setHidden:YES];
}
if ([cartController.selectedBillingAddress.street count] > 0) {
[cell.streetLabel setHidden:NO];
cell.streetLabel.text = [cartController.selectedBillingAddress.street firstObject];
} else {
[cell.streetLabel setHidden:YES];
}
if (cartController.selectedBillingAddress.city) {
[cell.cityLabel setHidden:NO];
cell.cityLabel.text = cartController.selectedBillingAddress.city;
} else {
[cell.cityLabel setHidden:YES];
}
if (cartController.selectedBillingAddress.region.region ) {
[cell.regionLabel setHidden:NO];
cell.regionLabel.text = cartController.selectedBillingAddress.region.region ;
} else {
[cell.regionLabel setHidden:YES];
}
if (cartController.selectedBillingAddress.country_name) {
[cell.countryLabel setHidden:NO];
cell.countryLabel.text = cartController.selectedBillingAddress.country_name;
} else {
[cell.countryLabel setHidden:YES];
}
UITapGestureRecognizer *gesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(selectShippingAddressBtnClick:)];
UIView *contenCell = [cell.subviews firstObject];
[contenCell addGestureRecognizer:gesture];
for ( UIView *uiview in cell.subviews) {
[uiview setUserInteractionEnabled:YES];
//uiview
for (UIView *element in uiview.subviews) {
if ([element.restorationIdentifier isEqualToString:@"shippingAddrSelect"]) {
UIButton *leftBtn = (UIButton*) element;
[leftBtn addTarget:self action:@selector(selectShippingAddressBtnClick:) forControlEvents:UIControlEventTouchUpInside];
}
}
}
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat width = CGRectGetWidth(screen);
//cell.sameAsBillingNSLayoutHeight.constant = 0;
[cell.sameAsBillingContainer setHidden:YES];
cell.nsLayoutWidth.constant = width-30;
[cell setNeedsLayout];
[cell layoutIfNeeded];
cell.delegate = cartController;
return cell;
}
}
-(void)bindingCellValue :(MNShippingCellCollectionViewCell*) cell address :(MNShippingAddress*)address {
}
-(void) selectShippingAddressBtnClick: (id) sender {
//add the ui indicator activity to the screen
UIView *faceView = [[UIView alloc] init];
faceView.restorationIdentifier = @"fadeViewId";
faceView.frame = self.collectionViewController.view.bounds;
faceView.backgroundColor = [UIColor grayColor];
faceView.alpha = 0.4;
self.fadeView = faceView;
[self.collectionViewController.view addSubview:faceView];
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
spinner.restorationIdentifier = @"spinnerId";
//
[self.collectionViewController.view addSubview:spinner];
spinner.center = self.collectionViewController.view.center;
spinner.hidesWhenStopped = true;
[spinner startAnimating];
// [NSThread detachNewThreadSelector: @selector(getSchoolList) toTarget: self withObject: nil];
///
[self performSelector:@selector(showShippingAddressScene:) withObject:sender afterDelay:1.0];
}
-(void)showShippingAddressScene:(id)spinner {
// UIActivityIndicatorView *stopSpinner = (UIActivityIndicatorView*) spinner;
// [stopSpinner stopAnimating];
// [self.fadeView removeFromSuperview];
MNCartViewController *myController = self.collectionViewController;
if (self.mode == 0) {
myController.presentAddressType = @"presentShipping";
} else {
myController.presentAddressType = @"presentBilling";
}
[myController presentSelectShippingAddressController:self];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment