feat: Add a debug screen for saved background positions
This commit is contained in:
+78
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// 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
|
||||
}()
|
||||
|
||||
|
||||
// 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 = EQNBackgroundPosition.load()
|
||||
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)
|
||||
return cell
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@objc private func onTapDeleteButton(_ sender: UIBarButtonItem) {
|
||||
EQNBackgroundPosition.reset()
|
||||
loadData()
|
||||
}
|
||||
|
||||
// MARK: - Class
|
||||
|
||||
@objc
|
||||
class func resetAll() {
|
||||
EQNBackgroundPosition.reset()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user