Showing
10 changed files
with
343 additions
and
9 deletions
This diff is collapsed. Click to expand it.
1 | { | 1 | { |
2 | "pins" : [ | 2 | "pins" : [ |
3 | { | 3 | { |
4 | + "identity" : "resegmentedcontrol", | ||
5 | + "kind" : "remoteSourceControl", | ||
6 | + "location" : "https://github.com/sh-khashimov/RESegmentedControl", | ||
7 | + "state" : { | ||
8 | + "revision" : "09d8cbd0da906c06d30fb057ab9902dc9d0e26b9", | ||
9 | + "version" : "0.5.1" | ||
10 | + } | ||
11 | + }, | ||
12 | + { | ||
4 | "identity" : "rsbarcodes_swift", | 13 | "identity" : "rsbarcodes_swift", |
5 | "kind" : "remoteSourceControl", | 14 | "kind" : "remoteSourceControl", |
6 | "location" : "https://github.com/yeahdongcn/RSBarcodes_Swift", | 15 | "location" : "https://github.com/yeahdongcn/RSBarcodes_Swift", | ... | ... |
1 | +// | ||
2 | +// AnalysisChildViewController.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisChildViewController: UITableViewController { | ||
11 | + | ||
12 | + public var index: Int = -1 | ||
13 | + var items: Array<AnalysisItem> = Array() | ||
14 | + | ||
15 | + // TODO: remove this when configuring model | ||
16 | + let hasMessage = true | ||
17 | + | ||
18 | + // lifecycle | ||
19 | + override func viewDidLoad() { | ||
20 | + | ||
21 | + super.viewDidLoad() | ||
22 | + | ||
23 | + self.refreshControl = UIRefreshControl() | ||
24 | + self.refreshControl?.addTarget(self, action: #selector(handleRefresh(_:)), for: .valueChanged) | ||
25 | + | ||
26 | + loadData() | ||
27 | + } | ||
28 | + | ||
29 | + // mvp | ||
30 | + private func loadData() { | ||
31 | + | ||
32 | + self.items = Array() | ||
33 | + } | ||
34 | + | ||
35 | + private func showLoading() { | ||
36 | + } | ||
37 | + | ||
38 | + private func showError() { | ||
39 | + } | ||
40 | + | ||
41 | + private func showContent() { | ||
42 | + } | ||
43 | + | ||
44 | + // private | ||
45 | + @objc func handleRefresh(_ refreshControl: UIRefreshControl) { | ||
46 | + | ||
47 | + loadData() | ||
48 | + } | ||
49 | + | ||
50 | + // MARK: - Table view data source | ||
51 | + override func numberOfSections(in tableView: UITableView) -> Int { | ||
52 | + return 2 | ||
53 | + } | ||
54 | + | ||
55 | + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
56 | + if (section == 0) { | ||
57 | + return 1; | ||
58 | + } | ||
59 | + | ||
60 | + return items.count | ||
61 | + } | ||
62 | + | ||
63 | + override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
64 | + if (indexPath.section == 0) { | ||
65 | + return hasMessage ? 380.0 : 280 | ||
66 | + } | ||
67 | + | ||
68 | + return 160.0 | ||
69 | + } | ||
70 | + | ||
71 | + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
72 | + | ||
73 | + // header | ||
74 | + if (indexPath.section == 0) { | ||
75 | + if (hasMessage) { | ||
76 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderMessageViewCell", for: indexPath) as! AnalysisHeaderMessageViewCell | ||
77 | + } | ||
78 | + | ||
79 | + return tableView.dequeueReusableCell(withIdentifier: "AnalysisHeaderViewCell", for: indexPath) as! AnalysisHeaderViewCell | ||
80 | + } | ||
81 | + | ||
82 | + let cell = tableView.dequeueReusableCell(withIdentifier: "AnalysisItemViewCell", for: indexPath) as! AnalysisItemViewCell | ||
83 | + cell.configureCell(item: items[indexPath.row]) | ||
84 | + | ||
85 | + return cell | ||
86 | + } | ||
87 | +} |
1 | +// | ||
2 | +// AnalysisHeaderMessageViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisHeaderMessageViewCell: UITableViewCell { | ||
11 | + | ||
12 | + // attributes | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var messageLabel: UILabel! | ||
15 | + @IBOutlet weak var titleLabel: UILabel! | ||
16 | + | ||
17 | + // lifecycle | ||
18 | + override func awakeFromNib() { | ||
19 | + super.awakeFromNib() | ||
20 | + | ||
21 | + // title | ||
22 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
23 | + titleLabel.text = "Αναλυτικά:" | ||
24 | + | ||
25 | + // message | ||
26 | + messageLabel.textColor = UIColor(rgb: 0x435563) | ||
27 | + messageLabel.layer.borderWidth = 1.0 | ||
28 | + messageLabel.layer.borderColor = UIColor(rgb: 0xB2CE69).cgColor | ||
29 | + messageLabel.text = "Μέχρι τώρα έχεις κερδίσει 20,00€ σε προσφορές από 3 κουπόνια!" | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | +extension AnalysisHeaderMessageViewCell { | ||
34 | + func configureCell(item: AnalysisItem) { | ||
35 | + | ||
36 | + // TODO: TO BE IMPLEMENTED | ||
37 | + } | ||
38 | +} |
1 | +// | ||
2 | +// AnalysisHeaderViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisHeaderViewCell: UITableViewCell { | ||
11 | + | ||
12 | + // attributes | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var titleLabel: UILabel! | ||
15 | + | ||
16 | + // lifecycle | ||
17 | + override func awakeFromNib() { | ||
18 | + super.awakeFromNib() | ||
19 | + | ||
20 | + // title | ||
21 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
22 | + titleLabel.text = "Αναλυτικά:" | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +extension AnalysisHeaderViewCell { | ||
27 | + func configureCell(item: AnalysisItem) { | ||
28 | + | ||
29 | + // TODO: TO BE IMPLEMENTED | ||
30 | + } | ||
31 | +} |
1 | +// | ||
2 | +// AnalysisItem.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +public class AnalysisItem: Codable { | ||
11 | + | ||
12 | + // attributes | ||
13 | + public var date: Date | ||
14 | + public var image_url: String? | ||
15 | + public var title: String? | ||
16 | + public let subtitle: String? | ||
17 | + public var price: Float | ||
18 | + | ||
19 | + // initialization | ||
20 | + public init() { | ||
21 | + self.date = Date() | ||
22 | + self.image_url = "" | ||
23 | + self.title = "" | ||
24 | + self.subtitle = "" | ||
25 | + self.price = 4.0 | ||
26 | + } | ||
27 | +} |
1 | +// | ||
2 | +// AnalysisItemViewCell.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import UIKit | ||
9 | + | ||
10 | +class AnalysisItemViewCell: UITableViewCell { | ||
11 | + | ||
12 | + @IBOutlet weak var dateLabel: UILabel! | ||
13 | + @IBOutlet weak var itemImage: UIImageView! | ||
14 | + @IBOutlet weak var titleLabel: UILabel! | ||
15 | + @IBOutlet weak var priceLabel: UILabel! | ||
16 | + @IBOutlet weak var subtitleLabel: UILabel! | ||
17 | + | ||
18 | + // lifecycle | ||
19 | + override func awakeFromNib() { | ||
20 | + super.awakeFromNib() | ||
21 | + | ||
22 | + // date | ||
23 | + dateLabel.textColor = UIColor(rgb: 0x435563) | ||
24 | + | ||
25 | + // title | ||
26 | + titleLabel.textColor = UIColor(rgb: 0x435563) | ||
27 | + | ||
28 | + // price | ||
29 | + priceLabel.textColor = UIColor(rgb: 0x435563) | ||
30 | + | ||
31 | + // subtitle | ||
32 | + subtitleLabel.textColor = UIColor(rgb: 0x8B97A3) | ||
33 | + } | ||
34 | +} | ||
35 | + | ||
36 | +extension AnalysisItemViewCell { | ||
37 | + func configureCell(item: AnalysisItem) { | ||
38 | + | ||
39 | + // TODO: this is not optimal. we need a static date formatter. we cannot instantiate a new object each time we render a new item. | ||
40 | + let dateFormatter = DateFormatter() | ||
41 | + dateFormatter.dateFormat = "dd-MM-yyyy" | ||
42 | + | ||
43 | + dateLabel.text = dateFormatter.string(from: item.date) | ||
44 | + //itemImage.image = | ||
45 | + titleLabel.text = item.title | ||
46 | + priceLabel.text = String(format: "%.2f€", item.price) | ||
47 | + subtitleLabel.text = item.subtitle | ||
48 | + | ||
49 | + } | ||
50 | +} |
... | @@ -2,30 +2,102 @@ | ... | @@ -2,30 +2,102 @@ |
2 | // LoyaltyAnalysisViewController.swift | 2 | // LoyaltyAnalysisViewController.swift |
3 | // SwiftWarplyFramework | 3 | // SwiftWarplyFramework |
4 | // | 4 | // |
5 | -// Created by Manos Chorianopoulos on 10/6/22. | 5 | +// Created by Manos Chorianopoulos on 18/7/22. |
6 | // | 6 | // |
7 | 7 | ||
8 | import UIKit | 8 | import UIKit |
9 | +import RESegmentedControl | ||
9 | 10 | ||
10 | @objc public class LoyaltyAnalysisViewController: UIViewController { | 11 | @objc public class LoyaltyAnalysisViewController: UIViewController { |
11 | 12 | ||
13 | + @IBOutlet weak var tabView: RESegmentedControl! | ||
14 | + @IBOutlet weak var contentView: UIView! | ||
15 | + var pageController: UIPageViewController! | ||
16 | + | ||
12 | public override func viewDidLoad() { | 17 | public override func viewDidLoad() { |
13 | super.viewDidLoad() | 18 | super.viewDidLoad() |
14 | 19 | ||
15 | self.hidesBottomBarWhenPushed = true | 20 | self.hidesBottomBarWhenPushed = true |
16 | 21 | ||
17 | - // Do any additional setup after loading the view. | 22 | + // setup view |
23 | + setBackButton() | ||
24 | + setNavigationTitle("Analysis") | ||
25 | + | ||
26 | + // tab | ||
27 | + let titles = ["Εξαργυρωμένα", "Μοιρασμένα δώρα"] | ||
28 | + var segmentItems: [SegmentModel] { | ||
29 | + return titles.map({ SegmentModel(title: $0) }) | ||
30 | + } | ||
31 | + | ||
32 | + let preset = BootstapPreset(backgroundColor: .white, selectedBackgroundColor: .white, border) | ||
33 | + tabView.configure(segmentItems: segmentItems, preset: preset) | ||
34 | + | ||
35 | + // pages | ||
36 | + pageController = UIPageViewController(transitionStyle:.scroll, navigationOrientation:.horizontal) | ||
37 | + pageController.dataSource = self; | ||
38 | + pageController.delegate = self; | ||
39 | + | ||
40 | + pageController.view.frame = contentView.bounds; | ||
41 | + addChild(pageController) | ||
42 | + contentView.addSubview(pageController.view) | ||
43 | + pageController .didMove(toParent: self) | ||
18 | } | 44 | } |
19 | 45 | ||
46 | + //////////////////////////////////////////////////////////////////////////////// | ||
47 | + private func viewControllerAt(_ index:Int) -> AnalysisChildViewController? | ||
48 | + { | ||
49 | + let analysisVC = AnalysisChildViewController() | ||
50 | + analysisVC.index = index; | ||
51 | + | ||
52 | + return analysisVC; | ||
53 | + } | ||
20 | 54 | ||
21 | - /* | 55 | +} |
22 | - // MARK: - Navigation | 56 | + |
57 | +// MARK: - PageViewController | ||
58 | +extension LoyaltyAnalysisViewController: UIPageViewControllerDataSource, UIPageViewControllerDelegate { | ||
59 | + | ||
60 | + public func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? { | ||
61 | + | ||
62 | + if let analysisVC = viewController as? AnalysisChildViewController { | ||
63 | + var index = analysisVC.index | ||
64 | + if (index == 1) { | ||
65 | + return nil; | ||
66 | + } | ||
67 | + | ||
68 | + index += 1; | ||
69 | + return viewControllerAt(index); | ||
70 | + } | ||
23 | 71 | ||
24 | - // In a storyboard-based application, you will often want to do a little preparation before navigation | 72 | + return nil; |
25 | - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { | ||
26 | - // Get the new view controller using segue.destination. | ||
27 | - // Pass the selected object to the new view controller. | ||
28 | } | 73 | } |
29 | - */ | ||
30 | 74 | ||
75 | + public func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? { | ||
76 | + | ||
77 | + if let analysisVC = viewController as? AnalysisChildViewController { | ||
78 | + var index = analysisVC.index | ||
79 | + if (index == 0) { | ||
80 | + return nil; | ||
81 | + } | ||
82 | + | ||
83 | + index -= 1; | ||
84 | + return viewControllerAt(index); | ||
85 | + } | ||
86 | + | ||
87 | + return nil; | ||
88 | + } | ||
89 | + | ||
90 | + | ||
91 | + public func pageViewController(_ pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) { | ||
92 | + | ||
93 | + if (!completed) { | ||
94 | + return; | ||
95 | + } | ||
96 | + | ||
97 | + | ||
98 | + if let childVCs = pageViewController.viewControllers as? [AnalysisChildViewController] { | ||
99 | + let currentIndex = childVCs[0].index | ||
100 | + tabView.selectedSegmentIndex = currentIndex | ||
101 | + } | ||
102 | + } | ||
31 | } | 103 | } | ... | ... |
This diff is collapsed. Click to expand it.
1 | +// | ||
2 | +// UIColorExtensions.swift | ||
3 | +// SwiftWarplyFramework | ||
4 | +// | ||
5 | +// Created by Manos Chorianopoulos on 18/7/22. | ||
6 | +// | ||
7 | + | ||
8 | +import Foundation | ||
9 | +import UIKit | ||
10 | + | ||
11 | +extension UIColor { | ||
12 | + convenience init(rgb: UInt) { | ||
13 | + self.init( | ||
14 | + red: CGFloat((rgb & 0xFF0000) >> 16) / 255.0, | ||
15 | + green: CGFloat((rgb & 0x00FF00) >> 8) / 255.0, | ||
16 | + blue: CGFloat(rgb & 0x0000FF) / 255.0, | ||
17 | + alpha: CGFloat(1.0) | ||
18 | + ) | ||
19 | + } | ||
20 | +} |
-
Please register or login to post a comment