265 lines
10 KiB
Swift
265 lines
10 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
|
|
|
|
class StupidAssCustomWidgetObservableObject: ObservableObject {
|
|
@Published var fuckingWrapped: CustomWidgetModel? = nil
|
|
@Published var showFuckingSheet = false
|
|
}
|
|
|
|
@StateObject private var selectedWidget = StupidAssCustomWidgetObservableObject()
|
|
|
|
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: $selectedWidget.showFuckingSheet) {
|
|
if let fuckingWrapped = selectedWidget.fuckingWrapped {
|
|
CreateWidgetView(customWidget: fuckingWrapped)
|
|
}
|
|
}
|
|
.background(
|
|
theme.currentTheme.bg
|
|
.edgesIgnoringSafeArea(.all)
|
|
)
|
|
}
|
|
|
|
private var changeIcon: some View {
|
|
ZStack {
|
|
theme.currentTheme.secondaryBGColor
|
|
VStack {
|
|
Text(String(localized: "settings_view_change_icon"))
|
|
.font(.body)
|
|
.foregroundColor(theme.currentTheme.labelColor)
|
|
|
|
HStack {
|
|
Button(action: {
|
|
UIApplication.shared.setAlternateIconName(nil)
|
|
}, label: {
|
|
Image("FeelsAppIcon", bundle: .main)
|
|
.resizable()
|
|
.frame(width: 50, height:50)
|
|
.cornerRadius(10)
|
|
})
|
|
|
|
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()
|
|
}
|
|
}
|
|
.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"))
|
|
.font(.body)
|
|
.foregroundColor(theme.currentTheme.labelColor)
|
|
|
|
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
|
|
VStack {
|
|
Text("Create Custom Widget")
|
|
.font(.body)
|
|
.foregroundColor(theme.currentTheme.labelColor)
|
|
.onTapGesture {
|
|
selectedWidget.fuckingWrapped = CustomWidgetModel.randomWidget
|
|
selectedWidget.showFuckingSheet = true
|
|
}
|
|
.padding()
|
|
ScrollView(.horizontal) {
|
|
HStack {
|
|
ForEach(UserDefaultsStore.getCustomWidgets(), id: \.uuid) { widget in
|
|
CustomWidgetView(customWidgetModel: widget)
|
|
.frame(width: 50, height: 50)
|
|
.cornerRadius(10)
|
|
.onTapGesture {
|
|
selectedWidget.fuckingWrapped = widget.copy() as? CustomWidgetModel
|
|
selectedWidget.showFuckingSheet = true
|
|
}
|
|
}
|
|
}
|
|
.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(.body)
|
|
.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()
|
|
}
|
|
}
|