StatusComparisonView.swift
13.1 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
//
// StatusComparisonView.swift
// hippo-watch Watch App
//
// Created by shihao on 2025/7/7.
//
import Foundation
import SwiftUI
import SDWebImageSwiftUI
struct StatusComparisonView: View {
@Environment(\.scenePhase) private var scenePhase
@StateObject private var vm = StatusComparisonViewModel()
@Binding var showPKView: Bool
@ObservedObject var userinfoManager = WatchUserinfoManager.share
@ObservedObject var dataManager = WatchDataManager.share
var body: some View {
GeometryReader { geometry in
VStack(spacing: 6.x) {
// 顶部时间和标题
HStack {
Text("PK")
.font(.system(size: 16, weight: .semibold))
.foregroundColor(.white)
.frame(width: 34.x, height: 34.x)
.background(Color.white.opacity(0.3))
.clipShape(Circle())
.onTapGesture {
showPKView = true
}
Spacer()
VStack(spacing: 2) {
Spacer()
Text("我们的状态")
.font(.system(size: 17))
.foregroundColor(.white)
}
}
.padding(.horizontal, 11.x)
.padding(.top, 13.x)
// 用户状态对比
HStack(spacing: 0) {
Spacer()
// 左侧用户
VStack(spacing: 0) {
// 压力状态动画
if isMeCustomTheme {
WebImage(url: myCustomThemeImageURL)
.resizable()
.frame(width: 67.x, height: 67.x)
.cornerRadius(12.x)
.overlay(RoundedRectangle(cornerRadius: 12.x).stroke(Color(hex: "#7F7F7F"), lineWidth: 1))
}else {
AnimatedGIFView(gifName: myCharacterAnimationName)
.frame(width: 80.x, height: 80.x)
}
// 用户信息
HStack(spacing: 4.x) {
WebImage(url: userinfoManager.myUserinfo?.avatar?.url)
.resizable()
.frame(width: 20.x, height: 20.x)
.background(.clear)
.clipShape(Circle())
VStack(alignment: .leading, spacing: 2) {
Text(myHRVStatusDescription)
.font(.system(size: 13, weight: .medium))
.foregroundColor(myHRVStatus?.watchStatusTextColor ?? .white)
Text(myHRVValueString)
.font(.system(size: 9))
.foregroundColor(.white.opacity(0.7))
}
}
.padding(.top, isMeCustomTheme ? 7.x : -10.x)
}
Spacer()
// 右侧用户
VStack(spacing: 0) {
// 压力状态动画
if isOtherCustomTheme {
WebImage(url: otherCustomThemeImageURL)
.resizable()
.frame(width: 67.x, height: 67.x)
.cornerRadius(12.x)
.overlay(RoundedRectangle(cornerRadius: 12.x).stroke(Color(hex: "#7F7F7F"), lineWidth: 1))
}else {
AnimatedGIFView(gifName: otherCharacterAnimationName)
.frame(width: 80.x, height: 80.x)
}
// 用户信息
HStack(spacing: 4.x) {
VStack(alignment: .trailing, spacing: 2) {
Text(otherHRVStatusDescription)
.font(.system(size: 13, weight: .medium))
.foregroundColor(otherHRVStatus?.watchStatusTextColor ?? .white)
Text(otherHRVValueString)
.font(.system(size: 9))
.foregroundColor(.white.opacity(0.7))
}
WebImage(url: userinfoManager.otherUserinfo?.avatar?.url)
.resizable()
.frame(width: 20.x, height: 20.x)
.background(.clear)
.clipShape(Circle())
}
.padding(.top, isOtherCustomTheme ? 7.x : -10.x)
}
Spacer()
}
Spacer()
// 底部想他按钮
HStack(spacing: 2.x) {
Image(userinfoManager.interactionActionType.buttonImage)
.resizable()
.frame(width: 28.x, height: 28.x)
.scaleEffect(x: -1, y: 1)
Text(userinfoManager.interactionActionType.title)
.font(.system(size: 15, weight: .regular))
.foregroundColor(.white)
}
.frame(maxWidth: .infinity)
.frame(height: 36.x)
.background(
RoundedRectangle(cornerRadius: 18.x)
.fill(Color(hex: "#758564FF").opacity(0.5))
)
.padding(.horizontal, 12.x)
.padding(.bottom, 10.x)
.onTapGesture {
vm.onInteractionClick()
ThinkSDKUtil.track(eventName: "click_doublefeel_watch_page",
properties: ["click_content": "互动键",
"page_type": "我们的状态",
"Interactive_type": WatchUserinfoManager.share.interactionActionType.title])
}
}
.navigationBarHidden(true)
.frame(width: geometry.size.width, height: geometry.size.height)
.background(
HStack(spacing: 0) {
LinearGradient(
gradient: Gradient(colors: myBgColors),
startPoint: .top,
endPoint: .bottom
)
LinearGradient(
gradient: Gradient(colors: otherBgColors),
startPoint: .top,
endPoint: .bottom
)
}
)
.overlay {
if let currentInteractionAction = vm.currentInteractionAction {
AnimatedGIFView(gifName: currentInteractionAction.statusComparisonAnimationName)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.top, 10.x)
}
}
}
.ignoresSafeArea(.all)
.onAppear {
dataManager.fetchCoupleLatestHRV()
ThinkSDKUtil.track(eventName: "enter_doublefeel_watch_page",
properties: ["page_type": "我们的状态"])
}
.onReceive(NotificationCenter.default.publisher(for: NotificationType.watchThemeChanged)) { notification in
vm.refreshTheme()
}
.onChange(of: scenePhase) { _, newPhase in
if newPhase == .active {
vm.refreshTheme()
}
}
}
private var myBgColors: [Color] {
let status = myHRVStatus ?? .normal
return status.watchStatusColors
}
private var otherBgColors: [Color] {
let status = otherHRVStatus ?? .normal
return status.watchStatusColors
}
private var myHRVStatusDescription: String {
guard let myHRVStatus else {
return "-"
}
if isMeCustomTheme == true {
return vm.myWatchTheme?.hrvStatusDescription(hrvStatus: myHRVStatus) ?? myHRVStatus.rawValue
}else {
return myHRVStatus.rawValue
}
}
private var otherHRVStatusDescription: String {
guard let otherHRVStatus else {
return "-"
}
if isOtherCustomTheme == true {
return vm.otherWatchTheme?.hrvStatusDescription(hrvStatus: otherHRVStatus) ?? otherHRVStatus.rawValue
}else {
return otherHRVStatus.rawValue
}
}
private var myHRVValueString: String {
if let value = dataManager.myLatestHRVData?.value {
if value.truncatingRemainder(dividingBy: 1) == 0 {
return String(format: "%.0f", value) + "ms"// 没有小数部分
} else {
return String(format: "%.1f", value) + "ms" // 最多一位小数
}
}
return "-ms"
}
private var otherHRVValueString: String {
if let value = dataManager.otherLatestHRVData?.value {
if value.truncatingRemainder(dividingBy: 1) == 0 {
return String(format: "%.0f", value) + "ms"// 没有小数部分
} else {
return String(format: "%.1f", value) + "ms" // 最多一位小数
}
}
return "-ms"
}
private var myHRVStatus: HRVStatus? {
return dataManager.myLatestHRVData?.status
}
private var otherHRVStatus: HRVStatus? {
return dataManager.otherLatestHRVData?.status
}
private var myCharacterAnimationName: String {
let character = userinfoManager.myUserinfo?.persona ?? .cat
print("我的hrvstatus:\(String(describing: myHRVStatus))")
return character.getCharacterAnimationFileName(myHRVStatus)
}
private var otherCharacterAnimationName: String {
let character = userinfoManager.otherUserinfo?.persona ?? .cat
return character.getCharacterAnimationFileName(otherHRVStatus)
}
private var isMeCustomTheme: Bool {
guard let theme = vm.myWatchTheme else {return false}
return theme.isDefaultTheme != true
}
private var isOtherCustomTheme: Bool {
guard let theme = vm.otherWatchTheme else {return false}
return theme.isDefaultTheme != true
}
private var myCustomThemeImageURL: URL? {
let hrvStatus = dataManager.myLatestHRVData?.status ?? .normal
if let imageUrl = vm.myWatchTheme?.hrvStatusThumnailImageURL(hrvStatus: hrvStatus) {
return URL(string: imageUrl)
}
return nil
}
private var otherCustomThemeImageURL: URL? {
let hrvStatus = dataManager.myLatestHRVData?.status ?? .normal
if let imageUrl = vm.otherWatchTheme?.hrvStatusThumnailImageURL(hrvStatus: hrvStatus) {
return URL(string: imageUrl)
}
return nil
}
}
fileprivate extension UserCharacter {
func getCharacterAnimationFileName(_ status: HRVStatus?) -> String {
switch self {
case .cat, .default:
switch status {
case .fullOfEnergy:
return "catFullOfEnergy"
case .normal:
return "catNormal"
case .overpressure:
return "catOverpressure"
case nil:
return "catNormal"
}
case .dog:
switch status {
case .fullOfEnergy:
return "dogFullOfEnergy"
case .normal:
return "dogNormal"
case .overpressure:
return "dogOverpressure"
case nil:
return "dogNormal"
}
case .rabbit:
switch status {
case .fullOfEnergy:
return "rabbitFullOfEnergy"
case .normal:
return "rabbitNormal"
case .overpressure:
return "rabbitOverpressure"
case nil:
return "rabbitNormal"
}
case .elephant:
switch status {
case .fullOfEnergy:
return "elephantFullOfEnergy"
case .normal:
return "elephantNormal"
case .overpressure:
return "elephantOverpressure"
case nil:
return "elephantNormal"
}
}
}
}