Files
Reflect/Shared/views/CustomizeView/CustomizeView.swift
2022-02-20 15:00:32 -06:00

238 lines
9.0 KiB
Swift

//
// CustomizeView.swift
// Feels (iOS)
//
// Created by Trey Tartt on 2/19/22.
//
import SwiftUI
struct CustomizeView: View {
@AppStorage(UserDefaultsStore.Keys.theme.rawValue, store: GroupUserDefaults.groupDefaults) private var theme: Theme = .system
@AppStorage(UserDefaultsStore.Keys.moodImages.rawValue, store: GroupUserDefaults.groupDefaults) private var imagePack: MoodImages = .FontAwesome
@AppStorage(UserDefaultsStore.Keys.moodTint.rawValue, store: GroupUserDefaults.groupDefaults) private var moodTint: MoodTints = .Default
@AppStorage(UserDefaultsStore.Keys.personalityPack.rawValue, store: GroupUserDefaults.groupDefaults) private var personalityPack: PersonalityPack = .Default
@State private var showCreateCustomWidget = false
let iconSets: [(String,String)] = [
("PurpleFeelsAppIcon", "PurpleAppIcon"),
("RedFeelsAppIcon", "RedAppIcon")
]
var body: some View {
ScrollView {
VStack {
Text(String(localized: "customize_view_title"))
.font(.title)
.foregroundColor(theme.currentTheme.labelColor)
.padding([.trailing, .leading], 55)
.padding([.top], 15)
createCustomWidget
changeIcon
themePicker
pickMoodImagePack
pickMoodTintPack
pickPeronsalityPack
}
}
.padding()
.sheet(isPresented: $showCreateCustomWidget) {
CreateWidgetView()
}
.background(
theme.currentTheme.bg
.edgesIgnoringSafeArea(.all)
)
}
private var changeIcon: some View {
ZStack {
theme.currentTheme.secondaryBGColor
VStack {
Text(String(localized: "settings_view_change_icon"))
HStack {
Button(action: {
UIApplication.shared.setAlternateIconName(nil)
}, label: {
Image("FeelsAppIcon", bundle: .main)
.resizable()
.frame(width: 50, height:50)
.cornerRadius(10)
})
.padding()
ForEach(iconSets, id: \.self.0){ iconSet in
Button(action: {
UIApplication.shared.setAlternateIconName(iconSet.1) { (error) in
// FIXME: Handle error
}
}, label: {
Image(iconSet.0, bundle: .main)
.resizable()
.frame(width: 50, height:50)
.cornerRadius(10)
})
.padding()
}
}
}
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var themePicker: some View {
ZStack {
theme.currentTheme.secondaryBGColor
VStack {
Text(String(localized: "settings_background_title"))
HStack {
Spacer()
ForEach(Theme.allCases, id:\.rawValue) { aTheme in
Button(action: {
theme = aTheme
}, label: {
VStack {
aTheme.currentTheme.preview
.overlay(
Circle()
.stroke(Color(UIColor.systemGray), style: StrokeStyle(lineWidth: 2))
)
Text(aTheme.title)
}
})
Spacer()
}
}
.padding(.top)
}
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var createCustomWidget: some View {
ZStack {
theme.currentTheme.secondaryBGColor
Button(action: {
showCreateCustomWidget = true
}, label: {
Text("Create Custom Widget")
})
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var pickMoodImagePack: some View {
ZStack {
theme.currentTheme.secondaryBGColor
VStack {
ForEach(MoodImages.allCases, id: \.rawValue) { images in
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
images.icon(forMood: mood)
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 35, height: 35)
.foregroundColor(
moodTint.color(forMood: mood)
)
}
.frame(minWidth: 0, maxWidth: .infinity)
.onTapGesture {
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred()
imagePack = images
}
}
if images.rawValue != (MoodImages.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 {
Divider()
}
}
}
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var pickMoodTintPack: some View {
ZStack {
theme.currentTheme.secondaryBGColor
VStack {
ForEach(MoodTints.allCases, id: \.rawValue) { tint in
HStack {
ForEach(Mood.allValues, id: \.self) { mood in
Circle()
.frame(width: 35, height: 35)
.foregroundColor(
tint.color(forMood: mood)
)
}
.frame(minWidth: 0, maxWidth: .infinity)
.onTapGesture {
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred()
moodTint = tint
}
}
if tint.rawValue != (MoodTints.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 {
Divider()
}
}
}
.padding()
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
private var pickPeronsalityPack: some View {
ZStack {
theme.currentTheme.secondaryBGColor
VStack {
ForEach(PersonalityPack.allCases, id: \.self) { aPack in
VStack(spacing: 10) {
Text(String(aPack.title()))
.font(.title)
.fontWeight(.bold)
.foregroundColor(theme.currentTheme.labelColor)
Text(aPack.randomPushNotificationTitle())
.font(.body)
.foregroundColor(Color(UIColor.systemGray))
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.onTapGesture {
let impactMed = UIImpactFeedbackGenerator(style: .heavy)
impactMed.impactOccurred()
personalityPack = aPack
LocalNotification.rescheduleNotifiations()
}
if aPack.rawValue != (PersonalityPack.allCases.sorted(by: { $0.rawValue > $1.rawValue }).first?.rawValue) ?? 0 {
Divider()
}
}
}
}
.fixedSize(horizontal: false, vertical: true)
.cornerRadius(10, corners: [.topLeft, .topRight, .bottomLeft, .bottomRight])
}
}
struct CustomizeView_Previews: PreviewProvider {
static var previews: some View {
CustomizeView()
}
}