Add CustomAlertController and functions called in alertController (Start group call and go to Device list view)

This commit is contained in:
Benoit Martins 2022-12-19 13:40:32 +01:00 committed by QuentinArguillere
parent fe3bf1035f
commit c96b7d6002
5 changed files with 154 additions and 72 deletions

View file

@ -103,7 +103,7 @@ static UICompositeViewDescription *compositeDescription = nil;
#pragma mark - Action Functions
- (IBAction)onBackClick:(id)sender {
ChatConversationView *view = VIEW(ChatConversationView);
ChatConversationViewSwift *view = VIEW(ChatConversationViewSwift);
[PhoneMainView.instance popToView:view.compositeViewDescription];
}

View file

@ -93,10 +93,10 @@ import DropDown
self.goBackChatListView()
},
action1: {
self.onCallClick(cChatRoom: self.chatRoom?.getCobject)
},
action1Bis: {
self.onCallClick(cChatRoom: self.chatRoom?.getCobject)
},
action2: {
self.tapChooseMenuItem(self.action2Button)
@ -189,4 +189,51 @@ import DropDown
changeSecureLevel(secureLevel: secureLevel != nil, imageBadge: secureLevel)
initDataSource(groupeChat: !isOneToOneChat, secureLevel: secureLevel != nil, cChatRoom: cChatRoom)
}
func onCallClick(cChatRoom: OpaquePointer?) {
let firstParticipant = chatRoom?.participants.first
let addr = (firstParticipant != nil) ? linphone_participant_get_address(firstParticipant?.getCobject) : linphone_chat_room_get_peer_address(cChatRoom);
let isOneToOneChat = chatRoom!.hasCapability(mask: Int(LinphoneChatRoomCapabilitiesOneToOne.rawValue))
if (!isOneToOneChat) {
//ConferenceViewModelBridge.startGroupCall(cChatRoom: cChatRoom!)
alertActionConferenceCall(cChatRoom: cChatRoom)
} else {
LinphoneManager.instance().call(addr)
}
}
func alertActionConferenceCall(cChatRoom: OpaquePointer?) {
let alertController = CustomAlertController(title: VoipTexts.conference_start_group_call_dialog_message, message: nil, preferredStyle: .alert)
alertController.setBackgroundColor(color: .darkGray)
alertController.setTitle(font: nil, color: .white)
alertController.setTint(color: .white)
alertController.setMaxWidth(alert: alertController)
alertController.addButtonsAlertController(alertController: alertController, buttonsViewHeightV: 60, buttonsAlertHeightV: 40)
self.present(alertController, animated: true, completion:{
alertController.view.superview?.isUserInteractionEnabled = true
alertController.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dismissOnTapOutsideOrCancel)))
})
alertController.ok_button_alert.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.onTapOkStartGroupCall)))
}
@objc func onTapOkStartGroupCall(){
self.dismiss(animated: true, completion: nil)
ConferenceViewModelBridge.startGroupCall(cChatRoom: (chatRoom?.getCobject)!)
}
@objc override func onTapOk() {
self.dismiss(animated: true, completion: nil)
let view: DevicesListView = self.VIEW(DevicesListView.compositeViewDescription())
view.room = chatRoom?.getCobject
PhoneMainView.instance().changeCurrentView(view.compositeViewDescription())
}
}

View file

