create all templates .... started to fill one out
This commit is contained in:
@@ -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 = "<group>"; };
|
||||
1C26190627960DC900FDC148 /* ChartViewItemBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChartViewItemBuildable.swift; sourceTree = "<group>"; };
|
||||
1C358FAC27ADD0C3002C83A6 /* Theme.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Theme.swift; sourceTree = "<group>"; };
|
||||
1C358FB027B0AD87002C83A6 /* SharingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingView.swift; sourceTree = "<group>"; };
|
||||
1C358FB227B0ADA4002C83A6 /* SharingTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SharingTemplate.swift; sourceTree = "<group>"; };
|
||||
1C358FB527B0AE15002C83A6 /* AllMoodsTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AllMoodsTotalTemplate.swift; sourceTree = "<group>"; };
|
||||
1C358FB727B0AEE3002C83A6 /* LongestStreakTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LongestStreakTemplate.swift; sourceTree = "<group>"; };
|
||||
1C358FB927B35252002C83A6 /* ActivityViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityViewController.swift; sourceTree = "<group>"; };
|
||||
1C358FBB27B352B1002C83A6 /* ShareButtonview.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShareButtonview.swift; sourceTree = "<group>"; };
|
||||
1C358FBD27B4D1F2002C83A6 /* CurrentStreakTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentStreakTemplate.swift; sourceTree = "<group>"; };
|
||||
1C358FBF27B4D20C002C83A6 /* MonthTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MonthTotalTemplate.swift; sourceTree = "<group>"; };
|
||||
1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WeekTotalTemplate.swift; sourceTree = "<group>"; };
|
||||
1C5F4975279C84090092F1B4 /* OnboardingData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnboardingData.swift; sourceTree = "<group>"; };
|
||||
1C5F4977279C945E0092F1B4 /* UserDefaultsStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsStore.swift; sourceTree = "<group>"; };
|
||||
1C683FC92792281400745862 /* Stats.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Stats.swift; sourceTree = "<group>"; };
|
||||
@@ -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 = "<group>";
|
||||
};
|
||||
1C358FB427B0ADF3002C83A6 /* SharingTemplates */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
1C358FB527B0AE15002C83A6 /* AllMoodsTotalTemplate.swift */,
|
||||
1C358FBD27B4D1F2002C83A6 /* CurrentStreakTemplate.swift */,
|
||||
1C358FB727B0AEE3002C83A6 /* LongestStreakTemplate.swift */,
|
||||
1C358FBF27B4D20C002C83A6 /* MonthTotalTemplate.swift */,
|
||||
1C358FC127B4D227002C83A6 /* WeekTotalTemplate.swift */,
|
||||
);
|
||||
path = SharingTemplates;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
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 = "<group>";
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
44
Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift
Normal file
44
Shared/Models/SharingTemplates/AllMoodsTotalTemplate.swift
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
44
Shared/Models/SharingTemplates/CurrentStreakTemplate.swift
Normal file
44
Shared/Models/SharingTemplates/CurrentStreakTemplate.swift
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
127
Shared/Models/SharingTemplates/LongestStreakTemplate.swift
Normal file
127
Shared/Models/SharingTemplates/LongestStreakTemplate.swift
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
44
Shared/Models/SharingTemplates/MonthTotalTemplate.swift
Normal file
44
Shared/Models/SharingTemplates/MonthTotalTemplate.swift
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
44
Shared/Models/SharingTemplates/WeekTotalTemplate.swift
Normal file
44
Shared/Models/SharingTemplates/WeekTotalTemplate.swift
Normal file
@@ -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())
|
||||
}
|
||||
}
|
||||
@@ -276,6 +276,17 @@ extension NSManagedObjectContext {
|
||||
}
|
||||
}
|
||||
|
||||
extension PersistenceController {
|
||||
func longestStreak() -> [MoodEntry] {
|
||||
// let predicate = NSPredicate(format: "forDate == %@", date as NSDate)
|
||||
|
||||
let fetchRequest = NSFetchRequest<MoodEntry>(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 {
|
||||
|
||||
22
Shared/Protocols/SharingTemplate.swift
Normal file
22
Shared/Protocols/SharingTemplate.swift
Normal file
@@ -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 }
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
16
Shared/views/ActivityViewController.swift
Normal file
16
Shared/views/ActivityViewController.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
import UIKit
|
||||
import SwiftUI
|
||||
|
||||
struct ActivityViewController: UIViewControllerRepresentable {
|
||||
|
||||
var activityItems: [Any]
|
||||
var applicationActivities: [UIActivity]? = nil
|
||||
|
||||
func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController {
|
||||
let controller = UIActivityViewController(activityItems: activityItems, applicationActivities: applicationActivities)
|
||||
return controller
|
||||
}
|
||||
|
||||
func updateUIViewController(_ uiViewController: UIActivityViewController, context: UIViewControllerRepresentableContext<ActivityViewController>) {}
|
||||
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
|
||||
42
Shared/views/ShareButtonview.swift
Normal file
42
Shared/views/ShareButtonview.swift
Normal file
@@ -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()
|
||||
}
|
||||
}
|
||||
105
Shared/views/SharingView.swift
Normal file
105
Shared/views/SharingView.swift
Normal file
@@ -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()
|
||||
}
|
||||
}
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user