114 lines
5.5 KiB
Swift
114 lines
5.5 KiB
Swift
//
|
||
// Constants.swift
|
||
// Earthquake Network
|
||
//
|
||
// Created by Andrea Busi on 14/07/23.
|
||
// Copyright © 2023 Earthquake Network. All rights reserved.
|
||
//
|
||
|
||
import Foundation
|
||
|
||
|
||
@objc
|
||
extension UserDefaults {
|
||
// UserDefaults condivisi con l'AppGroup
|
||
@objc(appGroupUserDefaults)
|
||
static let appGroup = UserDefaults(suiteName: "group.com.finazzi.distquake")
|
||
|
||
// Impostazioni della sezione `Allerta in tempo reale`
|
||
static let AllertaSismicaAbilitato = "NOTIFICHE_ALLERA_SISMICA_ABILITATO"
|
||
static let AllertaSismicaCriticalAlerts = "NOTIFICHE_ALLERA_SISMICA_CRITICAL_ALERTS"
|
||
static let AllertaSismicaSismiDaNotificare = "NOTIFICHE_ALLERA_SISMICA_SISMI_DA_NOTIFICARE"
|
||
static let AllertaSismicaRaggioSismiLievi = "NOTIFICHE_ALLERA_SISMICA_RAGGIO_SISMI_LIEVI"
|
||
static let AllertaSismicaRaggioSismiForti = "NOTIFICHE_ALLERA_SISMICA_RAGGIO_SISMI_FORTI"
|
||
|
||
// Impostazioni della sezione `Notifiche da reti sismiche`
|
||
static let NotificheRetiSismicheAbilitato = "NOTIFICHE_ATTIVA_RETI_SISMICHE"
|
||
static let NotificheRetiSismicheMagnitudoMinima = "NOTIFICHE_ATTIVA_RETI_ENERGIA_SISMI"
|
||
static let NotificheRetiSismicheDistanzaMassima = "NOTIFICHE_DISTANZA_POSIZIONE_RETI_SISMICHE"
|
||
static let NotificheRetiSismicheFiltroNotifiche = "NOTIFICHE_FILTRO_NOTIFICHE_RETI_SISMICHE"
|
||
|
||
// Impostazioni della sezione `Notifiche segnalazioni utente`
|
||
static let NotificheSegnalazioniUtenteAbilitato = "NOTIFICHE_SU_ATTIVA_SEGNALAZIONE_UTENTE"
|
||
static let NotificheSegnalazioniUtenteDistanzaPosizione = "NOTIFICHE_SU_DISTANZA_POSIZIONE"
|
||
|
||
// Messaggio in segnalazione utente
|
||
static let UserReportMessage = "DATA_MESSAGE_EQN"
|
||
static let UserReportCodeStatus = "CODE_MESSAGE_EQN"
|
||
|
||
// Proprietà e preferenze dell'utente
|
||
static let FirstAppStartExecuted = "EQNUserDefaultFirstAppStartExecuted"
|
||
/// Ultima posizione conosciuta dell'utente
|
||
static let UserDataLastLocation = "EQNLast_Location"
|
||
/// Token Firebase dell'utente corrente
|
||
static let UserDataFirebaseToken = "EQNToken_User"
|
||
/// Server user ID dell'utente corrente
|
||
static let UserDataUserId = "EQNUSER_ID"
|
||
/// Reti sismiche selezionate
|
||
static let UserDataSelectedSeismicNetworks = "IMPOSTAZIONE_ENTI_RETI_SISMICHEI"
|
||
/// Token delle notifiche push
|
||
static let UserDataPushToken = "EQNetwork.PushToken"
|
||
/// Numero di aperture dell'app per sbloccare la versione Pro scontata
|
||
static let UserDataProDiscountOpenCounter = "CONTEGGIO_APERTURE_PER_SCONTO"
|
||
/// Prezzo scontato per la versione pro scaduto
|
||
static let UserDataProDiscountExpired = "PREZZO_SCONTATO_SCADUTO"
|
||
/// Se `true` visualizza il tempo nelle annotazioni della mappa segnalazioni utente
|
||
static let UserReportExpandedView = "EQNData.UserReportExpandedView"
|
||
/// Se `true` visualizza le opzioni nella singole card in reti sismiche
|
||
static let AlertsShowCardOptions = "EQNetwork.AlertsShowAllCards"
|
||
/// Indica lo stile di pin da visualizzare nelle mappe
|
||
static let MapPinStyle = "EQNetwork.MapPinStyle"
|
||
/// Indica le informazioni da visualizzare nelle card `small` e `full` nella Lista Sismi
|
||
static let SeismicNetworksCardInformations = "EQNetwork.SeismicInformations";
|
||
/// Indica la tipologia di card da visualizzare nella Lista Sismi
|
||
static let SeismicNetworksCardStyle = "EQNetwork.SeismicNetworksCardStyle"
|
||
|
||
// Migrazioni
|
||
static let AppMigrationV5_3 = "EQNUserDefaultMigrationV5_3"
|
||
static let AppMigrationV5_4 = "EQNUserDefaultMigrationV5_4"
|
||
static let AppMigrationV5_8 = "EQNUserDefaultMigrationV5_8"
|
||
static let AppMigrationV5_8_2 = "EQNUserDefaultMigrationV5_8_2"
|
||
static let AppMigrationV5_9 = "EQNUserDefaultMigrationV5_9"
|
||
|
||
static let SettingsSeismicNetworkNotificationMigrationV5_8 = "EQNUserDefaultSettingsSeismicNetworkNotificationMigrationV5_8"
|
||
static let SettingsUserReportNotificationMigrationV5_8 = "EQNUserDefaultSettingsUserReportNotificationMigrationV5_8"
|
||
static let SismicFiltersMigrationV5_8 = "EQNUserDefaultSismicFiltersMigrationV5_8"
|
||
static let SaveSettingsNotificationMigrationV5_8 = "EQNUserDefaultSaveSettingsNotificationMigrationV5_8"
|
||
|
||
// Notifica allerta salvata
|
||
static let RealTimeAlertPayload = "EQNData.RealtimePushNotificationPayload"
|
||
static let RealTimeAlertDate = "EQNData.RealtimeAlertDate"
|
||
// Notifica rete sismica aperta
|
||
static let OfficialAlertPayload = "EQNData.OfficialPushNotificationPayload"
|
||
|
||
// 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"
|
||
}
|
||
|
||
extension UserDefaults {
|
||
|
||
/// Get a generic stored values
|
||
/// - Parameters:
|
||
/// - key: A key in the current user‘s defaults database.
|
||
/// - defaultValue: Default value to return if the key is not found
|
||
/// - Returns: The object associated with the specified key, or `defaultValue` if the key was not found.
|
||
func object<T>(forKey key: String, or defaultValue: T) -> T {
|
||
if let value = UserDefaults.standard.object(forKey: key) as? T {
|
||
return value
|
||
}
|
||
return defaultValue
|
||
}
|
||
|
||
func enumObject<T: RawRepresentable>(forKey key: String, or defaultValue: T) -> T {
|
||
if let rawValue = UserDefaults.standard.object(forKey: key) as? T.RawValue,
|
||
let value = T.init(rawValue: rawValue) {
|
||
return value
|
||
|
||
}
|
||
return defaultValue
|
||
}
|
||
}
|