NCUserStatus.swift 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. //
  2. // NCUserStatus.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/05/21.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. //
  9. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  10. //
  11. // This program is free software: you can redistribute it and/or modify
  12. // it under the terms of the GNU General Public License as published by
  13. // the Free Software Foundation, either version 3 of the License, or
  14. // (at your option) any later version.
  15. //
  16. // This program is distributed in the hope that it will be useful,
  17. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. // GNU General Public License for more details.
  20. //
  21. // You should have received a copy of the GNU General Public License
  22. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. //
  24. import UIKit
  25. import Foundation
  26. import NextcloudKit
  27. import DropDown
  28. class NCUserStatus: UIViewController {
  29. @IBOutlet weak var buttonCancel: UIBarButtonItem!
  30. @IBOutlet weak var onlineButton: UIButton!
  31. @IBOutlet weak var onlineImage: UIImageView!
  32. @IBOutlet weak var onlineLabel: UILabel!
  33. @IBOutlet weak var awayButton: UIButton!
  34. @IBOutlet weak var awayImage: UIImageView!
  35. @IBOutlet weak var awayLabel: UILabel!
  36. @IBOutlet weak var dndButton: UIButton!
  37. @IBOutlet weak var dndImage: UIImageView!
  38. @IBOutlet weak var dndLabel: UILabel!
  39. @IBOutlet weak var dndDescrLabel: UILabel!
  40. @IBOutlet weak var invisibleButton: UIButton!
  41. @IBOutlet weak var invisibleImage: UIImageView!
  42. @IBOutlet weak var invisibleLabel: UILabel!
  43. @IBOutlet weak var invisibleDescrLabel: UILabel!
  44. @IBOutlet weak var statusMessageLabel: UILabel!
  45. @IBOutlet weak var statusMessageEmojiTextField: emojiTextField!
  46. @IBOutlet weak var statusMessageTextField: UITextField!
  47. @IBOutlet weak var tableView: UITableView!
  48. @IBOutlet weak var clearStatusMessageAfterLabel: UILabel!
  49. @IBOutlet weak var clearStatusMessageAfterText: UILabel!
  50. @IBOutlet weak var clearStatusMessageButton: UIButton!
  51. @IBOutlet weak var setStatusMessageButton: UIButton!
  52. private var statusPredefinedStatuses: [NKUserStatus] = []
  53. private var clearAtTimestamp: Double = 0 // Unix Timestamp representing the time to clear the status
  54. private let borderWidthButton: CGFloat = 1.5
  55. private let borderColorButton: CGColor = NCBrandColor.shared.brand.cgColor
  56. // MARK: - View Life Cycle
  57. override func viewDidLoad() {
  58. super.viewDidLoad()
  59. self.navigationItem.title = NSLocalizedString("_online_status_", comment: "")
  60. view.backgroundColor = .systemBackground
  61. tableView.backgroundColor = .systemBackground
  62. buttonCancel.title = NSLocalizedString("_close_", comment: "")
  63. onlineButton.layer.cornerRadius = 10
  64. onlineButton.layer.masksToBounds = true
  65. onlineButton.backgroundColor = .systemGray5
  66. let onLine = NCUtility.shared.getUserStatus(userIcon: nil, userStatus: "online", userMessage: nil)
  67. onlineImage.image = onLine.onlineStatus
  68. onlineLabel.text = onLine.statusMessage
  69. onlineLabel.textColor = .label
  70. awayButton.layer.cornerRadius = 10
  71. awayButton.layer.masksToBounds = true
  72. awayButton.backgroundColor = .systemGray5
  73. let away = NCUtility.shared.getUserStatus(userIcon: nil, userStatus: "away", userMessage: nil)
  74. awayImage.image = away.onlineStatus
  75. awayLabel.text = away.statusMessage
  76. awayLabel.textColor = .label
  77. dndButton.layer.cornerRadius = 10
  78. dndButton.layer.masksToBounds = true
  79. dndButton.backgroundColor = .systemGray5
  80. let dnd = NCUtility.shared.getUserStatus(userIcon: nil, userStatus: "dnd", userMessage: nil)
  81. dndImage.image = dnd.onlineStatus
  82. dndLabel.text = dnd.statusMessage
  83. dndLabel.textColor = .label
  84. dndDescrLabel.text = dnd.descriptionMessage
  85. dndDescrLabel.textColor = .darkGray
  86. invisibleButton.layer.cornerRadius = 10
  87. invisibleButton.layer.masksToBounds = true
  88. invisibleButton.backgroundColor = .systemGray5
  89. let invisible = NCUtility.shared.getUserStatus(userIcon: nil, userStatus: "invisible", userMessage: nil)
  90. invisibleImage.image = invisible.onlineStatus
  91. invisibleLabel.text = invisible.statusMessage
  92. invisibleLabel.textColor = .label
  93. invisibleDescrLabel.text = invisible.descriptionMessage
  94. invisibleDescrLabel.textColor = .darkGray
  95. statusMessageLabel.text = NSLocalizedString("_status_message_", comment: "")
  96. statusMessageLabel.textColor = .label
  97. statusMessageEmojiTextField.delegate = self
  98. statusMessageEmojiTextField.backgroundColor = .systemGray5
  99. statusMessageTextField.delegate = self
  100. statusMessageTextField.placeholder = NSLocalizedString("_status_message_placehorder_", comment: "")
  101. statusMessageTextField.textColor = .label
  102. tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1))
  103. tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
  104. clearStatusMessageAfterLabel.text = NSLocalizedString("_clear_status_message_after_", comment: "")
  105. clearStatusMessageAfterLabel.textColor = .label
  106. clearStatusMessageAfterText.layer.cornerRadius = 5
  107. clearStatusMessageAfterText.layer.masksToBounds = true
  108. clearStatusMessageAfterText.layer.borderWidth = 0.2
  109. clearStatusMessageAfterText.layer.borderColor = UIColor.lightGray.cgColor
  110. clearStatusMessageAfterText.text = NSLocalizedString("_dont_clear_", comment: "")
  111. if traitCollection.userInterfaceStyle == .dark {
  112. clearStatusMessageAfterText.backgroundColor = .black
  113. clearStatusMessageAfterText.textColor = .white
  114. } else {
  115. clearStatusMessageAfterText.backgroundColor = .white
  116. clearStatusMessageAfterText.textColor = .black
  117. }
  118. let tap = UITapGestureRecognizer(target: self, action: #selector(self.actionClearStatusMessageAfterText(sender:)))
  119. clearStatusMessageAfterText.isUserInteractionEnabled = true
  120. clearStatusMessageAfterText.addGestureRecognizer(tap)
  121. clearStatusMessageAfterText.text = " " + NSLocalizedString("_dont_clear_", comment: "")
  122. clearStatusMessageButton.layer.cornerRadius = 20
  123. clearStatusMessageButton.layer.masksToBounds = true
  124. clearStatusMessageButton.layer.borderWidth = 0.5
  125. clearStatusMessageButton.layer.borderColor = UIColor.darkGray.cgColor
  126. clearStatusMessageButton.backgroundColor = .systemGray5
  127. clearStatusMessageButton.setTitle(NSLocalizedString("_clear_status_message_", comment: ""), for: .normal)
  128. clearStatusMessageButton.setTitleColor(.label, for: .normal)
  129. setStatusMessageButton.layer.cornerRadius = 20
  130. setStatusMessageButton.layer.masksToBounds = true
  131. setStatusMessageButton.backgroundColor = NCBrandColor.shared.brand
  132. setStatusMessageButton.setTitle(NSLocalizedString("_set_status_message_", comment: ""), for: .normal)
  133. setStatusMessageButton.setTitleColor(NCBrandColor.shared.brandText, for: .normal)
  134. getStatus()
  135. }
  136. override func viewWillDisappear(_ animated: Bool) {
  137. super.viewWillDisappear(animated)
  138. NextcloudKit.shared.getUserStatus { account, clearAt, icon, message, messageId, messageIsPredefined, status, statusIsUserDefined, _, data, error in
  139. if error == .success {
  140. NCManageDatabase.shared.setAccountUserStatus(userStatusClearAt: clearAt, userStatusIcon: icon, userStatusMessage: message, userStatusMessageId: messageId, userStatusMessageIsPredefined: messageIsPredefined, userStatusStatus: status, userStatusStatusIsUserDefined: statusIsUserDefined, account: account)
  141. }
  142. }
  143. }
  144. func dismissIfError(_ error: NKError) {
  145. if error != .success && error.errorCode != NCGlobal.shared.errorResourceNotFound {
  146. DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
  147. self.dismiss(animated: true) {
  148. NCContentPresenter.shared.showError(error: error)
  149. }
  150. }
  151. }
  152. }
  153. // MARK: ACTION
  154. @IBAction func actionCancel(_ sender: UIBarButtonItem) {
  155. self.dismiss(animated: true, completion: nil)
  156. }
  157. @IBAction func actionOnline(_ sender: UIButton) {
  158. self.onlineButton.layer.borderWidth = self.borderWidthButton
  159. self.onlineButton.layer.borderColor = self.borderColorButton
  160. self.awayButton.layer.borderWidth = 0
  161. self.awayButton.layer.borderColor = nil
  162. self.dndButton.layer.borderWidth = 0
  163. self.dndButton.layer.borderColor = nil
  164. self.invisibleButton.layer.borderWidth = 0
  165. self.invisibleButton.layer.borderColor = nil
  166. NextcloudKit.shared.setUserStatus(status: "online") { _, error in
  167. self.dismissIfError(error)
  168. }
  169. }
  170. @IBAction func actionAway(_ sender: UIButton) {
  171. self.onlineButton.layer.borderWidth = 0
  172. self.onlineButton.layer.borderColor = nil
  173. self.awayButton.layer.borderWidth = self.borderWidthButton
  174. self.awayButton.layer.borderColor = self.borderColorButton
  175. self.dndButton.layer.borderWidth = 0
  176. self.dndButton.layer.borderColor = nil
  177. self.invisibleButton.layer.borderWidth = 0
  178. self.invisibleButton.layer.borderColor = nil
  179. NextcloudKit.shared.setUserStatus(status: "away") { _, error in
  180. self.dismissIfError(error)
  181. }
  182. }
  183. @IBAction func actionDnd(_ sender: UIButton) {
  184. self.onlineButton.layer.borderWidth = 0
  185. self.onlineButton.layer.borderColor = nil
  186. self.awayButton.layer.borderWidth = 0
  187. self.awayButton.layer.borderColor = nil
  188. self.dndButton.layer.borderWidth = self.borderWidthButton
  189. self.dndButton.layer.borderColor = self.borderColorButton
  190. self.invisibleButton.layer.borderWidth = 0
  191. self.invisibleButton.layer.borderColor = nil
  192. NextcloudKit.shared.setUserStatus(status: "dnd") { _, error in
  193. self.dismissIfError(error)
  194. }
  195. }
  196. @IBAction func actionInvisible(_ sender: UIButton) {
  197. self.onlineButton.layer.borderWidth = 0
  198. self.onlineButton.layer.borderColor = nil
  199. self.awayButton.layer.borderWidth = 0
  200. self.awayButton.layer.borderColor = nil
  201. self.dndButton.layer.borderWidth = 0
  202. self.dndButton.layer.borderColor = nil
  203. self.invisibleButton.layer.borderWidth = self.borderWidthButton
  204. self.invisibleButton.layer.borderColor = self.borderColorButton
  205. NextcloudKit.shared.setUserStatus(status: "invisible") { _, error in
  206. self.dismissIfError(error)
  207. }
  208. }
  209. @objc func actionClearStatusMessageAfterText(sender: UITapGestureRecognizer) {
  210. let dropDown = DropDown()
  211. let appearance = DropDown.appearance()
  212. let clearStatusMessageAfterTextBackup = clearStatusMessageAfterText.text
  213. if traitCollection.userInterfaceStyle == .dark {
  214. appearance.backgroundColor = .black
  215. appearance.textColor = .white
  216. } else {
  217. appearance.backgroundColor = .white
  218. appearance.textColor = .black
  219. }
  220. appearance.cornerRadius = 5
  221. appearance.shadowRadius = 0
  222. appearance.animationEntranceOptions = .transitionCurlUp
  223. appearance.animationduration = 0.25
  224. appearance.setupMaskedCorners([.layerMaxXMaxYCorner, .layerMinXMaxYCorner])
  225. dropDown.dataSource.append(NSLocalizedString("_dont_clear_", comment: ""))
  226. dropDown.dataSource.append(NSLocalizedString("_30_minutes_", comment: ""))
  227. dropDown.dataSource.append(NSLocalizedString("_1_hour_", comment: ""))
  228. dropDown.dataSource.append(NSLocalizedString("_4_hours_", comment: ""))
  229. dropDown.dataSource.append(NSLocalizedString("day", comment: ""))
  230. dropDown.dataSource.append(NSLocalizedString("_this_week_", comment: ""))
  231. dropDown.anchorView = clearStatusMessageAfterText
  232. dropDown.topOffset = CGPoint(x: 0, y: -clearStatusMessageAfterText.bounds.height)
  233. dropDown.width = clearStatusMessageAfterText.bounds.width
  234. dropDown.direction = .top
  235. dropDown.selectionAction = { _, item in
  236. self.clearAtTimestamp = self.getClearAt(item)
  237. self.clearStatusMessageAfterText.text = " " + item
  238. }
  239. dropDown.cancelAction = { [unowned self] in
  240. clearStatusMessageAfterText.text = clearStatusMessageAfterTextBackup
  241. }
  242. clearStatusMessageAfterText.text = " " + NSLocalizedString("_select_option_", comment: "")
  243. dropDown.show()
  244. }
  245. @IBAction func actionClearStatusMessage(_ sender: UIButton) {
  246. NextcloudKit.shared.clearMessage { _, error in
  247. if error != .success {
  248. NCContentPresenter.shared.showError(error: error)
  249. }
  250. self.dismiss(animated: true)
  251. }
  252. }
  253. @IBAction func actionSetStatusMessage(_ sender: UIButton) {
  254. guard let message = statusMessageTextField.text else { return }
  255. NextcloudKit.shared.setCustomMessageUserDefined(statusIcon: statusMessageEmojiTextField.text, message: message, clearAt: clearAtTimestamp) { _, error in
  256. if error != .success {
  257. NCContentPresenter.shared.showError(error: error)
  258. }
  259. self.dismiss(animated: true)
  260. }
  261. }
  262. // MARK: - Networking
  263. func getStatus() {
  264. NextcloudKit.shared.getUserStatus { _, clearAt, icon, message, _, _, status, _, _, data, error in
  265. if error == .success || error.errorCode == NCGlobal.shared.errorResourceNotFound {
  266. if icon != nil {
  267. self.statusMessageEmojiTextField.text = icon
  268. }
  269. if message != nil {
  270. self.statusMessageTextField.text = message
  271. }
  272. if clearAt != nil {
  273. self.clearStatusMessageAfterText.text = " " + self.getPredefinedClearStatusText(clearAt: clearAt, clearAtTime: nil, clearAtType: nil)
  274. }
  275. switch status {
  276. case "online":
  277. self.onlineButton.layer.borderWidth = self.borderWidthButton
  278. self.onlineButton.layer.borderColor = self.borderColorButton
  279. case "away":
  280. self.awayButton.layer.borderWidth = self.borderWidthButton
  281. self.awayButton.layer.borderColor = self.borderColorButton
  282. case "dnd":
  283. self.dndButton.layer.borderWidth = self.borderWidthButton
  284. self.dndButton.layer.borderColor = self.borderColorButton
  285. case "invisible", "offline":
  286. self.invisibleButton.layer.borderWidth = self.borderWidthButton
  287. self.invisibleButton.layer.borderColor = self.borderColorButton
  288. default:
  289. print("No status")
  290. }
  291. NextcloudKit.shared.getUserStatusPredefinedStatuses { _, userStatuses, data, error in
  292. if error == .success {
  293. if let userStatuses = userStatuses {
  294. self.statusPredefinedStatuses = userStatuses
  295. }
  296. self.tableView.reloadData()
  297. }
  298. self.dismissIfError(error)
  299. }
  300. }
  301. self.dismissIfError(error)
  302. }
  303. }
  304. // MARK: - Algorithms
  305. func getClearAt(_ clearAtString: String) -> Double {
  306. let now = Date()
  307. let calendar = Calendar.current
  308. let gregorian = Calendar(identifier: .gregorian)
  309. let midnight = calendar.startOfDay(for: now)
  310. guard let tomorrow = calendar.date(byAdding: .day, value: 1, to: midnight) else { return 0 }
  311. guard let startweek = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: now)) else { return 0 }
  312. guard let endweek = gregorian.date(byAdding: .day, value: 6, to: startweek) else { return 0 }
  313. switch clearAtString {
  314. case NSLocalizedString("_dont_clear_", comment: ""):
  315. return 0
  316. case NSLocalizedString("_30_minutes_", comment: ""):
  317. let date = now.addingTimeInterval(1800)
  318. return date.timeIntervalSince1970
  319. case NSLocalizedString("_1_hour_", comment: ""), NSLocalizedString("_an_hour_", comment: ""):
  320. let date = now.addingTimeInterval(3600)
  321. return date.timeIntervalSince1970
  322. case NSLocalizedString("_4_hours_", comment: ""):
  323. let date = now.addingTimeInterval(14400)
  324. return date.timeIntervalSince1970
  325. case NSLocalizedString("day", comment: ""):
  326. return tomorrow.timeIntervalSince1970
  327. case NSLocalizedString("_this_week_", comment: ""):
  328. return endweek.timeIntervalSince1970
  329. default:
  330. return 0
  331. }
  332. }
  333. func getPredefinedClearStatusText(clearAt: NSDate?, clearAtTime: String?, clearAtType: String?) -> String {
  334. // Date
  335. if clearAt != nil {
  336. let from = Date()
  337. let to = clearAt! as Date
  338. let day = Calendar.current.dateComponents([.day], from: from, to: to).day ?? 0
  339. let hour = Calendar.current.dateComponents([.hour], from: from, to: to).hour ?? 0
  340. let minute = Calendar.current.dateComponents([.minute], from: from, to: to).minute ?? 0
  341. if day > 0 {
  342. if day == 1 { return NSLocalizedString("day", comment: "") }
  343. return "\(day) " + NSLocalizedString("_days_", comment: "")
  344. }
  345. if hour > 0 {
  346. if hour == 1 { return NSLocalizedString("_an_hour_", comment: "") }
  347. if hour == 4 { return NSLocalizedString("_4_hour_", comment: "") }
  348. return "\(hour) " + NSLocalizedString("_hours_", comment: "")
  349. }
  350. if minute > 0 {
  351. if minute >= 25 && minute <= 30 { return NSLocalizedString("_30_minutes_", comment: "") }
  352. if minute > 30 { return NSLocalizedString("_an_hour_", comment: "") }
  353. return "\(minute) " + NSLocalizedString("_minutes_", comment: "")
  354. }
  355. }
  356. // Period
  357. if clearAtTime != nil && clearAtType == "period" {
  358. switch clearAtTime {
  359. case "3600":
  360. return NSLocalizedString("_an_hour_", comment: "")
  361. case "1800":
  362. return NSLocalizedString("_30_minutes_", comment: "")
  363. default:
  364. return NSLocalizedString("_dont_clear_", comment: "")
  365. }
  366. }
  367. // End of
  368. if clearAtTime != nil && clearAtType == "end-of" {
  369. return NSLocalizedString(clearAtTime!, comment: "")
  370. }
  371. return NSLocalizedString("_dont_clear_", comment: "")
  372. }
  373. }
  374. extension NCUserStatus: UITextFieldDelegate {
  375. func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
  376. if textField is emojiTextField {
  377. if string.count == 0 {
  378. textField.text = "😀"
  379. return false
  380. }
  381. textField.text = string
  382. textField.endEditing(true)
  383. }
  384. return true
  385. }
  386. func textFieldShouldReturn(_ textField: UITextField) -> Bool {
  387. textField.resignFirstResponder()
  388. return false
  389. }
  390. }
  391. class emojiTextField: UITextField {
  392. override var textInputContextIdentifier: String? { "" } // return non-nil to show the Emoji keyboard ¯\_(ツ)_/¯
  393. override var textInputMode: UITextInputMode? {
  394. for mode in UITextInputMode.activeInputModes {
  395. if mode.primaryLanguage == "emoji" {
  396. return mode
  397. }
  398. }
  399. return nil
  400. }
  401. override init(frame: CGRect) {
  402. super.init(frame: frame)
  403. commonInit()
  404. }
  405. required init?(coder: NSCoder) {
  406. super.init(coder: coder)
  407. commonInit()
  408. }
  409. func commonInit() {
  410. NotificationCenter.default.addObserver(self, selector: #selector(inputModeDidChange), name: UITextInputMode.currentInputModeDidChangeNotification, object: nil)
  411. }
  412. @objc func inputModeDidChange(_ notification: Notification) {
  413. guard isFirstResponder else {
  414. return
  415. }
  416. DispatchQueue.main.async { [weak self] in
  417. self?.reloadInputViews()
  418. }
  419. }
  420. }
  421. extension NCUserStatus: UITableViewDelegate {
  422. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  423. return 45
  424. }
  425. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  426. guard let cell = tableView.cellForRow(at: indexPath) else { return }
  427. let status = statusPredefinedStatuses[indexPath.row]
  428. if let messageId = status.id {
  429. NextcloudKit.shared.setCustomMessagePredefined(messageId: messageId, clearAt: 0) { _, error in
  430. cell.isSelected = false
  431. if error == .success {
  432. let clearAtTimestampString = self.getPredefinedClearStatusText(clearAt: status.clearAt, clearAtTime: status.clearAtTime, clearAtType: status.clearAtType)
  433. self.statusMessageEmojiTextField.text = status.icon
  434. self.statusMessageTextField.text = status.message
  435. self.clearStatusMessageAfterText.text = " " + clearAtTimestampString
  436. self.clearAtTimestamp = self.getClearAt(clearAtTimestampString)
  437. }
  438. self.dismissIfError(error)
  439. }
  440. }
  441. }
  442. }
  443. extension NCUserStatus: UITableViewDataSource {
  444. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  445. return statusPredefinedStatuses.count
  446. }
  447. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  448. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
  449. cell.backgroundColor = tableView.backgroundColor
  450. let status = statusPredefinedStatuses[indexPath.row]
  451. let icon = cell.viewWithTag(10) as! UILabel
  452. let message = cell.viewWithTag(20) as! UILabel
  453. icon.text = status.icon
  454. var timeString = getPredefinedClearStatusText(clearAt: status.clearAt, clearAtTime: status.clearAtTime, clearAtType: status.clearAtType)
  455. if let messageText = status.message {
  456. message.text = messageText
  457. timeString = " - " + timeString
  458. let attributedString: NSMutableAttributedString = NSMutableAttributedString(string: messageText + timeString)
  459. attributedString.setColor(color: .lightGray, font: UIFont.systemFont(ofSize: 15), forText: timeString)
  460. message.attributedText = attributedString
  461. }
  462. return cell
  463. }
  464. }