Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/timer update #57

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions Pickle/Pickle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -789,10 +789,12 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Pickle/Preview Content\"";
DEVELOPMENT_TEAM = 7Y6TYDQ939;
DEVELOPMENT_TEAM = HP4XA8YZN3;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Pickle/Info.plist;
INFOPLIST_KEY_NSHealthShareUsageDescription = "건강 데이터를 조회할 때 사용되는 필요한 권한입니다.";
INFOPLIST_KEY_NSHealthUpdateUsageDescription = "건강 데이터를 조회할 때 사용되는 필요한 권한입니다.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand All @@ -804,7 +806,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.sojung.Pickle;
PRODUCT_BUNDLE_IDENTIFIER = com.ddudios.realpizza;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand All @@ -821,10 +823,12 @@
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_ASSET_PATHS = "\"Pickle/Preview Content\"";
DEVELOPMENT_TEAM = 7Y6TYDQ939;
DEVELOPMENT_TEAM = HP4XA8YZN3;
ENABLE_PREVIEWS = YES;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Pickle/Info.plist;
INFOPLIST_KEY_NSHealthShareUsageDescription = "건강 데이터를 조회할 때 사용되는 필요한 권한입니다.";
INFOPLIST_KEY_NSHealthUpdateUsageDescription = "건강 데이터를 조회할 때 사용되는 필요한 권한입니다.";
INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchScreen_Generation = YES;
Expand All @@ -836,7 +840,7 @@
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.0;
PRODUCT_BUNDLE_IDENTIFIER = com.sojung.Pickle;
PRODUCT_BUNDLE_IDENTIFIER = com.ddudios.realpizza;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
Expand Down
12 changes: 6 additions & 6 deletions Pickle/Pickle/Data/Model/Todo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ struct Todo: Identifiable {
let id: String
var content: String
var startTime: Date // 시작 시간 (15시부터)
var targetTime: TimeInterval // 목표 시간 (16시까지)
var spendTime: Date // 실제 종료 시간 (16시반까지)
var targetTime: TimeInterval // 목표 소요 시간 ex) 30분
var spendTime: TimeInterval // 실제 소요 시간 ex) 32분
var status: TodoStatus
}

