Dimitris Togias

fix implementation details

......@@ -19,6 +19,7 @@
1EBE97212865EE460080EFF7 /* MFYInboxTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */; };
1EBF5F072840E13F00B8B17F /* SwiftEventBus in Frameworks */ = {isa = PBXBuildFile; productRef = 1EBF5F062840E13F00B8B17F /* SwiftEventBus */; };
7630AD9A6242D60846D6750C /* Pods_SwiftWarplyFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C0D5F56DD4E5371A50AD2D87 /* Pods_SwiftWarplyFramework.framework */; };
A04D31DE288FF670000E43B5 /* HistoryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A04D31DD288FF670000E43B5 /* HistoryViewController.swift */; };
A079366E2885D07700064122 /* AnalysisChildViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366D2885D07700064122 /* AnalysisChildViewController.swift */; };
A07936702885D95600064122 /* AnalysisItemViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = A079366F2885D95600064122 /* AnalysisItemViewCell.swift */; };
A07936732885E67400064122 /* AnalysisItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = A07936722885E67400064122 /* AnalysisItem.swift */; };
......@@ -165,6 +166,7 @@
1EB5F4C728536FD60016F36E /* StepsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StepsViewController.swift; sourceTree = "<group>"; };
1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoyaltyAnalysisViewController.swift; sourceTree = "<group>"; };
1EBE97202865EE460080EFF7 /* MFYInboxTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MFYInboxTableViewCell.swift; sourceTree = "<group>"; };
A04D31DD288FF670000E43B5 /* HistoryViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HistoryViewController.swift; sourceTree = "<group>"; };
A079366D2885D07700064122 /* AnalysisChildViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisChildViewController.swift; sourceTree = "<group>"; };
A079366F2885D95600064122 /* AnalysisItemViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItemViewCell.swift; sourceTree = "<group>"; };
A07936722885E67400064122 /* AnalysisItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnalysisItem.swift; sourceTree = "<group>"; };
......@@ -333,6 +335,7 @@
A079367A2885F2D100064122 /* cells */,
1EB5F4C9285370C90016F36E /* LoyaltyAnalysisViewController.swift */,
A079366D2885D07700064122 /* AnalysisChildViewController.swift */,
A04D31DD288FF670000E43B5 /* HistoryViewController.swift */,
A09DBCAD2888BA8100DD50B0 /* SharingHistoryViewController.swift */,
);
name = analysis;
......@@ -888,6 +891,7 @@
E6A7791A282933E60045BBA8 /* WLAPPActionHandler.m in Sources */,
E6A778E1282933E60045BBA8 /* CouponViewController.swift in Sources */,
E6A77924282933E70045BBA8 /* NSString+SSToolkitAdditions.m in Sources */,
A04D31DE288FF670000E43B5 /* HistoryViewController.swift in Sources */,
E6A7792A282933E70045BBA8 /* AFNetworkActivityIndicatorManager.m in Sources */,
E6A77914282933E60045BBA8 /* WLUserManager.m in Sources */,
1EB236AF28816CAC0063777A /* NumbersTableViewCell.swift in Sources */,
......
......@@ -14,10 +14,15 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
@IBOutlet weak var messageLabel: UILabel!
@IBOutlet weak var titleLabel: UILabel!
public var loyaltyBadge:swiftApi.LoyaltyBadgeModel = swiftApi().getLoyaltyBadge()
// lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// image
itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
// title
titleLabel.textColor = UIColor(rgb: 0x435563)
titleLabel.text = "Αναλυτικά:"
......@@ -26,7 +31,12 @@ class AnalysisHeaderMessageViewCell: UITableViewCell {
messageLabel.textColor = UIColor(rgb: 0x435563)
messageLabel.layer.borderWidth = 1.0
messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor
messageLabel.text = "Μέχρι τώρα έχεις κερδίσει 20,00€ σε προσφορές από 3 κουπόνια!"
let totalCouponDiscount = Float(round(100 * loyaltyBadge._value) / 100)
var totalCouponDiscountString = "0"
totalCouponDiscountString = String(format: "%.2f", totalCouponDiscount).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
messageLabel.text = "Μέχρι τώρα έχεις κερδίσει " + totalCouponDiscountString + "€ σε προσφορές από " + String(loyaltyBadge._couponCount) + " κουπόνια!"
}
}
......
......@@ -17,6 +17,9 @@ class AnalysisHeaderViewCell: UITableViewCell {
override func awakeFromNib() {
super.awakeFromNib()
// image
itemImage.image = UIImage(named: "ic_gift_circle", in: Bundle(for: MyEmptyClass.self), compatibleWith: nil)
// title
titleLabel.textColor = UIColor(rgb: 0x435563)
titleLabel.text = "Αναλυτικά:"
......
......@@ -36,25 +36,39 @@ class AnalysisItemViewCell: UITableViewCell {
extension AnalysisItemViewCell {
func configureCell(item: swiftApi.SharingCouponModel) {
// TODO: this is not optimal. we need a static date formatter. we cannot instantiate a new object each time we render a new item.
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "dd-MM-yyyy"
if let date = item.date {
let dateString = dateFormatter.string(from: date)
dateLabel.text = dateString
} else {
dateLabel.text = ""
}
dateLabel.text = item._date
//itemImage.image =
titleLabel.text = item.name
priceLabel.text = String(format: "%.2f€", item.discount)
titleLabel.text = item._name
let priceFloat = Float(round(100 * (Float(item._discount) ?? 0.0)) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
if ("sent" == item.sharingType) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς @%", "69740000000")
} else if ("received" == item.sharingType) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από @%", "69740000000")
if ("sent" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι προς " + item._receiver_msisdn)
} else if ("received" == item._sharing_type) {
subtitleLabel.text = String(format: "Εκπτωτικό κουπόνι από " + item._sender_msisdn)
}
}
func configureCell(item: swiftApi.CouponItemModel) {
// COUPONSET: desc, img_preview, name, terms
// COUPON: coupon, expiration, discount, status
let couponSetData: swiftApi.CouponSetItemModel? = item.couponset_data
dateLabel.text = item.expiration ?? "" // TODO: change
itemImage.load(link: couponSetData?.img_preview ?? "", placeholder: UIImage(), cache: URLCache())
titleLabel.text = couponSetData?.name ?? ""
let priceFloat = Float(round(100 * (Float(item.discount ?? "") ?? 0.0)) / 100)
var priceString = "0"
priceString = String(format: "%.2f", priceFloat).replacingOccurrences(of: ".", with: ",", options: .literal, range: nil)
priceLabel.text = priceString + "€"
subtitleLabel.text = couponSetData?.short_description ?? ""
}
}
......
//
// HistoryViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class HistoryViewController: AnalysisChildViewController {
var loading: Bool = false
var items: Array<swiftApi.CouponItemModel> = swiftApi().getCouponList()
// TODO: remove this when configuring model
let hasMessage = true
// lifecycle
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl?.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged)
handleRefresh(self.refreshControl!)
}
// mvp
@objc func load() {
if (loading) {
return;
}
showLoading()
items = swiftApi().getOldCouponList()
showContent()
self.tableView.reloadData()
}
private func showLoading() {
loading = true
if (self.refreshControl!.isRefreshing) {
return;
}
self.refreshControl!.beginRefreshing()
}
private func showError() {
}
private func showContent() {
loading = false
self.refreshControl!.endRefreshing()
}
// private
func responseCallback (_ data: Array<swiftApi.CouponItemModel>?) -> Void {
self.items = data!
showContent()
DispatchQueue.main.async {
self.tableView.reloadData()
}
}
@objc func handleRefresh(_ refreshControl: UIRefreshControl) {
self.perform(_: #selector(load), with: nil, afterDelay: 0.5)
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if (section == 0) {
return 1;
}
return items.count
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (indexPath.section == 0) {
return hasMessage ? 380.0 : 280
}
return 140.0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// header
if (indexPath.section == 0) {
if (hasMessage) {
return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderMessageViewCell", for: indexPath) as! AnalysisHeaderMessageViewCell
}
return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderViewCell", for: indexPath) as! AnalysisHeaderViewCell
}
let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! AnalysisItemViewCell
cell.configureCell(item: items[indexPath.row])
return cell
}
}
......@@ -21,7 +21,7 @@ import RESegmentedControl
// setup view
setBackButton()
setNavigationTitle("Analysis")
setNavigationTitle("Ανάλυση")
// tab
let titles = ["Εξαργυρωμένα", "Μοιρασμένα δώρα"]
......@@ -41,24 +41,28 @@ import RESegmentedControl
addChild(pageController)
contentView.addSubview(pageController.view)
pageController .didMove(toParent: self)
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:false)
}
////////////////////////////////////////////////////////////////////////////////
private func viewControllerAt(_ index:Int) -> AnalysisChildViewController?
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if (index == 1) {
let analysisVC = SharingHistoryViewController()
let analysisVC = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SharingHistoryViewController
analysisVC.index = index;
return analysisVC;
}
let analysisVC = AnalysisChildViewController()
let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! HistoryViewController
analysisVC.index = index;
return analysisVC;
}
}
// MARK: - PageViewController
......
......@@ -13,7 +13,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
var items: Array<swiftApi.SharingCouponModel> = Array()
// TODO: remove this when configuring model
let hasMessage = true
let hasMessage = false
// lifecycle
override func viewDidLoad() {
......@@ -35,7 +35,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
showLoading()
// TODO: Implement API call
swiftApi().getSharingHistoryAsync(responseCallback)
}
private func showLoading() {
......@@ -53,7 +53,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
private func showContent() {
loading = true
loading = false
self.refreshControl!.endRefreshing()
}
......@@ -90,7 +90,7 @@ class SharingHistoryViewController: AnalysisChildViewController {
return hasMessage ? 380.0 : 280
}
return 160.0
return 140.0
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
......