-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevelSelectionView.swift
More file actions
517 lines (480 loc) · 19.8 KB
/
Copy pathLevelSelectionView.swift
File metadata and controls
517 lines (480 loc) · 19.8 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
//
// LevelSelectionView.swift
// InstantEnglish
//
// Created on 2024/12/08.
//
import SwiftUI
enum CourseType: String, CaseIterable {
case stepUp = "ステップアップ"
case test = "テスト用"
}
struct LevelSelectionView: View {
@ObservedObject var questionManager: QuestionManager
@Binding var isPresented: Bool
@State private var showLevelAssessment = false
@State private var selectedCourseType: CourseType = .stepUp
@State private var selectedStepUpCourse: (from: CEFRLevel, to: CEFRLevel)? = nil
let stepUpCourses: [StepUpCourse] = [
StepUpCourse(
fromLevel: .a1,
toLevel: .a2,
name: "A1 → A2 ステップアップ",
description: "基礎から日常会話へステップアップ",
questionCount: 5,
estimatedTime: 10
),
StepUpCourse(
fromLevel: .a2,
toLevel: .b1,
name: "A2 → B1 ステップアップ",
description: "日常会話から中級へステップアップ",
questionCount: 5,
estimatedTime: 12
),
StepUpCourse(
fromLevel: .b1,
toLevel: .b2,
name: "B1 → B2 ステップアップ",
description: "中級から上級中級へステップアップ",
questionCount: 5,
estimatedTime: 15
),
StepUpCourse(
fromLevel: .b2,
toLevel: .c1,
name: "B2 → C1 ステップアップ",
description: "上級中級から上級へステップアップ",
questionCount: 5,
estimatedTime: 18
),
StepUpCourse(
fromLevel: .c1,
toLevel: .c2,
name: "C1 → C2 ステップアップ",
description: "上級から最上級へステップアップ",
questionCount: 5,
estimatedTime: 20
)
]
let courses: [Course] = [
Course(
level: .a1,
name: "A1 基礎コース",
description: "基本的な日常表現と簡単な文を学びます",
questionCount: 8,
estimatedTime: 15
),
Course(
level: .a2,
name: "A2 日常会話コース",
description: "日常的な場面でよく使われる表現を学びます",
questionCount: 8,
estimatedTime: 20
),
Course(
level: .b1,
name: "B1 中級コース",
description: "仕事、学校、娯楽などで使われる標準的な表現を学びます",
questionCount: 8,
estimatedTime: 25
),
Course(
level: .b2,
name: "B2 上級中級コース",
description: "複雑な文章の要点を理解し、流暢に表現する方法を学びます",
questionCount: 8,
estimatedTime: 30
),
Course(
level: .c1,
name: "C1 上級コース",
description: "様々な分野の長文を理解し、流暢に表現する方法を学びます",
questionCount: 8,
estimatedTime: 35
),
Course(
level: .c2,
name: "C2 最上級コース",
description: "ほぼすべての内容を容易に理解し、流暢かつ正確に表現する方法を学びます",
questionCount: 8,
estimatedTime: 40
)
]
var body: some View {
ZStack {
// 背景
Color(.systemGroupedBackground)
.ignoresSafeArea()
ScrollView {
VStack(spacing: 20) {
// ヘッダー
VStack(spacing: 16) {
Text("CEFRレベルを選択")
.font(.title)
.fontWeight(.bold)
Text("あなたのレベルに合わせたコースを選んでください")
.font(.subheadline)
.foregroundColor(.secondary)
.multilineTextAlignment(.center)
// レベル測定テストボタン
Button(action: {
showLevelAssessment = true
}) {
HStack {
Image(systemName: "chart.bar.fill")
Text("レベル測定テストを受ける")
.fontWeight(.semibold)
}
.frame(maxWidth: .infinity)
.padding()
.background(
LinearGradient(
gradient: Gradient(colors: [Color.blue, Color.purple]),
startPoint: .leading,
endPoint: .trailing
)
)
.foregroundColor(.white)
.cornerRadius(12)
}
.padding(.horizontal)
// コースタイプ選択セグメント
Picker("コースタイプ", selection: $selectedCourseType) {
ForEach(CourseType.allCases, id: \.self) { type in
Text(type.rawValue).tag(type)
}
}
.pickerStyle(SegmentedPickerStyle())
.padding(.horizontal)
}
.padding(.top, 20)
.padding(.horizontal)
// 選択されたコースタイプに応じて表示を切り替え
if selectedCourseType == .stepUp {
// ステップアップコースセクション
VStack(alignment: .leading, spacing: 12) {
HStack {
Image(systemName: "arrow.up.circle.fill")
.foregroundColor(.orange)
Text("ステップアップコース")
.font(.headline)
.fontWeight(.semibold)
}
.padding(.horizontal)
LazyVStack(spacing: 12) {
ForEach(stepUpCourses) { stepUpCourse in
StepUpCourseCardView(
stepUpCourse: stepUpCourse,
onSelect: {
selectedStepUpCourse = (stepUpCourse.fromLevel, stepUpCourse.toLevel)
}
)
}
}
.padding(.horizontal)
}
.padding(.top, 8)
.padding(.bottom, 20)
} else {
// テスト用コースセクション
VStack(alignment: .leading, spacing: 12) {
HStack {
Image(systemName: "book.fill")
.foregroundColor(.blue)
Text("テスト用コース")
.font(.headline)
.fontWeight(.semibold)
}
.padding(.horizontal)
LazyVStack(spacing: 16) {
ForEach(courses) { course in
CourseCardView(
course: course,
onSelect: {
// コース選択時にリセット処理を実行
questionManager.resetQuiz()
questionManager.loadQuestionsForLevel(course.level)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) {
isPresented = false
}
}
)
}
}
.padding(.horizontal)
}
.padding(.top, 8)
.padding(.bottom, 20)
}
}
}
}
.navigationTitle("コース選択")
.navigationBarTitleDisplayMode(.large)
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
isPresented = false
}) {
HStack(spacing: 4) {
Image(systemName: "chevron.left")
Text("ホーム")
}
.font(.subheadline)
.foregroundColor(.blue)
}
}
}
.fullScreenCover(isPresented: $showLevelAssessment) {
LevelAssessmentView(
questionManager: questionManager,
isPresented: $showLevelAssessment
)
}
.sheet(item: Binding(
get: {
guard let course = selectedStepUpCourse else { return nil }
return StepUpCourseSelection(from: course.from, to: course.to)
},
set: { (course: StepUpCourseSelection?) in
if let course = course {
selectedStepUpCourse = (course.from, course.to)
} else {
selectedStepUpCourse = nil
}
}
)) { course in
NavigationView {
LessonSelectionView(
questionManager: questionManager,
isPresented: Binding(
get: { selectedStepUpCourse != nil },
set: { if !$0 { selectedStepUpCourse = nil } }
),
fromLevel: course.from,
toLevel: course.to
)
}
}
}
}
struct CourseCardView: View {
let course: Course
let onSelect: () -> Void
var body: some View {
Button(action: onSelect) {
HStack(spacing: 16) {
// レベルアイコン
ZStack {
Circle()
.fill(
LinearGradient(
gradient: Gradient(colors: [
colorForLevel(course.level),
colorForLevel(course.level).opacity(0.7)
]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.frame(width: 70, height: 70)
.shadow(color: colorForLevel(course.level).opacity(0.3), radius: 8, x: 0, y: 4)
Text(course.level.rawValue)
.font(.title)
.fontWeight(.bold)
.foregroundColor(.white)
}
// コース情報
VStack(alignment: .leading, spacing: 8) {
Text(course.name)
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.primary)
Text(course.description)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(2)
HStack(spacing: 16) {
HStack(spacing: 4) {
Image(systemName: "questionmark.circle.fill")
.font(.caption)
.foregroundColor(.blue)
Text("\(course.questionCount)問")
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.primary)
}
HStack(spacing: 4) {
Image(systemName: "clock.fill")
.font(.caption)
.foregroundColor(.orange)
Text("約\(course.estimatedTime)分")
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.primary)
}
}
}
Spacer()
// 矢印アイコン
Image(systemName: "chevron.right")
.font(.headline)
.foregroundColor(colorForLevel(course.level))
}
.padding(16)
.background(
RoundedRectangle(cornerRadius: 20)
.fill(Color(.systemBackground))
.shadow(color: Color.black.opacity(0.08), radius: 8, x: 0, y: 4)
)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(
LinearGradient(
gradient: Gradient(colors: [
colorForLevel(course.level).opacity(0.3),
colorForLevel(course.level).opacity(0.1)
]),
startPoint: .topLeading,
endPoint: .bottomTrailing
),
lineWidth: 2
)
)
}
.buttonStyle(PlainButtonStyle())
}
private func colorForLevel(_ level: CEFRLevel) -> Color {
switch level {
case .a1: return .green
case .a2: return .mint
case .b1: return .blue
case .b2: return .cyan
case .c1: return .purple
case .c2: return .indigo
}
}
}
struct StepUpCourseCardView: View {
let stepUpCourse: StepUpCourse
let onSelect: () -> Void
var body: some View {
Button(action: onSelect) {
HStack(spacing: 16) {
// レベルアイコン(矢印付き)
ZStack {
Circle()
.fill(
LinearGradient(
gradient: Gradient(colors: [
colorForLevel(stepUpCourse.fromLevel),
colorForLevel(stepUpCourse.toLevel)
]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.frame(width: 70, height: 70)
.shadow(color: colorForLevel(stepUpCourse.toLevel).opacity(0.3), radius: 8, x: 0, y: 4)
VStack(spacing: 3) {
Text(stepUpCourse.fromLevel.rawValue)
.font(.caption)
.fontWeight(.bold)
.foregroundColor(.white)
Image(systemName: "arrow.down")
.font(.caption2)
.foregroundColor(.white)
Text(stepUpCourse.toLevel.rawValue)
.font(.caption)
.fontWeight(.bold)
.foregroundColor(.white)
}
}
// コース情報
VStack(alignment: .leading, spacing: 8) {
HStack(spacing: 6) {
Image(systemName: "arrow.up.circle.fill")
.font(.caption)
.foregroundColor(.orange)
Text(stepUpCourse.displayName)
.font(.headline)
.fontWeight(.bold)
.foregroundColor(.primary)
}
Text(stepUpCourse.description)
.font(.subheadline)
.foregroundColor(.secondary)
.lineLimit(2)
HStack(spacing: 16) {
HStack(spacing: 4) {
Image(systemName: "questionmark.circle.fill")
.font(.caption)
.foregroundColor(.blue)
Text("\(stepUpCourse.questionCount)問")
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.primary)
}
HStack(spacing: 4) {
Image(systemName: "clock.fill")
.font(.caption)
.foregroundColor(.orange)
Text("約\(stepUpCourse.estimatedTime)分")
.font(.caption)
.fontWeight(.semibold)
.foregroundColor(.primary)
}
}
}
Spacer()
// 矢印アイコン
Image(systemName: "chevron.right")
.font(.headline)
.foregroundColor(colorForLevel(stepUpCourse.toLevel))
}
.padding(16)
.background(
RoundedRectangle(cornerRadius: 20)
.fill(Color(.systemBackground))
.shadow(color: Color.black.opacity(0.08), radius: 8, x: 0, y: 4)
)
.overlay(
RoundedRectangle(cornerRadius: 20)
.stroke(
LinearGradient(
gradient: Gradient(colors: [
colorForLevel(stepUpCourse.fromLevel).opacity(0.4),
colorForLevel(stepUpCourse.toLevel).opacity(0.4)
]),
startPoint: .leading,
endPoint: .trailing
),
lineWidth: 2
)
)
}
.buttonStyle(PlainButtonStyle())
}
private func colorForLevel(_ level: CEFRLevel) -> Color {
switch level {
case .a1: return .green
case .a2: return .mint
case .b1: return .blue
case .b2: return .cyan
case .c1: return .purple
case .c2: return .indigo
}
}
}
struct StepUpCourseSelection: Identifiable {
let id = UUID()
let from: CEFRLevel
let to: CEFRLevel
}
#Preview {
LevelSelectionView(
questionManager: QuestionManager(),
isPresented: .constant(true)
)
}