Skip to content

Commit

Permalink
improve: update sample app UI (SDKCF-6856)
Browse files Browse the repository at this point in the history
  • Loading branch information
Esakkiraja-Pothikannan authored Feb 7, 2024
1 parent 021e0d0 commit c771a68
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
3 changes: 3 additions & 0 deletions Sample/EventLogger/EventListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 6 additions & 5 deletions Sample/EventLogger/EventLoggerInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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
}
Expand Down
41 changes: 34 additions & 7 deletions Sample/EventLogger/EventLoggerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -192,6 +203,22 @@ struct EventLoggerView: View {
}
return customInfo.isEmpty ? true : false
}

private func sendUniqueEvent() {
for value in 0..<eventCount {
let eMessage = errorMessage + String(Date().timeIntervalSince1970)
let event = EventModel(sdkName: sdkName,
sdkVersion: sdkVersion,
errorCode: errorCode,
errorMessage: eMessage,
count: 1,
isCritical: isCritical,
info: customInfo)
interactor.logEvent(event) { isFinished in
isLoggingInprogress = (eventCount == value)
}
}
}
}

#if canImport(UIKit)
Expand Down

0 comments on commit c771a68

Please sign in to comment.