Blame view

Twear/Mine/Model/UserInfo.swift 10.7 KB
75d24c15   yangbin   123
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
  //
  //  UserInfo.swift
  //  Twear
  //
  //  Created by yangbin on 2021/12/8.
  //
  
  import UIKit
  import HandyJSON
  import SwiftDate
  
  class AdminModel: NSObject, HandyJSON {
      var userInfo: UserInfoModel = UserInfoModel()
      var device: DeviceModel = DeviceModel()
      required override init() { }
  }
  
  
  enum Platform: String, HandyJSONEnum {
      case _816 = "816"
      case _818 = "818"
      case _818_hq7 = "818_hq7"
      case other = "other"
  }
  
  class RemindModel: NSObject, HandyJSON {
      var isOn: Bool = false
      var startDate: Date = Date()
      var endDate: Date = Date()
      var interval: Int = 0
      var cycle: Int = 127
      
      init(isOn: Bool, startDate: Date, endDate: Date) {
          super.init()
          self.isOn = isOn
          self.startDate = startDate
          self.endDate = endDate
      }
      
      init(type: String) {
          super.init()
          self.isOn = false
          switch type {
          case "disturb":
              self.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 22, minute: 0).date
              self.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 22, minute: 0).date
          case "sedentary", "drink":
              self.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 9, minute: 0).date
              self.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: 23, minute: 00).date
              self.interval = 45
          default:
              break
          }
      }
      override func isEqual(_ object: Any?) -> Bool {
          if let otherFoo = object as? RemindModel {
              return self.isOn == otherFoo.isOn && self.startDate == otherFoo.startDate && self.endDate == otherFoo.endDate && self.interval == otherFoo.interval && self.cycle == otherFoo.cycle
          }
          return false
      }
      
      
      class func toRemindModel(_ bytes: [UInt8]) -> RemindModel {
          let remind = RemindModel()
          remind.isOn = bytes[0] == 1
          if bytes.count == 5 {
              remind.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[1]), minute: Int(bytes[2])).date
              remind.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[3]), minute: Int(bytes[4])).date
          } else if bytes.count == 6 {
              remind.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[1]), minute: 0).date
              remind.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[2]), minute: 0).date
              remind.cycle = Int(bytes[3])
              remind.interval = bytesToInt(Array(bytes[4..<bytes.count]))
          } else if bytes.count == 8 {
              remind.startDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[1]), minute: Int(bytes[2])).date
              remind.endDate = DateInRegion(year: 2000, month: 1, day: 1, hour: Int(bytes[3]), minute: Int(bytes[4])).date
              remind.cycle = Int(bytes[5])
              remind.interval = bytesToInt(Array(bytes[6..<bytes.count]))
          }
          return remind
      }
      
      func mapping(mapper: HelpingMapper) {
          mapper <<<
              startDate <-- CustomDateFormatTransform(formatString: "HH:mm")
          mapper <<<
              endDate <-- CustomDateFormatTransform(formatString: "HH:mm")
      }
      
      required override init() { }
  
  }
  
  class AlarmClockModel: NSObject, HandyJSON {
      var date: Date = Date()
      var isOn: Bool = false
      var cycle: Int = 0
      var remark: String = ""
      var cycleStr: String? {
          get {
              let array = UInt8(cycle).toAlarmClockCycle()
              if array[0] == 1 {
                  return LocString("不重复")
              } else {
                  var str = ""
  //                array.remove(at: 0)
                  for i in 1..<8 {
                      if array[i] == 1 {
                          switch i {
                          case 1:
                              str += " \(LocString("周一"))"
                          case 2:
                              str += " \(LocString("周二"))"
                          case 3:
                              str += " \(LocString("周三"))"
                          case 4:
                              str += " \(LocString("周四"))"
                          case 5:
                              str += " \(LocString("周五"))"
                          case 6:
                              str += " \(LocString("周六"))"
                          case 7:
                              str += " \(LocString("周日"))"
                          default:
                              break
                          }
                      }
                  }
                  if str != "" {
                      str = str.substring(fromIndex: 1)
                  }
                  return str
              }
          }
      }
      
      class func toAlarmClock(_ bytes: [UInt8]) -> AlarmClockModel {
          let alarmClock = AlarmClockModel()
          alarmClock.date = DateInRegion(year: 2000, month: 1, day: 1, hour:  Int(bytes[0]), minute: Int(bytes[1])).date
          alarmClock.cycle = Int(bytes[2])
          alarmClock.isOn = Int(bytes[4]) == 1
          return alarmClock
      }
      
      init(date: Date, isOn: Bool, cycle: Int) {
          self.date = date
          self.isOn = isOn
          self.cycle = cycle
      }
      
      func mapping(mapper: HelpingMapper) {
          mapper <<<
              date <-- CustomDateFormatTransform(formatString: "HH:mm")
      }
      
      
      func toBytes() -> [UInt8] {
          let bytes: [UInt8] = [UInt8(self.date.hour), UInt8(self.date.minute), UInt8(self.cycle), 0x01, isOn ? 0x01 : 0x00]
          print("闹钟:\(bytes)")
          return [UInt8(self.date.hour), UInt8(self.date.minute), UInt8(self.cycle), 0x01, isOn ? 0x01 : 0x00]
      }
      
      
      
      required override init() { }
  }
  
  
  class MessagePushModel: NSObject, HandyJSON {
      var value: Int {
          get {
              return bitsToInt([other ? 1 : 0, facebook ? 1 : 0, ins ? 1 : 0, linkedin ? 1 : 0, twitter ? 1 : 0, messenger ? 1 : 0, whatsapp ? 1 : 0, wechat ? 1 : 0, qq ? 1 : 0, sms ? 1 : 0, call ? 1 : 0])
          }
      }
  
      var call: Bool = false
      var sms: Bool = false
      var qq: Bool = false
      var wechat: Bool = false
      var whatsapp: Bool = false
      var messenger: Bool = false
      var twitter: Bool = false
      var linkedin: Bool = false
      var ins: Bool = false
      var facebook: Bool = false
      var other: Bool = false
      
      var app: Bool {
          get {
              return qq || wechat || whatsapp || messenger || twitter || linkedin || ins || facebook || other
          }
      }
      
      
      private func bitsToInt(_ bits: [Int]) -> Int {
          let decimalValue = bits.reduce(0) { v, byte in
              return v << 1 | Int(byte)
          }
          print(decimalValue)
          return Int(decimalValue)
      }
      
      required override init() { }
  }
  
  class MenstrualModel: NSObject, HandyJSON {
      var days: Int = 0
      var cycle: Int = 0
      var lastDate: Date?
  //    var calendar: MenstrualCalendarModel = MenstrualCalendarModel()
      
      init(days: Int, cycle: Int, lastDate: Date) {
          super.init()
          self.days = days
          self.cycle = cycle
          self.lastDate = lastDate
      }
      
      func mapping(mapper: HelpingMapper) {
          mapper <<<
              lastDate <-- CustomDateFormatTransform(formatString: "yyyy-MM-dd")
      }
      
      required override init() { }
  }
  
  class DeviceModel: NSObject, HandyJSON {
      var uuid: String = ""
      var name: String = ""
  //    var typeRaw: String = "other"
      var isSync: Bool = false
      var isConnected: Bool = false
      var mac: String = ""
      var push: MessagePushModel = MessagePushModel()
      var distanceUnit: Int = 0
      var temperatureUnit: Int = 0
      var timeFormat: Int = 0
      var wrist: Bool = false
      var disturb: RemindModel = RemindModel(type: "disturb")
      var drink: RemindModel = RemindModel(type: "drink")
      var sedentary: RemindModel = RemindModel(type: "sedentary")
      var alarmClocks: [AlarmClockModel] = []
      var type: String = ""
      var languageRaw: String = "system"
      var version: String = ""
      var allFunctions: [String] = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train",  "WomenHealth", "MotionRecord"]
      var homePage: [String] = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train",  "WomenHealth", "MotionRecord"]
      var queryArray: [String] {
          get {
              var array = allFunctions
              if let i = array.firstIndex(of: "MotionRecord") {
                  array.remove(at: i)
              }
              if let i = array.firstIndex(of: "WomenHealth") {
                  array.remove(at: i)
              }
              if platform == ._818 ||  platform == ._818_hq7 {
                  if let i = array.firstIndex(of: "BloodPressure") {
                      array.remove(at: i)
                  }
              }
              array.append(contentsOf: ["Step", "Setting"])
              return array
          }
      }
  
      var platform: Platform = .other
  
      init(uuid: String, name: String, platform: Platform, mac: String) {
          super.init()
          self.uuid = uuid
          self.name = name
          self.platform = platform
          self.mac = mac
          switch platform {
          case ._816:
              self.allFunctions = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train",  "MotionRecord"]
              self.homePage = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train",  "MotionRecord"]
  //            self.queryArray = ["BloodPressure", "BloodOxygen", "HeartRate", "Sleep", "Train", "Step", "Setting"]
          case ._818, ._818_hq7:
              self.allFunctions = ["BloodPressure", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"]
              self.homePage = ["BloodPressure", "HeartRate", "Sleep", "Train", "MotionRecord", "WomenHealth"]
  //            self.queryArray = ["BloodPressure", "Step", "HeartRate", "Sleep", "Train", "Setting"]
          case .other:
              break
          }
      }
      
      required override init() { }
  }
  
  class ContactModel: NSObject, HandyJSON {
      var name: String = ""
      var number: Int = 0
      var isSOS: Bool = false
      
      init(name: String, number: Int) {
          super.init()
          self.name = name
          self.number = number
      }
      
      required override init() { }
      
  }
  
  class UserInfoModel: NSObject, HandyJSON {
      var name: String = ""
      var gender: Int = 1 // 1 0
      var height: Int = 170 //cm
      var weight: Int = 65 //kg
      var age: Int = 24
      var phone: String = ""
      var userId: Int = Int(arc4random_uniform(89999999) + 10000000)
      var stepsGoal: Int = 8000
      var birth: Date = (DateInRegion().date - 24.years).dateAtStartOf(.year)
      var menstrual: MenstrualModel = MenstrualModel()
      var contacts: [ContactModel] = []
  //    var avatarUrl: String = "" //头像
      
      func mapping(mapper: HelpingMapper) {
          mapper <<<
              birth <-- CustomDateFormatTransform(formatString: "yyyy-MM-dd")
      }
      
      
      required override init() { }
  }