ButtonsContainerView.swift 5 KB
Newer Older
1
/*
Quentin Muret's avatar
Quentin Muret committed
2
 *  Copyright (C) 2017-2018 Savoir-faire Linux Inc.
3 4
 *
 *  Author: Kateryna Kostiuk <kateryna.kostiuk@savoirfairelinux.com>
5
 *  Author: Quentin Muret <quentin.muret@savoirfairelinux.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.
 */
import UIKit
import Reusable
import RxSwift

class ButtonsContainerView: UIView, NibLoadable {

27
    //Outlets
28 29
    @IBOutlet var containerView: UIView!
    @IBOutlet  weak var container: UIView!
30 31
    @IBOutlet weak var stackView: UIStackView!
    @IBOutlet weak var backgroundBlurEffect: UIVisualEffectView!
32 33 34 35 36 37
    @IBOutlet  weak var muteAudioButton: UIButton!
    @IBOutlet  weak var muteVideoButton: UIButton!
    @IBOutlet  weak var pauseCallButton: UIButton!
    @IBOutlet  weak var switchCameraButton: UIButton!
    @IBOutlet  weak var switchSpeakerButton: UIButton!
    @IBOutlet  weak var cancelButton: UIButton!
38 39 40 41

    //Constraints
    @IBOutlet weak var cancelButtonWidthConstraint: NSLayoutConstraint!
    @IBOutlet weak var cancelButtonBottomConstraint: NSLayoutConstraint!
42
    @IBOutlet weak var cancelButtonHeightConstraint: NSLayoutConstraint!
43
    @IBOutlet weak var stackViewYConstraint: NSLayoutConstraint!
44
    @IBOutlet weak var stackViewWidthConstraint: NSLayoutConstraint!
45 46
    @IBOutlet weak var containerHeightConstraint: NSLayoutConstraint!
    
47
    let disposeBag = DisposeBag()
48
    var isCallStarted: Bool = false
49 50 51 52

    var viewModel: ButtonsContainerViewModel? {
        didSet {
            self.viewModel?.observableCallOptions
53
                .observeOn(MainScheduler.instance)
54
                .subscribe(onNext: { [weak self] callOptions in
55 56
                    switch callOptions {
                    case .none:
57
                        self?.withoutOptions()
58
                    case .optionsWithoutSpeakerphone:
59
                        self?.optionsWithoutSpeaker()
60
                    case .optionsWithSpeakerphone:
61
                        self?.optionsWithSpeaker()
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
                    }
                }).disposed(by: self.disposeBag)
        }
    }
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.commonInit()
    }

    required init(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)!
        self.commonInit()
    }

    override open func didMoveToWindow() {
        super.didMoveToWindow()
        self.cancelButton.backgroundColor = UIColor.red
    }

    func commonInit() {
        Bundle.main.loadNibNamed("ButtonsContainerView", owner: self, options: nil)
        addSubview(containerView)
        containerView.frame = self.bounds
    }

    func withoutOptions() {
88 89 90 91 92 93 94 95
            self.container.backgroundColor = UIColor.clear
            self.backgroundBlurEffect.isHidden = true
            muteAudioButton.isHidden = true
            muteVideoButton.isHidden = true
            pauseCallButton.isHidden = true
            switchCameraButton.isHidden = true
            switchSpeakerButton.isHidden = true
            cancelButton.isHidden = false
96 97 98
    }

    func optionsWithSpeaker() {
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
        if !self.isCallStarted {
            self.isCallStarted = true
            self.backgroundBlurEffect.isHidden = false
            muteAudioButton.isHidden = false
            if self.viewModel?.isAudioOnly ?? false {
                muteVideoButton.isHidden = true
                switchCameraButton.isHidden = true
            } else {
                muteVideoButton.isHidden = false
                switchCameraButton.isHidden = false
            }
            pauseCallButton.isHidden = false
            switchSpeakerButton.isHidden = false
            switchSpeakerButton.alpha = 1.00
            switchSpeakerButton.isEnabled = true
            cancelButton.isHidden = false
115
        }
116 117 118
    }

    func optionsWithoutSpeaker() {
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
        if !self.isCallStarted {
            self.isCallStarted = true
            if self.viewModel?.isAudioOnly ?? false {
                muteVideoButton.isHidden = true
                switchCameraButton.isHidden = true
                switchSpeakerButton.isHidden = true
            } else {
                muteVideoButton.isHidden = false
                switchCameraButton.isHidden = false
                switchSpeakerButton.isHidden = false
            }
            self.muteAudioButton.isHidden = false
            self.backgroundBlurEffect.isHidden = false
            pauseCallButton.isHidden = false
            cancelButton.isHidden = false
134
        }
135 136
    }
}