Showing
4 changed files
with
163 additions
and
65 deletions
This diff is collapsed. Click to expand it.
| ... | @@ -8,10 +8,47 @@ | ... | @@ -8,10 +8,47 @@ |
| 8 | import UIKit | 8 | import UIKit |
| 9 | 9 | ||
| 10 | @objc public class OffersTableViewCell: UITableViewCell { | 10 | @objc public class OffersTableViewCell: UITableViewCell { |
| 11 | + @IBOutlet weak var cellView: UIView! | ||
| 12 | + @IBOutlet weak var campaignImage: UIImageView! | ||
| 13 | + @IBOutlet weak var titleLabel: UILabel! | ||
| 14 | + @IBOutlet weak var subtitleLabel: UILabel! | ||
| 15 | + @IBOutlet weak var discountBGImage: UIImageView! | ||
| 16 | + @IBOutlet weak var discountSmileImage: UIImageView! | ||
| 17 | + @IBOutlet weak var discountLabel: UILabel! | ||
| 18 | + | ||
| 19 | + var postImageURL: String? { | ||
| 20 | + didSet { | ||
| 21 | + if let url = postImageURL { | ||
| 22 | + self.campaignImage.image = UIImage() // UIImage(named: "loading") | ||
| 23 | + | ||
| 24 | + UIImage.loadImageUsingCacheWithUrlString(url) { image in | ||
| 25 | + // set the image only when we are still displaying the content for the image we finished downloading | ||
| 26 | + if url == self.postImageURL { | ||
| 27 | + self.campaignImage.image = image | ||
| 28 | + } | ||
| 29 | + } | ||
| 30 | + } | ||
| 31 | + else { | ||
| 32 | + self.campaignImage.image = nil | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + } | ||
| 11 | 36 | ||
| 12 | public override func awakeFromNib() { | 37 | public override func awakeFromNib() { |
| 13 | super.awakeFromNib() | 38 | super.awakeFromNib() |
| 14 | - // Initialization code | 39 | + |
| 40 | + // Add shadow | ||
| 41 | + self.layer.shadowColor = UIColor(red: 0.00, green: 0.00, blue: 0.00, alpha: 0.16).cgColor | ||
| 42 | + self.layer.shadowOffset = CGSize(width: 0.0, height: 3.0) | ||
| 43 | + self.layer.shadowOpacity = 1.0 | ||
| 44 | + self.layer.shadowRadius = 6.0 | ||
| 45 | + | ||
| 46 | + cellView.layer.cornerRadius = 5.0 | ||
| 47 | + cellView.clipsToBounds = true | ||
| 48 | + | ||
| 49 | + discountBGImage.image = UIImage(named: "offer_circle_orange", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
| 50 | + discountSmileImage.image = UIImage(named: "logo_smile_white_new", in: MyEmptyClass.resourceBundle(), compatibleWith: nil) | ||
| 51 | + | ||
| 15 | } | 52 | } |
| 16 | 53 | ||
| 17 | public override func setSelected(_ selected: Bool, animated: Bool) { | 54 | public override func setSelected(_ selected: Bool, animated: Bool) { |
| ... | @@ -20,4 +57,21 @@ import UIKit | ... | @@ -20,4 +57,21 @@ import UIKit |
| 20 | // Configure the view for the selected state | 57 | // Configure the view for the selected state |
| 21 | } | 58 | } |
| 22 | 59 | ||
| 60 | + public override func layoutSubviews() { | ||
| 61 | + super.layoutSubviews() | ||
| 62 | + //set the values for top,left,bottom,right margins | ||
| 63 | + let margins = UIEdgeInsets(top: 0, left: 0, bottom: 20, right: 0) | ||
| 64 | + contentView.frame = contentView.frame.inset(by: margins) | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + func configureCell(campaign: swiftApi.CampaignItemModel) { | ||
| 69 | + // campaignImage.load(link: campaign.logo_url ?? "", placeholder: UIImage(), cache: URLCache()) | ||
| 70 | + self.postImageURL = campaign.logo_url ?? "" | ||
| 71 | + | ||
| 72 | + titleLabel.text = campaign.title ?? "" | ||
| 73 | + subtitleLabel.text = campaign.subtitle ?? "" | ||
| 74 | + discountLabel.text = "10%" | ||
| 75 | + } | ||
| 76 | + | ||
| 23 | } | 77 | } | ... | ... |
| ... | @@ -8,22 +8,117 @@ | ... | @@ -8,22 +8,117 @@ |
| 8 | import UIKit | 8 | import UIKit |
| 9 | 9 | ||
| 10 | @objc public class OffersViewController: UIViewController { | 10 | @objc public class OffersViewController: UIViewController { |
| 11 | + @IBOutlet weak var tableView: UITableView! | ||
| 12 | + | ||
| 13 | + public var campaigns:Array<swiftApi.CampaignItemModel> = [] { | ||
| 14 | + didSet { | ||
| 15 | + DispatchQueue.main.async { | ||
| 16 | + self.tableView.reloadData() | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | + } | ||
| 11 | 20 | ||
| 12 | public override func viewDidLoad() { | 21 | public override func viewDidLoad() { |
| 13 | super.viewDidLoad() | 22 | super.viewDidLoad() |
| 14 | 23 | ||
| 15 | - // Do any additional setup after loading the view. | 24 | + getCampaignsRequest() |
| 25 | + | ||
| 26 | + tableView.delegate = self | ||
| 27 | + tableView.dataSource = self | ||
| 28 | + tableView.contentInset.top = 25 | ||
| 16 | } | 29 | } |
| 17 | 30 | ||
| 18 | 31 | ||
| 19 | - /* | 32 | +// MARK: - Requests |
| 20 | - // MARK: - Navigation | 33 | + func getCampaignsRequest() { |
| 34 | + swiftApi().getCampaignsAsyncNew(language: "en", filters: [String : Any](), getCampaignsCallback, failureCallback: {errorCode in | ||
| 35 | + print("========= getCampaignsCallback ERROR =========",errorCode) | ||
| 36 | + }) | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + func getCampaignsCallback (_ campaignsData: Array<swiftApi.CampaignItemModel>?) -> Void { | ||
| 40 | + if (campaignsData != nil) { | ||
| 41 | + DispatchQueue.main.async { | ||
| 42 | + self.campaigns = campaignsData ?? [] | ||
| 43 | + self.tableView.reloadData() | ||
| 44 | + } | ||
| 45 | + } else { | ||
| 46 | + print("========= getCampaignsCallback ERROR =========") | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | +} | ||
| 51 | + | ||
| 52 | +// MARK: - TableView | ||
| 53 | +extension OffersViewController: UITableViewDelegate, UITableViewDataSource{ | ||
| 54 | + | ||
| 55 | + public func numberOfSections(in tableView: UITableView) -> Int { | ||
| 56 | + return 1 | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
| 60 | + return self.campaigns.count | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | + public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
| 64 | + return 288.0 + 20.0 | ||
| 65 | +// return UITableViewAutomaticDimension | ||
| 66 | + } | ||
| 21 | 67 | ||
| 22 | - // In a storyboard-based application, you will often want to do a little preparation before navigation | 68 | + public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { |
| 23 | - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | 69 | + let cell = tableView.dequeueReusableCell(withIdentifier: "OffersTableViewCellId", for: indexPath) as! OffersTableViewCell |
| 24 | - // Get the new view controller using segue.destination. | 70 | + |
| 25 | - // Pass the selected object to the new view controller. | 71 | + cell.configureCell(campaign: campaigns[indexPath.row]) |
| 72 | + | ||
| 73 | + return cell | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | ||
| 77 | + let status = swiftApi().getNetworkStatus() | ||
| 78 | + if (status == -1 || status == 0) { | ||
| 79 | + self.showDialog("Δεν υπάρχει σύνδεση","Αυτή τη στιγμή βρίσκεσαι εκτός σύνδεσης. Παρακαλούμε βεβαιώσου ότι είσαι συνδεδεμένος στο διαδίκτυο και προσπάθησε ξανά.") | ||
| 80 | + } else { | ||
| 81 | + | ||
| 82 | + let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self)) | ||
| 83 | + let vc = storyboard.instantiateViewController(withIdentifier: "CampaignViewController") as! SwiftWarplyFramework.CampaignViewController | ||
| 84 | + var url = "" | ||
| 85 | + var params = "" | ||
| 86 | + | ||
| 87 | +// url = swiftApi().constructCampaignUrl(campaigns[indexPath.row]) | ||
| 88 | +// params = swiftApi().constructCampaignParams(campaigns[indexPath.row]) | ||
| 89 | + url = campaigns[indexPath.row].index_url ?? "" | ||
| 90 | + | ||
| 91 | + let encoder = JSONEncoder() | ||
| 92 | + encoder.outputFormatting = .prettyPrinted | ||
| 93 | + let data = try! encoder.encode(campaigns[indexPath.row]) | ||
| 94 | + | ||
| 95 | + print("Campaign_CLICK " + String(data: data, encoding: .utf8)!) | ||
| 96 | + | ||
| 97 | + print("CampaignUrl url onclick: " + url) | ||
| 98 | + vc.campaignUrl = url | ||
| 99 | + vc.params = params | ||
| 100 | + self.navigationController?.pushViewController(vc, animated: true) | ||
| 101 | + | ||
| 102 | + } | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + func showDialog(_ alertTitle: String, _ alertSubTitle: String) -> Void { | ||
| 106 | + | ||
| 107 | + let alert = UIAlertController(title: alertTitle, message: alertSubTitle, preferredStyle: .alert) | ||
| 108 | + alert.addAction(UIAlertAction(title: "OK", style: .default, handler: { action in | ||
| 109 | + switch action.style{ | ||
| 110 | + case .default: | ||
| 111 | + print("default") | ||
| 112 | + | ||
| 113 | + case .cancel: | ||
| 114 | + print("cancel") | ||
| 115 | + | ||
| 116 | + case .destructive: | ||
| 117 | + print("destructive") | ||
| 118 | + | ||
| 119 | + } | ||
| 120 | + })) | ||
| 121 | + self.present(alert, animated: true, completion: nil) | ||
| 26 | } | 122 | } |
| 27 | - */ | ||
| 28 | 123 | ||
| 29 | } | 124 | } | ... | ... |
| ... | @@ -1456,16 +1456,10 @@ public class swiftApi { | ... | @@ -1456,16 +1456,10 @@ public class swiftApi { |
| 1456 | 1456 | ||
| 1457 | func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { | 1457 | func campaignsCallback(_ campaignsData: [AnyHashable: Any]?) -> Void { |
| 1458 | var campaignsArray:Array<CampaignItemModel> = [] | 1458 | var campaignsArray:Array<CampaignItemModel> = [] |
| 1459 | - var carouselArray:Array<CampaignItemModel> = [] | ||
| 1460 | 1459 | ||
| 1461 | if let responseDataDictionary = campaignsData as? [String: AnyObject] { | 1460 | if let responseDataDictionary = campaignsData as? [String: AnyObject] { |
| 1462 | 1461 | ||
| 1463 | if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) { | 1462 | if (responseDataDictionary["MAPP_CAMPAIGNING-status"] as? Int == 1) { |
| 1464 | - let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 1465 | - dynatraceEvent._eventName = "custom_success_campaigns_loyalty" | ||
| 1466 | - dynatraceEvent._parameters = nil | ||
| 1467 | - // SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 1468 | - | ||
| 1469 | if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] { | 1463 | if let responseDataMapp = responseDataDictionary["MAPP_CAMPAIGNING"] as? [String: Any] { |
| 1470 | if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] { | 1464 | if let responseDataCampaigns = responseDataMapp["campaigns"] as? [[String : Any]?] { |
| 1471 | 1465 | ||
| ... | @@ -1475,64 +1469,24 @@ public class swiftApi { | ... | @@ -1475,64 +1469,24 @@ public class swiftApi { |
| 1475 | campaignsArray.append(tempCampaign) | 1469 | campaignsArray.append(tempCampaign) |
| 1476 | } | 1470 | } |
| 1477 | } | 1471 | } |
| 1478 | - } | ||
| 1479 | - } else { | ||
| 1480 | - getCampaignsCallback(nil) | ||
| 1481 | - } | ||
| 1482 | - | ||
| 1483 | - swiftApi().getCampaignsPersonalizedAsync(language: language, filters: filters, {campaignsPersonalizedData in | ||
| 1484 | - | ||
| 1485 | - campaignsArray = campaignsArray + (campaignsPersonalizedData ?? []) | ||
| 1486 | 1472 | ||
| 1487 | swiftApi().setUniqueCampaignList(campaignsArray) | 1473 | swiftApi().setUniqueCampaignList(campaignsArray) |
| 1488 | 1474 | ||
| 1489 | - carouselArray = campaignsArray.filter { | 1475 | + let sortedCampaigns = campaignsArray.sorted { |
| 1490 | - let tempCampaign = $0 | 1476 | + ($0._sorting ?? 0) < ($1._sorting ?? 0) |
| 1491 | - let isCarouselItem = (tempCampaign._carousel != nil) && (tempCampaign._carousel == "true") | ||
| 1492 | - | ||
| 1493 | - return (isCarouselItem) | ||
| 1494 | } | 1477 | } |
| 1495 | - swiftApi().setCarouselList(carouselArray) | ||
| 1496 | - | ||
| 1497 | - var filteredCampaigns = campaignsArray.filter { | ||
| 1498 | - let tempCampaign = $0 | ||
| 1499 | - let isCcmsOffer = (tempCampaign.ccms_offer != nil) && (tempCampaign.ccms_offer != "") && (tempCampaign.ccms_offer == "true") | ||
| 1500 | - let isTelco = (tempCampaign._type != nil && tempCampaign._type == "telco") | ||
| 1501 | 1478 | ||
| 1502 | - return (!(isCcmsOffer || isTelco)) | 1479 | + getCampaignsCallback(sortedCampaigns) |
| 1503 | } | 1480 | } |
| 1504 | - | 1481 | + } else { |
| 1505 | - // if (swiftApi().getConsumerInternal()?._answered == true) { | 1482 | + getCampaignsCallback(nil) |
| 1506 | - filteredCampaigns = filteredCampaigns.filter { $0.offer_category != "questionnaire" } | ||
| 1507 | - // } | ||
| 1508 | - | ||
| 1509 | - let sortedCampaigns = filteredCampaigns.sorted { | ||
| 1510 | - ($0._sorting ?? 0) < ($1._sorting ?? 0) | ||
| 1511 | } | 1483 | } |
| 1512 | 1484 | ||
| 1513 | - getCampaignsCallback(sortedCampaigns); | ||
| 1514 | - | ||
| 1515 | - // SwiftEventBus.post("campaigns_retrieved") | ||
| 1516 | - }, failureCallback: {errorCode in | ||
| 1517 | - | ||
| 1518 | - failureCallback(errorCode) | ||
| 1519 | - }) | ||
| 1520 | - | ||
| 1521 | } else { | 1485 | } else { |
| 1522 | - let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 1523 | - dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 1524 | - dynatraceEvent._parameters = nil | ||
| 1525 | - // SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 1526 | - | ||
| 1527 | getCampaignsCallback(nil) | 1486 | getCampaignsCallback(nil) |
| 1528 | } | 1487 | } |
| 1529 | 1488 | ||
| 1530 | } else { | 1489 | } else { |
| 1531 | - let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 1532 | - dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 1533 | - dynatraceEvent._parameters = nil | ||
| 1534 | - // SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 1535 | - | ||
| 1536 | getCampaignsCallback(nil) | 1490 | getCampaignsCallback(nil) |
| 1537 | } | 1491 | } |
| 1538 | } | 1492 | } |
| ... | @@ -1542,11 +1496,6 @@ public class swiftApi { | ... | @@ -1542,11 +1496,6 @@ public class swiftApi { |
| 1542 | print(error) | 1496 | print(error) |
| 1543 | print("====================") | 1497 | print("====================") |
| 1544 | 1498 | ||
| 1545 | - let dynatraceEvent = swiftApi.LoyaltySDKDynatraceEventModel() | ||
| 1546 | - dynatraceEvent._eventName = "custom_error_campaigns_loyalty" | ||
| 1547 | - dynatraceEvent._parameters = nil | ||
| 1548 | - // SwiftEventBus.post("dynatrace", sender: dynatraceEvent) | ||
| 1549 | - | ||
| 1550 | getCampaignsCallback(nil) | 1499 | getCampaignsCallback(nil) |
| 1551 | } | 1500 | } |
| 1552 | } | 1501 | } | ... | ... |
-
Please register or login to post a comment