Subversion Repositories Mobile Apps.GyroMouse

Rev

Rev 1 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 7
Line 12... Line 12...
12
    
12
    
13
    let client = (UIApplication.shared.delegate as! AppDelegate).client
13
    let client = (UIApplication.shared.delegate as! AppDelegate).client
14
    
14
    
15
    private lazy var loadingView: UIView = {
15
    private lazy var loadingView: UIView = {
16
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
16
        let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
17
        view.center = CGPoint(x: ScreenSize.SCREEN_WIDTH / 2, y: ScreenSize.SCREEN_HEIGHT / 2)
17
        view.center = CGPoint(x: UIScreen.main.bounds.size.width / 2, y: UIScreen.main.bounds.size.height / 2)
18
        view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8) //black
18
        view.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0.8) //black
19
        view.layer.cornerRadius = 15
19
        view.layer.cornerRadius = 15
20
        
20
        
21
        let spinner = UIActivityIndicatorView(style: .whiteLarge)
21
        let spinner = UIActivityIndicatorView(style: .whiteLarge)
22
        spinner.center = CGPoint(x: 50, y: 50)
22
        spinner.center = CGPoint(x: 50, y: 50)
Line 29... Line 29...
29
 
29
 
30
    override func viewDidLoad() {
30
    override func viewDidLoad() {
31
        super.viewDidLoad()
31
        super.viewDidLoad()
32
        
32
        
33
        let center = NotificationCenter.default
33
        let center = NotificationCenter.default
34
        center.addObserver(forName: ServerDiscoveredServicesDidChangeNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
34
        center.addObserver(forName: GyroMouseShouldRefreshServerListNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
35
                self.tableView.reloadData()
35
                self.tableView.reloadData()
36
        }
36
        }
37
        
37
        
38
        center.addObserver(forName: ClientDidCompleteLocalConnectionNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
38
        center.addObserver(forName: GyroMouseConnectionSuccessNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
39
            self.performSegue(withIdentifier: "mouse", sender: self)
39
            self.performSegue(withIdentifier: "mouse", sender: self)
40
            self.loadingView.removeFromSuperview()
40
            self.loadingView.removeFromSuperview()
41
        }
41
        }
42
        
42
        
43
        center.addObserver(forName: ClientDidFailLocalConnectionNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
43
        center.addObserver(forName: GyroMouseConnectionFailedNotification, object: client, queue: OperationQueue.main) {[unowned self] (_) -> Void in
44
            self.loadingView.removeFromSuperview()
44
            self.loadingView.removeFromSuperview()
45
            if #available(iOS 8.0, *) {
-
 
-
 
45
 
46
                let alert = UIAlertController(title: "error".localized, message: "connect_error".localized, preferredStyle: .alert)
46
            let alert = UIAlertController(title: "error".localized, message: "connect_error".localized, preferredStyle: .alert)
47
                let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
47
            let action = UIAlertAction(title: "Ok", style: .default, handler: nil)
48
                alert.addAction(action)
48
            alert.addAction(action)
49
                self.present(alert, animated: true, completion: nil)
49
            self.present(alert, animated: true, completion: nil)
50
            } else {
-
 
51
                let alert = UIAlertView(title: "Errore", message: "connect_error".localized, delegate: nil, cancelButtonTitle: "Ok")
-
 
52
                alert.show()
-
 
53
            }
-
 
54
        }
50
        }
55
        
51
        
56
        center.addObserver(forName: DidEnterBackgroundNotification, object: nil, queue: OperationQueue.main) {[unowned self] (_) -> Void in
52
        center.addObserver(forName: GyroMouseGoingBackgroundNotification, object: nil, queue: OperationQueue.main) {[unowned self] (_) -> Void in
57
            self.tableView.reloadData()
53
            self.tableView.reloadData()
58
        }
54
        }
59
        
55
        
60
    }
56
    }
61
    
57
    
62
    override func viewDidAppear(_ animated: Bool) {
58
    override func viewDidAppear(_ animated: Bool) {
63
        super.viewDidAppear(animated)
59
        super.viewDidAppear(animated)
64
    }
60
    }
65
    
61
    
66
    deinit {
62
    deinit {
67
        let center = NotificationCenter.default
-
 
68
        center.removeObserver(self)
63
         NotificationCenter.default.removeObserver(self)
69
    }
64
    }
70
 
65
 
71
    // MARK: - Table view data source
66
    // MARK: - Table view data source
72
 
67
 
73
    override func numberOfSections(in tableView: UITableView) -> Int {
68
    override func numberOfSections(in tableView: UITableView) -> Int {