Skip to content

Commit

Permalink
[Feature][Calling][CSS] Call history (#610)
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelprystinka authored Mar 7, 2023
1 parent 90e1653 commit 2ed8e5c
Show file tree
Hide file tree
Showing 23 changed files with 504 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
0570901C299EBAC000D7AE5F /* CallingDemoViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0570901B299EBAC000D7AE5F /* CallingDemoViewModel.swift */; };
1B0D8DC627F3B1B800F0C47A /* AzureCommunicationUIDemoAppCallTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B0D8DC527F3B1B800F0C47A /* AzureCommunicationUIDemoAppCallTests.swift */; };
1B3E3B4F285A8F690010E24E /* AzureCommunicationUIDemoAppSetupViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B3E3B4E285A8F690010E24E /* AzureCommunicationUIDemoAppSetupViewTests.swift */; };
1B5D6C0F29231B900072C66D /* CallConfigurationMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1B5D6C0929231B900072C66D /* CallConfigurationMocking.swift */; };
Expand Down Expand Up @@ -81,6 +82,7 @@

/* Begin PBXFileReference section */
026F091CB7F97EBA5A39610B /* Pods_AzureCommunicationUIDemoApp_AzureCommunicationUIDemoAppUITests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_AzureCommunicationUIDemoApp_AzureCommunicationUIDemoAppUITests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
0570901B299EBAC000D7AE5F /* CallingDemoViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CallingDemoViewModel.swift; sourceTree = "<group>"; };
1AA61EC7BE9A4B43EEC5DBCC /* Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppUITests.release.xcconfig"; path = "Target Support Files/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppUITests/Pods-AzureCommunicationUIDemoApp-AzureCommunicationUIDemoAppUITests.release.xcconfig"; sourceTree = "<group>"; };
1B0D8DC527F3B1B800F0C47A /* AzureCommunicationUIDemoAppCallTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AzureCommunicationUIDemoAppCallTests.swift; sourceTree = "<group>"; };
1B3E3B4E285A8F690010E24E /* AzureCommunicationUIDemoAppSetupViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AzureCommunicationUIDemoAppSetupViewTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -291,6 +293,7 @@
A87CEABB2729ECA600F3AE16 /* EntryViewController.swift */,
A85DDCB52728B23B001297B4 /* CallingDemoView.swift */,
A85DDCB42728B23A001297B4 /* CallingDemoViewController.swift */,
0570901B299EBAC000D7AE5F /* CallingDemoViewModel.swift */,
50D8EE9E2926C0C6003C3A95 /* ChatDemoView.swift */,
50D8EEA02926C0DD003C3A95 /* ChatDemoViewController.swift */,
50B390CE27D2996E0010A2ED /* SettingsView.swift */,
Expand Down Expand Up @@ -580,6 +583,7 @@
A85DDCB82728B23B001297B4 /* CallingDemoViewController.swift in Sources */,
50D8EE9F2926C0C6003C3A95 /* ChatDemoView.swift in Sources */,
50D8EEA12926C0DD003C3A95 /* ChatDemoViewController.swift in Sources */,
0570901C299EBAC000D7AE5F /* CallingDemoViewModel.swift in Sources */,
A8C69FB62728AE1A00143DB7 /* SceneDelegate.swift in Sources */,
1B981B0429480DA8002EB167 /* FloatingUITestWindow.swift in Sources */,
A87CEABC2729ECA600F3AE16 /* EntryViewController.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ struct CallingDemoView: View {
@State var isSettingsDisplayed: Bool = false
@State var isStartExperienceLoading: Bool = false
@State var errorMessage: String = ""
@State var isShowingCallHistory: Bool = false
@ObservedObject var envConfigSubject: EnvConfigSubject
@ObservedObject var callingViewModel: CallingDemoViewModel

let verticalPadding: CGFloat = 5
let horizontalPadding: CGFloat = 10
Expand All @@ -30,6 +32,7 @@ struct CallingDemoView: View {
displayNameTextField
meetingSelector
settingButton
showCallHistoryButton
startExperienceButton
Spacer()
}
Expand All @@ -43,6 +46,15 @@ struct CallingDemoView: View {
isErrorDisplayed = false
}))
}
.alert(isPresented: $isShowingCallHistory) {
Alert(
title: Text(callingViewModel.callHistoryTitle),
message: Text(callingViewModel.callHistoryMessage),
dismissButton:
.default(Text("Dismiss"), action: {
isShowingCallHistory = false
}))
}
.sheet(isPresented: $isSettingsDisplayed) {
SettingsView(envConfigSubject: envConfigSubject)
}
Expand Down Expand Up @@ -130,6 +142,13 @@ struct CallingDemoView: View {
.accessibility(identifier: AccessibilityId.startExperienceAccessibilityID.rawValue)
}

var showCallHistoryButton: some View {
Button("Show call history") {
isShowingCallHistory = true
}
.buttonStyle(DemoButtonStyle())
}

var isStartExperienceDisabled: Bool {
let acsToken = envConfigSubject.useExpiredToken ? envConfigSubject.expiredAcsToken : envConfigSubject.acsToken
if (envConfigSubject.selectedAcsTokenType == .token && acsToken.isEmpty)
Expand Down Expand Up @@ -282,7 +301,7 @@ extension CallingDemoView {
private func onError(_ error: CallCompositeError, callComposite: CallComposite) {
print("::::CallingDemoView::getEventsHandler::onError \(error)")
print("::::CallingDemoView error.code \(error.code)")
print("::::CallingDemoView debug info \(callComposite.debugInfo.currentOrLastCallId ?? "Unknown")")
callingViewModel.callHistory.last?.callIds.forEach { print("::::CallingDemoView call id \($0)") }
showError(for: error.code)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CallingDemoViewController: UIViewController {
static let buttonHorizontalInset: CGFloat = 20.0
static let buttonVerticalInset: CGFloat = 10.0
}
var callingViewModel: CallingDemoViewModel

private var selectedAcsTokenType: ACSTokenType = .token
private var acsTokenUrlTextField: UITextField!
Expand All @@ -32,6 +33,7 @@ class CallingDemoViewController: UIViewController {
private var groupCallTextField: UITextField!
private var teamsMeetingTextField: UITextField!
private var settingsButton: UIButton!
private var showCallHistoryButton: UIButton!
private var startExperienceButton: UIButton!
private var acsTokenTypeSegmentedControl: UISegmentedControl!
private var meetingTypeSegmentedControl: UISegmentedControl!
Expand Down Expand Up @@ -79,15 +81,19 @@ class CallingDemoViewController: UIViewController {

#if DEBUG
init(envConfigSubject: EnvConfigSubject,
callingViewModel: CallingDemoViewModel,
callingSDKHandlerMock: UITestCallingSDKWrapper? = nil) {
self.envConfigSubject = envConfigSubject
self.callingViewModel = callingViewModel
self.callingSDKWrapperMock = callingSDKHandlerMock
super.init(nibName: nil, bundle: nil)
self.combineEnvConfigSubject()
}
#else
init(envConfigSubject: EnvConfigSubject) {
init(envConfigSubject: EnvConfigSubject,
callingViewModel: CallingDemoViewModel) {
self.envConfigSubject = envConfigSubject
self.callingViewModel = callingViewModel
super.init(nibName: nil, bundle: nil)
self.combineEnvConfigSubject()
}
Expand Down Expand Up @@ -158,7 +164,7 @@ class CallingDemoViewController: UIViewController {
private func onError(_ error: CallCompositeError, callComposite: CallComposite) {
print("::::UIKitDemoView::getEventsHandler::onError \(error)")
print("::::UIKitDemoView error.code \(error.code)")
print("::::SwiftUIDemoView debug info \(callComposite.debugInfo.currentOrLastCallId ?? "Unknown")")
callingViewModel.callHistory.last?.callIds.forEach { print("::::UIKitDemoView call id \($0)") }
}

private func onRemoteParticipantJoined(to callComposite: CallComposite, identifiers: [CommunicationIdentifier]) {
Expand Down Expand Up @@ -354,6 +360,16 @@ class CallingDemoViewController: UIViewController {
present(settingsViewHostingController, animated: true, completion: nil)
}

@objc func onShowHistoryBtnPressed() {
let errorAlert = UIAlertController(title: callingViewModel.callHistoryTitle,
message: callingViewModel.callHistoryMessage,
preferredStyle: .alert)
errorAlert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))
present(errorAlert,
animated: true,
completion: nil)
}

@objc func onStartExperienceBtnPressed() {
startExperienceButton.isEnabled = false
startExperienceButton.backgroundColor = .systemGray3
Expand Down Expand Up @@ -494,6 +510,16 @@ class CallingDemoViewController: UIViewController {
right: LayoutConstants.buttonHorizontalInset)
settingsButton.accessibilityIdentifier = AccessibilityId.settingsButtonAccessibilityID.rawValue

showCallHistoryButton = UIButton()
showCallHistoryButton.setTitle("Show call history", for: .normal)
showCallHistoryButton.backgroundColor = .systemBlue
showCallHistoryButton.contentEdgeInsets = UIEdgeInsets.init(top: LayoutConstants.buttonVerticalInset,
left: LayoutConstants.buttonHorizontalInset,
bottom: LayoutConstants.buttonVerticalInset,
right: LayoutConstants.buttonHorizontalInset)
showCallHistoryButton.layer.cornerRadius = 8
showCallHistoryButton.addTarget(self, action: #selector(onShowHistoryBtnPressed), for: .touchUpInside)

startExperienceButton = UIButton()
startExperienceButton.backgroundColor = .systemBlue
startExperienceButton.setTitleColor(UIColor.white, for: .normal)
Expand Down Expand Up @@ -527,6 +553,22 @@ class CallingDemoViewController: UIViewController {
settingsButtonHStack.distribution = .fill
settingsButtonHStack.translatesAutoresizingMaskIntoConstraints = false

let showHistoryButtonHSpacer1 = UIView()
showHistoryButtonHSpacer1.translatesAutoresizingMaskIntoConstraints = false
showHistoryButtonHSpacer1.setContentHuggingPriority(.defaultLow, for: .horizontal)

let showHistoryButtonHSpacer2 = UIView()
showHistoryButtonHSpacer2.translatesAutoresizingMaskIntoConstraints = false
showHistoryButtonHSpacer2.setContentHuggingPriority(.defaultLow, for: .horizontal)

let showHistoryButtonHStack = UIStackView(arrangedSubviews: [showHistoryButtonHSpacer1,
showCallHistoryButton,
showHistoryButtonHSpacer2])
showHistoryButtonHStack.axis = .horizontal
showHistoryButtonHStack.alignment = .fill
showHistoryButtonHStack.distribution = .fill
showHistoryButtonHStack.translatesAutoresizingMaskIntoConstraints = false

let startButtonHSpacer1 = UIView()
startButtonHSpacer1.translatesAutoresizingMaskIntoConstraints = false
startButtonHSpacer1.setContentHuggingPriority(.defaultLow, for: .horizontal)
Expand Down Expand Up @@ -555,6 +597,7 @@ class CallingDemoViewController: UIViewController {
groupCallTextField,
teamsMeetingTextField,
settingsButtonHStack,
showHistoryButtonHStack,
startButtonHStack])
stackView.spacing = LayoutConstants.stackViewSpacingPortrait
stackView.axis = .vertical
Expand Down Expand Up @@ -586,6 +629,7 @@ class CallingDemoViewController: UIViewController {
stackView.bottomAnchor.constraint(equalTo: contentView.bottomAnchor).isActive = true

settingButtonHSpacer2.widthAnchor.constraint(equalTo: settingButtonHSpacer1.widthAnchor).isActive = true
showHistoryButtonHSpacer2.widthAnchor.constraint(equalTo: showHistoryButtonHSpacer1.widthAnchor).isActive = true
startButtonHSpacer2.widthAnchor.constraint(equalTo: startButtonHSpacer1.widthAnchor).isActive = true

updateAcsTokenTypeFields()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//

import Foundation
#if DEBUG
@testable import AzureCommunicationUICalling
#else
import AzureCommunicationUICalling
#endif

class CallingDemoViewModel: ObservableObject {
lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return dateFormatter
}()

var callHistoryTitle: String {
return "Total calls: \(callHistory.count)"
}

var callHistoryMessage: String {
var callHistoryMessage = "Last Call: none"
if let lastHistoryRecord = callHistory.last {
let formattedDate = dateFormatter.string(from: lastHistoryRecord.callStartedOn)
callHistoryMessage = "Last Call: \(formattedDate)\n"
callHistoryMessage += "Call Ids:\n"
callHistoryMessage += lastHistoryRecord.callIds.joined(separator: "\n")
}
return callHistoryMessage
}

var callHistory: [CallHistoryRecord] {
let callComposite = CallComposite()
let debugInfo = callComposite.debugInfo
let callHistory = debugInfo.callHistoryRecords
return callHistory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class EntryViewController: UIViewController {
private var callingSDKWrapperMock: UITestCallingSDKWrapper?
#endif
private var cancellables = Set<AnyCancellable>()
private let callingViewModel = CallingDemoViewModel()

override func viewDidLoad() {
super.viewDidLoad()
Expand Down Expand Up @@ -151,9 +152,10 @@ class EntryViewController: UIViewController {
@objc func onCallingSwiftUIPressed() {
#if DEBUG
let swiftUIDemoView = CallingDemoView(envConfigSubject: envConfigSubject,
callingViewModel: callingViewModel,
callingSDKWrapperMock: callingSDKWrapperMock)
#else
let swiftUIDemoView = CallingDemoView(envConfigSubject: envConfigSubject)
let swiftUIDemoView = CallingDemoView(envConfigSubject: envConfigSubject, callingViewModel: callingViewModel)
#endif
let swiftUIDemoViewHostingController = UIHostingController(rootView: swiftUIDemoView)
swiftUIDemoViewHostingController.modalPresentationStyle = .fullScreen
Expand All @@ -163,9 +165,11 @@ class EntryViewController: UIViewController {
@objc func onCallingUIKitPressed() {
#if DEBUG
let uiKitDemoViewController = CallingDemoViewController(envConfigSubject: envConfigSubject,
callingViewModel: callingViewModel,
callingSDKHandlerMock: callingSDKWrapperMock)
#else
let uiKitDemoViewController = CallingDemoViewController(envConfigSubject: envConfigSubject)
let uiKitDemoViewController = CallingDemoViewController(envConfigSubject: envConfigSubject,
callingViewModel: callingViewModel)
#endif
uiKitDemoViewController.modalPresentationStyle = .fullScreen
present(uiKitDemoViewController, animated: true, completion: nil)
Expand Down
2 changes: 1 addition & 1 deletion AzureCommunicationUI/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: dba06e7567902f624b6be4dac963332e701eb372

COCOAPODS: 1.11.3
COCOAPODS: 1.12.0
Loading

0 comments on commit 2ed8e5c

Please sign in to comment.