template sharing

This commit is contained in:
Trey t
2022-02-26 16:16:40 -06:00
parent 4b7c64cbc6
commit 7bcd9a3d13
4 changed files with 150 additions and 92 deletions

View File

@@ -64,16 +64,6 @@ struct AllMoodsTotalTemplate: View, SharingTemplate {
private var circularViews: some View {
VStack {
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
mood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(moodTint.color(forMood: mood))
}
}
VStack {
HStack {
ForEach(entries.prefix(2), id: \.mood) { model in
@@ -134,28 +124,46 @@ struct AllMoodsTotalTemplate: View, SharingTemplate {
var shareView: some View {
VStack {
Text(String(format: String(localized: "share_view_all_moods_total_template_title"), totalEntryCount))
Text(String(format: String(localized: "share_view_all_moods_total_template_title"), totalEntryCount))
.font(.title)
.foregroundColor(theme.currentTheme.labelColor)
.frame(maxWidth: .infinity, alignment: .center)
.padding()
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
Circle()
.frame(minWidth: 10, idealWidth: 70, maxWidth: 100, minHeight: 10, idealHeight: 70, maxHeight: 100)
.aspectRatio(contentMode: .fit)
.foregroundColor(moodTint.color(forMood: mood))
.overlay(
mood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.white)
.padding(9)
)
}
}
.padding()
circularViews
.padding()
Spacer()
}.padding()
}
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
.padding()
}
var mainView: some View {
VStack {
shareView
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
HStack(alignment: .center) {
Button(action: {
let _image = self.image
print(_image)
self.shareImage.showFuckingSheet = true
self.shareImage.fuckingWrappedShrable = _image
}, label: {
@@ -197,19 +205,22 @@ struct AllMoodsTotalTemplate: View, SharingTemplate {
var body: some View {
if isPreview {
preview
.padding([.leading, .trailing], -20)
shareView
.scaleEffect(2)
} else {
mainView
.padding([.leading, .trailing, .top])
}
}
}
struct AllMoodsSharingTemplate_Previews: PreviewProvider {
static var previews: some View {
AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
Group {
AllMoodsTotalTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
AllMoodsTotalTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true).shareView
}
}
}

View File

@@ -8,10 +8,6 @@
import SwiftUI
struct CurrentStreakTemplate: View, SharingTemplate {
var image: UIImage {
return UIImage(systemName: "square.and.arrow.up")!
}
static var description: String {
"Last 10 Days"
}
@@ -22,6 +18,8 @@ struct CurrentStreakTemplate: View, SharingTemplate {
let moodEntries: [MoodEntry]
@State var showSharingTemplate = false
@StateObject private var shareImage = StupidAssShareObservableObject()
@Environment(\.presentationMode) var presentationMode
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -53,6 +51,11 @@ struct CurrentStreakTemplate: View, SharingTemplate {
self.moodEntries = _moodEntries ?? [MoodEntry]()
}
var image: UIImage {
let image = shareView.asImage(size: CGSize(width: 666, height: 1190))
return image
}
var preview: some View {
HStack {
VStack {
@@ -79,7 +82,7 @@ struct CurrentStreakTemplate: View, SharingTemplate {
HStack {
VStack {
LazyVGrid(columns: columns, spacing: 0) {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(moodEntries) { entry in
entry.mood.icon
.resizable()
@@ -91,29 +94,40 @@ struct CurrentStreakTemplate: View, SharingTemplate {
}
.padding()
}
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
.padding()
}
var mainView: some View {
VStack {
shareView
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
Spacer()
HStack(alignment: .center) {
Button(action: {
showSharingTemplate = true
}, label: {
Text("Share")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.white)
.padding(.top, 20)
})
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
)
.padding(.trailing, -5)
HStack(alignment: .center) {
Button(action: {
let _image = self.image
print(_image)
self.shareImage.showFuckingSheet = true
self.shareImage.fuckingWrappedShrable = _image
}, label: {
Text("Share")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color.white)
.padding(.top, 20)
})
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
if let uiImage = self.shareImage.fuckingWrappedShrable {
ShareSheet(photo: uiImage)
}
}
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
)
.padding(.trailing, -5)
Button(action: {
presentationMode.wrappedValue.dismiss()
@@ -131,19 +145,16 @@ struct CurrentStreakTemplate: View, SharingTemplate {
.padding(.leading, -5)
}
.padding([.leading, .trailing], -20)
}.sheet(isPresented: $showSharingTemplate) {
ActivityViewController(activityItems: [self.image])
}
}
}
var body: some View {
if isPreview {
preview
.padding([.leading, .trailing], -20)
shareView
.scaleEffect(2)
} else {
mainView
.padding([.leading, .trailing, .top])
}
}
}
@@ -153,5 +164,7 @@ struct CurrentStreakTemplate_Previews: PreviewProvider {
CurrentStreakTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
CurrentStreakTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
CurrentStreakTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true).shareView
}
}

View File

@@ -9,10 +9,6 @@ import SwiftUI
import Algorithms
struct LongestStreakTemplate: View, SharingTemplate {
var image: UIImage {
return UIImage(systemName: "square.and.arrow.up")!
}
static var description: String {
"Longest Streak"
}
@@ -32,6 +28,8 @@ struct LongestStreakTemplate: View, SharingTemplate {
@State var selectedMood: Mood = .great
@State var showSharingTemplate = false
@StateObject private var shareImage = StupidAssShareObservableObject()
@Environment(\.presentationMode) var presentationMode
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -53,13 +51,17 @@ struct LongestStreakTemplate: View, SharingTemplate {
configureData(fakeData: self.fakeData, mood: self.selectedMood)
}
var image: UIImage {
let image = shareView.asImage(size: CGSize(width: 650, height: 400))
return image
}
private func configureData(fakeData: Bool, mood: Mood) {
var _moodEntries: [MoodEntry]?
if fakeData {
_moodEntries = PersistenceController.shared.randomEntries(count: 10)
} else {
_moodEntries = PersistenceController.shared.getData(startDate:startDate,
endDate: endDate,
includedDays: [1,2,3,4,5,6,7])
@@ -117,7 +119,12 @@ struct LongestStreakTemplate: View, SharingTemplate {
.frame(maxWidth: .infinity, alignment: .center)
.padding()
HStack {
selectedMood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 75, height: 75)
VStack {
Text(self.moodEntries.first?.forDate ?? Date(), formatter: itemFormatter)
.font(.title)
.foregroundColor(theme.currentTheme.labelColor)
@@ -137,31 +144,19 @@ struct LongestStreakTemplate: View, SharingTemplate {
.padding(.top, 1)
}
.padding()
HStack {
VStack {
LazyVGrid(columns: columns, spacing: 0) {
ForEach(moodEntries) { entry in
entry.mood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(moodTint.color(forMood: entry.mood))
}
}
}
}
.padding()
}
.onAppear(perform: {
self.configureData(fakeData: self.fakeData, mood: self.selectedMood)
})
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
.padding()
}
var mainView: some View {
VStack {
shareView
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
Spacer()
Menu(content: {
ForEach(Mood.allValues) { mood in
@@ -171,20 +166,25 @@ struct LongestStreakTemplate: View, SharingTemplate {
})
}
}, label: {
Text("Moods")
Text("Pick Mood")
.font(.title)
.fontWeight(.bold)
.foregroundColor(Color(UIColor.white))
.foregroundColor(theme.currentTheme.labelColor)
.padding()
})
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
theme.currentTheme.secondaryBGColor
)
.padding([.leading, .trailing], -5)
.cornerRadius(10)
.padding()
HStack(alignment: .center) {
Button(action: {
showSharingTemplate = true
let _image = self.image
print(_image)
self.shareImage.showFuckingSheet = true
self.shareImage.fuckingWrappedShrable = _image
}, label: {
Text("Share")
.font(.title)
@@ -192,6 +192,11 @@ struct LongestStreakTemplate: View, SharingTemplate {
.foregroundColor(Color.white)
.padding(.top, 20)
})
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
if let uiImage = self.shareImage.fuckingWrappedShrable {
ShareSheet(photo: uiImage)
}
}
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
@@ -221,20 +226,22 @@ struct LongestStreakTemplate: View, SharingTemplate {
var body: some View {
if isPreview {
preview
.padding([.leading, .trailing], -20)
shareView
.scaleEffect(2)
} else {
mainView
.padding([.leading, .trailing, .top])
}
}
}
struct CurrentStreakSharingTemplate_Previews: PreviewProvider {
static var previews: some View {
LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
LongestStreakTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
Group {
LongestStreakTemplate(isPreview: true, startDate: Date(), endDate: Date(), fakeData: true)
LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true)
LongestStreakTemplate(isPreview: false, startDate: Date(), endDate: Date(), fakeData: true).shareView
}
}
}

View File

@@ -20,6 +20,8 @@ struct MonthTotalTemplate: View, SharingTemplate {
private var month = Calendar.current.dateComponents([.month], from: Date()).month!
@State var showSharingTemplate = false
@StateObject private var shareImage = StupidAssShareObservableObject()
@Environment(\.presentationMode) var presentationMode
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@@ -68,7 +70,7 @@ struct MonthTotalTemplate: View, SharingTemplate {
}
var image: UIImage {
let image = shareView.snapshot()
let image = shareView.asImage(size: CGSize(width: 666, height: 1190))
return image
}
@@ -106,6 +108,23 @@ struct MonthTotalTemplate: View, SharingTemplate {
.frame(maxWidth: .infinity, alignment: .center)
.padding()
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
Circle()
.frame(minWidth: 10, idealWidth: 70, maxWidth: 100, minHeight: 10, idealHeight: 70, maxHeight: 100)
.aspectRatio(contentMode: .fit)
.foregroundColor(moodTint.color(forMood: mood))
.overlay(
mood.icon
.resizable()
.aspectRatio(contentMode: .fit)
.foregroundColor(.white)
.padding(9)
)
}
}
.padding()
VStack {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(moodEntries) { entry in
@@ -119,19 +138,23 @@ struct MonthTotalTemplate: View, SharingTemplate {
.padding()
circularViews
.padding([.trailing, .leading, .top])
.padding()
}
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
.padding()
}
var mainView: some View {
VStack {
shareView
.background(Color(UIColor.secondarySystemBackground))
.cornerRadius(10)
Spacer()
HStack(alignment: .center) {
Button(action: {
showSharingTemplate = true
let _image = self.image
self.shareImage.showFuckingSheet = true
self.shareImage.fuckingWrappedShrable = _image
}, label: {
Text("Share")
.font(.title)
@@ -139,6 +162,11 @@ struct MonthTotalTemplate: View, SharingTemplate {
.foregroundColor(Color.white)
.padding(.top, 20)
})
.sheet(isPresented: self.$shareImage.showFuckingSheet) {
if let uiImage = self.shareImage.fuckingWrappedShrable {
ShareSheet(photo: uiImage)
}
}
.frame(maxWidth: .infinity, alignment: .center)
.background(
Color.green
@@ -161,18 +189,15 @@ struct MonthTotalTemplate: View, SharingTemplate {
.padding(.leading, -5)
}
.padding([.leading, .trailing], -20)
}.sheet(isPresented: $showSharingTemplate) {
ActivityViewController(activityItems: [self.image])
}
}
var body: some View {
if isPreview {
preview
.padding([.leading, .trailing], -20)
shareView
.scaleEffect(2)
} else {
mainView
.padding([.leading, .trailing, .top])
}
}
}
@@ -182,5 +207,7 @@ struct MonthTotalTemplate_Previews: PreviewProvider {
MonthTotalTemplate(isPreview: true, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true)
MonthTotalTemplate(isPreview: false, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true)
MonthTotalTemplate(isPreview: false, startDate: Date().startOfMonth, endDate: Date().endOfMonth, fakeData: true).shareView
}
}