126 lines
4.5 KiB
Swift
126 lines
4.5 KiB
Swift
//
|
|
// CashExchangeRequestsViewController.swift
|
|
// PayCash
|
|
//
|
|
// Created by Saveliy Stavitsky on 7/21/21.
|
|
// Copyright © 2021 AM. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import class Resolver.Resolver
|
|
|
|
class CashExchangeRequestsViewController: UIViewController {
|
|
|
|
@IBOutlet var segmentedControl: UISegmentedControl!
|
|
@IBOutlet private weak var requestsTableView: UITableView!
|
|
|
|
var requestsService: CCCP.Service.ExchangeRequests { Resolver.resolve() }
|
|
|
|
private lazy var requestsEmptyView: CommonViewEmpty = {
|
|
CommonViewEmpty(
|
|
text: L10n.Cccp.Main.Requests.Empty.description,
|
|
image: Asset.cccpRequestsEmpty1.image)
|
|
}()
|
|
|
|
private let refresh = UIRefreshControl()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
navigationItem.title = L10n.Cash.ExchangeRequests.headerTitle
|
|
navigationItem.leftBarButtonItem = .pop(self)
|
|
|
|
segmentedControl.setTitle(L10n.Cccp.Main.Segment.myOrders, forSegmentAt: 0)
|
|
segmentedControl.setTitle(L10n.Cccp.Main.Segment.debt, forSegmentAt: 1)
|
|
|
|
refresh.addTarget(self, action: #selector(refreshViewApearance), for: .valueChanged)
|
|
requestsTableView.addSubview(refresh)
|
|
|
|
requestsTableView.allowsSelection = false
|
|
requestsTableView.showsVerticalScrollIndicator = false
|
|
requestsTableView.separatorStyle = .none
|
|
requestsTableView.register(cell: CCCPCellExchangeRequest.self)
|
|
|
|
Notification.subscribe(name: .didUpdateCryptocashExchangeRequests) {[weak self] _ in
|
|
DispatchQueue.main.async {
|
|
self?.refresh.endRefreshing()
|
|
self?.requestsTableView.reloadData()
|
|
// self?.requestsEmptyView.alpha = ((self?.requests.isEmpty ?? true) ? 1 : 0)
|
|
}
|
|
}
|
|
|
|
self.setupRequestsEmptyView()
|
|
}
|
|
|
|
private func setupRequestsEmptyView() {
|
|
requestsEmptyView.frame = CGRect(x: 0, y: 50, width: requestsTableView.frame.width,
|
|
height: requestsTableView.frame.height - 50)
|
|
requestsEmptyView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
requestsEmptyView.translatesAutoresizingMaskIntoConstraints = true
|
|
requestsEmptyView.alpha = 0
|
|
requestsTableView.addSubview(requestsEmptyView)
|
|
}
|
|
|
|
@objc func refreshViewApearance() {
|
|
requestsService.fetch()
|
|
}
|
|
|
|
@IBAction func segmentChange(_ sender: Any) {
|
|
requestsTableView.reloadData()
|
|
self.requestsEmptyView.alpha = (self.requests.isEmpty ? 1 : 0)
|
|
}
|
|
|
|
@IBAction func onCreate(_: AnyObject?) {
|
|
let createRequestViewController = StoryboardScene.Cccp.cccpControllerCreateExchangeRequest.instantiate()
|
|
navigationController?.pushViewController(createRequestViewController, animated: true)
|
|
}
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
Accounts().isLocked = true
|
|
|
|
if ((UIApplication.shared.windows.first!.rootViewController as? MainController)?.barNav.items?.count ?? 0) > 1 {
|
|
(UIApplication.shared.windows.first!.rootViewController as? MainController)?.barNav.popItem(animated: true)
|
|
}
|
|
|
|
refreshViewApearance()
|
|
}
|
|
|
|
override func viewWillDisappear(_ animated: Bool) {
|
|
super.viewWillDisappear(animated)
|
|
Accounts().isLocked = false
|
|
}
|
|
|
|
/*
|
|
// 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.
|
|
}
|
|
*/
|
|
|
|
}
|
|
|
|
extension CashExchangeRequestsViewController: UITableViewDelegate, UITableViewDataSource {
|
|
|
|
var requests: [CCCP.Model.ExchangeRequest] {
|
|
segmentedControl.selectedSegmentIndex == 0 ? (requestsService.requests) : requestsService.debts
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
let requestsTableViewCount = self.requests.count
|
|
self.requestsEmptyView.alpha = (requestsTableViewCount == 0) ? 1 : 0
|
|
return requestsTableViewCount
|
|
}
|
|
|
|
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let cell = tableView.dequeueReusableCell(CCCPCellExchangeRequest.self, indexPath: indexPath)
|
|
cell.tokens = Wallet.Service.Tokens.shared.balances.collection
|
|
cell.setup(request: requests[indexPath.row])
|
|
cell.parent = self
|
|
return cell
|
|
}
|
|
}
|