diff --git a/LiveTimeWidget/Assets.xcassets/alarm.imageset/Contents.json b/LiveTimeWidget/Assets.xcassets/alarm.imageset/Contents.json index c3bf5d5..c254524 100644 --- a/LiveTimeWidget/Assets.xcassets/alarm.imageset/Contents.json +++ b/LiveTimeWidget/Assets.xcassets/alarm.imageset/Contents.json @@ -6,6 +6,7 @@ "scale" : "1x" }, { + "filename" : "alarm (1).png", "idiom" : "universal", "scale" : "2x" }, diff --git a/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm (1).png b/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm (1).png new file mode 100644 index 0000000..80d8a1d Binary files /dev/null and b/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm (1).png differ diff --git a/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm.png b/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm.png index a8ddeab..c619dd8 100644 Binary files a/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm.png and b/LiveTimeWidget/Assets.xcassets/alarm.imageset/alarm.png differ diff --git a/LiveTimeWidget/LiveTimeWidget.swift b/LiveTimeWidget/LiveTimeWidget.swift index 0001d76..aaa2c75 100644 --- a/LiveTimeWidget/LiveTimeWidget.swift +++ b/LiveTimeWidget/LiveTimeWidget.swift @@ -13,34 +13,51 @@ struct LiveTimeWidget: Widget { var body: some WidgetConfiguration { ActivityConfiguration(for: LiveTimeAttributes.self) { context in // lock screen & standby(잠금 화면과 notification center, 그리고 전체화면 버전) - HStack { - Image(systemName: "leaf.fill") - .foregroundStyle(.customGreen) - Text("잔디를 심을 시간이에요!") - Spacer() - Text(context.state.restOfTime, style: .relative) - .foregroundStyle(.customGreen) - .frame(width: 77, height: 30) + VStack { + HStack { + Image(systemName: "leaf.fill") + .foregroundStyle(.customGreen) + Text("잔디를 심을 시간이에요!") + Spacer() + Text(context.state.restOfTime, style: .relative) + .foregroundStyle(.customGreen) + .frame(width: 77, height: 30) + } + Divider() + ProgressView(value: context.state.progressAmount, total: 600) + .padding() } - .padding() } dynamicIsland: { context in // dynamic island DynamicIsland { // expanded dynamic island bottom(다이나믹 아일랜드 꾹 눌러서 확장되는 버전) + DynamicIslandExpandedRegion(.leading) { + Image("alarm") + .resizable() + .scaledToFit() + } + DynamicIslandExpandedRegion(.trailing) { + Text(context.state.restOfTime, style: .relative) + .foregroundStyle(.customGreen) + } DynamicIslandExpandedRegion(.bottom) { VStack { - Text("잔디 심을 시간이에요!") - Text(context.state.restOfTime, style: .relative) - .foregroundStyle(.customGreen) - Button("click") {} - .tint(.customGreen) + Divider() + .frame(minHeight: 1) + .overlay(.customGreen) + Button(action: {}, label: { + Spacer() + Text("Button") + Spacer() + }) + .foregroundColor(.customGreen) + .buttonStyle(.plain) } .padding() } } compactLeading: { // compact leading(다이나믹 아일랜드 소형 버전 왼쪽) - Image(systemName: "leaf.fill") - .foregroundStyle(.customGreen) + Image("alarm") } compactTrailing: { // compact trailing(다이나믹 아일랜드 소형 버전 오른쪽) Text(context.state.restOfTime, style: .relative) diff --git a/MC2-Team3-Pilling.xcodeproj/project.pbxproj b/MC2-Team3-Pilling.xcodeproj/project.pbxproj index b756f80..23136d1 100644 --- a/MC2-Team3-Pilling.xcodeproj/project.pbxproj +++ b/MC2-Team3-Pilling.xcodeproj/project.pbxproj @@ -18,6 +18,8 @@ 21B273082BFB390C002BCC67 /* Model.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B273072BFB390C002BCC67 /* Model.swift */; }; 21B2730C2BFB7301002BCC67 /* SwiftDataTestView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B2730B2BFB7301002BCC67 /* SwiftDataTestView.swift */; }; 21B2730E2BFB85E2002BCC67 /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B2730D2BFB85E2002BCC67 /* Config.swift */; }; + 21B5E33B2BFCC83700D1FC06 /* PiriFirstView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B5E33A2BFCC83700D1FC06 /* PiriFirstView.swift */; }; + 21B5E33D2BFCDB3A00D1FC06 /* PiriSecondView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21B5E33C2BFCDB3A00D1FC06 /* PiriSecondView.swift */; }; 939C87E02BF307B600572EDC /* MC2_Team3_PillingApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 939C87DF2BF307B600572EDC /* MC2_Team3_PillingApp.swift */; }; 939C87E22BF307B600572EDC /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 939C87E12BF307B600572EDC /* ContentView.swift */; }; 939C87E42BF307B600572EDC /* Item.swift in Sources */ = {isa = PBXBuildFile; fileRef = 939C87E32BF307B600572EDC /* Item.swift */; }; @@ -70,6 +72,8 @@ 21B273072BFB390C002BCC67 /* Model.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Model.swift; sourceTree = ""; }; 21B2730B2BFB7301002BCC67 /* SwiftDataTestView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftDataTestView.swift; sourceTree = ""; }; 21B2730D2BFB85E2002BCC67 /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; + 21B5E33A2BFCC83700D1FC06 /* PiriFirstView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiriFirstView.swift; sourceTree = ""; }; + 21B5E33C2BFCDB3A00D1FC06 /* PiriSecondView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiriSecondView.swift; sourceTree = ""; }; 939C87DC2BF307B600572EDC /* MC2-Team3-Pilling.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "MC2-Team3-Pilling.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 939C87DF2BF307B600572EDC /* MC2_Team3_PillingApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MC2_Team3_PillingApp.swift; sourceTree = ""; }; 939C87E12BF307B600572EDC /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; @@ -131,16 +135,18 @@ 219E17582BF6ED79007B7DC1 /* View */ = { isa = PBXGroup; children = ( + 93EF92D52BFC4187004DEEF1 /* ChooseStatusView.swift */, 939C87E12BF307B600572EDC /* ContentView.swift */, 9B0411752BF593A0006F8BB9 /* MainView.swift */, 939C88312BF6B4AC00572EDC /* MedicineSheetView.swift */, 939C882D2BF5CC9100572EDC /* OnboardingFirstView.swift */, 939C88352BF6B9BC00572EDC /* OnboardingSecondView.swift */, + 21B5E33A2BFCC83700D1FC06 /* PiriFirstView.swift */, + 21B5E33C2BFCDB3A00D1FC06 /* PiriSecondView.swift */, + 939C88732BFBA01C00572EDC /* PopoverView.swift */, 939C882F2BF5CC9F00572EDC /* SettingView.swift */, 939C88372BF6DF7000572EDC /* SplashScreenView.swift */, - 939C88732BFBA01C00572EDC /* PopoverView.swift */, 21B2730B2BFB7301002BCC67 /* SwiftDataTestView.swift */, - 93EF92D52BFC4187004DEEF1 /* ChooseStatusView.swift */, ); path = View; sourceTree = ""; @@ -148,10 +154,10 @@ 219E17592BF6ED88007B7DC1 /* Model */ = { isa = PBXGroup; children = ( - 1B6530432BFB7C1600452ACB /* LiveTimeAttributes.swift */, + 21B2730D2BFB85E2002BCC67 /* Config.swift */, 939C87E32BF307B600572EDC /* Item.swift */, + 1B6530432BFB7C1600452ACB /* LiveTimeAttributes.swift */, 21B273072BFB390C002BCC67 /* Model.swift */, - 21B2730D2BFB85E2002BCC67 /* Config.swift */, ); path = Model; sourceTree = ""; @@ -316,6 +322,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + 21B5E33B2BFCC83700D1FC06 /* PiriFirstView.swift in Sources */, 939C87E22BF307B600572EDC /* ContentView.swift in Sources */, 93EF92D62BFC4187004DEEF1 /* ChooseStatusView.swift in Sources */, 939C882E2BF5CC9100572EDC /* OnboardingFirstView.swift in Sources */, @@ -325,6 +332,7 @@ 939C88362BF6B9BC00572EDC /* OnboardingSecondView.swift in Sources */, 939C88302BF5CC9F00572EDC /* SettingView.swift in Sources */, 939C88742BFBA01C00572EDC /* PopoverView.swift in Sources */, + 21B5E33D2BFCDB3A00D1FC06 /* PiriSecondView.swift in Sources */, 21B2730C2BFB7301002BCC67 /* SwiftDataTestView.swift in Sources */, 939C87E42BF307B600572EDC /* Item.swift in Sources */, 9BE4AA1D2BF6E280008BE893 /* CustomFont.swift in Sources */, 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 2a75591..5acce62 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.7"> String { - let format = "yyyy-MM-dd HH:mm:ss" - let dateFormatter = DateFormatter() - dateFormatter.timeZone = TimeZone.current - dateFormatter.dateFormat = format - return dateFormatter.string(from: date) - } - func DayStringToDate(dateString: String) -> Date? { - let format = "yyyy-MM-dd HH:mm:ss" - let dateFormatter = DateFormatter() - dateFormatter.timeZone = TimeZone.current - dateFormatter.dateFormat = format - return dateFormatter.date(from: dateString) - } - func AlarmDateToString(date: Date) -> String { - let format = "HH:mm" + + func DateToString(date: Date,format:String) -> String { + let dateFormatter = DateFormatter() dateFormatter.timeZone = TimeZone.current dateFormatter.dateFormat = format return dateFormatter.string(from: date) } + func StringToDate(dateString: String,format:String) -> Date? { + + let dateFormatter = DateFormatter() + dateFormatter.timeZone = TimeZone.current + dateFormatter.dateFormat = format + + return dateFormatter.date(from: dateString) + } + func AlarmStringToDate(dateString: String) -> Date? { let format = "HH:mm" let dateFormatter = DateFormatter() dateFormatter.timeZone = TimeZone.current dateFormatter.dateFormat = format + return dateFormatter.date(from: dateString) } - - +// func AlarmDateToString(date: Date) -> String { +// let format = "HH:mm" +// let dateFormatter = DateFormatter() +// dateFormatter.timeZone = TimeZone.current +// dateFormatter.dateFormat = format +// return dateFormatter.string(from: date) +// } +// func AlarmStringToDate(dateString: String) -> Date? { +// let format = "HH:mm" +// let dateFormatter = DateFormatter() +// dateFormatter.timeZone = TimeZone.current +// dateFormatter.dateFormat = format +// return dateFormatter.date(from: dateString) +// } + static let dummyPillInfos: [PillInfo] = [ PillInfo(pillName: "쎄스콘정", intakeDay: 21, placeboDay: 7), PillInfo(pillName: "미뉴렛정", intakeDay: 21, placeboDay: 7), @@ -96,10 +105,14 @@ class Config{ PillInfo(pillName: "야스민정", intakeDay: 21, placeboDay: 7), PillInfo(pillName: "야즈정", intakeDay: 24, placeboDay: 4), PillInfo(pillName: "클래라정", intakeDay: 26, placeboDay: 2) + ] - - + } let myArray: [Int] = [1, 2 , 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3] var colorArr:[Color] = [.customGray,.customGreen,.customGreen,.white] +let days = ["일", "월", "화", "수", "목", "금", "토"] +let dayformat = "yyyy-MM-dd" +let dayToHourformat = "yyyy-MM-dd HH:mm:ss" +let Hourformat = "HH:mm" diff --git a/MC2-Team3-Pilling/Model/LiveTimeAttributes.swift b/MC2-Team3-Pilling/Model/LiveTimeAttributes.swift index bf7f90e..74582ea 100644 --- a/MC2-Team3-Pilling/Model/LiveTimeAttributes.swift +++ b/MC2-Team3-Pilling/Model/LiveTimeAttributes.swift @@ -13,5 +13,6 @@ struct LiveTimeAttributes: ActivityAttributes { public struct ContentState: Codable, Hashable { var restOfTime: Date + var progressAmount: Double } } diff --git a/MC2-Team3-Pilling/Model/Model.swift b/MC2-Team3-Pilling/Model/Model.swift index 44ebbc2..0d8bae1 100644 --- a/MC2-Team3-Pilling/Model/Model.swift +++ b/MC2-Team3-Pilling/Model/Model.swift @@ -35,21 +35,44 @@ final class PeriodPill:Identifiable{ @Relationship var pillInfo:PillInfo var startIntake:String var finishIntake:String? = nil - var intakeCal:[Int] - var intakeCalTime:[String] + var intakeCal:[DayData] var missDay:Int +// init(pillInfo: PillInfo, startIntake: String) { +// self.id = UUID() +// self.pillInfo = pillInfo +// self.startIntake = startIntake +// self.intakeCal = [] +// self.missDay = 0 +// } init(pillInfo: PillInfo, startIntake: String) { self.id = UUID() self.pillInfo = pillInfo self.startIntake = startIntake - self.intakeCal = [] - self.intakeCalTime = [] + self.intakeCal = Array(repeating: DayData(), count: pillInfo.wholeDay) self.missDay = 0 } } +@Model +final class DayData:Identifiable{ + @Attribute(.unique) let id:UUID + var status:Int + var time:String? + var sideEffect:[Bool] + var memo:String + + init() { + self.id = UUID() + self.status = 0 + self.sideEffect = Array(repeating: false, count: 3) + self.memo = "" + } + + +} + @Model final class PillInfo:Identifiable{ @Attribute(.unique) let id:UUID diff --git a/MC2-Team3-Pilling/View/ChooseStatusView.swift b/MC2-Team3-Pilling/View/ChooseStatusView.swift index 3e4c329..7a54047 100644 --- a/MC2-Team3-Pilling/View/ChooseStatusView.swift +++ b/MC2-Team3-Pilling/View/ChooseStatusView.swift @@ -7,8 +7,28 @@ import SwiftUI +// 복용 여부 enum +enum DosageType: Int, CaseIterable, Identifiable { + case notYet = 0 + case onePill = 1 + case twoPills = 2 + + var id: Self { self } + + var takingType: String { + switch self { + case .notYet: + "미복용" + case .onePill: + "복용" + case .twoPills: + "2알 복용" + } + } +} + struct ChooseStatusView: View { - @State private var selectedNum = 0 +// @State private var selectedNum = 0 @State private var takeMedicineTime: Date = Date() // 부작용 섹션 vars @@ -17,6 +37,10 @@ struct ChooseStatusView: View { @State private var swellingToggle = false @State var sideEffectMemo: String = "" + @State private var dosageType: DosageType = .notYet + +// @Binding var showingChooseStatus: Bool +// var body: some View { VStack { @@ -26,66 +50,76 @@ struct ChooseStatusView: View { .largeTitle() Text("/28") .secondaryTitle() + + Spacer() } - // 약 복용 여부 확인 - Picker("selection", selection: $selectedNum) { - ForEach(1..<4) { num in - Text("\(num)") + ScrollView() { + // 약 복용 여부 확인 + Picker("selection", selection: $dosageType) { + ForEach(DosageType.allCases) { dosageType in + Text("\(dosageType.takingType)").tag(dosageType.rawValue) + } } - } - .pickerStyle(.segmented) - // selection Print 되는 값 확인 - // .onChange(of: selectedNum) { newValue in - // print("Selected number: \(newValue)") - // } - - // 복용시간 버튼 - Button(action: { + + .pickerStyle(.segmented) + .padding(.vertical, 15) + // selection Print 되는 값 확인 + // .onChange(of: selectedNum) { newValue in + // print("Selected number: \(newValue)") + // } + - }, label: { - ZStack{ - HStack { - Image(systemName: "clock") - Text("복용 시간") - .secondaryRegular() - Spacer() - + // 복용시간 버튼 + Button(action: { + + }, label: { + ZStack{ + HStack { + Image(systemName: "clock") + Text("복용 시간") + .secondaryRegular() + Spacer() + + } + DatePicker("", selection: $takeMedicineTime, displayedComponents: .hourAndMinute) } - DatePicker("", selection: $takeMedicineTime, displayedComponents: .hourAndMinute) - } - .padding([.leading, .trailing], 20) - }) - .padding(.vertical, 16) - .frame(maxWidth: .infinity) - .background(.customGray02) - .clipShape(RoundedRectangle(cornerRadius: 10)) - .foregroundColor(.secondary) - .padding() - - // 부작용 섹션 - VStack { - Toggle("부정출혈", isOn: $irrBleedingToggle) - .padding([.leading, .trailing], 20) - Toggle("구역질", isOn: $nauseaToggle) - .padding([.leading, .trailing], 20) - Toggle("붓기", isOn: $swellingToggle) .padding([.leading, .trailing], 20) + }) + .padding(.vertical, 16) + .frame(maxWidth: .infinity) + .background(.customGray02) + .clipShape(RoundedRectangle(cornerRadius: 10)) + .foregroundColor(.secondary) + - HStack { - Text("메모") + + // 부작용 섹션 + VStack { + Toggle("부정출혈", isOn: $irrBleedingToggle) + + Toggle("구역질", isOn: $nauseaToggle) - TextField("Enter your side effect", text: $sideEffectMemo) - .padding(5) - .background(Color(uiColor: .secondarySystemBackground)) + Toggle("붓기", isOn: $swellingToggle) + + HStack { + Text("메모") + .padding(.trailing, 10) + TextField("", text: $sideEffectMemo) + .padding(5) + .background(Color(uiColor: .secondarySystemBackground)) + } } - .padding() + .padding([.top, .bottom], 15) + .padding([.leading, .trailing], 10) + } - // footer button - Button(action: {}, label: { + Button(action: { +// self.showingChooseStatus = false + }, label: { Text("수정") .font(.title3) .bold() @@ -95,12 +129,15 @@ struct ChooseStatusView: View { .background(.customGreen) .clipShape(RoundedRectangle(cornerRadius: 20)) .foregroundColor(.black) - .padding() } + + .padding(25) + } } #Preview { - ChooseStatusView() +// ChooseStatusView() + MainView() } diff --git a/MC2-Team3-Pilling/View/ContentView.swift b/MC2-Team3-Pilling/View/ContentView.swift index 8294c5a..89ce938 100644 --- a/MC2-Team3-Pilling/View/ContentView.swift +++ b/MC2-Team3-Pilling/View/ContentView.swift @@ -18,8 +18,9 @@ struct ContentView: View { @Environment(\.modelContext) private var modelContext @State private var isTracking = false - @State private var alarmTime = dateFormatter.date(from: "\(Date.now.formatted(date: .numeric, time: .omitted))_12:00:00")! + @State private var alarmTime = dateFormatter.date(from: "\(Date.now.formatted(date: .numeric, time: .omitted))_23:00:00")! @State private var activity: Activity? = nil + @State private var progressAmount = 0.0 @Query private var user: [UserInfo] // 하나만 쓰고싶다면? @@ -42,9 +43,14 @@ struct ContentView: View { NavigationLink(destination: SplashScreenView()){ Text("SplashScreenView") } + NavigationLink(destination: ChooseStatusView()){ Text("ChooseStatusView") } + NavigationLink(destination: PiriFirstView()){ + Text("PiriView") + } + } @@ -53,13 +59,14 @@ struct ContentView: View { isTracking.toggle() if isTracking { // start live activity + progressAmount = 0.0 let attributes = LiveTimeAttributes() - let state = LiveTimeAttributes.ContentState(restOfTime: alarmTime) + let state = LiveTimeAttributes.ContentState(restOfTime: alarmTime, progressAmount: progressAmount) let content = ActivityContent(state: state, staleDate: nil) activity = try? Activity.request(attributes: attributes, content: content, pushType: nil) } else { // end live activity - let state = LiveTimeAttributes.ContentState(restOfTime: alarmTime) + let state = LiveTimeAttributes.ContentState(restOfTime: alarmTime, progressAmount: 600) let content = ActivityContent(state: state, staleDate: alarmTime.addingTimeInterval(600)) Task { await activity?.end(content, dismissalPolicy:.immediate) @@ -69,6 +76,20 @@ struct ContentView: View { Text(isTracking ? "end live activity" : "start live activity") }) .buttonStyle(.bordered) + if isTracking { + Button(action: { + progressAmount += 50 + let attributes = LiveTimeAttributes() + let state = LiveTimeAttributes.ContentState(restOfTime: alarmTime, progressAmount: progressAmount) + let content = ActivityContent(state: state, staleDate: nil) + Task { + await activity?.update(content) + } + }, label: { + Text("update live activity") + }) + .buttonStyle(.bordered) + } if isTracking { HStack { Text("알람까지 남은 시간") diff --git a/MC2-Team3-Pilling/View/MainView.swift b/MC2-Team3-Pilling/View/MainView.swift index 7999f25..12a924e 100644 --- a/MC2-Team3-Pilling/View/MainView.swift +++ b/MC2-Team3-Pilling/View/MainView.swift @@ -6,12 +6,16 @@ // import SwiftUI - +import SwiftData struct MainView: View { @State private var showingPopover = false @State var startNum = 4 @State var statusMessage: Config.StatusMessage = .plantGrass @State var isModal = false + @State var userInfo:UserInfo = UserInfo(scheduleTime: "11:00", curPill: PeriodPill(pillInfo: Config.dummyPillInfos[0], startIntake: "2024-05-17 11:45:46")) + @Query var user:[UserInfo] + @State var time = Date() + var body: some View { NavigationStack { ZStack { @@ -23,6 +27,7 @@ struct MainView: View { Button(action: { showingPopover = true }, label: { + Image(systemName: "info.circle.fill") .Icon() }) @@ -47,13 +52,26 @@ struct MainView: View { HStack { Text("4일차") .largeTitle() - Text("/28") - .secondaryTitle() + if let whole = user.first?.curPill.pillInfo.wholeDay{ + Text("/\(String(describing: whole))") + .secondaryTitle() + } + else{ + Text("") + } + } - Label("24/4", systemImage: "calendar") - .secondaryRegular() - Label("17:00", systemImage: "clock.fill") + if let intakeDay=user.first?.curPill.pillInfo.intakeDay,let placeboday=user.first?.curPill.pillInfo.placeboDay{ + Label("\(String(describing: intakeDay))/\(String(describing: placeboday))", systemImage: "calendar") + .secondaryRegular() + }else{ + Label("", systemImage: "calendar") + .secondaryRegular() + } + + Label(user.first?.scheduleTime ?? "00:00", systemImage: "clock.fill") .secondaryRegular() + } Spacer() } @@ -81,7 +99,7 @@ struct MainView: View { } .regular() - ForEach(0..<4) { y in + ForEach(0..<(user.first?.curPill.pillInfo.wholeDay ?? 28)/7) { y in HStack { ForEach(0..<7) { x in if x==3 && y==0{ @@ -93,6 +111,9 @@ struct MainView: View { else if x==0 && y == 0{ TodayCell(isModal: $isModal, backgroundColor: colorArr[myArray[y*7+x]]) } + else if x>=3 && y == 3{ + PlaceboCell(isModal: $isModal, backgroundColor: Color.white) + } else{ ActivateCell(isModal: $isModal, backgroundColor: colorArr[myArray[y*7+x]]) } @@ -120,16 +141,20 @@ struct MainView: View { .padding() } .sheet(isPresented: $isModal){ - EmptyView() + ChooseStatusView() +// ChooseStatusView() + .presentationDetents([.medium]) } } + .onAppear { + var scheduleTime = user.first?.scheduleTime + print(scheduleTime) + time = Config().StringToDate(dateString: scheduleTime ?? "2024-05-21 15:14:27", format: Hourformat) ?? Date() + } } } -#Preview { - MainView() -} struct GreenGradient: View { var body: some View { @@ -141,7 +166,7 @@ struct GreenGradient: View { struct DayView: View { var num:Int var body: some View { - Text(Config().days[num]) + Text(days[num]) .frame(width: 45, height: 45) } } @@ -159,6 +184,26 @@ struct ActivateCell: View { } } +} +struct PlaceboCell: View { + @Binding var isModal:Bool + var backgroundColor: Color + var body: some View { + Rectangle() + .foregroundColor(.clear) + .frame(width: 45, height: 45) + .cornerRadius(10) + .overlay( + RoundedRectangle(cornerRadius: 10) + .inset(by: 0.5) + .stroke(Color(red: 0.91, green: 0.91, blue: 0.92), lineWidth: 1) + ) + .onTapGesture { + isModal = true + print(isModal) + } + } + } struct TodayCell: View { @Binding var isModal:Bool @@ -167,7 +212,7 @@ struct TodayCell: View { Rectangle() .foregroundColor(.clear) .frame(width: 45, height: 45) - .background(backgroundColor) + .background(.clear) .cornerRadius(10) .overlay( RoundedRectangle(cornerRadius: 10) diff --git a/MC2-Team3-Pilling/View/MedicineSheetView.swift b/MC2-Team3-Pilling/View/MedicineSheetView.swift index 81ae473..eae2980 100644 --- a/MC2-Team3-Pilling/View/MedicineSheetView.swift +++ b/MC2-Team3-Pilling/View/MedicineSheetView.swift @@ -3,7 +3,9 @@ import SwiftUI struct MedicineSheetView: View { @State private var searchText = "" + @Binding var showingMedicineSheet: Bool + @Binding var selectedPill: PillInfo? diff --git a/MC2-Team3-Pilling/View/PiriFirstView.swift b/MC2-Team3-Pilling/View/PiriFirstView.swift new file mode 100644 index 0000000..696c2ae --- /dev/null +++ b/MC2-Team3-Pilling/View/PiriFirstView.swift @@ -0,0 +1,116 @@ +// +// PiriView.swift +// MC2-Team3-Pilling +// +// Created by ram on 5/21/24. +// + + +import SwiftUI + +struct PiriFirstView: View { + @State private var showingMedicineSheet = false + @State var isActive = false + @State var pillInfo = PillInfo(pillName: "야즈", intakeDay: 24, placeboDay: 4) + @State var intakeDay = 4 + var body: some View { + Image("making-plan") + .resizable() + .frame(width: 240, height: 240) + + // Text + HStack { + VStack(alignment: .leading) { + Text("복용하고 계신 약을 알려주세요!") + .largeBold() + .padding(.bottom, 2) + + Text("설정은 추후에 변경 가능합니다.") + .secondaryRegular() + } + Spacer() + } + .padding() + + + // Selecting box + VStack { + Button(action: { + self.showingMedicineSheet = true + }, label: { + // sfSymbol 부재 : medicine-bottle-one + HStack { + Image(systemName: "pill.circle.fill") + Text("약 종류") + .secondaryRegular() + Spacer() + Image(systemName: "chevron.right") + } + .padding([.leading, .trailing], 25) + }) + .padding(.vertical, 20) + .frame(maxWidth: .infinity) + .background(.customGray02) + .clipShape(RoundedRectangle(cornerRadius: 10)) + .foregroundColor(.secondary) + .padding([.leading, .trailing], 16) +// .sheet(isPresented: $showingMedicineSheet){ +// // MedicineSheetView(showingMedicineSheet: true) +//// MedicineSheetView(selectedPill: $showingMedicineSheet) +//// .presentationDetents([.medium]) +// } + + + + Button(action: {}, label: { + // sfSymbol 부재 : uis-calender + HStack { + Image(systemName: "note") + Text("현재 복용 일수") + .secondaryRegular() + Spacer() + } + .padding([.leading, .trailing], 25) + }) + .padding(.vertical, 20) + .frame(maxWidth: .infinity) + .background(.customGray02) + .clipShape(RoundedRectangle(cornerRadius: 10)) + .foregroundColor(.secondary) + .padding([.leading, .trailing], 16) + + } + + Spacer() + + VStack { + // footer button + Button(action: { + pillInfo = Config.dummyPillInfos[0] + intakeDay = 5 + + isActive = true // 네비게이션 링크를 활성화 + }, label: { + Text("다음으로") + .largeBold() + }) + .padding(.vertical, 30) + .frame(maxWidth: .infinity) + .background(Color.customGreen) + .clipShape(RoundedRectangle(cornerRadius: 20)) + .foregroundColor(.black) + .padding() + + // 버튼과 네비게이션링크를 같이 띄우는 방법? + + NavigationLink( + destination: PiriSecondView(pillInfo: $pillInfo,intakeDay:$intakeDay), + isActive: $isActive, + label: { + EmptyView() // 보이지 않게 설정 + } + ) + } + } + +} diff --git a/MC2-Team3-Pilling/View/PiriSecondView.swift b/MC2-Team3-Pilling/View/PiriSecondView.swift new file mode 100644 index 0000000..8cddfd3 --- /dev/null +++ b/MC2-Team3-Pilling/View/PiriSecondView.swift @@ -0,0 +1,143 @@ +// +// PiriSecondView.swift +// MC2-Team3-Pilling +// +// Created by ram on 5/21/24. +// + +import SwiftUI +import SwiftData +struct PiriSecondView: View { + @State private var alarmTime: Date = Date() + @State private var alarmToggle = false + @Binding var pillInfo:PillInfo + @Binding var intakeDay:Int + @State var isActive = false + @Environment(\.modelContext) private var modelContext + @Query var user:[UserInfo] + + + var body: some View { + VStack{ + Image("clock") + .resizable() + .frame(width: 240, height: 240) + + // Text + HStack { + VStack(alignment: .leading) { + // Text + Text("알람 받을 시간을 설정해주세요!") + .largeBold() + .padding(.bottom, 2) + + Text("설정은 추후에 변경 가능합니다.") + .secondaryRegular() + } + Spacer() + } + .padding() + + + Button(action: { + }, label: { + + ZStack{ +// HStack { +// Image(systemName: "clock") +// Text("복용 시간") +// .secondaryTitle() +// Spacer() +// +// } + DatePicker("복용 시간", selection: $alarmTime, displayedComponents: .hourAndMinute) + + } + .padding([.leading, .trailing], 20) + + } + ) + .padding(.vertical, 20) + .frame(maxWidth: .infinity) + .background(.customGray02) + .clipShape(RoundedRectangle(cornerRadius: 10)) + .foregroundColor(.secondary) + .padding() + + + VStack(alignment: .leading){ + Toggle("소리 알람여부추가", isOn: $alarmToggle) + .regular() + .padding(.bottom, 2) + + HStack { + Image(systemName: "info.circle.fill") + Text("소리를 OFF하면 라이브 액티비티로만 알려줘요!") + .font(.callout) + } + .foregroundStyle(.secondary) + } + .padding() + + Spacer() + + Button(action: { + print(alarmTime) + var scheduleTime = Config().DateToString(date: alarmTime, format: Hourformat) + print(scheduleTime) + var periodPill = save(pillInfo: pillInfo, curIntakeDay: intakeDay) + + print(periodPill) + var userInfo = UserInfo(scheduleTime: scheduleTime, curPill: periodPill) +// print(userInfo.curPill.startIntake) + var pillInfo = user.first?.curPill +// print(userInfo) +// for index in 22...26{ +// userInfo.curPill.intakeCal[index].status = 3 +// } +// for index in (pillInfo?.pillInfo.intakeDay ?? 24)...(pillInfo?.pillInfo.wholeDay ?? 28)-1{ +// userInfo.curPill.intakeCal[index].status = 3 +// } +// print(userInfo.curPill.intakeCal) + + modelContext.insert(userInfo) + do { + try modelContext.save() + print("스데 저장 성공") + } catch { + print("Failed to save context: \(error.localizedDescription)") + } + isActive = true + }) { + Text("설정완료!") + .font(.title3) + .bold() + .frame(maxWidth: .infinity) + .padding() + .background(Color.customGreen) + .clipShape(RoundedRectangle(cornerRadius: 20)) + .foregroundColor(.black) + .padding() + } + + // NavigationLink with isActive binding + NavigationLink(destination: MainView(), isActive: $isActive) { + EmptyView() + } + + } + .onAppear{ + print(intakeDay) + } + } + func save(pillInfo:PillInfo,curIntakeDay:Int) -> PeriodPill{ + + let currentDate = Date() + let calendar = Calendar.current + let startDate = calendar.date(byAdding: .day, value: -curIntakeDay, to: currentDate) + let startIntakeString = Config().DateToString(date: startDate ?? currentDate,format:dayformat) //디폴트값 수정해야함 + return PeriodPill(pillInfo: pillInfo, startIntake: startIntakeString) + + } +} + diff --git a/MC2-Team3-Pilling/View/SwiftDataTestView.swift b/MC2-Team3-Pilling/View/SwiftDataTestView.swift index 531ce95..4c31ae6 100644 --- a/MC2-Team3-Pilling/View/SwiftDataTestView.swift +++ b/MC2-Team3-Pilling/View/SwiftDataTestView.swift @@ -11,6 +11,7 @@ import SwiftData struct SwiftDataTestView: View { @Environment(\.modelContext) private var modelContext @State var txt = "" + @Query var user: [UserInfo] var body: some View { @@ -24,11 +25,14 @@ struct SwiftDataTestView: View { } catch { print("Failed to save context: \(error.localizedDescription)") } + } , label: { /*@START_MENU_TOKEN@*/Text("Button")/*@END_MENU_TOKEN@*/ }) - + withAnimation{ + Text(user.first?.curPill.pillInfo.pillName ?? "없음") + } } .padding()