feat: Add sort feature in Seismic list
This commit is contained in:
@@ -75,6 +75,7 @@ extension UserDefaults {
|
||||
|
||||
// Filtri sezioni reti sismiche
|
||||
static let SeismicFilterOption = "EQN_SISMI_TIPOLOGIA_FILTRO"
|
||||
static let SeismicSort = "EQN_SISMI_TIPOLOGIA_ORDINAMENTO"
|
||||
static let SeismicMagnitudoMinima = "EQN_MAGNITUDO_MINIMA"
|
||||
static let SeismicDistanzaMassima = "EQN_DISTANZA_MASSIMA"
|
||||
}
|
||||
|
||||
+26
@@ -25,6 +25,7 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
||||
|
||||
@IBOutlet private weak var tableView: UITableView?
|
||||
@IBOutlet private weak var expandeCollapseButton: UIBarButtonItem!
|
||||
@IBOutlet private weak var sortButton: UIBarButtonItem!
|
||||
weak var currentMapController: SeismicNetworksMapDetailViewController?
|
||||
|
||||
/// The ad loader
|
||||
@@ -68,6 +69,23 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
||||
tableView?.register(SeismicNetworkTableViewCell.self, forCellReuseIdentifier: SeismicNetworkTableViewCell.Identifier)
|
||||
tableView?.register(SeismicNetworkAdvertiseTableViewCell.self, forCellReuseIdentifier: SeismicNetworkAdvertiseTableViewCell.Identifier)
|
||||
tableView?.emptyDataSetSource = self
|
||||
|
||||
setupSortMenu()
|
||||
}
|
||||
|
||||
private func setupSortMenu() {
|
||||
let currentSort = EQNSeismic.shared.sort
|
||||
sortButton.menu = UIMenu(title: "", image: nil, identifier: nil, options: [], children: [
|
||||
UIAction(title: NSLocalizedString("sort_date", comment: ""), image: UIImage(systemName: "calendar"), state: currentSort == .time ? .on : .off) { [weak self ] _ in
|
||||
self?.changeSort(to: .time)
|
||||
},
|
||||
UIAction(title: NSLocalizedString("sort_position", comment: ""), image: UIImage(systemName: "ruler"), state: currentSort == .position ? .on : .off) { [weak self] _ in
|
||||
self?.changeSort(to: .position)
|
||||
},
|
||||
UIAction(title: NSLocalizedString("sort_magnitude", comment: ""), image: UIImage(systemName: "thermometer"), state: currentSort == .magnitude ? .on : .off) { [weak self] _ in
|
||||
self?.changeSort(to: .magnitude)
|
||||
}
|
||||
])
|
||||
}
|
||||
|
||||
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
|
||||
@@ -159,6 +177,14 @@ class SeismicNetworksViewController: UIViewController, UITableViewDelegate, UITa
|
||||
return seismics
|
||||
}
|
||||
|
||||
private func changeSort(to sort: EQNSeismic.Sort) {
|
||||
EQNSeismic.shared.sort = sort
|
||||
EQNSeismic.shared.saveFilters()
|
||||
|
||||
setupSortMenu()
|
||||
refreshUI()
|
||||
}
|
||||
|
||||
// MARK: - Actions
|
||||
|
||||
@IBAction func refreshDataTapped(_ sender: Any) {
|
||||
|
||||
@@ -17,9 +17,16 @@ import Foundation
|
||||
case worldWide
|
||||
}
|
||||
|
||||
enum Sort: Int {
|
||||
case time
|
||||
case position
|
||||
case magnitude
|
||||
}
|
||||
|
||||
@objc static let shared = EQNSeismic()
|
||||
|
||||
@objc var filterOption: FilterType
|
||||
var sort: Sort
|
||||
var maximumDistance: String
|
||||
@objc var minimumMagnitude: String
|
||||
|
||||
@@ -31,6 +38,7 @@ import Foundation
|
||||
|
||||
let defaults = UserDefaults.standard
|
||||
filterOption = defaults.enumObject(forKey: UserDefaults.SeismicFilterOption, or: .positionRelevant)
|
||||
sort = defaults.enumObject(forKey: UserDefaults.SeismicSort, or: .time)
|
||||
maximumDistance = defaults.object(forKey: UserDefaults.SeismicDistanzaMassima, or: EQNData.DefaultFilterRadius.value)
|
||||
minimumMagnitude = defaults.object(forKey: UserDefaults.SeismicMagnitudoMinima, or: EQNData.DefaultFilterMagnitude.value)
|
||||
|
||||
@@ -43,6 +51,7 @@ import Foundation
|
||||
public func saveFilters() {
|
||||
let defaults = UserDefaults.standard
|
||||
defaults.set(filterOption.rawValue, forKey: UserDefaults.SeismicFilterOption)
|
||||
defaults.set(sort.rawValue, forKey: UserDefaults.SeismicSort)
|
||||
defaults.set(maximumDistance, forKey: UserDefaults.SeismicDistanzaMassima)
|
||||
defaults.set(minimumMagnitude, forKey: UserDefaults.SeismicMagnitudoMinima)
|
||||
}
|
||||
@@ -177,8 +186,28 @@ import Foundation
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: non fare force unwrap
|
||||
filtered.sort(by: { $0.date! > $1.date! })
|
||||
switch sort {
|
||||
case .time:
|
||||
filtered.sort(by: { seismic1, seismic2 in
|
||||
guard let date1 = seismic1.date else {
|
||||
return false
|
||||
}
|
||||
|
||||
guard let date2 = seismic2.date else {
|
||||
return true
|
||||
}
|
||||
|
||||
return date1 > date2
|
||||
})
|
||||
case .position:
|
||||
filtered.sort { seismic1, seismic2 in
|
||||
seismic1.userDistance > seismic2.userDistance
|
||||
}
|
||||
case .magnitude:
|
||||
filtered.sort { seismic1, seismic2 in
|
||||
seismic1.magnitude.doubleValue > seismic2.magnitude.doubleValue
|
||||
}
|
||||
}
|
||||
|
||||
return filtered
|
||||
}
|
||||
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"filename" : "navbar-icon-sort.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"filename" : "navbar-icon-sort@2x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"filename" : "navbar-icon-sort@3x.png",
|
||||
"idiom" : "universal",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
|
After Width: | Height: | Size: 118 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
BIN
Binary file not shown.
|
After Width: | Height: | Size: 167 B |
@@ -196,6 +196,7 @@
|
||||
<action selector="openFilterTapped:" destination="tVM-DH-fmv" id="76a-Bl-bCj"/>
|
||||
</connections>
|
||||
</barButtonItem>
|
||||
<barButtonItem image="navbar-icon-sort" id="LyU-KI-3Mb"/>
|
||||
<barButtonItem image="navbar-icon-arrow-collapse" id="HTN-07-s5p">
|
||||
<connections>
|
||||
<action selector="collapseExpandTapped:" destination="tVM-DH-fmv" id="EnD-92-5ZX"/>
|
||||
@@ -205,6 +206,7 @@
|
||||
</navigationItem>
|
||||
<connections>
|
||||
<outlet property="expandeCollapseButton" destination="HTN-07-s5p" id="lxP-Im-NME"/>
|
||||
<outlet property="sortButton" destination="LyU-KI-3Mb" id="969-Zg-YBB"/>
|
||||
<outlet property="tableView" destination="q4o-YO-KLX" id="tee-h5-dZi"/>
|
||||
<segue destination="6LP-zk-O1z" kind="presentation" identifier="ShowFilters" modalPresentationStyle="overCurrentContext" modalTransitionStyle="crossDissolve" id="Nzu-iH-UgB"/>
|
||||
<segue destination="Rfp-kt-2Kx" kind="presentation" identifier="ShowCardSettings" modalPresentationStyle="overCurrentContext" modalTransitionStyle="crossDissolve" id="VWw-16-xGw"/>
|
||||
@@ -2176,6 +2178,7 @@ Sisma rilevato da 10 smartphone</string>
|
||||
<image name="navbar-icon-arrow-collapse" width="24" height="24"/>
|
||||
<image name="navbar-icon-filters" width="24" height="24"/>
|
||||
<image name="navbar-icon-refresh" width="24" height="24"/>
|
||||
<image name="navbar-icon-sort" width="24" height="24"/>
|
||||
<image name="priority" width="100" height="100"/>
|
||||
<image name="sunrise" width="85" height="85"/>
|
||||
<image name="sunset" width="85" height="85"/>
|
||||
|
||||
@@ -232,3 +232,6 @@
|
||||
"calendar_missing_permission" = "لا يمكن فتح التقويم ، تأكد من تعيين الأذونات الصحيحة.";
|
||||
"error_server_registration" = "لم يكن من الممكن التسجيل في خادم التطبيق. التسجيل مطلوب لتلقي التنبيهات في الوقت الحقيقي وإشعارات الزلازل.";
|
||||
"retry" = "أعد المحاولة";
|
||||
"sort_date" = "حجم";
|
||||
"sort_position" = "مسافة";
|
||||
"sort_magnitude" = "تاريخ";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Το ημερολόγιο δεν μπορεί να ανοίξει, βεβαιωθείτε ότι έχετε ρυθμίσει τα σωστά δικαιώματα.";
|
||||
"error_server_registration" = "Δεν ήταν δυνατό να εγγραφείτε με το διακομιστή. Η εγγραφή υποχρεούται να λαμβάνει ειδοποιήσεις σε πραγματικό χρόνο και ειδοποιήσεις σεισμού.";
|
||||
"retry" = "Προσπαθησε ξανα";
|
||||
"sort_date" = "Ημερομηνία";
|
||||
"sort_position" = "Απόσταση";
|
||||
"sort_magnitude" = "Μέγεθος";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "The calendar cannot be opened, make sure you have set the correct permissions.";
|
||||
"error_server_registration" = "It was not possible to register with the Earthquake Network server. Registration is required to receive real-time alerts and earthquake notifications.";
|
||||
"retry" = "Retry";
|
||||
"sort_date" = "Date";
|
||||
"sort_position" = "Distance";
|
||||
"sort_magnitude" = "Magnitude";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "El calendario no se puede abrir, asegúrese de haber configurado los permisos correctos.";
|
||||
"error_server_registration" = "No fue posible registrarse en el servidor de Sismo Detector. Es necesario registrarse para recibir alertas y notificaciones de terremotos en tiempo real.";
|
||||
"retry" = "Reintentar";
|
||||
"sort_date" = "Fecha";
|
||||
"sort_position" = "Distancia";
|
||||
"sort_magnitude" = "Magnitud";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Le calendrier ne peut pas être ouvert, assurez-vous d'avoir défini les autorisations appropriées.";
|
||||
"error_server_registration" = "Il n'a pas été possible de s'inscrire auprès du serveur. L'inscription est requise pour recevoir des alertes en temps réel et des notifications de tremblement de terre.";
|
||||
"retry" = "Réessayez";
|
||||
"sort_date" = "Date";
|
||||
"sort_position" = "Distance";
|
||||
"sort_magnitude" = "Magnitude";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Kalendar se ne može otvoriti, provjerite jeste li postavili ispravna dopuštenja.";
|
||||
"error_server_registration" = "Nije bilo moguće registrirati se na poslužitelju mreže potresnih mreža. Registracija je potrebna za primanje upozorenja u stvarnom vremenu i obavijesti o potresima.";
|
||||
"retry" = "Pokušaj ponovo";
|
||||
"sort_date" = "Datum";
|
||||
"sort_position" = "Udaljenost";
|
||||
"sort_magnitude" = "Magnituda";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Kalender tidak dapat dibuka, pastikan Anda telah mengatur izin yang benar.";
|
||||
"error_server_registration" = "Itu tidak mungkin untuk mendaftar dengan server Jaringan Gempa. Pendaftaran diperlukan untuk menerima peringatan waktu nyata dan pemberitahuan gempa bumi.";
|
||||
"retry" = "Mencoba kembali";
|
||||
"sort_date" = "Tanggal";
|
||||
"sort_position" = "Jarak";
|
||||
"sort_magnitude" = "Magnitudo";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Il calendario non può essere aperto, assicurati di aver dato il permesso alla app";
|
||||
"error_server_registration" = "Non è stato possibile registrarsi al server di Rilevatore Terremoto. La registrazione è necessaria per poter ricevere allerte in tempo reale e notifiche.";
|
||||
"retry" = "Ritenta";
|
||||
"sort_date" = "Data";
|
||||
"sort_position" = "Distanza";
|
||||
"sort_magnitude" = "Magnitudo";
|
||||
|
||||
@@ -231,3 +231,6 @@
|
||||
"calendar_missing_permission" = "Takvim açılamıyor, doğru izinleri ayarladığınızdan emin olun.";
|
||||
"error_server_registration" = "Deprem Ağı sunucusuna kayıt olmak mümkün olmadı. Gerçek zamanlı uyarılar ve deprem bildirimleri almak için kayıt yaptırmanız gerekir.";
|
||||
"retry" = "Yeniden dene";
|
||||
"sort_date" = "Tarih";
|
||||
"sort_position" = "Mesafe";
|
||||
"sort_magnitude" = "Büyüklüğü";
|
||||
|
||||
Reference in New Issue
Block a user