Manos Chorianopoulos

market history fixes

......@@ -34,16 +34,41 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
messageLabel.layer.borderColor = UIColor(rgb: 0x1DA6B9).cgColor
messageLabel.layer.cornerRadius = 5
let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
// messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"
}
}
extension AnalysisHeaderMessageViewCell {
func configureCell(isEmpty: Bool, isMarket: Bool) {
if (isEmpty == true) {
emptyLabel.isHidden = false
} else {
emptyLabel.isHidden = true
}
if (isMarket == true) {
itemImage.image = UIImage(named: "ic_history_market", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
let oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = swiftApi().getOldUnifiedCouponList()
let oldUnifiedCouponListLength = oldUnifiedCouponList.count
var unifiedCouponsDiscount: Float = 0.0
for coupon in oldUnifiedCouponList {
if let discountFloat = Float(coupon.discount ?? "0.0") {
unifiedCouponsDiscount += discountFloat
}
}
let totalCouponDiscount = Float(round(100 * unifiedCouponsDiscount) / 100)
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
// messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"
let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
let coupBoldText = totalCouponDiscountString + "€"
let coupNormalText2 = " σε προσφορές από "
let coupBoldText2 = String(loyaltyBadge._couponCount)
let coupBoldText2 = String(oldUnifiedCouponListLength)
let coupNormalText3 = " κουπόνια!"
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PFSquareSansPro-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16)]
......@@ -60,22 +85,34 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
coupAttributedString.append(coupBoldString2)
coupAttributedString.append(coupNormalString3)
messageLabel.attributedText = coupAttributedString
}
}
extension AnalysisHeaderMessageViewCell {
func configureCell(isEmpty: Bool, isMarket: Bool) {
if (isEmpty == true) {
emptyLabel.isHidden = false
} else {
emptyLabel.isHidden = true
}
if (isMarket == true) {
itemImage.image = UIImage(named: "ic_history_market", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
} else {
itemImage.image = UIImage(named: "ic_gift_circle_2", in: MyEmptyClass.resourceBundle(), compatibleWith: nil)
let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
let coupNormalText1 = "Μέχρι τώρα έχεις κερδίσει "
let coupBoldText = totalCouponDiscountString + "€"
let coupNormalText2 = " σε προσφορές από "
let coupBoldText2 = String(loyaltyBadge._couponCount)
let coupNormalText3 = " κουπόνια!"
let attrRegular = [NSAttributedString.Key.font : UIFont(name: "PFSquareSansPro-Regular", size: 17) ?? UIFont.systemFont(ofSize: 16)]
let attrBold = [NSAttributedString.Key.font : UIFont(name: "PFSquareSansPro-Bold", size: 17) ?? UIFont.boldSystemFont(ofSize: 16)]
let coupAttributedString = NSMutableAttributedString(string:coupNormalText1, attributes:attrRegular)
let coupBoldString = NSMutableAttributedString(string: coupBoldText, attributes:attrBold)
let coupNormalString2 = NSMutableAttributedString(string:coupNormalText2, attributes:attrRegular)
let coupBoldString2 = NSMutableAttributedString(string: coupBoldText2, attributes:attrBold)
let coupNormalString3 = NSMutableAttributedString(string:coupNormalText3, attributes:attrRegular)
coupAttributedString.append(coupBoldString)
coupAttributedString.append(coupNormalString2)
coupAttributedString.append(coupBoldString2)
coupAttributedString.append(coupNormalString3)
messageLabel.attributedText = coupAttributedString
}
}
......
......@@ -118,4 +118,42 @@ extension AnalysisItemViewCell {
// subtitleLabel.text = htmlText.htmlToString
}
func configureCell(item: swiftApi.CouponItemModel, isMarket: Bool) {
// COUPONSET: desc, img_preview, name, terms, merchant_uuid
// COUPON: coupon, expiration, discount, status
// MERCHANT: _img_preview,_admin_name
// let merchantList:Array<swiftApi.MerchantModel> = swiftApi().getMerchantList()
// let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
//
// titleLabel.text = ""
//
// for merchant in merchantList {
// if (merchant._uuid == couponSetData?.merchant_uuid) {
// // itemImage.load(link: merchant._img_preview, placeholder: UIImage(), cache: URLCache())
// self.postImageURL = merchant._img_preview
// titleLabel.text = merchant._admin_name
// break;
// }
// }
titleLabel.text = item.name
self.postImageURL = item.image
dateLabel.text = item.redeemed ?? ""
let priceFloat = Float(round(100 * (Float(item.discount ?? "0.0") ?? 0.0 )) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
subtitleLabel.text = "Έκπτωτικό κουπόνι"
// subtitleLabel.text = couponSetData?.short_description ?? ""
// OR
// let htmlText = couponSetData?.inner_text ?? ""
// subtitleLabel.text = htmlText.htmlToString
}
}
......
......@@ -524,7 +524,7 @@
<scene sceneID="Unf-jQ-yhe">
<objects>
<tableViewController storyboardIdentifier="MarketSharingHistoryViewController" id="R2a-Tw-n8n" customClass="MarketSharingHistoryViewController" customModule="SwiftWarplyFramework" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="CQc-tP-sD3">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="CQc-tP-sD3">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
......@@ -746,7 +746,7 @@
<scene sceneID="33f-Co-X5F">
<objects>
<tableViewController storyboardIdentifier="MarketHistoryViewController" id="iFj-6f-ytl" customClass="MarketHistoryViewController" customModule="SwiftWarplyFramework" customModuleProvider="target" sceneMemberID="viewController">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="Ruu-TU-GVv">
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="none" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="-1" estimatedSectionHeaderHeight="-1" sectionFooterHeight="-1" estimatedSectionFooterHeight="-1" id="Ruu-TU-GVv">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
......
......@@ -9,7 +9,7 @@ import UIKit
class MarketHistoryViewController: AnalysisChildViewController {
var loading: Bool = false
var items: Array<swiftApi.CouponItemModel> = swiftApi().getOldCouponList()
var items: Array<swiftApi.CouponItemModel> = swiftApi().getOldUnifiedCouponList()
var showMore = false
// TODO: remove this when configuring model
......@@ -38,7 +38,7 @@ class MarketHistoryViewController: AnalysisChildViewController {
showLoading()
items = swiftApi().getOldCouponList()
items = swiftApi().getOldUnifiedCouponList()
self.showMore = (self.items.count > 3)
......@@ -131,7 +131,7 @@ class MarketHistoryViewController: AnalysisChildViewController {
}
let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! SwiftWarplyFramework.AnalysisItemViewCell
cell.configureCell(item: items[indexPath.row])
cell.configureCell(item: items[indexPath.row], isMarket: true)
return cell
}
......@@ -142,7 +142,7 @@ class MarketHistoryViewController: AnalysisChildViewController {
}
if (self.showMore && indexPath.row == 3) {
self.items = swiftApi().getOldCouponList()
self.items = swiftApi().getOldUnifiedCouponList()
self.showMore = false
self.tableView.reloadData()
}
......
......@@ -118,7 +118,7 @@ import SwiftEventBus
if (index == 1) {
swiftApi().logTrackersEvent("click", ("LoyaltyHistoryScreen:" + "TabShared"))
let analysisVC = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SwiftWarplyFramework.SharingHistoryViewController
let analysisVC = storyboard.instantiateViewController(withIdentifier:"MarketSharingHistoryViewController") as! SwiftWarplyFramework.MarketSharingHistoryViewController
analysisVC.index = index;
return analysisVC;
......@@ -126,7 +126,7 @@ import SwiftEventBus
swiftApi().logTrackersEvent("click", ("LoyaltyHistoryScreen:" + "TabExpired"))
let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! SwiftWarplyFramework.HistoryViewController
let analysisVC = storyboard.instantiateViewController(withIdentifier:"MarketHistoryViewController") as! SwiftWarplyFramework.MarketHistoryViewController
analysisVC.index = index;
return analysisVC;
......
......@@ -523,15 +523,12 @@ import SwiftEventBus
}
func updateMarketBadge() {
for uniCoupon in self.unifiedCoupons {
for coupon in uniCoupon._coupons {
if (coupon.status == 1) {
unifiedCouponsDiscount = 0.0
for coupon in swiftApi().getOldUnifiedCouponList() {
if let discountFloat = Float(coupon.discount ?? "0.0") {
unifiedCouponsDiscount += discountFloat
}
}
}
}
if (totalCouponValue == 0.0 && loyaltyBadge._couponCount == 0 && dfyCoupons.count == 0 && coupons.count == 0 && unifiedCoupons.count == 0 && unifiedCouponsDiscount == 0.0) {
emptyView.isHidden = false
......@@ -642,6 +639,18 @@ import SwiftEventBus
@IBAction func marketBadgeButtonAction(_ sender: Any) {
print("Market Badge pressed!")
// TODO: add action - open marketHistory after check
if (self.unifiedCouponsDiscount > 0.0) {
// let firebaseEvent = swiftApi.LoyaltySDKFirebaseEventModel()
// firebaseEvent._eventName = "did_tap_deals_for_you_badge"
// firebaseEvent.setParameter = ("screen", "Loyalty Wallet")
// SwiftEventBus.post("firebase", sender: firebaseEvent)
// swiftApi().logTrackersEvent("click", ("LoyaltyWalletScreen:" + "LoyaltyBanner"))
let storyboard = UIStoryboard(name: "Main", bundle: Bundle(for: MyEmptyClass.self))
let vc = storyboard.instantiateViewController(withIdentifier: "MarketLoyaltyAnalysisViewController") as! SwiftWarplyFramework.MarketLoyaltyAnalysisViewController
self.navigationController?.pushViewController(vc, animated: true)
}
}
}
......
......@@ -18,6 +18,7 @@ public struct GlobalVariables {
static var oldCouponList: Array<swiftApi.CouponItemModel> = []
static var couponSetList: Array<swiftApi.CouponSetItemModel> = []
static var unifiedCouponList: Array<swiftApi.UnifiedCouponModel> = []
static var oldUnifiedCouponList: Array<swiftApi.CouponItemModel> = []
static var loyaltyBadge: swiftApi.LoyaltyBadgeModel = swiftApi.LoyaltyBadgeModel()
static var consumer: swiftApi.ProfileModel?
static var consumerInternal: swiftApi.ProfileModel?
......@@ -153,6 +154,16 @@ public class swiftApi {
}
public func setOldUnifiedCouponList(_ coupons: Array<CouponItemModel>) {
GlobalVariables.oldUnifiedCouponList = coupons
}
public func getOldUnifiedCouponList() -> Array<CouponItemModel> {
return GlobalVariables.oldUnifiedCouponList
}
public func startTrackingSteps(_ getStepsCallback: @escaping (_ steps: Int) -> Void) -> Void {
if (GlobalVariables.trackingStepsEnabled == false) {
......@@ -6852,6 +6863,7 @@ public class swiftApi {
func getUnifiedCallback(_ responseData: [AnyHashable: Any]?) -> Void {
var unifiedCouponsArray:Array<UnifiedCouponModel> = []
var oldUnifiedCouponsArray:Array<CouponItemModel> = []
if let responseDataDictionary = responseData as? [String: AnyObject] {
......@@ -6868,14 +6880,25 @@ public class swiftApi {
if let itemDictionary = item {
if let itemDictionaryStauts = itemDictionary["status"] as? String {
if (itemDictionaryStauts == "active") {
let tempCampaign = UnifiedCouponModel(dictionary: itemDictionary)
unifiedCouponsArray.append(tempCampaign)
let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary)
unifiedCouponsArray.append(tempUniCoupon)
}
// Old Unified Coupons
let tempUniCoupon = UnifiedCouponModel(dictionary: itemDictionary)
for item in tempUniCoupon._coupons {
if (item.status == 0) {
oldUnifiedCouponsArray.append(item)
}
}
}
}
}
swiftApi().setUnifiedCouponList(unifiedCouponsArray)
swiftApi().setOldUnifiedCouponList(oldUnifiedCouponsArray)
successCallback(unifiedCouponsArray)
}
} else {
......