Commit f40e31fd authored by Kateryna Kostiuk's avatar Kateryna Kostiuk Committed by Andreas Traczyk

UI: hide switch speakerphone button

Hide switch speakerphone button during call when headset is connected

Change-Id: I83c0a2b727a4d48abe941ba85c21f9f48ea15f64
Reviewed-by: Andreas Traczyk's avatarAndreas Traczyk <andreas.traczyk@savoirfairelinux.com>
parent b82c2bf5
......@@ -38,6 +38,7 @@ class ButtonsContainerView: UIView, NibLoadable {
var viewModel: ButtonsContainerViewModel? {
didSet {
self.viewModel?.observableCallOptions
.observeOn(MainScheduler.instance)
.subscribe(onNext: { (callOptions) in
switch callOptions {
case .none:
......
......@@ -28,6 +28,7 @@ enum CallOptions {
class ButtonsContainerViewModel {
let callService: CallsService
let audioService: AudioService
let callID: String
let disposeBag = DisposeBag()
......@@ -36,8 +37,9 @@ class ButtonsContainerViewModel {
return self.avalaibleCallOptions.asObservable()
}()
init(with callService: CallsService, callID: String) {
init(with callService: CallsService, audioService: AudioService, callID: String) {
self.callService = callService
self.audioService = audioService
self.callID = callID
checkCallOptions()
}
......@@ -50,7 +52,8 @@ class ButtonsContainerViewModel {
return true
})
}()
callIsActive.subscribe(onNext: { active in
callIsActive
.subscribe(onNext: { active in
if !active {
return
}
......@@ -64,8 +67,9 @@ class ButtonsContainerViewModel {
private func connectToSpeaker() {
let speakerIsAvailable: Observable<Bool> = {
//TODO map to service
return Observable.just(true)
return self.audioService.enableSwitchAudio.map({ (hide) in
!hide
})
}()
speakerIsAvailable.subscribe(onNext: { available in
if available {
......
......@@ -56,10 +56,6 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
private var task: DispatchWorkItem?
override var inputAccessoryView: UIView {
return self.buttonsContainer
}
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(screenTapped))
......@@ -127,13 +123,6 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
.bind(to: self.buttonsContainer.switchSpeakerButton.rx.image())
.disposed(by: self.disposeBag)
self.viewModel.speakerSwitchable
.observeOn(MainScheduler.instance)
.bind(to: self.buttonsContainer.switchSpeakerButton.rx.isEnabled)
.disposed(by: self.disposeBag)
self.buttonsContainer.switchSpeakerButton.isEnabled = !(self.viewModel.isHeadsetConnected)
self.viewModel.pauseCallButtonState
.observeOn(MainScheduler.instance)
.bind(to: self.buttonsContainer.pauseCallButton.rx.image())
......@@ -216,6 +205,8 @@ class CallViewController: UIViewController, StoryboardBased, ViewModelBased {
self.showCancelButton()
} else if !self.viewModel.isAudioOnly {
self.hideCancelButton()
} else {
self.buttonsContainer.bottomSpaceConstraint.constant = 30
}
}).disposed(by: self.disposeBag)
......
......@@ -75,6 +75,8 @@ class CallViewModel: Stateable, ViewModel {
isHeadsetConnected = self.audioService.isHeadsetConnected.value
isAudioOnly = call.isAudioOnly
containerViewModel = ButtonsContainerViewModel(with: self.callService, audioService: self.audioService, callID: call.callId)
}
}
......@@ -261,9 +263,11 @@ class CallViewModel: Stateable, ViewModel {
})
}()
lazy var containerViewModel: ButtonsContainerViewModel = {
return ButtonsContainerViewModel(with: self.callService, callID: (self.call?.callId)!)
}()
var containerViewModel: ButtonsContainerViewModel?
// lazy var containerViewModel: ButtonsContainerViewModel = {
// return ButtonsContainerViewModel(with: self.callService, audioService: self.audioService, callID: (self.call?.callId)!)
// }()
required init(with injectionBag: InjectionBag) {
self.callService = injectionBag.callService
......
......@@ -39,6 +39,10 @@ class AudioService {
var isHeadsetConnected = Variable<Bool>(false)
var isOutputToSpeaker = Variable<Bool>(true)
var enableSwitchAudio: Observable<Bool> {
return self.isHeadsetConnected.asObservable()
}
init(withAudioAdapter audioAdapter: AudioAdapter) {
self.audioAdapter = audioAdapter
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment