Created
June 14, 2019 11:12
-
-
Save chaitanyaSoni96/5e2830199558124cca98633777bea680 to your computer and use it in GitHub Desktop.
CSKolodaViewController Extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaViewControllerBusinessManager.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController: BusinessManagerDelegate{ | |
func viewDidLoadForExtension(){ | |
// let businessMan:BusinessManager = BusinessManager() | |
let businessManager: BusinessManager? = (UIApplication.shared.delegate as? AppDelegate)?.businessManager | |
let data = categoryArray[currentIndexOfCat] as? CategoryCatalogTreeData | |
businessManager!.getCatalogCategoryAssignedProducts(data, delegate: self, refresh: false) | |
SVProgressHUD.show(withStatus: "Loading...") | |
SVProgressHUD.setBackgroundColor(UIColor.clear) | |
SVProgressHUD.setRingThickness(5.0) | |
SVProgressHUD.setFadeInAnimationDuration(1.2) | |
SVProgressHUD.setOffsetFromCenter(UIOffset(horizontal: 0.0, vertical: 60.0)) | |
} | |
func addToFavourites() { | |
// let businessMan:BusinessManager = BusinessManager() | |
let businessManager: BusinessManager? = (UIApplication.shared.delegate as? AppDelegate)?.businessManager | |
let data = array[currentDisplayedKoladaCardIndex] as? CatalogCategoryAssignedProductsData | |
businessManager!.updateProduct(data, favorite: true) | |
} | |
func dataReceived(_ response: Any!, dataRequest: DataRequest!) { | |
if (dataRequest.requestType == RequestTypeGetRESTCatalogProducts) { | |
DispatchQueue.global(qos: .default).async(execute: { DispatchQueue.main.async(execute: { SVProgressHUD.dismiss() }) }) | |
array = response as? NSArray | |
productAraay = response as? NSArray | |
kolodaView.resetCurrentCardIndex() | |
nextCatBtn.isUserInteractionEnabled = true | |
previousCatBtn.isUserInteractionEnabled = true | |
// getAdditionalParams(data: array) | |
self.navigationController?.navigationBar.topItem?.title = categoryNames[currentIndexOfCat] as? String | |
}else if(dataRequest.requestType == RequestTypeCatalogProductAttributeMediaList){ | |
print("RequestTypeCatalogProductAttributeMediaList Response - \(response as! NSMutableArray)") | |
let reponseArray = response as! NSMutableArray | |
for media in reponseArray{ | |
let mediaData = media as! CatalogProductAttributeMediaData | |
print(mediaData.imageUrl) | |
currentSelectedProductMediaArray.append(mediaData.imageUrl) | |
} | |
collectionViewForProductDetail.reloadData() | |
print(currentSelectedProductMediaArray) | |
} | |
} | |
func failWithError(_ errorMessage: String!) { | |
print("Error getting data from server in:CSKolodaViewController - \(errorMessage!)") | |
} | |
func getAdditionalParams(data:CatalogCategoryAssignedProductsData)->Array<Any>{ | |
let jsonData = getJsonDataForAssociatedProd(data: data) | |
let associatedProd = try? JSONDecoder().decode(AssociatedProd.self, from:jsonData) | |
let dict:Dictionary = associatedProd!.dropdata | |
let keys = dict.keys | |
var keysArray = Array<Any>() | |
for key in keys{ | |
keysArray.append(key) | |
let tempDict = dict[key] | |
let tempSizeDict = tempDict!["180"] //size | |
let sizeAll = tempSizeDict?.all | |
let sizeVar = sizeAll?.optionslabel | |
let sizeKey = tempSizeDict?.value | |
let tempColorDict = tempDict!["92"] //color | |
let colorAll = tempColorDict?.all | |
let colorVar = colorAll?.optionslabel | |
let colorKey = tempColorDict?.value | |
/* | |
productInfo = { | |
code = size; | |
id = 180; | |
image = "<null>"; | |
label = Size; | |
optionslabel = 40; | |
price = "260.0000"; | |
qty = "0.0000"; | |
*/ | |
let dictSize = ["code":sizeAll?.code, | |
"id":sizeAll?.id, | |
"image":sizeAll?.image, | |
"label":sizeAll?.label, | |
"optionslabel":sizeAll?.optionslabel, | |
"price":sizeAll?.price, | |
"qty":sizeAll?.qty]as NSDictionary | |
/* | |
productInfo = { | |
code = color; | |
id = 92; | |
image = "<null>"; | |
label = Color; | |
optionslabel = Black; | |
price = "260.0000"; | |
qty = "0.0000"; | |
}; | |
*/ | |
let dictColor = ["code":colorAll?.code, | |
"id":colorAll?.id, | |
"image":colorAll?.image, | |
"label":colorAll?.label, | |
"optionslabel":colorAll?.optionslabel, | |
"price":colorAll?.price, | |
"qty":colorAll?.qty] as NSDictionary | |
sizeArray.append(sizeVar!) | |
sizeKeys.append(sizeKey!) | |
colorArray.append(colorVar!) | |
colorKeys.append(colorKey!) | |
productInfoSize = dictSize | |
productInfoColor = dictColor | |
} | |
// dictToDisplay = [sizeArray:sizeKeys,colorArray:colorKeys] | |
return [sizeArray,sizeKeys,colorArray,colorKeys] | |
} | |
func getJsonDataForAssociatedProd(data:CatalogCategoryAssignedProductsData) -> Data { | |
let originalString = data.associatedProd! as NSString | |
let backSlash = #"\"# | |
print(backSlash) | |
let doubleQuotes = #"" ""# | |
let replacedString1 = originalString.replacingOccurrences(of: #"/\"#, with: "") | |
let replacedString2 = replacedString1.replacingOccurrences(of: "null", with: doubleQuotes) | |
print(originalString) | |
print(replacedString2) | |
// let dataForSerialization:NSData = NSData | |
let jsonData: Data? = replacedString2.data(using: .utf8) | |
let associatedProducts:Any | |
do { | |
associatedProducts = try JSONSerialization.jsonObject(with: jsonData!, options:.allowFragments) | |
print(associatedProducts) | |
} catch { | |
} | |
return jsonData! | |
} | |
} | |
extension Array where Element:Equatable { | |
func removeDuplicates() -> [Element] { | |
var result = [Element]() | |
for value in self { | |
if result.contains(value) == false { | |
result.append(value) | |
} | |
} | |
return result | |
} | |
} | |
// To parse the JSON, add this file to your project and do: | |
// | |
// let associatedProd = try? newJSONDecoder().decode(AssociatedProd.self, from: jsonData) | |
struct AssociatedProd: Codable { | |
let dropdata: [String: [String: Dropdatum]] | |
} | |
struct Dropdatum: Codable { | |
let value: String | |
let all: All | |
} | |
struct All: Codable { | |
let id: String | |
let code: Code | |
let label: Label | |
let optionslabel, price, qty: String | |
let image: Image | |
} | |
enum Code: String, Codable { | |
case color = "color" | |
case size = "size" | |
} | |
enum Image: String, Codable { | |
case empty = " " | |
} | |
enum Label: String, Codable { | |
case color = "Color" | |
case size = "Size" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaVCCartManager.swift | |
// SellQwik | |
// | |
// Created by Admin on 23/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController{ | |
@objc func addToCartActionFromCartView(){ | |
if(buttonForColourSelect.titleLabel?.text == "Select Color"){ | |
showAlert(withTitle: "Scan", message: "Please Select Color", style: .alert, actions: [UIAlertAction(title: "OK", style: .default, handler: nil)]) | |
}else if(buttonForSizeSelect.titleLabel?.text == "Select Size"){ | |
showAlert(withTitle: "Scan", message: "Please Select Size", style: .alert, actions: [UIAlertAction(title: "OK", style: .default, handler: nil)]) | |
}else if(currentSelectedQuantity == 0){ | |
showAlert(withTitle: "Scan", message: "Please Select Quantity", style: .alert, actions: [UIAlertAction(title: "OK", style: .default, handler: nil)]) | |
}else{ | |
let orderDict = makeDictForAddToCart(data: array[currentDisplayedKoladaCardIndex] as! CatalogCategoryAssignedProductsData) | |
// let businessManager = BusinessManager() | |
let businessManager: BusinessManager? = (UIApplication.shared.delegate as? AppDelegate)?.businessManager | |
// print("shoppingCartArray.count before adding\(businessManager.shoppingCartArray.count)") | |
businessManager!.addItem(toCart: orderDict as? [AnyHashable : Any]) | |
// print("shoppingCartArray.count after adding\(businessManager.shoppingCartArray.count)") | |
} | |
let controller = RootViewController() | |
controller.updateFocusIfNeeded() | |
} | |
func makeDictForAddToCart(data:CatalogCategoryAssignedProductsData)->NSDictionary{ | |
let indexForSizeKeyArray = self.sizeArray.index(of: self.buttonForSizeSelect.titleLabel!.text!) | |
if(self.sizeKeys[indexForSizeKeyArray!] != ""){ | |
self.currentSelectedSize = self.sizeKeys[indexForSizeKeyArray!] | |
print("currentSelectedSize = \(currentSelectedSize)") | |
} | |
let indexForColourKeyArray = self.colorArray.index(of: self.buttonForColourSelect.titleLabel!.text!) | |
if(self.colorKeys[indexForColourKeyArray!] != ""){ | |
self.currentSelectedColor = self.colorKeys[indexForColourKeyArray!] | |
print("currentSelectedColor = \(currentSelectedColor)") | |
} | |
let productData = getProductData(data: data) | |
/* | |
productInfo = { | |
code = "SellQwik.Code.size"; | |
id = 180; | |
image = "SellQwik.Image.empty"; | |
label = "SellQwik.Label.size"; | |
optionslabel = 38; | |
price = "280.0000"; | |
qty = "0.0000"; | |
}; | |
*/ | |
let optionForColor = productInfoColor.value(forKey:"optionslabel") | |
let optionForSize = productInfoSize.value(forKey:"optionslabel") | |
let optionTextForColor = "\(optionForColor!)" | |
let optionTextForSize = "\(optionForSize!)" | |
let dictForAddToCart:NSDictionary = [ | |
"assoc_prod":[ | |
["assoc_prodID":"92", | |
"assoc_prodValue":currentSelectedColor, | |
// "productInfo":[ | |
// "code":productInfoColor.value(forKey: "code"), | |
// "id":productInfoColor.value(forKey: "id"), | |
// "image":productInfoColor.value(forKey: "image"), | |
// "label":productInfoColor.value(forKey: "label"), | |
"optionslabel":optionTextForColor, | |
// "price":productInfoColor.value(forKey: "price"), | |
// "qty":productInfoColor.value(forKey: "qty") | |
// ] | |
], | |
["assoc_prodID":"180", | |
"assoc_prodValue":currentSelectedSize, | |
// "productInfo":[ | |
// "code":productInfoSize.value(forKey: "code"), | |
// "id":productInfoSize.value(forKey: "id"), | |
// "image":productInfoSize.value(forKey: "image"), | |
// "label":productInfoSize.value(forKey: "label"), | |
"optionslabel":optionTextForSize, | |
// "price":productInfoSize.value(forKey: "price"), | |
// "qty":productInfoSize.value(forKey: "qty") | |
// ] | |
] | |
], | |
"productData":productData, | |
"qty":currentSelectedQuantity | |
] as NSDictionary | |
print(dictForAddToCart) | |
return dictForAddToCart as NSDictionary | |
} | |
func getProductData(data:CatalogCategoryAssignedProductsData)->NSDictionary{ | |
let productId = data.productId ?? 0 | |
let type = data.type ?? "" | |
let set = data.set ?? 0 | |
let sku = data.sku ?? "" | |
let position = data.position ?? 0 | |
let brand = data.brand ?? "" | |
let price = data.price ?? "" | |
let qty = data.qty ?? 0 | |
let name = data.name ?? "" | |
let description = data.description ?? "" | |
let shortDescription = data.shortDescription ?? "" | |
let image = data.image ?? "" | |
let link = data.link ?? "" | |
let categoryId = data.categoryId ?? 0 | |
let associatedProd = data.associatedProd ?? "" | |
let additionalParameters = data.additionalParameters ?? [""] | |
let wsp = data.wsp ?? "" | |
let linkDownloads = data.linkDownloads ?? "" | |
let productData = ["productId":productId, | |
"type":type, | |
"set":set, | |
"sku":sku, | |
"position":position, | |
"brand":brand, | |
"price":price, | |
"qty":qty, | |
"name":name, | |
"description":description, | |
"shortDescription":shortDescription, | |
"image":image, | |
"link":link, | |
"categoryId":categoryId, | |
"associatedProd":associatedProd, | |
"additionalParameters":additionalParameters, | |
"wsp":wsp, | |
"linkDownloads":linkDownloads] as NSDictionary | |
return productData | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaViewControllerCollectionViewDatasource.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController:UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout{ | |
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { | |
if(currentSelectedProductMediaArray != nil){ | |
if(currentSelectedProductMediaArray.count != 0){ | |
return currentSelectedProductMediaArray.count | |
} | |
} | |
return 0 | |
} | |
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { | |
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath) | |
// cell.backgroundColor = hexStringToUIColor(hex: "#BB215B") | |
let imageViewForProductImages = UIImageView(frame: CGRect(x: cell.frame.origin.x, y: cell.frame.origin.y, width: cell.frame.size.width, height: cell.frame.size.height)) | |
imageViewForProductImages.moa.url = currentSelectedProductMediaArray[indexPath.row] | |
cell.addSubview(imageViewForProductImages) | |
return cell | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { | |
return CGSize(width: collectionView.frame.height, height: collectionView.frame.height) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaViewControllerKoladaViewDatasource.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
import Koloda | |
extension CSKolodaViewController: KolodaViewDataSource { | |
func kolodaNumberOfCards(_ koloda:KolodaView) -> Int { | |
if(array != nil && array.count > 0){ | |
return array.count | |
} | |
return 0 | |
} | |
func kolodaSpeedThatCardShouldDrag(_ koloda: KolodaView) -> DragSpeed { | |
return .fast | |
} | |
func koloda(_ koloda: KolodaView, viewForCardAt index: Int) -> UIView { | |
let theViewToCustomize = UIView() | |
theViewToCustomize.frame = self.kolodaView.frame | |
let cardView = CSKolodaCardView() | |
return cardView.setView(catProdItem: array![index] as! CatalogCategoryAssignedProductsData, viewToCustomize: theViewToCustomize) | |
} | |
func koloda(_ koloda: KolodaView, viewForCardOverlayAt index: Int) -> OverlayView? { | |
return Bundle.main.loadNibNamed("CustomOverlayView", owner: self, options: nil)![0] as? OverlayView | |
} | |
} | |
extension CSKolodaViewController: KolodaViewDelegate { | |
func kolodaDidRunOutOfCards(_ koloda: KolodaView) { | |
increaseCat() | |
} | |
func koloda(_ koloda: KolodaView, didSelectCardAt index: Int) { | |
print("DidSelect atIndex\(index)") | |
if(array != nil && array.count != 0){ | |
_ = getAdditionalParams(data: array[index] as! CatalogCategoryAssignedProductsData) | |
let data = array[index] as! CatalogCategoryAssignedProductsData | |
let businessManager: BusinessManager? = (UIApplication.shared.delegate as? AppDelegate)?.businessManager | |
businessManager?.getCatalogProductAttributeMediaList(forProduct: data, delegate: self) | |
setProductViewPopup(data: data) | |
} | |
} | |
func koloda(_ koloda: KolodaView, allowedDirectionsForIndex index: Int) -> [SwipeResultDirection] { | |
return [.topLeft,.bottomLeft,.topRight,.bottomRight,.left,.right] | |
} | |
func koloda(_ koloda: KolodaView, didShowCardAt index: Int) { | |
currentDisplayedKoladaCardIndex = index; | |
print(index) | |
} | |
func kolodaSwipeThresholdRatioMargin(_ koloda: KolodaView) -> CGFloat? { | |
return 0.3 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaViewControllerTableViewDatasource.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController:UITableViewDataSource{ | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
let colorArrayForTableView = colorArray.removeDuplicates() | |
let sizeArrayForTableView = sizeArray.removeDuplicates() | |
if(tableView.tag == 11001){ | |
return sizeArrayForTableView.count | |
} | |
if(tableView.tag == 11002){ | |
return colorArrayForTableView.count | |
} | |
return 0 | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = UITableViewCell(style: .default, reuseIdentifier: "cellType") | |
let colorArrayForTableView = colorArray.removeDuplicates() | |
var sizeArrayForTableView = sizeArray.removeDuplicates() | |
sizeArrayForTableView.sort() | |
if(tableView.tag == 11001){ | |
cell.textLabel?.text = sizeArrayForTableView[indexPath.row] | |
} | |
if(tableView.tag == 11002){ | |
cell.textLabel?.text = colorArrayForTableView[indexPath.row] | |
} | |
return cell | |
} | |
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { | |
if(tableView.tag == 11001){ | |
return "Sizes" | |
} | |
if(tableView.tag == 11002){ | |
return "Colours" | |
} | |
return "" | |
} | |
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { | |
return 30 | |
} | |
} | |
extension CSKolodaViewController:UITableViewDelegate{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaVCViewActions.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController{ | |
@objc func closeAddToCart(from:UIButton){ | |
if from.tag == 10001{ | |
addToCartBaseView.isHidden = true | |
cartView.isHidden = true | |
}else if from.tag == 12001{ | |
viewForProductDetail.isHidden = true | |
} | |
resetSubviews() | |
} | |
func resetSubviews(){ | |
buttonForSizeSelect.setTitle("Select Size", for: .normal) | |
buttonForSizeSelect.titleLabel?.text = "Select Size" | |
buttonForColourSelect.setTitle("Select Color", for: .normal) | |
buttonForColourSelect.titleLabel?.text = "Select Color" | |
updateQtyLabel.text = "1" | |
currentSelectedQuantity = 1 | |
nameLabelForProductDetail.text = "" | |
mrpLabelForProductDetail.text = "" | |
currentSelectedProductMediaArray.removeAll() | |
collectionViewForProductDetail.reloadData() | |
} | |
func showAlert(withTitle title:String, message:String, style:UIAlertController.Style, actions:[UIAlertAction]){ | |
let alert = UIAlertController(title: title, message: message, preferredStyle: style) | |
for action in actions{ | |
alert.addAction(action) | |
} | |
DispatchQueue.main.async(execute: { | |
self.present(alert, animated: true) | |
}) | |
} | |
func setNavBackBTN(){ | |
// let backBTN = | |
} | |
func navBackPressed() { | |
} | |
@objc func setDropDown(from:UIButton) { | |
if(from.tag == 10002){ | |
//sizeSelectBtn | |
dropDownForSize.show() | |
}else if(from.tag == 10003){ | |
//colorSelectBTN | |
dropDownForColour.show() | |
} | |
} | |
@objc func increaseCat(){ | |
// if(categoryArray.count-1>currentIndexOfCat){ | |
// currentIndexOfCat += 1 | |
// nextCatBtn.isUserInteractionEnabled = false | |
// self.title = categoryNames[currentIndexOfCat] | |
// nextCatBtn.setTitle(categoryNames[currentIndexOfCat], for: .normal) | |
// | |
// currentIndexOfCat = categoryNames.index(of: nextCatBtn.titleLabel?.text!) | |
// | |
// viewDidLoadForExtension() | |
// } | |
currentIndexOfCat = categoryNames.index(of: nextCatBtn.titleLabel?.text!) | |
updateTitles() | |
viewDidLoadForExtension() | |
} | |
@objc func decreaseCat(){ | |
// if(currentIndexOfCat != 0){ | |
// currentIndexOfCat -= 1 | |
// previousCatBtn.isUserInteractionEnabled = false | |
// self.title = categoryNames[currentIndexOfCat] | |
// | |
// currentIndexOfCat = categoryNames.index(of: previousCatBtn.titleLabel?.text!) | |
// | |
// viewDidLoadForExtension() | |
// } | |
currentIndexOfCat = categoryNames.index(of: previousCatBtn.titleLabel?.text!) | |
updateTitles() | |
viewDidLoadForExtension() | |
} | |
func updateTitles(){ | |
if(currentIndexOfCat == 0){ | |
previousCatBtn.setTitle(categoryNames[categoryNames.count-1] as? String, for: .normal) | |
nextCatBtn.setTitle(categoryNames[1] as? String, for: .normal) | |
}else if(currentIndexOfCat == categoryNames.count - 1){ | |
previousCatBtn.setTitle(categoryNames[currentIndexOfCat - 1] as? String, for: .normal) | |
nextCatBtn.setTitle(categoryNames[0] as? String, for: .normal) | |
}else{ | |
previousCatBtn.setTitle(categoryNames[currentIndexOfCat - 1] as? String, for: .normal) | |
nextCatBtn.setTitle(categoryNames[currentIndexOfCat + 1] as? String, for: .normal) | |
} | |
self.navigationController?.navigationBar.topItem?.title = "" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CSKolodaViewControllerViewConfigurator.swift | |
// SellQwik | |
// | |
// Created by Admin on 18/04/19. | |
// | |
import Foundation | |
extension CSKolodaViewController{ | |
@objc func setOrderPopUp() { | |
if let data = array[currentDisplayedKoladaCardIndex] as? CatalogCategoryAssignedProductsData{ | |
arrayToDisplay = getAdditionalParams(data: data) as! [[String]] | |
var tempArray = [String]() | |
addToCartBaseView.frame = self.view.window!.frame | |
addToCartBaseView.layer.cornerRadius = 5.0 | |
productImageView.contentMode = .scaleAspectFit | |
productImageView.moa.url = data.image | |
dropDownForSize.anchorView = buttonForSizeSelect | |
tempArray = (arrayToDisplay[0]).removeDuplicates() | |
tempArray.sort() | |
dropDownForSize.dataSource = tempArray | |
dropDownForSize.selectionAction = { [unowned self] (index: Int, item: String) in | |
print("Selected item: \(item) at index: \(index)") | |
self.buttonForSizeSelect.titleLabel?.text = item | |
} | |
dropDownForSize.bottomOffset = CGPoint(x: 0, y:(dropDownForSize.anchorView?.plainView.bounds.height)!) | |
dropDownForSize.topOffset = CGPoint(x: 0, y:-(dropDownForSize.anchorView?.plainView.bounds.height)!) | |
dropDownForSize.animationEntranceOptions = .transitionFlipFromTop | |
dropDownForSize.dismissMode = .automatic | |
dropDownForSize.direction = .bottom | |
dropDownForColour.anchorView = buttonForColourSelect | |
tempArray = (arrayToDisplay[2]).removeDuplicates() | |
tempArray.sort() | |
dropDownForColour.dataSource = tempArray | |
dropDownForColour.selectionAction = { [unowned self] (index: Int, item: String) in | |
print("Selected item: \(item) at index: \(index)") | |
self.buttonForColourSelect.titleLabel?.text = item | |
} | |
dropDownForColour.bottomOffset = CGPoint(x: 0, y:(dropDownForColour.anchorView?.plainView.bounds.height)!) | |
dropDownForColour.topOffset = CGPoint(x: 0, y:-(dropDownForColour.anchorView?.plainView.bounds.height)!) | |
dropDownForColour.animationEntranceOptions = .transitionCurlDown | |
dropDownForColour.dismissMode = .automatic | |
dropDownForColour.direction = .bottom | |
addToCartBaseView.isHidden = false | |
cartView.isHidden = false | |
} | |
} | |
func setProductViewPopup(data:CatalogCategoryAssignedProductsData) { | |
resetSubviews() | |
_ = getAdditionalParams(data: data) | |
imageViewForProductDetail.moa.url = data.image | |
nameLabelForProductDetail.text = data.name | |
mrpLabelForProductDetail.text = "MRP ₹\(data.price!)" | |
// addToCartButtonForProductDetail | |
colourTableViewForProductDetail.reloadData() | |
sizeTableViewForProductDetail.reloadData() | |
viewForProductDetail.isHidden = false | |
} | |
@objc func updateQty(sender: UIButton){ | |
let integerForLabel = Int(updateQtyLabel.text!) | |
var currentQty:Int = integerForLabel! | |
if(sender.tag == 10004){ | |
currentQty += 1 | |
}else if(sender.tag == 10005 && currentQty > 1){ | |
currentQty -= 1 | |
} | |
self.currentSelectedQuantity = currentQty | |
updateQtyLabel.text = String(currentQty) | |
} | |
func setControls() { | |
nextCatBtn.addTarget(self, action: #selector(increaseCat), for: .touchUpInside) | |
previousCatBtn.addTarget(self, action: #selector(decreaseCat), for: .touchUpInside) | |
addToCartButtonForProductDetail.addTarget(self, action: #selector(setOrderPopUp), for: .touchUpInside) | |
closeButtonForProductDetail.tag = 12001 | |
closeButtonForProductDetail.addTarget(self, action: #selector(closeAddToCart(from:)), for: .touchUpInside) | |
closeBtnForAddToCart.tag = 10001 | |
closeBtnForAddToCart.addTarget(self, action:#selector(closeAddToCart(from:)), for: .touchUpInside) | |
buttonForSizeSelect.tag = 10002 | |
buttonForSizeSelect.addTarget(self, action: #selector(setDropDown(from:)), for: .touchUpInside) | |
buttonForColourSelect.tag = 10003 | |
buttonForColourSelect.addTarget(self, action: #selector(setDropDown(from:)), for: .touchUpInside) | |
addQtyButton.tag = 10004 | |
addQtyButton.addTarget(self, action: #selector(updateQty(sender:)), for: .touchUpInside) | |
substractQtyButton.tag = 10005 | |
substractQtyButton.addTarget(self, action: #selector(updateQty(sender:)), for: .touchUpInside) | |
} | |
func setCornersForCategoryButtons() { | |
// let button = previousBtn | |
previousCatBtn.backgroundColor = .clear | |
let prevBTNborderLayer = CAShapeLayer() | |
prevBTNborderLayer.fillColor = hexStringToUIColor(hex: "#DB3263").cgColor | |
prevBTNborderLayer.borderWidth = 2.0 | |
let previousBtnBorderPath = UIBezierPath(roundedRect: previousCatBtn.bounds, | |
byRoundingCorners: [.topRight], | |
cornerRadii: CGSize(width:10.0, height: 10.0)) | |
prevBTNborderLayer.path = previousBtnBorderPath.cgPath | |
previousCatBtn.layer.insertSublayer(prevBTNborderLayer, at: 0) | |
nextCatBtn.backgroundColor = .clear | |
let nextBTNborderLayer = CAShapeLayer() | |
nextBTNborderLayer.fillColor = hexStringToUIColor(hex: "#DB3263").cgColor | |
nextBTNborderLayer.borderWidth = 2.0 | |
let nextBtnBorderPath = UIBezierPath(roundedRect: previousCatBtn.bounds, | |
byRoundingCorners: [.topLeft], | |
cornerRadii: CGSize(width:10.0, height: 10.0)) | |
nextBTNborderLayer.path = nextBtnBorderPath.cgPath | |
nextCatBtn.layer.insertSublayer(nextBTNborderLayer, at: 0) | |
} | |
func hexStringToUIColor (hex:String) -> UIColor { | |
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased() | |
if (cString.hasPrefix("#")) { | |
cString.remove(at: cString.startIndex) | |
} | |
if ((cString.count) != 6) { | |
return UIColor.gray | |
} | |
var rgbValue:UInt32 = 0 | |
Scanner(string: cString).scanHexInt32(&rgbValue) | |
return UIColor( | |
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, | |
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0, | |
blue: CGFloat(rgbValue & 0x0000FF) / 255.0, | |
alpha: CGFloat(1.0) | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment