From c771a685e988893ab0ef655bcd57de7e28066ba2 Mon Sep 17 00:00:00 2001 From: Esakkiraja-Pothikannan <72430496+Esakkiraja-Pothikannan@users.noreply.github.com> Date: Wed, 7 Feb 2024 12:02:13 +0530 Subject: [PATCH] improve: update sample app UI (SDKCF-6856) --- Sample/EventLogger/EventListView.swift | 3 ++ .../EventLogger/EventLoggerInteractor.swift | 11 ++--- Sample/EventLogger/EventLoggerView.swift | 41 +++++++++++++++---- 3 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Sample/EventLogger/EventListView.swift b/Sample/EventLogger/EventListView.swift index 473c09a..db50256 100644 --- a/Sample/EventLogger/EventListView.swift +++ b/Sample/EventLogger/EventListView.swift @@ -9,6 +9,9 @@ struct EventListView: View { } var body: some View { + VStack(alignment: .leading) { + Text("Total number of Unique Count: \(eventList.count)") + } List(eventList, id: \.self) { item in Text(item) } diff --git a/Sample/EventLogger/EventLoggerInteractor.swift b/Sample/EventLogger/EventLoggerInteractor.swift index 1ba60a2..9f0f943 100644 --- a/Sample/EventLogger/EventLoggerInteractor.swift +++ b/Sample/EventLogger/EventLoggerInteractor.swift @@ -8,7 +8,7 @@ enum Constant { struct EventLoggerInteractor: EventLogging { func logEvent(_ event: EventModel, completionHandler: @escaping ((Bool) -> Void)) { let info = convertToJson(event.info) - for value in 1...event.count { + for _ in 1...event.count { DispatchQueue.main.async { if event.isCritical { REventLogger.shared.sendCriticalEvent(sourceName: event.sdkName, @@ -41,7 +41,9 @@ struct EventLoggerInteractor: EventLogging { let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] else { return [] } - return json.values.compactMap({ convertToString($0) }) + let sortedValues = json.values.compactMap({$0 as? [String: Any]}) + .sorted(by: { $0["firstOccurrenceOn"] as! Double > $1["firstOccurrenceOn"] as! Double }) + return sortedValues.compactMap({ convertToString($0) }) } func getConfiguration() -> (apiKey: String, apiEndpoint: String) { @@ -50,9 +52,8 @@ struct EventLoggerInteractor: EventLogging { return (apiKey, apiEndpoint) } - private func convertToString(_ value: Any) -> String? { - guard let dictionary = value as? [String: Any], - let data = try? JSONSerialization.data(withJSONObject: dictionary, options: .prettyPrinted), + private func convertToString(_ value: [String: Any]) -> String? { + guard let data = try? JSONSerialization.data(withJSONObject: value, options: [.sortedKeys, .prettyPrinted]), let jsonString = String(data: data, encoding: .utf8) else { return nil } diff --git a/Sample/EventLogger/EventLoggerView.swift b/Sample/EventLogger/EventLoggerView.swift index f0514a9..11833e2 100644 --- a/Sample/EventLogger/EventLoggerView.swift +++ b/Sample/EventLogger/EventLoggerView.swift @@ -126,14 +126,25 @@ struct EventLoggerView: View { updatedFocusFiled() } - Button(action: { - isLoggingInprogress = true - hideKeyboard() - sendEvent() - }) { - Text(isCritical ? "Log Critical Event" : "Log Warning Event") + Section { + Button(action: { + isLoggingInprogress = true + hideKeyboard() + sendEvent() + }) { + Text(isCritical ? "Log Critical Event" : "Log Warning Event") + } + .disabled(disableLogEvent()) + + Button(action: { + isLoggingInprogress = true + hideKeyboard() + sendUniqueEvent() + }) { + Text("Log Unique Event") + } + .disabled(disableLogEvent()) } - .disabled(disableLogEvent()) Section { NavigationLink(destination: EventListView(interactor: interactor) @@ -192,6 +203,22 @@ struct EventLoggerView: View { } return customInfo.isEmpty ? true : false } + + private func sendUniqueEvent() { + for value in 0..