@ -125,86 +125,21 @@ import linphonesw
func alertAction() {
let alertController = UIAlertController(title: VoipTexts.alert_dialog_secure_badge_button_chat_conversation_title, message: nil, preferredStyle: .alert)
let alertController = CustomAlertController(title: VoipTexts.alert_dialog_secure_badge_button_chat_conversation_title, message: nil, preferredStyle: .alert)
alertController.setBackgroundColor(color: .darkGray)
alertController.setTitle(font: nil, color: .white)
alertController.setTint(color: .white)
alertController.setMaxWidth(alert: alertController)
addButtonsAlertController(alertController: alertController)
alertController.addButtonsAlertController(alertController: alertController, buttonsViewHeightV: 60, checkboxViewHeightV: 50, buttonsAlertHeightV: 40)
self.present(alertController, animated: true, completion:{
alertController.view.superview?.isUserInteractionEnabled = true
alertController.view.superview?.subviews[0].addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dismissOnTapOutsideOrCancel)))
})
}
@objc func dismissOnTapOutsideOrCancel(){
self.dismiss(animated: true, completion: nil)
}
@objc func dismissOnTapOk(){
self.dismiss(animated: true, completion: nil)
}
@objc func switchCheckedValue(){
isChecked = !isChecked
checkBoxButton.isSelected = isChecked
}
func addButtonsAlertController(alertController: UIAlertController){
let buttonsView = UIView()
alertController.view.addSubview(buttonsView)
buttonsView.translatesAutoresizingMaskIntoConstraints = false
buttonsView.bottomAnchor.constraint(equalTo: alertController.view.bottomAnchor, constant: -10).isActive = true
buttonsView.rightAnchor.constraint(equalTo: alertController.view.rightAnchor, constant: -10).isActive = true
buttonsView.leftAnchor.constraint(equalTo: alertController.view.leftAnchor, constant: 10).isActive = true
buttonsView.heightAnchor.constraint(equalToConstant: 75).isActive = true
alertController.view.translatesAutoresizingMaskIntoConstraints = false
alertController.view.heightAnchor.constraint(equalToConstant: 350).isActive = true
cancel_button_alert.setTitle(VoipTexts.cancel.uppercased(), for: .normal)
cancel_button_alert.backgroundColor = .systemRed
cancel_button_alert.layer.cornerRadius = 5
cancel_button_alert.addTarget(self, action: #selector(dismissOnTapOutsideOrCancel), for: .touchUpInside)
buttonsView.addSubview(cancel_button_alert)
cancel_button_alert.alignParentLeft(withMargin: 40).size(w: 100, h: 50).done()
ok_button_alert.setTitle(VoipTexts.ok.uppercased(), for: .normal)
ok_button_alert.backgroundColor = .systemGreen
ok_button_alert.layer.cornerRadius = 5
ok_button_alert.addTarget(self, action: #selector(dismissOnTapOk), for: .touchUpInside)
buttonsView.addSubview(ok_button_alert)
ok_button_alert.alignParentRight(withMargin: 40).size(w: 100, h: 50).done()
let checkboxView = UIView()
alertController.view.addSubview(checkboxView)
checkboxView.translatesAutoresizingMaskIntoConstraints = false
checkboxView.bottomAnchor.constraint(equalTo: buttonsView.topAnchor, constant: -10).isActive = true
checkboxView.centerXAnchor.constraint(equalTo: alertController.view.centerXAnchor).isActive = true
checkboxView.heightAnchor.constraint(equalToConstant: 50).isActive = true
checkboxView.width(180).done()
checkBoxButton.setImage(UIImage(named:"checkbox_unchecked.png"), for: .normal)
checkBoxButton.setImage(UIImage(named:"checkbox_checked.png"), for: .selected)
checkBoxButton.addTarget(self, action: #selector(switchCheckedValue), for: .touchUpInside)
checkboxView.addSubview(checkBoxButton)
checkBoxText.text = VoipTexts.alert_dialog_secure_badge_button_chat_conversation_checkboxtext
checkBoxText.textColor = .white
checkboxView.addSubview(checkBoxText)
checkBoxText.toRightOf(checkBoxButton, withLeftMargin: -5).size(w: 130, h: 50).done()
alertController.ok_button_alert.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.onTapOk)))
}
func changeTitle(titleString: String){
@ -220,7 +155,7 @@ import linphonesw
floatingButton.isHidden = true
}
}
func changeCallIcon(groupeChat: Bool){
if(groupeChat){
action1Button.isHidden = true
@ -230,4 +165,12 @@ import linphonesw
action1BisButton.isHidden = true
}
}
@objc func dismissOnTapOutsideOrCancel(){
self.dismiss(animated: true, completion: nil)
}
@objc func onTapOk(){
self.dismiss(animated: true, completion: nil)
}
}

