From 9fc7774b291202eba93bb4fdb5c75dc93304776d Mon Sep 17 00:00:00 2001 From: Lee Sohyeon Date: Thu, 23 May 2024 17:36:42 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Commit:=20=EC=BD=94=EB=93=9C=20=EB=B3=B4?= =?UTF-8?q?=EC=A1=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xcshareddata/xcschemes/MC2-Team3-Pilling.xcscheme | 2 +- MC2-Team3-Pilling/View/MainView.swift | 8 ++++---- MC2-Team3-Pilling/View/SettingView.swift | 5 ----- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/MC2-Team3-Pilling.xcodeproj/xcshareddata/xcschemes/MC2-Team3-Pilling.xcscheme b/MC2-Team3-Pilling.xcodeproj/xcshareddata/xcschemes/MC2-Team3-Pilling.xcscheme index 5acce62..2a75591 100644 --- a/MC2-Team3-Pilling.xcodeproj/xcshareddata/xcschemes/MC2-Team3-Pilling.xcscheme +++ b/MC2-Team3-Pilling.xcodeproj/xcshareddata/xcschemes/MC2-Team3-Pilling.xcscheme @@ -1,7 +1,7 @@ + version = "1.8"> Date: Thu, 23 May 2024 21:06:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20SettingView=20Data=20Binding=20?= =?UTF-8?q?=EC=84=B1=EA=B3=B5=20-=20=ED=8C=8C=EC=9D=B4=EB=A6=AC=20?= =?UTF-8?q?=EB=8D=95=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extentsion/model+extension.swift | 1 + MC2-Team3-Pilling/View/MainView.swift | 8 +++--- .../View/MedicineSheetView.swift | 4 +++ MC2-Team3-Pilling/View/SettingView.swift | 28 +++++++++++++++++-- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/MC2-Team3-Pilling/Extentsion/model+extension.swift b/MC2-Team3-Pilling/Extentsion/model+extension.swift index 65f08dc..d4bd0fd 100644 --- a/MC2-Team3-Pilling/Extentsion/model+extension.swift +++ b/MC2-Team3-Pilling/Extentsion/model+extension.swift @@ -24,6 +24,7 @@ extension Config{ dateFormatter.dateFormat = format return dateFormatter.string(from: date) } + static func StringToDate(dateString: String,format:String) -> Date? { let dateFormatter = DateFormatter() diff --git a/MC2-Team3-Pilling/View/MainView.swift b/MC2-Team3-Pilling/View/MainView.swift index 6712ca9..4d93f91 100644 --- a/MC2-Team3-Pilling/View/MainView.swift +++ b/MC2-Team3-Pilling/View/MainView.swift @@ -52,10 +52,10 @@ struct MainView: View { .padding() .presentationCompactAdaptation(.popover) } -// NavigationLink(destination: SettingView(selectedPill: $selectedPill, showingMedicineSheet: $showingMedicineSheet), label: { -// Image(systemName: "gearshape") -// .Icon() -// }) + NavigationLink(destination: SettingView(selectedPill: $selectedPill, showingMedicineSheet: $showingMedicineSheet), label: { + Image(systemName: "gearshape") + .Icon() + }) } // status header diff --git a/MC2-Team3-Pilling/View/MedicineSheetView.swift b/MC2-Team3-Pilling/View/MedicineSheetView.swift index 537b7b2..2c0f8db 100644 --- a/MC2-Team3-Pilling/View/MedicineSheetView.swift +++ b/MC2-Team3-Pilling/View/MedicineSheetView.swift @@ -1,5 +1,6 @@ import SwiftUI +import SwiftData struct MedicineSheetView: View { @State private var searchText = "" @@ -8,6 +9,7 @@ struct MedicineSheetView: View { @Environment(\.presentationMode) var presentationMode @Binding var selectedPill: PillInfo? + @Query var user:[UserInfo] // let BirthControlNames = [ // "쎄스콘정", "미뉴렛정", "에이리스정", "머시론정", @@ -28,9 +30,11 @@ struct MedicineSheetView: View { List(filteredBirthControl) { pill in Button(action: { selectedPill = pill + print(pill.pillName) if selectedPill == pill { + user.first?.curPill?.pillInfo=selectedPill! self.presentationMode.wrappedValue.dismiss() } diff --git a/MC2-Team3-Pilling/View/SettingView.swift b/MC2-Team3-Pilling/View/SettingView.swift index 36a02e1..4fc8344 100644 --- a/MC2-Team3-Pilling/View/SettingView.swift +++ b/MC2-Team3-Pilling/View/SettingView.swift @@ -6,11 +6,15 @@ // import SwiftUI +import SwiftData struct SettingView: View { - @State private var selectedAlarmTime = Date.now + @Environment(\.modelContext) private var modelContext + @Query var user:[UserInfo] + + @State private var selectedAlarmTime = Date() @State private var isSoundOn = false - // @State private var selectedPill = 0 +// @State private var selectedPill = 0 @Binding var selectedPill: PillInfo? @State private var isShowingPills = false @Binding var showingMedicineSheet: Bool @@ -35,7 +39,7 @@ struct SettingView: View { NavigationLink(destination: MedicineSheetView(showingMedicineSheet: $showingMedicineSheet, selectedPill: $selectedPill)) { HStack { - Text("Select Pill") + Text("약 선택") Spacer() if let pill = selectedPill { Text(pill.pillName) @@ -50,11 +54,29 @@ struct SettingView: View { Section("알림") { DatePicker("시간", selection: $selectedAlarmTime, displayedComponents: .hourAndMinute) + .onChange(of: selectedAlarmTime) { oldValue, newValue in + let newValueToString = Config.DateToString(date: newValue, format: Hourformat) + user.first?.scheduleTime = newValueToString + print(newValueToString) + } Toggle("알람", isOn: $isSoundOn) + .onChange(of: isSoundOn) { oldValue, newValueAlarm in + user.first?.isAlarm = newValueAlarm + } + // Optional, unWrapped } } + .onAppear{ + if let userInfo = user.first { + selectedPill = userInfo.curPill?.pillInfo + selectedAlarmTime = Config.StringToDate(dateString: userInfo.scheduleTime, format: Hourformat)! +// selectedAlarmTime = Config.DateToString(date: selectedAlarmTime, format: Hourformat) + isSoundOn = userInfo.isAlarm + } + + } .navigationTitle("Settings") // .sheet(isPresented: $isShowingPills, content: { // Text("Pills")