From 96f766c8c9850cf4fd3cb77393b910670e9137de Mon Sep 17 00:00:00 2001 From: Trey t Date: Wed, 9 Feb 2022 23:03:47 -0600 Subject: [PATCH] create all templates .... started to fill one out --- Feels.xcodeproj/project.pbxproj | 50 ++++++- .../AllMoodsTotalTemplate.swift | 44 ++++++ .../CurrentStreakTemplate.swift | 44 ++++++ .../LongestStreakTemplate.swift | 127 ++++++++++++++++++ .../SharingTemplates/MonthTotalTemplate.swift | 44 ++++++ .../SharingTemplates/WeekTotalTemplate.swift | 44 ++++++ Shared/Persistence.swift | 11 ++ .../ChartDataBuildable.swift | 0 .../ChartViewItemBuildable.swift | 0 Shared/Protocols/SharingTemplate.swift | 22 +++ Shared/Random.swift | 12 ++ Shared/views/ActivityViewController.swift | 16 +++ Shared/views/ContentView.swift | 4 +- Shared/views/ShareButtonview.swift | 42 ++++++ Shared/views/SharingView.swift | 105 +++++++++++++++ en.lproj/Localizable.strings | 2 +- 16 files changed, 561 insertions(+), 6 deletions(-) create mode 100644 Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift create mode 100644 Shared/Models/SharingTemplates/CurrentStreakTemplate.swift create mode 100644 Shared/Models/SharingTemplates/LongestStreakTemplate.swift create mode 100644 Shared/Models/SharingTemplates/MonthTotalTemplate.swift create mode 100644 Shared/Models/SharingTemplates/WeekTotalTemplate.swift rename Shared/{Protocol => Protocols}/ChartDataBuildable.swift (100%) rename Shared/{Protocol => Protocols}/ChartViewItemBuildable.swift (100%) create mode 100644 Shared/Protocols/SharingTemplate.swift create mode 100644 Shared/views/ActivityViewController.swift create mode 100644 Shared/views/ShareButtonview.swift create mode 100644 Shared/views/SharingView.swift diff --git a/Feels.xcodeproj/project.pbxproj b/Feels.xcodeproj/project.pbxproj index c268d6a..68642c4 100644 --- a/Feels.xcodeproj/project.pbxproj +++ b/Feels.xcodeproj/project.pbxproj @@ -17,6 +17,15 @@ 1C26190327960CE500FDC148 /* ChartDataBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C26190227960CE500FDC148 /* ChartDataBuildable.swift */; }; 1C26190727960DC900FDC148 /* ChartViewItemBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */; }; 1C358FAD27ADD0C3002C83A6 /* Theme.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FAC27ADD0C3002C83A6 /* Theme.swift */; }; + 1C358FB127B0AD87002C83A6 /* SharingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FB027B0AD87002C83A6 /* SharingView.swift */; }; + 1C358FB327B0ADA4002C83A6 /* SharingTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FB227B0ADA4002C83A6 /* SharingTemplate.swift */; }; + 1C358FB627B0AE15002C83A6 /* AllMoodsTotalTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FB527B0AE15002C83A6 /* AllMoodsTotalTemplate.swift */; }; + 1C358FB827B0AEE3002C83A6 /* LongestStreakTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FB727B0AEE3002C83A6 /* LongestStreakTemplate.swift */; }; + 1C358FBA27B35252002C83A6 /* ActivityViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FB927B35252002C83A6 /* ActivityViewController.swift */; }; + 1C358FBC27B352B1002C83A6 /* ShareButtonview.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FBB27B352B1002C83A6 /* ShareButtonview.swift */; }; + 1C358FBE27B4D1F2002C83A6 /* CurrentStreakTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FBD27B4D1F2002C83A6 /* CurrentStreakTemplate.swift */; }; + 1C358FC027B4D20C002C83A6 /* MonthTotalTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FBF27B4D20C002C83A6 /* MonthTotalTemplate.swift */; }; + 1C358FC227B4D227002C83A6 /* WeekTotalTemplate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */; }; 1C5F4976279C84090092F1B4 /* OnboardingData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4975279C84090092F1B4 /* OnboardingData.swift */; }; 1C5F4978279C945E0092F1B4 /* UserDefaultsStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */; }; 1C683FCA2792281400745862 /* Stats.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1C683FC92792281400745862 /* Stats.swift */; }; @@ -122,6 +131,15 @@ 1C26190227960CE500FDC148 /* ChartDataBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartDataBuildable.swift; sourceTree = ""; }; 1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewItemBuildable.swift; sourceTree = ""; }; 1C358FAC27ADD0C3002C83A6 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = ""; }; + 1C358FB027B0AD87002C83A6 /* SharingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingView.swift; sourceTree = ""; }; + 1C358FB227B0ADA4002C83A6 /* SharingTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingTemplate.swift; sourceTree = ""; }; + 1C358FB527B0AE15002C83A6 /* AllMoodsTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllMoodsTotalTemplate.swift; sourceTree = ""; }; + 1C358FB727B0AEE3002C83A6 /* LongestStreakTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongestStreakTemplate.swift; sourceTree = ""; }; + 1C358FB927B35252002C83A6 /* ActivityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewController.swift; sourceTree = ""; }; + 1C358FBB27B352B1002C83A6 /* ShareButtonview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareButtonview.swift; sourceTree = ""; }; + 1C358FBD27B4D1F2002C83A6 /* CurrentStreakTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentStreakTemplate.swift; sourceTree = ""; }; + 1C358FBF27B4D20C002C83A6 /* MonthTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthTotalTemplate.swift; sourceTree = ""; }; + 1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekTotalTemplate.swift; sourceTree = ""; }; 1C5F4975279C84090092F1B4 /* OnboardingData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingData.swift; sourceTree = ""; }; 1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = ""; }; 1C683FC92792281400745862 /* Stats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = ""; }; @@ -221,13 +239,26 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 1C26190127960CDA00FDC148 /* Protocol */ = { + 1C26190127960CDA00FDC148 /* Protocols */ = { isa = PBXGroup; children = ( 1C26190227960CE500FDC148 /* ChartDataBuildable.swift */, 1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */, + 1C358FB227B0ADA4002C83A6 /* SharingTemplate.swift */, ); - path = Protocol; + path = Protocols; + sourceTree = ""; + }; + 1C358FB427B0ADF3002C83A6 /* SharingTemplates */ = { + isa = PBXGroup; + children = ( + 1C358FB527B0AE15002C83A6 /* AllMoodsTotalTemplate.swift */, + 1C358FBD27B4D1F2002C83A6 /* CurrentStreakTemplate.swift */, + 1C358FB727B0AEE3002C83A6 /* LongestStreakTemplate.swift */, + 1C358FBF27B4D20C002C83A6 /* MonthTotalTemplate.swift */, + 1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */, + ); + path = SharingTemplates; sourceTree = ""; }; 1CA03771279A291F00D26164 /* Onboarding */ = { @@ -264,6 +295,9 @@ 1CAD602C27A5C1C800C520BD /* SettingsView.swift */, 1CAD602B27A5C1C800C520BD /* SmallRollUpHeaderView.swift */, 1CAD603D27A6ECCD00C520BD /* SwitchableView.swift */, + 1C358FB027B0AD87002C83A6 /* SharingView.swift */, + 1C358FB927B35252002C83A6 /* ActivityViewController.swift */, + 1C358FBB27B352B1002C83A6 /* ShareButtonview.swift */, ); path = Views; sourceTree = ""; @@ -298,7 +332,7 @@ 1CD90B5C278C7EAD001C4FEA /* Random.swift */, 1C683FC92792281400745862 /* Stats.swift */, 1CA03771279A291F00D26164 /* Onboarding */, - 1C26190127960CDA00FDC148 /* Protocol */, + 1C26190127960CDA00FDC148 /* Protocols */, 1CAD602A27A5C1C800C520BD /* Views */, 1CD90B60278C7EBA001C4FEA /* Models */, 1CD90AF0278C7DE0001C4FEA /* Assets.xcassets */, @@ -369,6 +403,7 @@ 1CD90B60278C7EBA001C4FEA /* Models */ = { isa = PBXGroup; children = ( + 1C358FB427B0ADF3002C83A6 /* SharingTemplates */, 1CA0376F2799FFA600D26164 /* ContentModeViewModel.swift */, 1CC469AB27907D48003E0C6E /* DayChartView.swift */, 1C2618FD27960A4F00FDC148 /* FilterViewModel.swift */, @@ -589,7 +624,9 @@ 1CAD603727A5C1C800C520BD /* FilterView.swift in Sources */, 1C683FCA2792281400745862 /* Stats.swift in Sources */, 1CAD603E27A6ECCD00C520BD /* SwitchableView.swift in Sources */, + 1C358FBC27B352B1002C83A6 /* ShareButtonview.swift in Sources */, 1CD90B76278C8119001C4FEA /* LocalNotification.swift in Sources */, + 1C358FB627B0AE15002C83A6 /* AllMoodsTotalTemplate.swift in Sources */, 1CD90B16278C7DE0001C4FEA /* Feels.xcdatamodeld in Sources */, 1CC469AA278F30A0003E0C6E /* BGTask.swift in Sources */, 1CAD603B27A5C1C800C520BD /* ContentView.swift in Sources */, @@ -601,18 +638,25 @@ 1C2618FE27960A4F00FDC148 /* FilterViewModel.swift in Sources */, 1C744F2C278CE15600953A57 /* AppDelegate.swift in Sources */, 1CD90B63278C7EBA001C4FEA /* Mood.swift in Sources */, + 1C358FBE27B4D1F2002C83A6 /* CurrentStreakTemplate.swift in Sources */, 1CAD603527A5C1C800C520BD /* SettingsView.swift in Sources */, 1CD90B53278C7E7A001C4FEA /* FeelsWidget.intentdefinition in Sources */, 1CC469AC27907D48003E0C6E /* DayChartView.swift in Sources */, 1C26190327960CE500FDC148 /* ChartDataBuildable.swift in Sources */, 1CAD603627A5C1C800C520BD /* GraphView.swift in Sources */, 1CD90B66278C7EBA001C4FEA /* MoodEntryExtension.swift in Sources */, + 1C358FB327B0ADA4002C83A6 /* SharingTemplate.swift in Sources */, + 1C358FB827B0AEE3002C83A6 /* LongestStreakTemplate.swift in Sources */, + 1C358FB127B0AD87002C83A6 /* SharingView.swift in Sources */, 1CD90B1C278C7DE0001C4FEA /* Persistence.swift in Sources */, 1CA0377A279A296E00D26164 /* OnboardingMain.swift in Sources */, + 1C358FBA27B35252002C83A6 /* ActivityViewController.swift in Sources */, 1C5F4978279C945E0092F1B4 /* UserDefaultsStore.swift in Sources */, 1CD90B18278C7DE0001C4FEA /* FeelsApp.swift in Sources */, + 1C358FC027B4D20C002C83A6 /* MonthTotalTemplate.swift in Sources */, 1CA03777279A295600D26164 /* OnboardingTitle.swift in Sources */, 1C358FAD27ADD0C3002C83A6 /* Theme.swift in Sources */, + 1C358FC227B4D227002C83A6 /* WeekTotalTemplate.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift b/Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift new file mode 100644 index 0000000..cf4c8c3 --- /dev/null +++ b/Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift @@ -0,0 +1,44 @@ +// +// AllMoods.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/6/22. +// + +import SwiftUI + +struct AllMoodsTotalTemplate: View, SharingTemplate { + static var description: String { + "AllMoodsSharingTemplate" + } + + var isPreview: Bool + + var startDate: Date + var endDate: Date + + var preview: some View { + Rectangle() + .frame(width: 150, height: 50, alignment: .leading) + } + + var mainView: some View { + Text("AllMoodsSharingTemplate body") + } + + var body: some View { + if isPreview { + preview + } else { + mainView + } + } +} + +struct AllMoodsSharingTemplate_Previews: PreviewProvider { + static var previews: some View { + AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + + AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + } +} diff --git a/Shared/Models/SharingTemplates/CurrentStreakTemplate.swift b/Shared/Models/SharingTemplates/CurrentStreakTemplate.swift new file mode 100644 index 0000000..ecd0e34 --- /dev/null +++ b/Shared/Models/SharingTemplates/CurrentStreakTemplate.swift @@ -0,0 +1,44 @@ +// +// CurrentStreakTemplate.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/9/22. +// + +import SwiftUI + +struct CurrentStreakTemplate: View, SharingTemplate { + static var description: String { + "CurrentStreakTemplate" + } + + var isPreview: Bool + + var startDate: Date + var endDate: Date + + var preview: some View { + Rectangle() + .frame(width: 150, height: 50, alignment: .leading) + } + + var mainView: some View { + Text("CurrentStreakTemplate body") + } + + var body: some View { + if isPreview { + preview + } else { + mainView + } + } +} + +struct CurrentStreakTemplate_Previews: PreviewProvider { + static var previews: some View { + CurrentStreakTemplate(isPreview: true, startDate: Date(), endDate: Date()) + + CurrentStreakTemplate(isPreview: false, startDate: Date(), endDate: Date()) + } +} diff --git a/Shared/Models/SharingTemplates/LongestStreakTemplate.swift b/Shared/Models/SharingTemplates/LongestStreakTemplate.swift new file mode 100644 index 0000000..8b792e2 --- /dev/null +++ b/Shared/Models/SharingTemplates/LongestStreakTemplate.swift @@ -0,0 +1,127 @@ +// +// AllMoods.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/6/22. +// + +import SwiftUI + +struct LongestStreakTemplate: View, SharingTemplate { + static var description: String { + "Share your longest streak!!!!" + } + + @State private var showSharingTemplate = false + + var isPreview: Bool + var startDate: Date + var endDate: Date + + var entries: [MoodEntry] + + init(isPreview: Bool, startDate: Date, endDate: Date) { + self.isPreview = isPreview + self.startDate = startDate + self.endDate = endDate + + /* + get all + Split on missing entries + Longest subarray + */ + + entries = PersistenceController.shared.randomEntries(count: 10) + } + + var image: UIImage { + let image = shit.snapshot() + return image + } + + var preview: some View { + ZStack { + VStack { + HStack { + Text("Longest Streak") + Spacer() + Text(String(entries.count)) + } + Text("From") + HStack { + Text(String(entries.first?.forDate?.description ?? "")) + Text("-") + Text(String(entries.last?.forDate?.description ?? "")) + } + } + } + .background( + Color.red + ) + } + + var shit: some View { + ZStack { + VStack { + HStack { + Text("Longest Streak") + Spacer() + Text(String(entries.count)) + } + Text("From") + HStack { + Text(String(entries.first?.forDate?.description ?? "")) + Text("-") + Text(String(entries.last?.forDate?.description ?? "")) + } + } + } + .background( + Color.red + ) + } + + var mainView: some View { + ZStack { + shit + + VStack { + Spacer() + + HStack { + Spacer() + + Button(action: { + showSharingTemplate = true + }, label: { + Image(systemName: "square.and.arrow.up") + .foregroundColor(.black) + }) + } + } + } + .sheet(isPresented: $showSharingTemplate) { + ActivityViewController(activityItems: [self.image]) + } + .padding() + .background( + Color.red + ) + } + + var body: some View { + if isPreview { + preview + } else { + mainView + } + } +} + +struct CurrentStreakSharingTemplate_Previews: PreviewProvider { + static var previews: some View { + LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date()) + + LongestStreakTemplate(isPreview: true, startDate: Date(), endDate: Date()) + } +} diff --git a/Shared/Models/SharingTemplates/MonthTotalTemplate.swift b/Shared/Models/SharingTemplates/MonthTotalTemplate.swift new file mode 100644 index 0000000..a14c498 --- /dev/null +++ b/Shared/Models/SharingTemplates/MonthTotalTemplate.swift @@ -0,0 +1,44 @@ +// +// MonthTotalTemplate.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/9/22. +// + +import SwiftUI + +struct MonthTotalTemplate: View, SharingTemplate { + static var description: String { + "MonthTotalTemplate" + } + + var isPreview: Bool + + var startDate: Date + var endDate: Date + + var preview: some View { + Rectangle() + .frame(width: 150, height: 50, alignment: .leading) + } + + var mainView: some View { + Text("MonthTotalTemplate body") + } + + var body: some View { + if isPreview { + preview + } else { + mainView + } + } +} + +struct MonthTotalTemplate_Previews: PreviewProvider { + static var previews: some View { + MonthTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + + MonthTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + } +} diff --git a/Shared/Models/SharingTemplates/WeekTotalTemplate.swift b/Shared/Models/SharingTemplates/WeekTotalTemplate.swift new file mode 100644 index 0000000..d2dd24c --- /dev/null +++ b/Shared/Models/SharingTemplates/WeekTotalTemplate.swift @@ -0,0 +1,44 @@ +// +// WeekTotalTemplate.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/9/22. +// + +import SwiftUI + +struct WeekTotalTemplate: View, SharingTemplate { + static var description: String { + "WeekTotalTemplate" + } + + var isPreview: Bool + + var startDate: Date + var endDate: Date + + var preview: some View { + Rectangle() + .frame(width: 150, height: 50, alignment: .leading) + } + + var mainView: some View { + Text("WeekTotalTemplate body") + } + + var body: some View { + if isPreview { + preview + } else { + mainView + } + } +} + +struct WeekTotalTemplate_Previews: PreviewProvider { + static var previews: some View { + WeekTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + + WeekTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + } +} diff --git a/Shared/Persistence.swift b/Shared/Persistence.swift index bbf8c67..3aabd0e 100644 --- a/Shared/Persistence.swift +++ b/Shared/Persistence.swift @@ -276,6 +276,17 @@ extension NSManagedObjectContext { } } +extension PersistenceController { + func longestStreak() -> [MoodEntry] { +// let predicate = NSPredicate(format: "forDate == %@", date as NSDate) + + let fetchRequest = NSFetchRequest(entityName: "MoodEntry") +// fetchRequest.predicate = predicate + fetchRequest.sortDescriptors = [NSSortDescriptor(key: "forDate", ascending: true)] + let data = try! viewContext.fetch(fetchRequest) + return data + } +} class NSCustomPersistentContainer: NSPersistentContainer { override open class func defaultDirectoryURL() -> URL { diff --git a/Shared/Protocol/ChartDataBuildable.swift b/Shared/Protocols/ChartDataBuildable.swift similarity index 100% rename from Shared/Protocol/ChartDataBuildable.swift rename to Shared/Protocols/ChartDataBuildable.swift diff --git a/Shared/Protocol/ChartViewItemBuildable.swift b/Shared/Protocols/ChartViewItemBuildable.swift similarity index 100% rename from Shared/Protocol/ChartViewItemBuildable.swift rename to Shared/Protocols/ChartViewItemBuildable.swift diff --git a/Shared/Protocols/SharingTemplate.swift b/Shared/Protocols/SharingTemplate.swift new file mode 100644 index 0000000..7d19b3d --- /dev/null +++ b/Shared/Protocols/SharingTemplate.swift @@ -0,0 +1,22 @@ +// +// SharingTemplate.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/6/22. +// + +import Foundation +import SwiftUI + +protocol SharingTemplate { + associatedtype MainView : View + associatedtype Preview : View + + var startDate: Date { get } + var endDate: Date { get } + var isPreview: Bool { get } + static var description: String { get } + + @ViewBuilder var mainView: Self.MainView { get } + @ViewBuilder var preview: Self.Preview { get } +} diff --git a/Shared/Random.swift b/Shared/Random.swift index 2eed27b..f818233 100644 --- a/Shared/Random.swift +++ b/Shared/Random.swift @@ -56,4 +56,16 @@ extension View { func cornerRadius(_ radius: CGFloat, corners: UIRectCorner) -> some View { clipShape( RoundedCorner(radius: radius, corners: corners) ) } + + func snapshot() -> UIImage { + let controller = UIHostingController(rootView: self) + let view = controller.view + let targetSize = controller.view.intrinsicContentSize + view?.bounds = CGRect(origin: .zero, size: targetSize) + view?.backgroundColor = .clear + let renderer = UIGraphicsImageRenderer(size: targetSize) + return renderer.image { _ in + view?.drawHierarchy(in: controller.view.bounds, afterScreenUpdates: true) + } + } } diff --git a/Shared/views/ActivityViewController.swift b/Shared/views/ActivityViewController.swift new file mode 100644 index 0000000..985eb56 --- /dev/null +++ b/Shared/views/ActivityViewController.swift @@ -0,0 +1,16 @@ +import UIKit +import SwiftUI + +struct ActivityViewController: UIViewControllerRepresentable { + + var activityItems: [Any] + var applicationActivities: [UIActivity]? = nil + + func makeUIViewController(context: UIViewControllerRepresentableContext) -> UIActivityViewController { + let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities) + return controller + } + + func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext) {} + +} diff --git a/Shared/views/ContentView.swift b/Shared/views/ContentView.swift index 530494e..985690f 100644 --- a/Shared/views/ContentView.swift +++ b/Shared/views/ContentView.swift @@ -51,9 +51,9 @@ struct ContentView: View { Label(String(localized: "content_view_tab_filter"), systemImage: "calendar.circle") } - GraphView() + SharingView() .tabItem { - Label(String(localized: "content_view_tab_stats"), systemImage: "chart.line.uptrend.xyaxis") + Label(String(localized: "content_view_tab_share"), systemImage: "square.and.arrow.up") } }.sheet(isPresented: $needsOnboarding, onDismiss: { diff --git a/Shared/views/ShareButtonview.swift b/Shared/views/ShareButtonview.swift new file mode 100644 index 0000000..be6b7a1 --- /dev/null +++ b/Shared/views/ShareButtonview.swift @@ -0,0 +1,42 @@ +// +// ShareButtonview.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/8/22. +// + +import SwiftUI + +struct ShareButtonview: View, Equatable { + static func == (lhs: ShareButtonview, rhs: ShareButtonview) -> Bool { + lhs.image == rhs.image + } + + @State private var showSheet = false + @State var image: UIImage? { + didSet { + showSheet = true + } + } + + var body: some View { + Button(action: { + showSheet = true + }, label: { + Image(systemName: "square.and.arrow.up") + .foregroundColor(.black) + }) + + if showSheet { + if let image = image { + ActivityViewController(activityItems: [image]) + } + } + } +} + +struct ShareButtonview_Previews: PreviewProvider { + static var previews: some View { + ShareButtonview() + } +} diff --git a/Shared/views/SharingView.swift b/Shared/views/SharingView.swift new file mode 100644 index 0000000..70a6493 --- /dev/null +++ b/Shared/views/SharingView.swift @@ -0,0 +1,105 @@ +// +// SharingView.swift +// Feels (iOS) +// +// Created by Trey Tartt on 2/6/22. +// + +import SwiftUI + +struct WrappedSharable: Hashable, Equatable { + static func == (lhs: WrappedSharable, rhs: WrappedSharable) -> Bool { + lhs.id == rhs.id + } + + func hash(into hasher: inout Hasher) { + hasher.combine(id) + } + + let id = UUID() + let preview: AnyView + let destination: AnyView + let description: String +} + +struct SharingView: View { + @AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system + + @State private var selectedShare: WrappedSharable? + @State private var showSharingTemplate = false + + let sharebleItems: [WrappedSharable] = [ + WrappedSharable(preview: AnyView( + AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + ),destination: AnyView( + AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + ),description: AllMoodsTotalTemplate.description), + + WrappedSharable(preview: AnyView( + CurrentStreakTemplate(isPreview: true, startDate: Date(), endDate: Date()) + ), destination: AnyView( + CurrentStreakTemplate(isPreview: false, startDate: Date(), endDate: Date()) + ), description: CurrentStreakTemplate.description), + + WrappedSharable(preview: AnyView( + LongestStreakTemplate(isPreview: true, startDate: Date(), endDate: Date()) + ), destination: AnyView( + LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date()) + ), description: LongestStreakTemplate.description), + + WrappedSharable(preview: AnyView( + MonthTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + ), destination: AnyView( + MonthTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + ), description: MonthTotalTemplate.description), + + WrappedSharable(preview: AnyView( + WeekTotalTemplate(isPreview: true, startDate: Date(), endDate: Date()) + ), destination: AnyView( + WeekTotalTemplate(isPreview: false, startDate: Date(), endDate: Date()) + ), description: WeekTotalTemplate.description) + ] + + func didDismiss() { + showSharingTemplate = false + } + + var body: some View { + ScrollView { + ForEach(sharebleItems, id: \.self) { item in + ZStack { + Color(theme.currentTheme.secondaryBGColor) + + item.preview + .opacity(0.5) + + VStack { + Spacer() + Text(item.description) + .frame(minWidth: 0, maxWidth: .infinity) + .background( + Color.white + ) + .frame(minHeight: 22, maxHeight: 22) + } + } + .frame(minHeight: 88, maxHeight: 88) + .cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight]) + .onTapGesture ( perform: { + selectedShare = item + showSharingTemplate = true + }) + } + .padding() + }.sheet(isPresented: $showSharingTemplate, + onDismiss: didDismiss) { + selectedShare?.destination + } + } +} + +struct SharingView_Previews: PreviewProvider { + static var previews: some View { + SharingView() + } +} diff --git a/en.lproj/Localizable.strings b/en.lproj/Localizable.strings index d25fc25..ba34bd2 100644 --- a/en.lproj/Localizable.strings +++ b/en.lproj/Localizable.strings @@ -32,7 +32,7 @@ "content_view_tab_main" = "Main"; "content_view_tab_filter" = "Filter"; -"content_view_tab_stats" = "Stats"; +"content_view_tab_share" = "Share"; "content_view_fill_in_missing_entry" = "Update %@"; "content_view_fill_in_missing_entry_cancel" = "Cancel"; "content_view_delete_entry" = "Delete this entry";