Skip to content

Commit

Permalink
refactor(Share): improve code of sharing feature (Dimillian#260)
Browse files Browse the repository at this point in the history
* When trying to work on Dimillian#251, but cannot fix the initial issue. At
least these improvements can be merged
  • Loading branch information
renaudjenny authored Jun 14, 2020
1 parent f370cd0 commit 31eb059
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
4 changes: 4 additions & 0 deletions ACHNBrowserUI/ACHNBrowserUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -254,6 +255,7 @@
4C2D6773245F4EA2005831C4 /* TurnipsChartAverageCurve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartAverageCurve.swift; sourceTree = "<group>"; };
4C2D6775245F4F55005831C4 /* TurnipsChartMinMaxCurves.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartMinMaxCurves.swift; sourceTree = "<group>"; };
4C2D6777245F4FE8005831C4 /* TurnipsChartMinBuyPriceCurve.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartMinBuyPriceCurve.swift; sourceTree = "<group>"; };
4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Sequence+Unique.swift"; sourceTree = "<group>"; };
4C382EE7244E418800F446BA /* DismissingKeyboardOnSwipe.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DismissingKeyboardOnSwipe.swift; sourceTree = "<group>"; };
4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Collection+SafeDirectAccess.swift"; sourceTree = "<group>"; };
4C7F2F772461F10300930928 /* TurnipsChartVerticalLegend.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TurnipsChartVerticalLegend.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -569,6 +571,7 @@
693E2BC7246697FC00B85CB8 /* Image.swift */,
3DECE21A2483BC82001F24BA /* EditMode.swift */,
4C6E95FC24842F690074433B /* Collection+SafeDirectAccess.swift */,
4C30BFC2249627FC003E96A2 /* Sequence+Unique.swift */,
);
path = extensions;
sourceTree = "<group>";
Expand Down Expand Up @@ -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 */,
Expand Down
17 changes: 17 additions & 0 deletions ACHNBrowserUI/ACHNBrowserUI/extensions/Sequence+Unique.swift
Original file line number Diff line number Diff line change
@@ -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 }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityControllerView>) -> 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<ActivityControllerView>) {

}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class ItemDetailSource: NSObject, UIActivityItemSource {

metadata.title = name
metadata.imageProvider = NSItemProvider(object: image)
metadata.imageProvider = NSItemProvider(object: image)

return metadata
}
Expand Down
3 changes: 2 additions & 1 deletion ACHNBrowserUI/ACHNBrowserUI/views/shared/Sheet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 31eb059

Please sign in to comment.