"Fossies" - the Fresh Open Source Software Archive

Member "jitsi-meet-5079/ios/app/watchos/extension/InterfaceController.swift" (17 Jun 2021, 3884 Bytes) of package /linux/misc/jitsi-meet-5079.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Swift source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    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 
   18 import WatchKit
   19 import WatchConnectivity
   20 import Foundation
   21 
   22 
   23 class InterfaceController: WKInterfaceController {
   24 
   25     @IBOutlet var infoLabel: WKInterfaceLabel!
   26     @IBOutlet var table: WKInterfaceTable!
   27 
   28     override func didAppear(){
   29         self.updateUI(ExtensionDelegate.currentJitsiMeetContext)
   30     }
   31 
   32     func updateUI(_ newContext:JitsiMeetContext) {
   33       if (newContext.recentURLs == nil || newContext.recentURLs!.count == 0) {
   34         infoLabel.setText("There are no recent meetings. Please use the app on the phone to start a new call.")
   35 
   36         table.setHidden(true)
   37         infoLabel.setHidden(false)
   38       } else {
   39         updateRecents(withRecents: newContext.recentURLs!, currentContext: newContext)
   40 
   41         table.setHidden(false)
   42         infoLabel.setHidden(true)
   43       }
   44     }
   45 
   46     private func updateRecents(withRecents recents: NSArray, currentContext: JitsiMeetContext) {
   47         // Updating the # of rows only if it actually changed prevents from blinking the UI
   48         if (table.numberOfRows != recents.count) {
   49             table.setNumberOfRows(recents.count, withRowType: "MeetingRowType")
   50         }
   51 
   52         for (index, entry) in recents.enumerated() {
   53             let entryDict = entry as! NSDictionary
   54             let roomURL = entryDict["conference"] as! NSString
   55             let timestamp = entryDict["date"] as! NSNumber
   56 
   57             // Prepare values
   58             let room = roomURL.components(separatedBy: "/").last
   59             let date = Date(timeIntervalSince1970: timestamp.doubleValue / 1000)  // timestamp is taken with Date.now() in JS, which uses milliseconds
   60             let dateFormatter = DateFormatter()
   61             dateFormatter.timeZone = TimeZone.current
   62             dateFormatter.locale = NSLocale.current
   63             dateFormatter.dateFormat = "HH:mm yyyy-MM-dd"
   64             let strDate = dateFormatter.string(from: date)
   65 
   66             // Update row controller
   67             let controller = table.rowController(at: index) as! MeetingRowController
   68             controller.room = room
   69             controller.roomUrl = roomURL as String
   70             controller.roomLabel.setText(room)
   71             controller.timeLabel.setText(strDate)
   72 
   73             // Change the background for the active meeting
   74             if (controller.roomUrl == currentContext.conferenceURL) {
   75                 controller.rowGroup.setBackgroundColor(UIColor(red: 0.125, green: 0.58, blue: 0.98, alpha: 1))
   76             } else {
   77                 controller.rowGroup.setBackgroundColor(UIColor(red: 0.949, green: 0.956, blue: 1, alpha: 0.14))
   78             }
   79         }
   80     }
   81 
   82     override func contextForSegue(withIdentifier segueIdentifier: String, in table: WKInterfaceTable, rowIndex: Int) -> Any? {
   83         let controller = table.rowController(at: rowIndex) as! MeetingRowController
   84         let currentContext = ExtensionDelegate.currentJitsiMeetContext
   85 
   86         // Copy the current context and add the joinConferenceURL to trigger the command when the in-call screen is displayed
   87         let actionContext = JitsiMeetContext(jmContext: currentContext)
   88         actionContext.joinConferenceURL = controller.roomUrl
   89 
   90         print("WATCH contextForSegue: \(actionContext.description)");
   91 
   92         return actionContext;
   93     }
   94 }