View file

@ -0,0 +1,88 @@
//
// CustomAlertController.swift
// linphone
//
// Created by Benoît Martins on 19/12/2022.
//
import Foundation
class CustomAlertController: UIAlertController {
let cancel_button_alert = UIButton()
let ok_button_alert = UIButton()
let checkBoxButton = CallControlButton(buttonTheme:VoipTheme.nav_button("checkbox_unchecked"))
var isChecked = false
let checkBoxText = UILabel()
var isSecure : Bool = false
let isGroupChat : Bool = false
let levelMaxSecure : Bool = false
@objc func dismissOnTapOutsideOrCancel(){
self.dismiss(animated: true, completion: nil)
}
@objc func onTapOk(){
self.dismiss(animated: true, completion: nil)
}
@objc func switchCheckedValue(){
isChecked = !isChecked
checkBoxButton.isSelected = isChecked
}
func addButtonsAlertController(alertController: UIAlertController, buttonsViewHeightV: CGFloat, checkboxViewHeightV: CGFloat? = nil, buttonsAlertHeightV: CGFloat){
let buttonsViewHeight = buttonsViewHeightV
let checkboxViewHeight = checkboxViewHeightV ?? 0
let buttonsAlertHeight = buttonsAlertHeightV
let alertControllerHeight : CGFloat = (buttonsViewHeight + checkboxViewHeight + buttonsAlertHeight) * 2
let buttonsView = UIView()
alertController.view.addSubview(buttonsView)
buttonsView.translatesAutoresizingMaskIntoConstraints = false
buttonsView.bottomAnchor.constraint(equalTo: alertController.view.bottomAnchor, constant: -10).isActive = true
buttonsView.rightAnchor.constraint(equalTo: alertController.view.rightAnchor, constant: -10).isActive = true
buttonsView.leftAnchor.constraint(equalTo: alertController.view.leftAnchor, constant: 10).isActive = true
buttonsView.heightAnchor.constraint(equalToConstant: buttonsViewHeight).isActive = true
alertController.view.translatesAutoresizingMaskIntoConstraints = false
alertController.view.heightAnchor.constraint(equalToConstant: alertControllerHeight).isActive = true
cancel_button_alert.setTitle(VoipTexts.cancel.uppercased(), for: .normal)
cancel_button_alert.backgroundColor = .systemRed
cancel_button_alert.layer.cornerRadius = 5
cancel_button_alert.addTarget(self, action: #selector(dismissOnTapOutsideOrCancel), for: .touchUpInside)
buttonsView.addSubview(cancel_button_alert)
cancel_button_alert.alignParentLeft(withMargin: 40).size(w: 100, h: buttonsAlertHeight).done()
ok_button_alert.setTitle(VoipTexts.ok.uppercased(), for: .normal)
ok_button_alert.backgroundColor = .systemGreen
ok_button_alert.layer.cornerRadius = 5
ok_button_alert.addTarget(self, action: #selector(onTapOk), for: .touchUpInside)
buttonsView.addSubview(ok_button_alert)
ok_button_alert.alignParentRight(withMargin: 40).size(w: 100, h: buttonsAlertHeight).done()
if(checkboxViewHeight != 0){
let checkboxView = UIView()
alertController.view.addSubview(checkboxView)
checkboxView.translatesAutoresizingMaskIntoConstraints = false
checkboxView.bottomAnchor.constraint(equalTo: buttonsView.topAnchor, constant: -5).isActive = true
checkboxView.centerXAnchor.constraint(equalTo: alertController.view.centerXAnchor).isActive = true
checkboxView.heightAnchor.constraint(equalToConstant: checkboxViewHeight).isActive = true
checkboxView.width(180).done()
checkBoxButton.setImage(UIImage(named:"checkbox_unchecked.png"), for: .normal)
checkBoxButton.setImage(UIImage(named:"checkbox_checked.png"), for: .selected)
checkBoxButton.addTarget(self, action: #selector(switchCheckedValue), for: .touchUpInside)
checkboxView.addSubview(checkBoxButton)
checkBoxText.text = VoipTexts.alert_dialog_secure_badge_button_chat_conversation_checkboxtext
checkBoxText.textColor = .white
checkboxView.addSubview(checkBoxText)
checkBoxText.toRightOf(checkBoxButton, withLeftMargin: -5).height(checkboxViewHeight).done()
checkBoxText.sizeToFit()
}
}
}

View file

@ -947,6 +947,7 @@
D7421D9E29228A5200290CAB /* ChatConversationViewSwift.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7421D9D29228A5200290CAB /* ChatConversationViewSwift.swift */; };
D74A44912923BAF90017D063 /* BackActionsNavigationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D74A44902923BAF90017D063 /* BackActionsNavigationView.swift */; };
D77057F1292E4A340031A970 /* ChatConversationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D77057F0292E4A340031A970 /* ChatConversationViewModel.swift */; };
D7A7545029507038005C9D4A /* CustomAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7A7544F29507038005C9D4A /* CustomAlertController.swift */; };
D7C6DE7D2947331A00756E03 /* UIAlertController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C6DE7C2947331A00756E03 /* UIAlertController.swift */; };
D7C6DE832948CF3100756E03 /* DropDownCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D7C6DE812948CF3100756E03 /* DropDownCell.swift */; };
D7C6DE842948CF3100756E03 /* DropDownCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D7C6DE822948CF3100756E03 /* DropDownCell.xib */; };
@ -2185,6 +2186,7 @@
D7421D9D29228A5200290CAB /* ChatConversationViewSwift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatConversationViewSwift.swift; sourceTree = "<group>"; };
D74A44902923BAF90017D063 /* BackActionsNavigationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BackActionsNavigationView.swift; sourceTree = "<group>"; };
D77057F0292E4A340031A970 /* ChatConversationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatConversationViewModel.swift; sourceTree = "<group>"; };
D7A7544F29507038005C9D4A /* CustomAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomAlertController.swift; sourceTree = "<group>"; };
D7C6DE7C2947331A00756E03 /* UIAlertController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIAlertController.swift; sourceTree = "<group>"; };
D7C6DE812948CF3100756E03 /* DropDownCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DropDownCell.swift; sourceTree = "<group>"; };
D7C6DE822948CF3100756E03 /* DropDownCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DropDownCell.xib; sourceTree = "<group>"; };
@ -3452,6 +3454,7 @@
C63F71B0285A24B10066163B /* TimestampUtils.swift */,
D74A44902923BAF90017D063 /* BackActionsNavigationView.swift */,
D7C6DE7C2947331A00756E03 /* UIAlertController.swift */,
D7A7544F29507038005C9D4A /* CustomAlertController.swift */,
);
path = Util;
sourceTree = "<group>";
@ -5164,6 +5167,7 @@
D3807FF015C2894A005BE9BC /* IASKSettingsStore.m in Sources */,
C63F7234285A24B10066163B /* ConferenceViewModel.swift in Sources */,
8CA70AD11F9E0AE100A3D2EB /* ChatConversationInfoView.m in Sources */,
D7A7545029507038005C9D4A /* CustomAlertController.swift in Sources */,
D3807FF215C2894A005BE9BC /* IASKSettingsStoreFile.m in Sources */,
C63F720F285A24B10066163B /* ConferenceWaitingRoomViewModel.swift in Sources */,
C63F7248285A24B10066163B /* MicMuted.swift in Sources */,