Expand Down Expand Up @@ -93,26 +93,26 @@ extension Todo {
content: "",
startTime: Date(),
targetTime: 0,
spendTime: Date(),
spendTime: 10,
status: .ready)
}
let sampleTodoList: [Todo] = [
Todo(id: UUID().uuidString,
content: "이력서 작성하기",
startTime: Date(),
targetTime: 3600,
spendTime: Date() + 5400,
spendTime: 5400,
status: .ready),
Todo(id: UUID().uuidString,
content: "ADS 작성하기",
startTime: Date(),
targetTime: 1800,
spendTime: Date() + 1800,
spendTime: 1800,
status: .ready),
Todo(id: UUID().uuidString,
content: "Readme 작성하기",
startTime: Date(),
targetTime: 5400,
spendTime: Date() + 3600,
spendTime: 3600,
status: .ready),
]
6 changes: 3 additions & 3 deletions Pickle/Pickle/Data/Repository/Realm/Object/TodoObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ class TodoObject: Object, Identifiable {
@Persisted var content: String
@Persisted var startTime: Date
@Persisted var targetTime: TimeInterval
@Persisted var spendTime: Date
@Persisted var spendTime: TimeInterval
@Persisted var status: TodoStatusPersisted

convenience init(content: String,
startTime: Date,
targetTime: TimeInterval,
spendTime: Date,
spendTime: TimeInterval,
status: TodoStatusPersisted) {
self.init()
self.content = content
Expand All @@ -34,7 +34,7 @@ class TodoObject: Object, Identifiable {
content: String,
startTime: Date,
targetTime: TimeInterval,
spendTime: Date,
spendTime: TimeInterval,
status: TodoStatusPersisted) {
self.init(content: content,
startTime: startTime,
Expand Down
2 changes: 1 addition & 1 deletion Pickle/Pickle/Screen/Add/RegisterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ struct RegisterView: View {
content: content,
startTime: startTime,
targetTime: resultTime.timeIntervalSince(startTime),
spendTime: startTime,
spendTime: 0,
status: .ready)
}

Expand Down
116 changes: 61 additions & 55 deletions Pickle/Pickle/Screen/Home/TimerReportView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,82 @@ import SwiftUI
struct TimerReportView: View {

@Environment(\.dismiss) private var dismiss
@EnvironmentObject var todoStore: TodoStore

@Binding var isShowingReportSheet: Bool
@Binding var isComplete: Bool
@Binding var isShowingTimerView: Bool

var todo: Todo
var spendTime: TimeInterval

var body: some View {
VStack {
Text("대단해요! 피자 한 조각을 얻었어요!!🍕")
.font(Font.pizzaHeadlineBold)
.padding()
if todo.spendTime >= 60{
Text("대단해요! 피자 한 조각을 얻었어요!!🍕")
.font(.pizzaBody)
.padding()

Image("smilePizza")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: .screenWidth * 0.75)
} else {
Text("다음에는 피자 조각을 얻어봐요")
.font(.pizzaBody)
.padding()
}

Image("smilePizza")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: .screenWidth * 0.75)

VStack {
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(.quaternary)
.frame(height: 80)
.padding(.horizontal)
.padding(.vertical, 4)
VStack {
Group {
HStack {
Text("총 소요 시간")
Text("목표 시간")
Spacer()
Text(convertSecondsToTime(timeInSecond: Int(todo.targetTime)))
}
HStack {
Text("소요 시간")
Spacer()
Text(convertSecondsToTime(timeInSecond: Int(spendTime)))
Text(convertSecondsToTime(timeInSecond: Int(todo.spendTime)))
}
}
.font(.pizzaTitle2Bold)
.padding(.horizontal, 40)
.font(.pizzaBody)
.padding(.horizontal, 5)
.padding()
}
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(.quaternary)
.frame(height: 80)
.padding(.horizontal)
.padding(.vertical, 4)
.clipShape(RoundedRectangle(cornerRadius: 12)) // clip corners
.background(
RoundedRectangle(cornerRadius: 12) // stroke border
.stroke(.quaternary, lineWidth: 1)
)
.padding(.horizontal, .screenWidth * 0.1)
.padding(.bottom)

VStack {
Group {
HStack {
Text("시작 시간")
Spacer()
Text("\(todo.startTime.format("a hh:mm"))")
}
}
.font(.pizzaTitle2Bold)
.padding(.horizontal, 40)
}
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(.quaternary)
.frame(height: 80)
.padding(.horizontal)
.padding(.vertical, 4)
Group {
HStack {
Text("종료 시간")
Spacer()
Text("\(todo.spendTime.format("a hh:mm"))")
Text("\((todo.startTime + todo.spendTime).format("a hh:mm"))")
}
}
.font(.pizzaTitle2Bold)
.padding(.horizontal, 40)
.font(.pizzaBody)
.padding(.horizontal, 5)
.padding()
}
.clipShape(RoundedRectangle(cornerRadius: 12)) // clip corners
.background(
RoundedRectangle(cornerRadius: 12) // stroke border
.stroke(.quaternary, lineWidth: 1)
)
.padding(.horizontal, .screenWidth * 0.1)
.padding(.bottom)

}

Button(action: {
Expand All @@ -86,7 +94,7 @@ struct TimerReportView: View {
dismiss()
}, label: {
Text("확인")
.font(.title3)
.font(.pizzaBody)
.bold()
.padding(.vertical, 8)
.frame(width: .screenWidth * 0.2)
Expand All @@ -97,31 +105,29 @@ struct TimerReportView: View {
.tint(.primary)
}
.onAppear {
isComplete = true
isComplete = true
}
.task {
await todoStore.fetch()
}
}

func convertSecondsToTime(timeInSecond: Int) -> String {
let hours = timeInSecond / 3600 // 시
let minutes = (timeInSecond - hours*3600) / 60 // 분
let seconds = timeInSecond % 60 // 초
let minutes = timeInSecond / 60 // 분
return String(format: "%02i분 ", minutes)

if timeInSecond >= 3600 {
return String(format: "%02i시간 %02i분 %02i초", hours, minutes, seconds)
} else {
return String(format: "%02i분 %02i초", minutes, seconds)
}
}
}

struct TimerReportView_Previews: PreviewProvider {
static var previews: some View {
TimerReportView(isShowingReportSheet: .constant(false), isComplete: .constant(false), isShowingTimerView: .constant(false), todo: Todo(id: UUID().uuidString,
content: "이력서 작성하기",
startTime: Date(),
targetTime: 60,
spendTime: Date() + 5400,
status: .ready),
spendTime: 603)
content: "이력서 작성하기",
startTime: Date(),
targetTime: 60,
spendTime: 5400,
status: .ready))
.environmentObject(TodoStore())

}
}
45 changes: 39 additions & 6 deletions Pickle/Pickle/Screen/Home/TimerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SwiftUI

struct TimerView: View {
@Environment(\.dismiss) private var dismiss
@EnvironmentObject var todoStore: TodoStore

var todo: Todo
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect()
Expand Down Expand Up @@ -43,7 +44,7 @@ struct TimerView: View {
.padding(.bottom, 40)
} else {
Text(todo.content)
.font(Font.pizzaTitleBold)
.font(Font.system(size: 28, weight: .bold))
.padding(.top)

// TODO: RegisterView처럼 랜덤으로 바꿔주기
Expand Down Expand Up @@ -129,6 +130,7 @@ struct TimerView: View {
isShowGiveupAlert = true
isComplete = true
} else {
updateDone(spendTime: spendTime)
isShowingReportSheet = true
isComplete = true
}
Expand All @@ -145,6 +147,7 @@ struct TimerView: View {

Button(action: {
// 포기 alert띄우기
updateGiveup(spendTime: spendTime)
isGiveupSign = true
isShowGiveupAlert = true
}, label: {
Expand Down Expand Up @@ -192,10 +195,40 @@ struct TimerView: View {
}
// TimerReportView Sheet로!
.sheet(isPresented: $isShowingReportSheet) {
TimerReportView(isShowingReportSheet: $isShowingReportSheet, isComplete: $isComplete, isShowingTimerView: $isShowingTimerView, todo: todo, spendTime: spendTime)
TimerReportView(isShowingReportSheet: $isShowingReportSheet, isComplete: $isComplete, isShowingTimerView: $isShowingTimerView, todo: todo)
}
}

func updateStart() {
let todo = Todo(id: todo.id,
content: todo.content,
startTime: Date(),
targetTime: todo.targetTime,
spendTime: todo.spendTime,
status: .ongoing)
todoStore.update(todo: todo)
}

func updateGiveup(spendTime: TimeInterval) {
let todo = Todo(id: todo.id,
content: todo.content,
startTime: todo.startTime,
targetTime: todo.targetTime,
spendTime: spendTime,
status: .giveUp)
todoStore.update(todo: todo)
}

func updateDone(spendTime: TimeInterval) {
let todo = Todo(id: todo.id,
content: todo.content,
startTime: todo.startTime,
targetTime: todo.targetTime,
spendTime: spendTime,
status: .done)
todoStore.update(todo: todo)
}

// TODO: 한시간 안넘어가면 분, 초 만 보여주기
// 초 -> HH:MM:SS로 보여주기
func convertSecondsToTime(timeInSecond: TimeInterval) -> String {
Expand Down Expand Up @@ -231,8 +264,7 @@ struct TimerView: View {
// 남은 시간 계산하기
func calcRemain() {
isStart = false
// TODO: targetTime 초? or 분?
// TODO: 여기서 시작시간 update
updateStart()
self.settingTime = todo.targetTime
self.timeRemaining = settingTime
}
Expand Down Expand Up @@ -260,9 +292,10 @@ struct TimerView_Previews: PreviewProvider {
TimerView(todo: Todo(id: UUID().uuidString,
content: "이력서 작성하기",
startTime: Date(),
targetTime: 3800,
spendTime: Date() + 5400,
targetTime: 60,
spendTime: 5400,
status: .ready), isShowingTimerView: .constant(false))
.environmentObject(TodoStore())
}
}
}
Loading