Skip to content

Commit 38a0afd

Browse files
authored
Merge pull request #1 from alyxferrari/version-0.5
2 parents c70c990 + 54ee3bc commit 38a0afd

File tree

28 files changed

+792
-96
lines changed

28 files changed

+792
-96
lines changed

Sobretium.xcodeproj/project.pbxproj

Lines changed: 288 additions & 14 deletions
Large diffs are not rendered by default.

Sobretium.xcodeproj/xcuserdata/alyxferrari.xcuserdatad/xcschemes/xcschememanagement.plist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@
99
<key>orderHint</key>
1010
<integer>0</integer>
1111
</dict>
12+
<key>SobretiumWatch Watch App.xcscheme_^#shared#^_</key>
13+
<dict>
14+
<key>orderHint</key>
15+
<integer>2</integer>
16+
</dict>
17+
<key>SobretiumWidgetExtension.xcscheme_^#shared#^_</key>
18+
<dict>
19+
<key>orderHint</key>
20+
<integer>1</integer>
21+
</dict>
1222
</dict>
1323
</dict>
1424
</plist>

Sobretium/ContentView.swift

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,31 @@ import LocalAuthentication
1111
struct ContentView: View {
1212
@AppStorage("stealth") var stealth: Bool = false
1313
@AppStorage("biometry") var biometry: Bool = false
14+
@AppStorage("launchCount") var launchCount: Int = 0
1415
@State var addTrackerSheetPresented: Bool = false
1516
@State var editTrackerSheetPresented: Bool = false
1617
@FetchRequest(sortDescriptors: []) var entries: FetchedResults<SobrietyEntry>
1718
@State var deletionCandidate: SobrietyEntry?
1819
@State var deletionAlertPresented: Bool = false
1920
@Environment(\.managedObjectContext) var moc
2021
@State var authenticated: Bool = false
22+
@State var linkSelection: String?
2123
var body: some View {
2224
NavigationView {
2325
if authenticated {
24-
VStack {
26+
Group {
2527
if entries.count == 0 {
26-
Text("No Saved Trackers")
27-
.font(.title)
28-
Text("Press the + button to get started")
28+
VStack {
29+
Text("No Saved Trackers")
30+
.font(.title)
31+
Text("Press the + button to get started")
32+
}
2933
} else {
3034
List {
3135
Section(header: Text(stealth ? "Trackers" : "Sobriety Trackers")) {
3236
ForEach(entries) { entry in
3337
if entry.startDate != nil && entry.name != nil {
34-
NavigationLink {
38+
NavigationLink(tag: entry.name!, selection: $linkSelection) {
3539
RingView(entry)
3640
} label: {
3741
Text(entry.name!)
@@ -46,7 +50,6 @@ struct ContentView: View {
4650
}
4751
.tint(.red)
4852
Button {
49-
print("fart")
5053
editTrackerSheetPresented = true
5154
} label: {
5255
Image(systemName: "square.and.pencil")
@@ -109,9 +112,7 @@ struct ContentView: View {
109112
}
110113
func authenticate() {
111114
if !biometry {
112-
withAnimation {
113-
authenticated = true
114-
}
115+
showView()
115116
return
116117
}
117118
let context = LAContext()
@@ -120,23 +121,32 @@ struct ContentView: View {
120121
let reason = "Touch ID access is needed for biometric authentication."
121122
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authenticationError in
122123
if success {
123-
withAnimation {
124-
authenticated = true
125-
}
124+
showView()
126125
} else {
127-
authenticate() // TODO: replace with PIN code
126+
authenticate()
128127
}
129128
}
130129
} else {
131130
biometry = false
132-
withAnimation {
133-
authenticated = true
134-
}
131+
showView()
135132
}
136133
if let error = error {
137134
print(error)
138135
}
139136
}
137+
func showView() {
138+
launchCount += 1
139+
for entry in entries {
140+
if entry.defaultEntry {
141+
linkSelection = entry.name!
142+
authenticated = true
143+
return
144+
}
145+
}
146+
withAnimation {
147+
authenticated = true
148+
}
149+
}
140150
func deleteAddiction(_ addiction: SobrietyEntry) {
141151
deletionCandidate = addiction
142152
deletionAlertPresented = true

Sobretium/DataController.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ import Foundation
99
import CoreData
1010

1111
class DataController: ObservableObject {
12-
let container = NSPersistentContainer(name: "SobrietyEntry")
12+
let container = NSPersistentCloudKitContainer(name: "SobrietyEntry")
1313
init() {
1414
container.loadPersistentStores { description, error in
1515
if let error = error {
1616
print("core data made a booboo: \(error.localizedDescription)")
1717
}
1818
}
19+
container.viewContext.automaticallyMergesChangesFromParent = true
1920
}
2021
}

Sobretium/Info.plist

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>UIBackgroundModes</key>
6+
<array>
7+
<string>remote-notification</string>
8+
</array>
9+
</dict>
10+
</plist>
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ struct SobrietyRings: View {
2929
self._tiny = State(initialValue: tiny)
3030
self._entry = State(initialValue: entry)
3131
self._type = State(initialValue: type)
32-
self._theme = State(initialValue: Theme.themes[Int(entry.themeIndex)])
32+
if entry.themeIndex > Theme.themes.count - 1 {
33+
self._theme = State(initialValue: Theme.prideThemes[Int(entry.themeIndex) - Theme.themes.count])
34+
} else {
35+
self._theme = State(initialValue: Theme.themes[Int(entry.themeIndex)])
36+
}
3337
}
3438
var body: some View {
3539
GeometryReader { geometry in

Sobretium/Settings/SettingsView.swift

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,38 @@ struct SettingsView: View {
1616
@State var biometryToggleLabel: String = "Enable \(SettingsView.authenticationType())"
1717
@State var biometryMissingAlert: Bool = false
1818
@State var biometryUnsupportedAlert: Bool = false
19+
@State var stealthInfoAlert: Bool = false
20+
@State var performanceInfoAlert: Bool = false
1921
var body: some View {
2022
List {
21-
Toggle("Stealth Mode", isOn: $stealth)
22-
Toggle("Performance Mode", isOn: $performance)
23+
Toggle(isOn: $stealth) {
24+
HStack {
25+
Text("Stealth Mode")
26+
Image(systemName: "info.circle")
27+
.foregroundColor(.accentColor)
28+
.onTapGesture {
29+
stealthInfoAlert = true
30+
}
31+
.alert("Stealth mode removes most indicators that this app is for tracking sobriety.", isPresented: $stealthInfoAlert) {
32+
Button("OK", role: .cancel) {}
33+
}
34+
Spacer()
35+
}
36+
}
37+
Toggle(isOn: $performance) {
38+
HStack {
39+
Text("Performance Mode")
40+
Image(systemName: "info.circle")
41+
.foregroundColor(.accentColor)
42+
.onTapGesture {
43+
performanceInfoAlert = true
44+
}
45+
.alert("Performance mode removes shadows and graphical effects to reduce battery usage.", isPresented: $performanceInfoAlert) {
46+
Button("OK", role: .cancel) {}
47+
}
48+
Spacer()
49+
}
50+
}
2351
Toggle(biometryToggleLabel, isOn: $biometry)
2452
.onChange(of: biometry, perform: authenticate)
2553
.alert("\(SettingsView.authenticationType()) is not set up on your device.", isPresented: $biometryMissingAlert) {

Sobretium/Sheets/EditTrackerSheet.swift

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,27 @@ import SwiftUI
1010
struct EditTrackerSheet: View {
1111
@Environment(\.presentationMode) var presentation
1212
@Environment(\.managedObjectContext) var moc
13+
@FetchRequest(sortDescriptors: []) var entries: FetchedResults<SobrietyEntry>
1314
@AppStorage("stealth") var stealth: Bool = false
1415
@State var entry: SobrietyEntry
1516
@State var name: String
1617
@State var pickerDate: Date
1718
@State var subtitle: String
1819
@State var currentTheme: String
20+
@State var defaultEntry: Bool
21+
@State var defaultInfoAlert: Bool = false
1922
let initialTheme: Int32
2023
init(_ entry: SobrietyEntry) {
2124
self._entry = State(initialValue: entry)
2225
self._name = State(initialValue: entry.name!)
2326
self._pickerDate = State(initialValue: entry.startDate!)
2427
self._subtitle = State(initialValue: entry.subtitle ?? "")
25-
self._currentTheme = State(initialValue: Theme.themes[Int(entry.themeIndex)].name)
28+
self._defaultEntry = State(initialValue: entry.defaultEntry)
29+
if entry.themeIndex > Theme.themes.count - 1 {
30+
self._currentTheme = State(initialValue: Theme.prideThemes[Int(entry.themeIndex) - Theme.themes.count].name)
31+
} else {
32+
self._currentTheme = State(initialValue: Theme.themes[Int(entry.themeIndex)].name)
33+
}
2634
initialTheme = entry.themeIndex
2735
}
2836
var body: some View {
@@ -48,7 +56,25 @@ struct EditTrackerSheet: View {
4856
Text(currentTheme)
4957
}
5058
.onAppear {
51-
currentTheme = Theme.themes[Int(entry.themeIndex)].name
59+
if entry.themeIndex > Theme.themes.count - 1 {
60+
currentTheme = Theme.prideThemes[Int(entry.themeIndex) - Theme.themes.count].name
61+
} else {
62+
currentTheme = Theme.themes[Int(entry.themeIndex)].name
63+
}
64+
}
65+
}
66+
Toggle(isOn: $defaultEntry) {
67+
HStack {
68+
Text(stealth ? "Default Tracker" : "Default Sobriety Tracker")
69+
Image(systemName: "info.circle")
70+
.foregroundColor(.accentColor)
71+
.onTapGesture {
72+
defaultInfoAlert = true
73+
}
74+
.alert("Your default tracker will automatically open when you open the app.", isPresented: $defaultInfoAlert) {
75+
Button("OK", role: .cancel) {}
76+
}
77+
Spacer()
5278
}
5379
}
5480
}
@@ -73,6 +99,12 @@ struct EditTrackerSheet: View {
7399
} else {
74100
entry.subtitle = subtitle
75101
}
102+
if defaultEntry {
103+
for entry in entries {
104+
entry.defaultEntry = false
105+
}
106+
}
107+
entry.defaultEntry = defaultEntry
76108
try? moc.save()
77109
presentation.wrappedValue.dismiss()
78110
}

0 commit comments

Comments
 (0)