您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

InterfaceController.swift 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright @ 2018-present 8x8, Inc.
  3. * Copyright @ 2017-2018 Atlassian Pty Ltd
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. import WatchKit
  18. import WatchConnectivity
  19. import Foundation
  20. class InterfaceController: WKInterfaceController {
  21. @IBOutlet var infoLabel: WKInterfaceLabel!
  22. @IBOutlet var table: WKInterfaceTable!
  23. override func didAppear(){
  24. self.updateUI(ExtensionDelegate.currentJitsiMeetContext)
  25. }
  26. func updateUI(_ newContext:JitsiMeetContext) {
  27. if (newContext.recentURLs == nil || newContext.recentURLs!.count == 0) {
  28. infoLabel.setText("There are no recent meetings. Please use the app on the phone to start a new call.")
  29. table.setHidden(true)
  30. infoLabel.setHidden(false)
  31. } else {
  32. updateRecents(withRecents: newContext.recentURLs!, currentContext: newContext)
  33. table.setHidden(false)
  34. infoLabel.setHidden(true)
  35. }
  36. }
  37. private func updateRecents(withRecents recents: NSArray, currentContext: JitsiMeetContext) {
  38. // Updating the # of rows only if it actually changed prevents from blinking the UI
  39. if (table.numberOfRows != recents.count) {
  40. table.setNumberOfRows(recents.count, withRowType: "MeetingRowType")
  41. }
  42. for (index, entry) in recents.enumerated() {
  43. let entryDict = entry as! NSDictionary
  44. let roomURL = entryDict["conference"] as! NSString
  45. let timestamp = entryDict["date"] as! NSNumber
  46. // Prepare values
  47. let room = roomURL.components(separatedBy: "/").last
  48. let date = Date(timeIntervalSince1970: timestamp.doubleValue / 1000) // timestamp is taken with Date.now() in JS, which uses milliseconds
  49. let dateFormatter = DateFormatter()
  50. dateFormatter.timeZone = TimeZone.current
  51. dateFormatter.locale = NSLocale.current
  52. dateFormatter.dateFormat = "HH:mm yyyy-MM-dd"
  53. let strDate = dateFormatter.string(from: date)
  54. // Update row controller
  55. let controller = table.rowController(at: index) as! MeetingRowController
  56. controller.room = room
  57. controller.roomUrl = roomURL as String
  58. controller.roomLabel.setText(room)
  59. controller.timeLabel.setText(strDate)
  60. // Change the background for the active meeting
  61. if (controller.roomUrl == currentContext.conferenceURL) {
  62. controller.rowGroup.setBackgroundColor(UIColor(red: 0.125, green: 0.58, blue: 0.98, alpha: 1))
  63. } else {
  64. controller.rowGroup.setBackgroundColor(UIColor(red: 0.949, green: 0.956, blue: 1, alpha: 0.14))
  65. }
  66. }
  67. }
  68. override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
  69. let controller = table.rowController(at: rowIndex) as! MeetingRowController
  70. let currentContext = ExtensionDelegate.currentJitsiMeetContext
  71. // Copy the current context and add the joinConferenceURL to trigger the command when the in-call screen is displayed
  72. let actionContext = JitsiMeetContext(jmContext: currentContext)
  73. actionContext.joinConferenceURL = controller.roomUrl
  74. print("WATCH contextForSegue: \(actionContext.description)");
  75. return actionContext;
  76. }
  77. }