Skip to content

Commit

Permalink
Add option to toggle map and weather
Browse files Browse the repository at this point in the history
  • Loading branch information
pakerwreah committed Sep 11, 2024
1 parent f316173 commit 5c28b5f
Show file tree
Hide file tree
Showing 31 changed files with 178 additions and 95 deletions.
8 changes: 4 additions & 4 deletions Calendr.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
3421930827999FB7002BCD36 /* TimeZone+Factory.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421930727999FB7002BCD36 /* TimeZone+Factory.swift */; };
3421AD3D25BA1D0800A4F468 /* SettingsViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421AD3C25BA1D0800A4F468 /* SettingsViewModelTests.swift */; };
3421DA0E2693E35000056837 /* EventListViewPreview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA0D2693E35000056837 /* EventListViewPreview.swift */; };
3421DA122693E70E00056837 /* MockPopoverSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA112693E70E00056837 /* MockPopoverSettings.swift */; };
3421DA122693E70E00056837 /* MockEventDetailsSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA112693E70E00056837 /* MockEventDetailsSettings.swift */; };
3421DA142693E75A00056837 /* MockCalendarServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA132693E75A00056837 /* MockCalendarServiceProvider.swift */; };
3421DA162693EDEB00056837 /* MockCalendarSettings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA152693EDEB00056837 /* MockCalendarSettings.swift */; };
3421DA182693EEBD00056837 /* MockDateProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3421DA172693EEBD00056837 /* MockDateProvider.swift */; };
Expand Down Expand Up @@ -215,7 +215,7 @@
3421930727999FB7002BCD36 /* TimeZone+Factory.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "TimeZone+Factory.swift"; sourceTree = "<group>"; };
3421AD3C25BA1D0800A4F468 /* SettingsViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewModelTests.swift; sourceTree = "<group>"; };
3421DA0D2693E35000056837 /* EventListViewPreview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventListViewPreview.swift; sourceTree = "<group>"; };
3421DA112693E70E00056837 /* MockPopoverSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPopoverSettings.swift; sourceTree = "<group>"; };
3421DA112693E70E00056837 /* MockEventDetailsSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockEventDetailsSettings.swift; sourceTree = "<group>"; };
3421DA132693E75A00056837 /* MockCalendarServiceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCalendarServiceProvider.swift; sourceTree = "<group>"; };
3421DA152693EDEB00056837 /* MockCalendarSettings.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockCalendarSettings.swift; sourceTree = "<group>"; };
3421DA172693EEBD00056837 /* MockDateProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockDateProvider.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -427,12 +427,12 @@
3421DA132693E75A00056837 /* MockCalendarServiceProvider.swift */,
3421DA152693EDEB00056837 /* MockCalendarSettings.swift */,
3421DA172693EEBD00056837 /* MockDateProvider.swift */,
3421DA112693E70E00056837 /* MockEventDetailsSettings.swift */,
34F201322693F562006CE2FF /* MockEventListSettings.swift */,
345CC36D2C8CE13100B0DD1A /* MockGeocodeServiceProvider.swift */,
34299F742C72507100A0269B /* MockLocalNotificationProvider.swift */,
34299F722C724FA000A0269B /* MockNetworkServiceProvider.swift */,
346C5A4B2BC2D87F0007106C /* MockNextEventSettings.swift */,
3421DA112693E70E00056837 /* MockPopoverSettings.swift */,
34F4C47C2A6C56AA00397C80 /* MockScreenProvider.swift */,
34F4C47E2A6C57B300397C80 /* MockStatusItemSettings.swift */,
345EAD492C8E26EE00D56857 /* MockWeatherServiceProvider.swift */,
Expand Down Expand Up @@ -1048,7 +1048,7 @@
345CC36E2C8CE13100B0DD1A /* MockGeocodeServiceProvider.swift in Sources */,
347D0F9825952F89002451EC /* AppDelegate.swift in Sources */,
3449403225C348C70020E664 /* CalendarPickerViewController.swift in Sources */,
3421DA122693E70E00056837 /* MockPopoverSettings.swift in Sources */,
3421DA122693E70E00056837 /* MockEventDetailsSettings.swift in Sources */,
3477F3E825FD52AA008EA888 /* NSViewController+Rx.swift in Sources */,
34B5A09325B0CE6F00F7F7ED /* SettingsViewController.swift in Sources */,
34C1D41E2C6E567100295E5E /* ProcessInfo.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions Calendr/Assets/Strings.generated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ internal enum Strings {
internal enum Events {
/// Finished
internal static let finished = Strings.tr("Localizable", "settings.events.finished", fallback: "Finished")
/// Show map and weather
internal static let showMap = Strings.tr("Localizable", "settings.events.show_map", fallback: "Show map and weather")
internal enum Finished {
/// Fade
internal static let fade = Strings.tr("Localizable", "settings.events.finished.fade", fallback: "Fade")
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/de.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"settings.calendar.show_declined_events_tooltip" = "Dies funktioniert nur, wenn es auch in der nativen Kalender-App aktiviert ist.";

"settings.events" = "Termine";
"settings.events.show_map" = "Karte und Wetter anzeigen";
"settings.events.finished" = "Erledigt";
"settings.events.finished.fade" = "Verblassen";
"settings.events.finished.hide" = "Verstecken";
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"settings.calendar.show_declined_events_tooltip" = "This only works if it is also enabled in the native Calendar app.";

"settings.events" = "Events";
"settings.events.show_map" = "Show map and weather";
"settings.events.finished" = "Finished";
"settings.events.finished.fade" = "Fade";
"settings.events.finished.hide" = "Hide";
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/es.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"settings.calendar.show_declined_events_tooltip" = "Esto solo funciona si también está habilitado en la aplicación Calendario nativa.";

"settings.events" = "Eventos";
"settings.events.show_map" = "Mostrar mapa y clima";
"settings.events.finished" = "Finalizados";
"settings.events.finished.fade" = "Sombrear";
"settings.events.finished.hide" = "Esconder";
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/fr.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"settings.calendar.show_declined_events_tooltip" = "Cela ne fonctionne que s'il est également activé dans l'application Calendrier native.";

"settings.events" = "Événements";
"settings.events.show_map" = "Afficher la carte et la météo";
"settings.events.finished" = "Terminés";
"settings.events.finished.fade" = "Atténuer";
"settings.events.finished.hide" = "Masquer";
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/it.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"settings.calendar.show_declined_events_tooltip" = "Questo funziona solo se attivato nell'app di sistema Calendar.";

"settings.events" = "Eventi";
"settings.events.show_map" = "Mostra mappa e meteo";
"settings.events.finished" = "Finiti";
"settings.events.finished.fade" = "Dissolvi";
"settings.events.finished.hide" = "Nascondi";
Expand Down
1 change: 1 addition & 0 deletions Calendr/Assets/pt.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"settings.calendar.show_declined_events_tooltip" = "Isso só funciona se também estiver ativado no aplicativo Calendário nativo.";

"settings.events" = "Eventos";
"settings.events.show_map" = "Mostrar mapa e clima";
"settings.events.finished" = "Terminados";
"settings.events.finished.fade" = "Sombrear";
"settings.events.finished.hide" = "Ocultar";
Expand Down
32 changes: 18 additions & 14 deletions Calendr/Events/EventDetails/EventDetailsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -310,19 +310,23 @@ class EventDetailsViewController: NSViewController, PopoverDelegate, MKMapViewDe
if !viewModel.location.isEmpty {
locationLabel.stringValue = viewModel.location
detailsStackView.addArrangedSubview(makeLine())

let weatherContainer = NSView().with(size: CGSize(width: 30, height: 26))

let locationStack = NSStackView(.horizontal).with(alignment: .centerY)
locationStack.setHuggingPriority(.defaultHigh, for: .vertical)
locationStack.addArrangedSubview(locationLabel)
locationStack.addArrangedSubview(weatherContainer)

detailsStackView.addArrangedSubview(locationStack)

let mapIndex = detailsStackView.arrangedSubviews.count
addLocationMap(at: mapIndex)
addLocationWeather(in: weatherContainer)

if viewModel.canShowMap.value {
let weatherContainer = NSView().with(size: CGSize(width: 30, height: 26))

let locationStack = NSStackView(.horizontal).with(alignment: .centerY)
locationStack.setHuggingPriority(.defaultHigh, for: .vertical)
locationStack.addArrangedSubview(locationLabel)
locationStack.addArrangedSubview(weatherContainer)

detailsStackView.addArrangedSubview(locationStack)

let mapIndex = detailsStackView.arrangedSubviews.count
addLocationMap(at: mapIndex)
addLocationWeather(in: weatherContainer)
} else {
detailsStackView.addArrangedSubview(locationLabel)
}
}

if !viewModel.duration.isEmpty {
Expand Down Expand Up @@ -528,7 +532,7 @@ class EventDetailsViewController: NSViewController, PopoverDelegate, MKMapViewDe
.take(1)

Observable.combineLatest(
popoverView, viewModel.popoverSettings.popoverMaterial
popoverView, viewModel.settings.popoverMaterial
)
.bind { $0.material = $1 }
.disposed(by: disposeBag)
Expand Down
40 changes: 22 additions & 18 deletions Calendr/Events/EventDetails/EventDetailsViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ class EventDetailsViewModel {
let notes: String
let participants: [Participant]
let link: EventLink?
let popoverSettings: PopoverSettings
let settings: EventDetailsSettings
let showSkip: Bool
let optimisticLoadTime: DispatchTimeInterval

let canShowMap = BehaviorSubject<Bool>(value: false)
let coordinates: Maybe<Coordinates>
let weather: Maybe<(Weather, isAllDay: Bool)>
let isInProgress: Observable<Bool>
Expand Down Expand Up @@ -66,7 +67,7 @@ class EventDetailsViewModel {
geocoder: GeocodeServiceProviding,
weatherService: WeatherServiceProviding,
workspace: WorkspaceServiceProviding,
popoverSettings: PopoverSettings,
settings: EventDetailsSettings,
isShowingObserver: AnyObserver<Bool>,
isInProgress: Observable<Bool>,
source: EventDetailsSource,
Expand All @@ -75,7 +76,7 @@ class EventDetailsViewModel {
self.event = event
self.dateProvider = dateProvider
self.calendarService = calendarService
self.popoverSettings = popoverSettings
self.settings = settings
self.isShowingObserver = isShowingObserver
self.isInProgress = isInProgress
self.workspace = workspace
Expand Down Expand Up @@ -164,23 +165,26 @@ class EventDetailsViewModel {
return .event(.skip)
}

coordinates = Maybe.create { observer in
Task {
guard let address = event.location, !address.isEmpty else {
observer(.completed)
return
}
if let coordinates = event.coordinates {
observer(.success(coordinates))
}
else if let coordinates = await geocoder.geocodeAddressString(address) {
let showMap = settings.showMap.take(1)

showMap.bind(to: canShowMap).disposed(by: disposeBag)

coordinates = showMap.asSingle().flatMapMaybe { showMap in
guard showMap, let address = event.location, !address.isEmpty else {
return .empty()
}
if let coordinates = event.coordinates {
return .just(coordinates)
}
return Maybe.create { observer in
Task {
guard let coordinates = await geocoder.geocodeAddressString(address) else {
return observer(.completed)
}
observer(.success(coordinates))
}
else {
observer(.completed)
}
return Disposables.create()
}
return Disposables.create()
}
.asObservable()
.share(replay: 1, scope: .forever)
Expand Down Expand Up @@ -208,7 +212,7 @@ class EventDetailsViewModel {
// trigger early fetch and keep value
weather.subscribe().disposed(by: disposeBag)

optimisticLoadTime = .milliseconds(event.location.isNilOrEmpty ? 0 : 50)
optimisticLoadTime = .milliseconds(canShowMap.value && !event.location.isNilOrEmpty ? 50 : 0)
}

func makeContextMenuViewModel() -> (any ContextMenuViewModel)? {
Expand Down
2 changes: 1 addition & 1 deletion Calendr/Events/EventList/EventListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class EventListViewModel {
geocoder: geocoder,
weatherService: weatherService,
workspace: workspace,
popoverSettings: settings,
settings: settings,
isShowingDetails: isShowingDetails.asObserver(),
isTodaySelected: isTodaySelected,
scheduler: scheduler
Expand Down
8 changes: 4 additions & 4 deletions Calendr/Events/EventList/EventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class EventViewModel {
private let calendarService: CalendarServiceProviding
private let geocoder: GeocodeServiceProviding
private let weatherService: WeatherServiceProviding
private let popoverSettings: PopoverSettings
private let settings: EventDetailsSettings

let workspace: WorkspaceServiceProviding

Expand All @@ -43,14 +43,14 @@ class EventViewModel {
geocoder: GeocodeServiceProviding,
weatherService: WeatherServiceProviding,
workspace: WorkspaceServiceProviding,
popoverSettings: PopoverSettings,
settings: EventDetailsSettings,
isShowingDetails: AnyObserver<Bool>,
isTodaySelected: Bool,
scheduler: SchedulerType
) {

self.event = event
self.popoverSettings = popoverSettings
self.settings = settings
self.dateProvider = dateProvider
self.calendarService = calendarService
self.workspace = workspace
Expand Down Expand Up @@ -205,7 +205,7 @@ class EventViewModel {
geocoder: geocoder,
weatherService: weatherService,
workspace: workspace,
popoverSettings: popoverSettings,
settings: settings,
isShowingObserver: isShowingDetails,
isInProgress: isInProgress,
source: .list,
Expand Down
6 changes: 3 additions & 3 deletions Calendr/MenuBar/NextEventViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class NextEventViewModel {

private let type: NextEventType
private let userDefaults: UserDefaults
private let popoverSettings: PopoverSettings
private let settings: EventDetailsSettings
private let dateProvider: DateProviding
private let calendarService: CalendarServiceProviding
private let geocoder: GeocodeServiceProviding
Expand Down Expand Up @@ -91,7 +91,7 @@ class NextEventViewModel {
self.calendarService = calendarService
self.geocoder = geocoder
self.weatherService = weatherService
self.popoverSettings = settings
self.settings = settings
self.workspace = workspace
self.isShowingDetails = isShowingDetails
self.fontSize = settings.eventStatusItemFontSize
Expand Down Expand Up @@ -269,7 +269,7 @@ class NextEventViewModel {
geocoder: geocoder,
weatherService: weatherService,
workspace: workspace,
popoverSettings: popoverSettings,
settings: settings,
isShowingObserver: isShowingDetails,
isInProgress: isInProgress,
source: .menubar,
Expand Down
23 changes: 23 additions & 0 deletions Calendr/Mocks/MockEventDetailsSettings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// MockEventDetailsSettings.swift
// Calendr
//
// Created by Paker on 05/07/2021.
//

#if DEBUG

import RxSwift

class MockEventDetailsSettings: EventDetailsSettings {

let showMap: Observable<Bool>
let popoverMaterial: Observable<PopoverMaterial>

init(showMap: Bool = false, popoverMaterial: PopoverMaterial = .popover) {
self.showMap = .just(showMap)
self.popoverMaterial = .just(popoverMaterial)
}
}

#endif
2 changes: 1 addition & 1 deletion Calendr/Mocks/MockEventListSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import Foundation
import RxSwift

class MockEventListSettings: MockPopoverSettings, EventListSettings {
class MockEventListSettings: MockEventDetailsSettings, EventListSettings {

let showPastEvents: Observable<Bool>

Expand Down
2 changes: 1 addition & 1 deletion Calendr/Mocks/MockNextEventSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import RxSwift

class MockNextEventSettings: MockPopoverSettings, NextEventSettings {
class MockNextEventSettings: MockEventDetailsSettings, NextEventSettings {

let showEventStatusItem: Observable<Bool>
let eventStatusItemFontSize: Observable<Float>
Expand Down
21 changes: 0 additions & 21 deletions Calendr/Mocks/MockPopoverSettings.swift

This file was deleted.

Loading

0 comments on commit 5c28b5f

Please sign in to comment.