Manos Chorianopoulos

Merge remote-tracking branch 'origin/feat/analysis_vc' into swift_sdk_development

{
"pins" : [
{
"identity" : "resegmentedcontrol",
"kind" : "remoteSourceControl",
"location" : "https://github.com/sh-khashimov/RESegmentedControl",
"state" : {
"revision" : "09d8cbd0da906c06d30fb057ab9902dc9d0e26b9",
"version" : "0.5.1"
}
},
{
"identity" : "rsbarcodes_swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/yeahdongcn/RSBarcodes_Swift",
......
//
// AnalysisChildViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisChildViewController: UITableViewController {
public var index: Int = -1
}
//
// AnalysisHeaderMessageViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisHeaderMessageViewCell: UITableViewCell {
// attributes
@IBOutlet weak var itemImage: UIImageView!
@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 = "Αναλυτικά:"
// message
messageLabel.textColor = UIColor(rgb: 0x435563)
messageLabel.layer.borderWidth = 1.0
messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor
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) + " κουπόνια!"
}
}
extension AnalysisHeaderMessageViewCell {
func configureCell(item: AnalysisItem) {
// TODO: TO BE IMPLEMENTED
}
}
//
// AnalysisHeaderViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisHeaderViewCell: UITableViewCell {
// attributes
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
// 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 = "Αναλυτικά:"
}
}
extension AnalysisHeaderViewCell {
func configureCell(item: AnalysisItem) {
// TODO: TO BE IMPLEMENTED
}
}
//
// AnalysisItem.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
public class AnalysisItem: Codable {
// attributes
public var date: Date
public var image_url: String?
public var title: String?
public let subtitle: String?
public var price: Float
// initialization
public init() {
self.date = Date()
self.image_url = ""
self.title = ""
self.subtitle = ""
self.price = 4.0
}
}
//
// AnalysisItemViewCell.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class AnalysisItemViewCell: UITableViewCell {
@IBOutlet weak var dateLabel: UILabel!
@IBOutlet weak var itemImage: UIImageView!
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var priceLabel: UILabel!
@IBOutlet weak var subtitleLabel: UILabel!
// lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// date
dateLabel.textColor = UIColor(rgb: 0x435563)
// title
titleLabel.textColor = UIColor(rgb: 0x435563)
// price
priceLabel.textColor = UIColor(rgb: 0x435563)
// subtitle
subtitleLabel.textColor = UIColor(rgb: 0x8B97A3)
}
}
extension AnalysisItemViewCell {
func configureCell(item: swiftApi.SharingCouponModel) {
dateLabel.text = item._date
//itemImage.image =
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._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
}
}
......@@ -2,30 +2,133 @@
// LoyaltyAnalysisViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 10/6/22.
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
import RESegmentedControl
@objc public class LoyaltyAnalysisViewController: UIViewController {
@IBOutlet weak var leftButton: UIButton!
@IBOutlet weak var rightButton: UIButton!
@IBOutlet weak var contentView: UIView!
var pageController: UIPageViewController!
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
// Do any additional setup after loading the view.
// setup view
setBackButton()
setNavigationTitle("Ανάλυση")
// tab
leftButton.setTitle("Εξαργυρωμένα", for:.normal)
leftButton.backgroundColor = . clear
leftButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
rightButton.setTitle("Μοιρασμένα δώρα", for:.normal)
rightButton.backgroundColor = . clear
rightButton.setTitleColor(UIColor(rgb: 0x2EAFB9), for:.normal)
// pages
pageController = UIPageViewController(transitionStyle:.scroll, navigationOrientation:.horizontal)
pageController.dataSource = self;
pageController.delegate = self;
pageController.view.frame = contentView.bounds;
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 = storyboard.instantiateViewController(withIdentifier:"SharingHistoryViewController") as! SharingHistoryViewController
analysisVC.index = index;
return analysisVC;
}
let analysisVC = storyboard.instantiateViewController(withIdentifier:"HistoryViewController") as! HistoryViewController
analysisVC.index = index;
return analysisVC;
}
// MARK: - Handlers
@IBAction func handleLeft() {
let analysisVC = self.viewControllerAt(0)
pageController.setViewControllers([analysisVC!], direction:.reverse, animated:true)
}
@IBAction func handleRight() {
let analysisVC = self.viewControllerAt(1)
pageController.setViewControllers([analysisVC!], direction:.forward, animated:true)
}
}
// MARK: - PageViewController
extension LoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
/*
// MARK: - Navigation
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 1) {
return nil;
}
*/
index += 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
if let analysisVC = viewController as? AnalysisChildViewController {
var index = analysisVC.index
if (index == 0) {
return nil;
}
index -= 1;
return viewControllerAt(index);
}
return nil;
}
public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
if (!completed) {
return;
}
if let childVCs = pageViewController.viewControllers as? [AnalysisChildViewController] {
let currentIndex = childVCs[0].index
if (currentIndex == 0) {
leftButton.isSelected = true
rightButton.isSelected = false
} else {
leftButton.isSelected = false
rightButton.isSelected = true
}
}
}
}
......
......@@ -63,6 +63,7 @@
- (NSDictionary*) getCoupons;
- (NSDictionary*) getTransactionHistory;
- (NSDictionary*) getPointsHistory;
- (NSDictionary*) getSharingHistory;
- (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes;
- (NSDictionary*)getAddress;
- (NSDictionary*)editAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes andUuid:(NSString*)uuid;
......
......@@ -940,6 +940,35 @@ NSString *VERIFY_URL = @"/partners/cosmote/verify";
return resp;
}
- (NSDictionary*) getSharingHistory
{
__block NSDictionary *resp = [NSDictionary alloc];
__block BOOL isRunLoopNested = NO;
__block BOOL isOperationCompleted = NO;
[[Warply sharedService] getSharingHistoryWithSuccessBlock:^(NSDictionary *response) {
resp = response;
isOperationCompleted = YES;
if (isRunLoopNested) {
CFRunLoopStop(CFRunLoopGetCurrent()); // CFRunLoopRun() returns
}
} failureBlock:^(NSError *error) {
NSLog(@"%@", error);
resp = nil;
isOperationCompleted = YES;
if (isRunLoopNested) {
CFRunLoopStop(CFRunLoopGetCurrent()); // CFRunLoopRun() returns
}
}];
if ( ! isOperationCompleted) {
isRunLoopNested = YES;
NSLog(@"Waiting...");
CFRunLoopRun(); // Magic!
isRunLoopNested = NO;
}
return resp;
}
- (NSDictionary*)addAddress:(NSString*)friendlyName andAddressName:(NSString*)addressName andAddressNumber:(NSString*)addressNumber andPostalCode:(NSString*)postalCode andFloorNumber:(NSNumber*)floorNumber andDoorbell:(NSString*)doorbel andRegion:(NSString*)region andLatitude:(NSString*)latitude andLongitude:(NSString*)longitude andNotes:(NSString*)notes {
__block NSDictionary *resp = [NSDictionary alloc];
__block BOOL isRunLoopNested = NO;
......
//
// SharingHistoryViewController.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import UIKit
class SharingHistoryViewController: AnalysisChildViewController {
var loading: Bool = false
var items: Array<swiftApi.SharingCouponModel> = Array()
// TODO: remove this when configuring model
let hasMessage = false
// 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()
swiftApi().getSharingHistoryAsync(responseCallback)
}
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.SharingCouponModel>?) -> 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
}
}
//
// UIColorExtensions.swift
// SwiftWarplyFramework
//
// Created by Manos Chorianopoulos on 18/7/22.
//
import Foundation
import UIKit
extension UIColor {
convenience init(rgb: UInt) {
self.init(
red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgb & 0x0000FF) / 255.0,
alpha: CGFloat(1.0)
)
}
}
......@@ -156,7 +156,6 @@ public class swiftApi {
return GlobalVariables.dfyCoupons
}
public class CouponSetItemModel: Codable {
public let uuid: String?
public let admin_name: String?
......