72 lines
2.7 KiB
Swift
72 lines
2.7 KiB
Swift
//
|
|
// SettingsSeismicNetworksViewController.swift
|
|
// Earthquake Network
|
|
//
|
|
// Created by Busi Andrea on 26/08/2020.
|
|
// Copyright © 2020 Earthquake Network. All rights reserved.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class SettingsSeismicNetworksViewController: UITableViewController {
|
|
|
|
var networks = [EQNSeismicNetwork]()
|
|
|
|
override func viewDidLoad() {
|
|
super.viewDidLoad()
|
|
|
|
tableView.register(SettingDetailTableViewCell.self, forCellReuseIdentifier: SettingDetailTableViewCell.Identifier)
|
|
tableView.register(SettingSectionHeaderView.self, forHeaderFooterViewReuseIdentifier: SettingSectionHeaderView.Identifier)
|
|
|
|
networks = EQNData.seismicNetworks().sorted(by: { $0.acronym < $1.acronym })
|
|
}
|
|
|
|
// MARK: - Table view data source
|
|
|
|
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: SettingSectionHeaderView.Identifier) as! SettingSectionHeaderView
|
|
headerView.titleLabel.text = NSLocalizedString("options_agencies", comment: "");
|
|
return headerView
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
CGFloat(SettingSectionHeaderView.Height)
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
networks.count
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
let network = networks[indexPath.row]
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: SettingDetailTableViewCell.Identifier, for: indexPath) as! SettingDetailTableViewCell
|
|
cell.textLabel?.text = "\(network.acronym) (\(network.country))"
|
|
|
|
if EQNNotificheReteSismiche.shared().listaEnti.contains(network.acronym) {
|
|
cell.accessoryType = .checkmark
|
|
} else {
|
|
cell.accessoryType = .none
|
|
}
|
|
|
|
return cell
|
|
}
|
|
|
|
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
tableView.deselectRow(at: indexPath, animated: true)
|
|
|
|
let network = networks[indexPath.row]
|
|
|
|
var savedNetworks = EQNNotificheReteSismiche.shared().listaEnti
|
|
if let index = savedNetworks.firstIndex(where: { $0 == network.acronym }) {
|
|
savedNetworks.remove(at: index)
|
|
} else {
|
|
savedNetworks.append(network.acronym)
|
|
}
|
|
|
|
EQNNotificheReteSismiche.shared().listaEnti = savedNetworks
|
|
EQNNotificheReteSismiche.shared().saveUserInfo()
|
|
|
|
tableView.reloadData()
|
|
}
|
|
}
|