85 lines
2.5 KiB
Swift
85 lines
2.5 KiB
Swift
//
|
|
// EQNBackgrounPositionDebugViewController.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Andrea Busi on 14/08/23.
|
|
// Copyright © 2023 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
import CoreLocation
|
|
|
|
|
|
class EQNBackgroundPositionDebugViewController: UITableViewController {
|
|
|
|
private var positions = [EQNBackgroundPosition]()
|
|
private let formatter: DateFormatter = {
|
|
let formatter = DateFormatter()
|
|
formatter.timeStyle = .medium
|
|
formatter.dateStyle = .medium
|
|
return formatter
|
|
}()
|
|
private let helper = EQNBackgroundPositionDebugHelper()
|
|
|
|
|
|
// MARK: - Init
|
|
|
|
convenience init() {
|
|
self.init(style: .insetGrouped)
|
|
}
|
|
|
|
// MARK: - View Lifecycle
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
configureUI()
|
|
loadData()
|
|
}
|
|
|
|
private func configureUI() {
|
|
tableView.rowHeight = UITableView.automaticDimension
|
|
tableView.estimatedRowHeight = 60.0
|
|
|
|
navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .trash, target: self, action: #selector(onTapDeleteButton(_:)))
|
|
}
|
|
|
|
private func loadData() {
|
|
positions = helper.loadPosition()
|
|
tableView.reloadData()
|
|
}
|
|
|
|
// MARK: - Table view data source
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
positions.count
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let position = positions[indexPath.row]
|
|
let cell = UITableViewCell(style: .subtitle, reuseIdentifier: "PositionCell")
|
|
cell.textLabel?.text = formatter.string(from: position.date)
|
|
cell.detailTextLabel?.text = String(format: "Lat: %.4f - Lon: %.4f", position.coordinate.latitude, position.coordinate.longitude)
|
|
var imageView: UIImageView?
|
|
switch position.request {
|
|
case .none:
|
|
imageView = nil
|
|
case .some(true):
|
|
imageView = .init(image: .init(systemName: "checkmark.circle.fill"))
|
|
imageView?.tintColor = AppTheme.Colors.green
|
|
case .some(false):
|
|
imageView = .init(image: .init(systemName: "x.circle.fill"))
|
|
imageView?.tintColor = AppTheme.Colors.red
|
|
}
|
|
cell.accessoryView = imageView
|
|
return cell
|
|
}
|
|
|
|
// MARK: - Actions
|
|
|
|
@objc private func onTapDeleteButton(_ sender: UIBarButtonItem) {
|
|
helper.resetPositions()
|
|
loadData()
|
|
}
|
|
}
|