Renamed ContntView to HomeView, cleaned up SettingsView
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
6C560B852B495DED00FDB70C /* SleepDebtApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B842B495DED00FDB70C /* SleepDebtApp.swift */; };
|
||||
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B862B495DED00FDB70C /* ContentView.swift */; };
|
||||
6C560B872B495DED00FDB70C /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B862B495DED00FDB70C /* HomeView.swift */; };
|
||||
6C560B892B495DEE00FDB70C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B882B495DEE00FDB70C /* Assets.xcassets */; };
|
||||
6C560B8C2B495DEE00FDB70C /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */; };
|
||||
6C560B932B495E3A00FDB70C /* HealthKitManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6C560B922B495E3A00FDB70C /* HealthKitManager.swift */; };
|
||||
@@ -19,7 +19,7 @@
|
||||
/* Begin PBXFileReference section */
|
||||
6C560B812B495DED00FDB70C /* SleepDebt.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SleepDebt.app; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
6C560B842B495DED00FDB70C /* SleepDebtApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepDebtApp.swift; sourceTree = "<group>"; };
|
||||
6C560B862B495DED00FDB70C /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
6C560B862B495DED00FDB70C /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
|
||||
6C560B882B495DEE00FDB70C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
6C560B8B2B495DEE00FDB70C /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
6C560B922B495E3A00FDB70C /* HealthKitManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitManager.swift; sourceTree = "<group>"; };
|
||||
@@ -60,7 +60,7 @@
|
||||
children = (
|
||||
6C560B942B49605000FDB70C /* SleepDebt.entitlements */,
|
||||
6C560B842B495DED00FDB70C /* SleepDebtApp.swift */,
|
||||
6C560B862B495DED00FDB70C /* ContentView.swift */,
|
||||
6C560B862B495DED00FDB70C /* HomeView.swift */,
|
||||
6CD7B4BA2B49AA5100D1D8B8 /* SleepDebtTabView.swift */,
|
||||
6CD7B4BC2B49AB3F00D1D8B8 /* SettingsView.swift */,
|
||||
6C560B922B495E3A00FDB70C /* HealthKitManager.swift */,
|
||||
@@ -148,7 +148,7 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
6C560B872B495DED00FDB70C /* ContentView.swift in Sources */,
|
||||
6C560B872B495DED00FDB70C /* HomeView.swift in Sources */,
|
||||
6CD7B4BB2B49AA5100D1D8B8 /* SleepDebtTabView.swift in Sources */,
|
||||
6CD7B4BD2B49AB3F00D1D8B8 /* SettingsView.swift in Sources */,
|
||||
6C560B852B495DED00FDB70C /* SleepDebtApp.swift in Sources */,
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// SleepDebt
|
||||
//
|
||||
// Created by Oliver Hnát on 06.01.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct ContentView: View {
|
||||
@EnvironmentObject var manager: HealthKitManager
|
||||
var desiredAmountOfSleep = 8
|
||||
var body: some View {
|
||||
VStack {
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundStyle(.tint)
|
||||
// Button(action: {
|
||||
// print(manager.sleepForLastXDays)
|
||||
// var seconds = Int(manager.getSleepForLast7Days())
|
||||
// print("hours: ", seconds / 3600, " minutes: ", (seconds % 3600) / 60, " seconds: ", (seconds % 3600) % 60)
|
||||
// seconds = Int(manager.getSleepForLast30Days())
|
||||
// print("hours: ", seconds / 3600, " minutes: ", (seconds % 3600) / 60, " seconds: ", (seconds % 3600) % 60)
|
||||
// }) {
|
||||
// Text("Hello, world!")
|
||||
// }
|
||||
}
|
||||
.padding()
|
||||
// .onAppear {
|
||||
// print(manager.sleepForLastXDays)
|
||||
// var seconds = Int(manager.getSleepForLast7Days())
|
||||
// print("hours: ", seconds / 3600, " minutes: ", (seconds % 3600) / 60, " seconds: ", (seconds % 3600) % 60)
|
||||
// seconds = Int(manager.getSleepForLast30Days())
|
||||
// print("hours: ", seconds / 3600, " minutes: ", (seconds % 3600) / 60, " seconds: ", (seconds % 3600) % 60)
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
ContentView()
|
||||
.environmentObject(HealthKitManager())
|
||||
}
|
||||
26
SleepDebt/HomeView.swift
Normal file
26
SleepDebt/HomeView.swift
Normal file
@@ -0,0 +1,26 @@
|
||||
//
|
||||
// ContentView.swift
|
||||
// SleepDebt
|
||||
//
|
||||
// Created by Oliver Hnát on 06.01.2024.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct HomeView: View {
|
||||
@EnvironmentObject var manager: HealthKitManager
|
||||
var desiredAmountOfSleep = 8
|
||||
var body: some View {
|
||||
VStack {
|
||||
Image(systemName: "globe")
|
||||
.imageScale(.large)
|
||||
.foregroundStyle(.tint)
|
||||
}
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
HomeView()
|
||||
.environmentObject(HealthKitManager())
|
||||
}
|
||||
@@ -10,61 +10,55 @@ import SwiftUI
|
||||
struct SettingsView: View {
|
||||
@State var sleepDebtPeriod = 30
|
||||
@State var repaymentPeriod = 7
|
||||
@State var desiredHoursOfSleep = 8
|
||||
@FocusState private var focusItem: Bool
|
||||
private var repaymentString = "Repayment period (days)"
|
||||
private var sleepDebtString = "Sleep debt period (days)"
|
||||
let formatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .decimal
|
||||
return formatter
|
||||
}()
|
||||
private var desiredHoursOfSleepString = "Desired hours of sleep"
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
|
||||
List {
|
||||
Section {
|
||||
LabeledContent {
|
||||
TextField("", value: $sleepDebtPeriod, formatter: formatter)
|
||||
.keyboardType(.numberPad)
|
||||
.onSubmit {
|
||||
focusItem = false
|
||||
}
|
||||
.focused($focusItem)
|
||||
.multilineTextAlignment(.trailing)
|
||||
.foregroundStyle(.blue)
|
||||
} label: {
|
||||
Text(sleepDebtString)
|
||||
.fixedSize()
|
||||
}
|
||||
|
||||
.lineLimit(1)
|
||||
LabeledContent {
|
||||
TextField("", value: $repaymentPeriod, formatter: formatter)
|
||||
.keyboardType(.numberPad)
|
||||
.onSubmit {
|
||||
focusItem = false
|
||||
}
|
||||
.focused($focusItem)
|
||||
.multilineTextAlignment(.trailing)
|
||||
.foregroundStyle(.blue)
|
||||
|
||||
} label: {
|
||||
Text(repaymentString)
|
||||
.fixedSize()
|
||||
}
|
||||
SettingsNumberField(value: $sleepDebtPeriod, focusItem: $focusItem, text: sleepDebtString)
|
||||
SettingsNumberField(value: $repaymentPeriod, focusItem: $focusItem, text: repaymentString)
|
||||
SettingsNumberField(value: $desiredHoursOfSleep, focusItem: $focusItem, text: desiredHoursOfSleepString)
|
||||
}
|
||||
|
||||
}
|
||||
.onTapGesture{
|
||||
focusItem = false
|
||||
}
|
||||
.navigationTitle("Settings")
|
||||
.navigationTitle("Settings")
|
||||
}
|
||||
.onTapGesture{
|
||||
focusItem = false
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
#Preview {
|
||||
SettingsView()
|
||||
}
|
||||
|
||||
struct SettingsNumberField: View {
|
||||
@Binding var value: Int
|
||||
var focusItem: FocusState<Bool>.Binding
|
||||
var text: String
|
||||
let formatter: NumberFormatter = {
|
||||
let formatter = NumberFormatter()
|
||||
formatter.numberStyle = .decimal
|
||||
return formatter
|
||||
}()
|
||||
var body: some View {
|
||||
LabeledContent {
|
||||
TextField("", value: $value, formatter: formatter)
|
||||
.keyboardType(.numberPad)
|
||||
.focused(focusItem)
|
||||
.multilineTextAlignment(.trailing)
|
||||
.foregroundStyle(.blue)
|
||||
} label: {
|
||||
Text(text)
|
||||
.fixedSize()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ struct SleepDebtTabView: View {
|
||||
@StateObject var healthKitManager = HealthKitManager()
|
||||
var body: some View {
|
||||
TabView(selection: $selectedTab) {
|
||||
ContentView()
|
||||
HomeView()
|
||||
.tag("Home")
|
||||
.tabItem {
|
||||
Image(systemName: "house")
|
||||
|
||||
Reference in New Issue
Block a user