From 09685fd4a73281a3fcd5ac01d9cc2e535e80ded9 Mon Sep 17 00:00:00 2001 From: Andrea Busi Date: Thu, 17 Nov 2022 22:21:59 +0100 Subject: [PATCH] feat: Store user selection for compact/expanded view in suer report --- .../project.pbxproj | 4 ++++ .../SegnalazioniMapViewController.swift | 9 ++++---- Sources/Earthquake Network/Costanti.h | 1 + .../Models/AppPreferences.swift | 23 +++++++++++++++++++ 4 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 Sources/Earthquake Network/Models/AppPreferences.swift diff --git a/Sources/Earthquake Network.xcodeproj/project.pbxproj b/Sources/Earthquake Network.xcodeproj/project.pbxproj index c9007c9..f9ccf8d 100644 --- a/Sources/Earthquake Network.xcodeproj/project.pbxproj +++ b/Sources/Earthquake Network.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ 6552C13829262119008E723C /* Shogun in Frameworks */ = {isa = PBXBuildFile; productRef = 6552C13729262119008E723C /* Shogun */; }; 6552C13A2926261D008E723C /* Shogun in Frameworks */ = {isa = PBXBuildFile; productRef = 6552C1392926261D008E723C /* Shogun */; }; 6552C140292678BD008E723C /* warning_yellow.png in Resources */ = {isa = PBXBuildFile; fileRef = 6552C13F292678BD008E723C /* warning_yellow.png */; }; + 6552C1462926DBA1008E723C /* AppPreferences.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6552C1452926DBA1008E723C /* AppPreferences.swift */; }; 6557CB2A2607676B00962757 /* triangle2_yellow.png in Resources */ = {isa = PBXBuildFile; fileRef = 6557CAC52607676200962757 /* triangle2_yellow.png */; }; 6557CB2B2607676B00962757 /* star_purple.png in Resources */ = {isa = PBXBuildFile; fileRef = 6557CAC62607676200962757 /* star_purple.png */; }; 6557CB2C2607676B00962757 /* oct_white.png in Resources */ = {isa = PBXBuildFile; fileRef = 6557CAC72607676200962757 /* oct_white.png */; }; @@ -303,6 +304,7 @@ 654D18C325F93C0600BB6DB0 /* PasquakesMapViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasquakesMapViewController.swift; sourceTree = ""; }; 654D18C825F93CD700BB6DB0 /* EQNMapAnnotationPastquake.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EQNMapAnnotationPastquake.swift; sourceTree = ""; }; 6552C13F292678BD008E723C /* warning_yellow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = warning_yellow.png; sourceTree = ""; }; + 6552C1452926DBA1008E723C /* AppPreferences.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppPreferences.swift; sourceTree = ""; }; 6557CAC52607676200962757 /* triangle2_yellow.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = triangle2_yellow.png; sourceTree = ""; }; 6557CAC62607676200962757 /* star_purple.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = star_purple.png; sourceTree = ""; }; 6557CAC72607676200962757 /* oct_white.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = oct_white.png; sourceTree = ""; }; @@ -1084,6 +1086,7 @@ 8CF4F4D9216D44930057110B /* EQNPastquakes.h */, 8CF4F4DA216D44930057110B /* EQNPastquakes.m */, 65E1226B285C92AA000E294A /* EQNRealtimeAlert.swift */, + 6552C1452926DBA1008E723C /* AppPreferences.swift */, ); path = Models; sourceTree = ""; @@ -1611,6 +1614,7 @@ 8CBD3DCA2149B9AD0070C963 /* AllerteViewController.m in Sources */, DC646F32252B698B000AA5FD /* AlertsSeismicNotificationCompactTableViewCell.swift in Sources */, DCF10DCD24D2C935009F34C3 /* EQNPurchaseAvailability.swift in Sources */, + 6552C1462926DBA1008E723C /* AppPreferences.swift in Sources */, DC08803F24F5A89000186D97 /* SettingEnableTableViewCell.swift in Sources */, 6586971125F44C26009C0182 /* EQNBlurredCloseButton.swift in Sources */, 8CAFD7C521825E4A00F8BD29 /* EQNSisma.m in Sources */, diff --git a/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift b/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift index c1e5d22..d064fe6 100644 --- a/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift +++ b/Sources/Earthquake Network/Controllers/Reports/SegnalazioniMapViewController.swift @@ -21,12 +21,11 @@ class SegnalazioniMapViewController: EQNBaseMapViewController { false } + private let appPreferences = AppPreferences.shared /// Contains circles and related colors to draw overlays on the map private var mapCircles = [MapCircle]() /// Reports currently showned on the map private var filteredReports = [EQNSegnalazione]() - /// Defines if time has to be shown on map annotations - private var showAnnotationTime = false // MARK: - UI @@ -191,7 +190,7 @@ class SegnalazioniMapViewController: EQNBaseMapViewController { } @objc private func onTapMapDetailStyleButton(_ sender: Any) { - showAnnotationTime.toggle() + appPreferences.userReportExpandedView.toggle() loadDataSource() } @@ -339,10 +338,10 @@ class SegnalazioniMapViewController: EQNBaseMapViewController { return nil } - let identifier = showAnnotationTime ? EQNCustomAnnotationView.SingleLineIdentifier : EQNCustomAnnotationView.SmallIdentifier + let identifier = appPreferences.userReportExpandedView ? EQNCustomAnnotationView.SingleLineIdentifier : EQNCustomAnnotationView.SmallIdentifier let annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier, for: annotation) as! EQNCustomAnnotationView - let size = showAnnotationTime ? EQNCustomAnnotationView.SingleLineImageHeight : EQNCustomAnnotationView.SmallViewImageHeight + let size = appPreferences.userReportExpandedView ? EQNCustomAnnotationView.SingleLineImageHeight : EQNCustomAnnotationView.SmallViewImageHeight annotationView.image = annotation.image(with: size) annotationView.title = annotation.timeDifference annotationView.canShowCallout = true diff --git a/Sources/Earthquake Network/Costanti.h b/Sources/Earthquake Network/Costanti.h index b709f2a..d8aa940 100644 --- a/Sources/Earthquake Network/Costanti.h +++ b/Sources/Earthquake Network/Costanti.h @@ -75,6 +75,7 @@ static NSString * const EQNUserDefaultLastLocation = @"EQNLast_Location"; static NSString * const EQNUserDefaultSeismicNetworkCards = @"EQNData.RetiSismiche"; static NSString * const EQNUserDefaultRealTimeAlertPayload = @"EQNData.RealtimeAlertPayload"; static NSString * const EQNUserDefaultRealTimeAlertDate = @"EQNData.RealtimeAlertDate"; +static NSString * const EQNUserDefaultUserReportExpandedView = @"EQNData.UserReportExpandedView"; static NSString * const EQNUserDefaultMigrationV5_3 = @"EQNUserDefaultMigrationV5_3"; diff --git a/Sources/Earthquake Network/Models/AppPreferences.swift b/Sources/Earthquake Network/Models/AppPreferences.swift new file mode 100644 index 0000000..cb9b758 --- /dev/null +++ b/Sources/Earthquake Network/Models/AppPreferences.swift @@ -0,0 +1,23 @@ +// +// AppPreferences.swift +// Earthquake Network +// +// Created by Andrea Busi on 17/11/22. +// Copyright © 2022 Earthquake Network. All rights reserved. +// + +import Foundation + + +class AppPreferences { + + static let shared = AppPreferences() + + // MARK: - Public + + /// Defines if time has to be shown on map annotations in User Reports + var userReportExpandedView: Bool { + get { UserDefaults.standard.bool(forKey: EQNUserDefaultUserReportExpandedView) } + set { UserDefaults.standard.set(newValue, forKey: EQNUserDefaultUserReportExpandedView) } + } +}