-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPushNotificationSettingsView.swift
More file actions
114 lines (110 loc) · 4.29 KB
/
PushNotificationSettingsView.swift
File metadata and controls
114 lines (110 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
//
// PushNotificationSettingsView.swift
// DevLog
//
// Created by opfic on 5/14/25.
//
import SwiftUI
struct PushNotificationSettingsView: View {
@State var viewModel: PushNotificationSettingsViewModel
var body: some View {
List {
Section(content: {
Toggle(isOn:
Binding(
get: { viewModel.state.pushNotificationEnable },
set: { viewModel.send(.setPushNotificationEnable($0)) }
)) {
Text(String(localized: "push_settings_enable"))
}
.tint(.blue)
}, footer: {
Text(String(localized: "push_settings_footer"))
})
Section {
ForEach([9, 15, 18, 21], id: \.self) { hour in
if let date = Calendar.current.date(bySettingHour: hour, minute: 0, second: 0, of: Date()) {
HStack {
Text(formattedTimeString(date))
Spacer()
if viewModel.state.pushNotificationHour == hour &&
viewModel.state.pushNotificationMinute == 0 {
Image(systemName: "checkmark")
.foregroundStyle(Color.blue)
}
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.send(.selectPresetTime(date))
}
}
}
HStack {
Text(String(localized: "push_settings_custom"))
Spacer()
Text(formattedTimeString(viewModel.state.viewPushNotificationTime))
.foregroundStyle(.secondary)
if viewModel.state.pushNotificationMinute != 0 {
Image(systemName: "checkmark")
.foregroundStyle(Color.blue)
}
}
.contentShape(Rectangle())
.onTapGesture {
viewModel.send(.setShowTimePicker(true))
}
}
.disabled(!viewModel.state.pushNotificationEnable)
.opacity(viewModel.state.pushNotificationEnable ? 1.0 : 0.2)
}
.listStyle(.insetGrouped)
.navigationTitle(String(localized: "nav_push_settings"))
.overlay {
if viewModel.state.isLoading {
LoadingView()
}
}
.onAppear {
viewModel.send(.fetchSettings)
}
.sheet(isPresented: Binding(
get: { viewModel.state.showTimePicker },
set: { viewModel.send(.setShowTimePicker($0)) }
)) {
NavigationStack {
DatePicker(
"",
selection: Binding(
get: { viewModel.state.sheetPushNotificationTime },
set: { viewModel.send(.setPushNotificationTime(sheet: $0)) }
),
displayedComponents: .hourAndMinute
)
.datePickerStyle(.wheel)
.labelsHidden()
.onAppear { UIDatePicker.appearance().minuteInterval = 5 }
.onDisappear { UIDatePicker.appearance().minuteInterval = 1 /* 기본값으로 복원 */ }
.toolbar {
ToolbarLeadingButton {
viewModel.send(.rollbackUpdate)
}
ToolbarTrailingButton {
viewModel.send(.confirmUpdate)
}
}
.background(
GeometryReader { geometry in
Color.clear.onAppear {
viewModel.send(.setSheetHeight(geometry.size.height))
}
}
)
}
.presentationDragIndicator(.hidden)
.presentationDetents([.height(viewModel.state.sheetHeight)])
}
}
private func formattedTimeString(_ date: Date) -> String {
date.formatted(.dateTime.hour().minute())
}
}