Dimitris Togias

implement analysis vc

{
"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
var items: Array<AnalysisItem> = Array()
// 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)
loadData()
}
// mvp
private func loadData() {
self.items = Array()
}
private func showLoading() {
}
private func showError() {
}
private func showContent() {
}
// private
@objc func handleRefresh(_ refreshControl: UIRefreshControl) {
loadData()
}
// 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 160.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
}
}
//
// 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!
// lifecycle
override func awakeFromNib() {
super.awakeFromNib()
// 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
messageLabel.text = "Μέχρι τώρα έχεις κερδίσει 20,00€ σε προσφορές από 3 κουπόνια!"
}
}
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()
// 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: AnalysisItem) {
// 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"
dateLabel.text = dateFormatter.string(from: item.date)
//itemImage.image =
titleLabel.text = item.title
priceLabel.text = String(format: "%.2f€", item.price)
subtitleLabel.text = item.subtitle
}
}
......@@ -2,30 +2,102 @@
// 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 tabView: RESegmentedControl!
@IBOutlet weak var contentView: UIView!
var pageController: UIPageViewController!
public override func viewDidLoad() {
super.viewDidLoad()
self.hidesBottomBarWhenPushed = true
// setup view
setBackButton()
setNavigationTitle("Analysis")
// tab
let titles = ["Εξαργυρωμένα", "Μοιρασμένα δώρα"]
var segmentItems: [SegmentModel] {
return titles.map({ SegmentModel(title: $0) })
}
// Do any additional setup after loading the view.
let preset = BootstapPreset(backgroundColor: .white, selectedBackgroundColor: .white, border)
tabView.configure(segmentItems: segmentItems, preset: preset)
// 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)
}
////////////////////////////////////////////////////////////////////////////////
private func viewControllerAt(_ index:Int) -> AnalysisChildViewController?
{
let analysisVC = AnalysisChildViewController()
analysisVC.index = index;
return analysisVC;
}
/*
// MARK: - Navigation
}
// 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.
// MARK: - PageViewController
extension LoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate {
public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
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
tabView.selectedSegmentIndex = currentIndex
}
}
*/
}
......
//
// 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)
)
}
}