-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpeakHomeView.swift
More file actions
312 lines (272 loc) · 9.76 KB
/
Copy pathSpeakHomeView.swift
File metadata and controls
312 lines (272 loc) · 9.76 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
//
// SpeakHomeView.swift
// InstantEnglish
//
// ホーム画面(スピーキング特化)
//
import SwiftUI
struct SpeakHomeView: View {
@EnvironmentObject var conversationManager: ConversationManager
@EnvironmentObject var progressManager: ProgressManager
@State private var selectedCategory: ConversationScenario.ScenarioCategory? = nil
@State private var selectedDifficulty: ConversationScenario.Difficulty? = nil
var body: some View {
NavigationView {
ZStack {
// 背景
LinearGradient(
colors: [Color.blue.opacity(0.1), Color.purple.opacity(0.1)],
startPoint: .topLeading,
endPoint: .bottomTrailing
)
.ignoresSafeArea()
ScrollView {
VStack(spacing: 24) {
// ヘッダー
headerView
.padding(.top, 20)
// 統計カード
statsView
.padding(.horizontal)
// カテゴリ選択
categoryView
.padding(.horizontal)
// 難易度選択
difficultyView
.padding(.horizontal)
// シナリオリスト
scenarioListView
.padding(.horizontal)
.padding(.bottom, 20)
}
}
}
.navigationTitle("Speak English")
.sheet(isPresented: Binding(
get: { conversationManager.currentScenario != nil },
set: { if !$0 { conversationManager.endConversation() } }
)) {
NavigationView {
ConversationView()
.environmentObject(conversationManager)
}
}
}
}
// MARK: - Header
private var headerView: some View {
VStack(spacing: 12) {
Image(systemName: "mic.circle.fill")
.font(.system(size: 60))
.foregroundColor(.blue)
Text("英語で会話を始めましょう")
.font(.title2)
.fontWeight(.bold)
Text("AIとリアルタイムで会話練習")
.font(.subheadline)
.foregroundColor(.secondary)
}
}
// MARK: - Stats
private var statsView: some View {
HStack(spacing: 16) {
StatCard(
icon: "message.fill",
title: "会話数",
value: "\(conversationManager.conversationHistory.count)",
color: .blue
)
StatCard(
icon: "star.fill",
title: "平均スコア",
value: String(format: "%.0f%%", averageScore),
color: .yellow
)
StatCard(
icon: "clock.fill",
title: "練習時間",
value: "\(totalPracticeMinutes)分",
color: .green
)
}
}
private var averageScore: Double {
let scores = conversationManager.conversationHistory.map { $0.finalScore }
guard !scores.isEmpty else { return 0 }
return scores.reduce(0, +) / Double(scores.count) * 100
}
private var totalPracticeMinutes: Int {
conversationManager.conversationHistory.compactMap { session in
guard let endTime = session.endTime else { return nil }
return Int(endTime.timeIntervalSince(session.startTime) / 60)
}.reduce(0, +)
}
// MARK: - Category
private var categoryView: some View {
VStack(alignment: .leading, spacing: 12) {
Text("カテゴリ")
.font(.headline)
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 12) {
ForEach(ConversationScenario.ScenarioCategory.allCases, id: \.self) { category in
CategoryButton(
category: category,
isSelected: selectedCategory == category
) {
selectedCategory = selectedCategory == category ? nil : category
}
}
}
}
}
}
// MARK: - Difficulty
private var difficultyView: some View {
VStack(alignment: .leading, spacing: 12) {
Text("難易度")
.font(.headline)
HStack(spacing: 12) {
ForEach(ConversationScenario.Difficulty.allCases, id: \.self) { difficulty in
DifficultyButton(
difficulty: difficulty,
isSelected: selectedDifficulty == difficulty
) {
selectedDifficulty = selectedDifficulty == difficulty ? nil : difficulty
}
}
}
}
}
// MARK: - Scenario List
private var scenarioListView: some View {
VStack(alignment: .leading, spacing: 12) {
Text("会話シナリオ")
.font(.headline)
let filteredScenarios = getFilteredScenarios()
if filteredScenarios.isEmpty {
Text("シナリオが見つかりません")
.foregroundColor(.secondary)
.padding()
} else {
ForEach(filteredScenarios) { scenario in
ScenarioCard(scenario: scenario)
.onTapGesture {
conversationManager.startConversation(scenario: scenario)
}
}
}
}
}
private func getFilteredScenarios() -> [ConversationScenario] {
var scenarios = ConversationScenarios.defaultScenarios
if let category = selectedCategory {
scenarios = scenarios.filter { $0.category == category }
}
if let difficulty = selectedDifficulty {
scenarios = scenarios.filter { $0.difficulty == difficulty }
}
return scenarios
}
}
// MARK: - Stat Card
struct StatCard: View {
let icon: String
let title: String
let value: String
let color: Color
var body: some View {
VStack(spacing: 8) {
Image(systemName: icon)
.font(.title2)
.foregroundColor(color)
Text(value)
.font(.title)
.fontWeight(.bold)
Text(title)
.font(.caption)
.foregroundColor(.secondary)
}
.frame(maxWidth: .infinity)
.padding()
.background(Color(.systemBackground))
.cornerRadius(12)
.shadow(radius: 2)
}
}
// MARK: - Category Button
struct CategoryButton: View {
let category: ConversationScenario.ScenarioCategory
let isSelected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
Text(category.rawValue)
.font(.subheadline)
.fontWeight(.medium)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(isSelected ? Color.blue : Color(.systemGray5))
.foregroundColor(isSelected ? .white : .primary)
.cornerRadius(20)
}
}
}
// MARK: - Difficulty Button
struct DifficultyButton: View {
let difficulty: ConversationScenario.Difficulty
let isSelected: Bool
let action: () -> Void
var body: some View {
Button(action: action) {
Text(difficulty.rawValue)
.font(.subheadline)
.fontWeight(.medium)
.padding(.horizontal, 20)
.padding(.vertical, 10)
.frame(maxWidth: .infinity)
.background(isSelected ? Color.blue : Color(.systemGray5))
.foregroundColor(isSelected ? .white : .primary)
.cornerRadius(12)
}
}
}
// MARK: - Scenario Card
struct ScenarioCard: View {
let scenario: ConversationScenario
var body: some View {
VStack(alignment: .leading, spacing: 8) {
HStack {
Text(scenario.title)
.font(.headline)
Spacer()
Text(scenario.difficulty.rawValue)
.font(.caption)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(difficultyColor)
.foregroundColor(.white)
.cornerRadius(8)
}
Text(scenario.description)
.font(.subheadline)
.foregroundColor(.secondary)
HStack {
Label(scenario.category.rawValue, systemImage: "tag.fill")
.font(.caption)
.foregroundColor(.blue)
Spacer()
}
}
.padding()
.background(Color(.systemBackground))
.cornerRadius(12)
.shadow(radius: 2)
}
private var difficultyColor: Color {
switch scenario.difficulty {
case .beginner: return .green
case .intermediate: return .orange
case .advanced: return .red
}
}
}