|
8 | 8 | import SwiftUI |
9 | 9 | import FamilyControls |
10 | 10 |
|
| 11 | +import Lottie |
| 12 | + |
11 | 13 | struct AppActivityView: View { |
12 | 14 | var activityReport: ActivityReport |
13 | 15 | var body: some View { |
14 | | - VStack(alignment: .center) { |
| 16 | + VStack() { |
| 17 | + HeaderView(activityReport: activityReport) |
| 18 | + |
| 19 | + .padding(.bottom, 40) |
15 | 20 | ForEach(activityReport.apps) { eachApp in |
16 | 21 | ListView(eachApp: eachApp) |
17 | 22 | .padding(.horizontal, 20) |
18 | 23 | } |
19 | | - Spacer() |
| 24 | + } |
| 25 | + } |
| 26 | +} |
| 27 | + |
| 28 | +struct HeaderView: View { |
| 29 | + var activityReport: ActivityReport |
| 30 | + @ObservedObject var screenTimeViewModel = ScreenTimeViewModel() |
| 31 | + |
| 32 | + var body: some View { |
| 33 | + |
| 34 | + VStack(alignment: .leading) { |
| 35 | + ZStack(alignment: .topLeading) { |
| 36 | + LottieView(animation: .named(activityReport.titleState.isEmpty ? "Main-A-final.json" : activityReport.titleState[0])) |
| 37 | + .playing(loopMode: .autoReverse) |
| 38 | + .resizable() |
| 39 | + VStack(alignment: .leading){ |
| 40 | + Text(activityReport.titleState.isEmpty ? StringLiteral.Home.usageStatusA : activityReport.titleState[1]) |
| 41 | + .font(.text1_medium_22) |
| 42 | + .foregroundStyle(.whiteText) |
| 43 | + .frame(alignment: .topLeading) |
| 44 | + .padding(EdgeInsets(top: 8, |
| 45 | + leading: 20, |
| 46 | + bottom: 0, |
| 47 | + trailing: 0)) |
| 48 | + Spacer() |
| 49 | + VStack(alignment: .leading) { |
| 50 | + Text("목표 사용 시간 \(convertMillisecondsToHourString(milliseconds: activityReport.totalGoalTime)) 중") |
| 51 | + .font(.detail4_medium_12) |
| 52 | + .foregroundStyle(.gray2) |
| 53 | + .frame(alignment: .leading) |
| 54 | + .padding(EdgeInsets(top: 0, |
| 55 | + leading: 20, |
| 56 | + bottom: 0, |
| 57 | + trailing: 0)) |
| 58 | + HStack { |
| 59 | + Text("\(convertMillisecondsToHourString(milliseconds: activityReport.totalDuration)) 사용") |
| 60 | + .font(.title2_semibold_24) |
| 61 | + .foregroundStyle(.whiteText) |
| 62 | + .frame(maxWidth: .infinity, alignment: .leading) |
| 63 | + Spacer() |
| 64 | + Text(convertMillisecondsToHourString(milliseconds: activityReport.remainTime) + " 남음") |
| 65 | + .font(.detail3_semibold_12) |
| 66 | + .foregroundStyle(.whiteText) |
| 67 | + } |
| 68 | + . padding(EdgeInsets(top: 2, |
| 69 | + leading: 20, |
| 70 | + bottom: 24, |
| 71 | + trailing: 20)) |
| 72 | + ProgressView(value: Double(activityReport.totalDuration), total: Double(activityReport.totalGoalTime)) |
| 73 | + .foregroundStyle(.gray5) |
| 74 | + .padding(EdgeInsets(top: 0, |
| 75 | + leading: 20, |
| 76 | + bottom: 0, |
| 77 | + trailing: 20)) |
| 78 | + .tint(.whiteText) |
| 79 | + } |
| 80 | + .frame(maxHeight: 83) |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + .onAppear() { |
| 85 | + if activityReport.totalDuration == activityReport.totalGoalTime { |
| 86 | + screenTimeViewModel.handleSetBlockApplication() |
| 87 | + } |
| 88 | + } |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +extension HeaderView { |
| 93 | + func convertMillisecondsToHourString(milliseconds: Int) -> String { |
| 94 | + let secondsTotal = milliseconds / 1000 |
| 95 | + let hours = secondsTotal / 3600 |
| 96 | + let minutes = (secondsTotal % 3600) / 60 |
| 97 | + |
| 98 | + if hours > 0 { |
| 99 | + if minutes > 0 { |
| 100 | + return "\(hours)시간 \(minutes)분" |
| 101 | + } else { |
| 102 | + return "\(hours)시간" |
| 103 | + } |
| 104 | + } else { |
| 105 | + return "\(minutes)분" |
20 | 106 | } |
21 | 107 | } |
22 | 108 | } |
@@ -70,5 +156,5 @@ struct ListView: View { |
70 | 156 | } |
71 | 157 | .frame(height: 72) |
72 | 158 | } |
73 | | - |
| 159 | + |
74 | 160 | } |
0 commit comments