diff --git a/ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj b/ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj index 8d2882ea..ae4c9861 100644 --- a/ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj +++ b/ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 3D9AB093248257DF00B47041 /* CustomTaskFormViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3D9AB092248257DF00B47041 /* CustomTaskFormViewModel.swift */; }; 3DECE21B2483BC83001F24BA /* EditMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3DECE21A2483BC82001F24BA /* EditMode.swift */; }; 4C16FB41247AC9B0009F24E3 /* GridStack.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C16FB40247AC9B0009F24E3 /* GridStack.swift */; }; + 4C30BFC3249627FD003E96A2 /* Sequence+Unique.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */; }; 4C6E95FD24842F690074433B /* Collection+SafeDirectAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */; }; 4C7F555D248B91C80089F26C /* TodayVillagerVisitsSection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4C7F555C248B91C80089F26C /* TodayVillagerVisitsSection.swift */; }; 690A72C924752BF4001E7294 /* villagersLikes in Resources */ = {isa = PBXBuildFile; fileRef = 690A72C824752BF4001E7294 /* villagersLikes */; }; @@ -254,6 +255,7 @@ 4C2D6773245F4EA2005831C4 /* TurnipsChartAverageCurve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartAverageCurve.swift; sourceTree = ""; }; 4C2D6775245F4F55005831C4 /* TurnipsChartMinMaxCurves.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartMinMaxCurves.swift; sourceTree = ""; }; 4C2D6777245F4FE8005831C4 /* TurnipsChartMinBuyPriceCurve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartMinBuyPriceCurve.swift; sourceTree = ""; }; + 4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+Unique.swift"; sourceTree = ""; }; 4C382EE7244E418800F446BA /* DismissingKeyboardOnSwipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissingKeyboardOnSwipe.swift; sourceTree = ""; }; 4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+SafeDirectAccess.swift"; sourceTree = ""; }; 4C7F2F772461F10300930928 /* TurnipsChartVerticalLegend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartVerticalLegend.swift; sourceTree = ""; }; @@ -569,6 +571,7 @@ 693E2BC7246697FC00B85CB8 /* Image.swift */, 3DECE21A2483BC82001F24BA /* EditMode.swift */, 4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */, + 4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */, ); path = extensions; sourceTree = ""; @@ -1290,6 +1293,7 @@ 69157BC92471A5A1005B9002 /* TurnipsChartGrid.swift in Sources */, 4C7F555D248B91C80089F26C /* TodayVillagerVisitsSection.swift in Sources */, 69157BCA2471A5A1005B9002 /* CollectionRowView.swift in Sources */, + 4C30BFC3249627FD003E96A2 /* Sequence+Unique.swift in Sources */, AE0B5B5C247AD7590075CF16 /* DesignFormViewModel.swift in Sources */, AE51C2E324801D5D00F074EC /* ChoreListRowView.swift in Sources */, 69E67EF0249376DF00ED7AC8 /* DodoCodeRow.swift in Sources */, diff --git a/ACHNBrowserUI/ACHNBrowserUI/extensions/Sequence+Unique.swift b/ACHNBrowserUI/ACHNBrowserUI/extensions/Sequence+Unique.swift new file mode 100644 index 00000000..9cf9f350 --- /dev/null +++ b/ACHNBrowserUI/ACHNBrowserUI/extensions/Sequence+Unique.swift @@ -0,0 +1,17 @@ +// +// Sequence+Unique.swift +// ACHNBrowserUI +// +// Created by Renaud JENNY on 14/06/2020. +// Copyright © 2020 Thomas Ricouard. All rights reserved. +// + +import Foundation + +// See tobiasdm answer https://stackoverflow.com/questions/27624331/unique-values-of-array-in-swift +extension Sequence where Iterator.Element: Hashable { + func unique() -> [Iterator.Element] { + var seen: [Iterator.Element: Bool] = [:] + return filter { seen.updateValue(true, forKey: $0) == nil } + } +} diff --git a/ACHNBrowserUI/ACHNBrowserUI/representables/ActivityControllerView.swift b/ACHNBrowserUI/ACHNBrowserUI/representables/ActivityControllerView.swift index d4a21be9..45ae98c3 100644 --- a/ACHNBrowserUI/ACHNBrowserUI/representables/ActivityControllerView.swift +++ b/ACHNBrowserUI/ACHNBrowserUI/representables/ActivityControllerView.swift @@ -11,23 +11,24 @@ import SwiftUI #if !os(tvOS) public struct ActivityControllerView: UIViewControllerRepresentable { - - public let activityItems: [Any] - public let applicationActivities: [UIActivity]? - - public init(activityItems: [Any], applicationActivities: [UIActivity]?) { - self.activityItems = activityItems - self.applicationActivities = applicationActivities - } + @Environment(\.presentationMode) var presentation + public var activityItems: [Any] + public var applicationActivities: [UIActivity]? public func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIActivityViewController { - return UIActivityViewController(activityItems: activityItems, - applicationActivities: applicationActivities) + let controller = UIActivityViewController( + activityItems: activityItems, + applicationActivities: applicationActivities + ) + controller.completionWithItemsHandler = { _, _, _, _ in + self.presentation.wrappedValue.dismiss() + } + return controller } public func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext) { - + } } #endif diff --git a/ACHNBrowserUI/ACHNBrowserUI/viewModels/VillagerDetailViewModel.swift b/ACHNBrowserUI/ACHNBrowserUI/viewModels/VillagerDetailViewModel.swift index e242c369..b3aeae7c 100644 --- a/ACHNBrowserUI/ACHNBrowserUI/viewModels/VillagerDetailViewModel.swift +++ b/ACHNBrowserUI/ACHNBrowserUI/viewModels/VillagerDetailViewModel.swift @@ -37,7 +37,10 @@ public class VillagerDetailViewModel: ObservableObject { self?.preferredItems = items }) - self.likes = Array(Set(Items.shared.villagersLike.values.first(where: { $0.id == filename })!.likes)) + self.likes = Items.shared.villagersLike.values + .first(where: { $0.id == filename })? + .likes + .unique() } else { self.villagerItems = nil diff --git a/ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailSource.swift b/ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailSource.swift index 6c9a9c66..c8ba985e 100644 --- a/ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailSource.swift +++ b/ACHNBrowserUI/ACHNBrowserUI/views/items/detail/ItemDetailSource.swift @@ -32,7 +32,6 @@ class ItemDetailSource: NSObject, UIActivityItemSource { metadata.title = name metadata.imageProvider = NSItemProvider(object: image) - metadata.imageProvider = NSItemProvider(object: image) return metadata } diff --git a/ACHNBrowserUI/ACHNBrowserUI/views/shared/Sheet.swift b/ACHNBrowserUI/ACHNBrowserUI/views/shared/Sheet.swift index 5246354a..2d0ce4e5 100644 --- a/ACHNBrowserUI/ACHNBrowserUI/views/shared/Sheet.swift +++ b/ACHNBrowserUI/ACHNBrowserUI/views/shared/Sheet.swift @@ -11,7 +11,8 @@ import Backend struct Sheet: View { enum SheetType: Identifiable { - case safari(URL), share(content: [Any]) + case safari(URL) + case share(content: [Any]) case about case userListForm(editingList: UserList?) case customTasks(collection: UserCollection)