Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ struct ActivityLogDetailView: View {

enum ViewState: Equatable {
case loading
case loaded(String, isSharing: Bool)
case loaded([String], isSharing: Bool)
case error(Error)

static func == (lhs: ActivityLogDetailView.ViewState, rhs: ActivityLogDetailView.ViewState) -> Bool {
return switch (lhs, rhs) {
case (.loading, .loading): true
case (.loaded(let lhscontent, let lhsisSharing), .loaded(let rhscontent, let rhsisSharing)):
lhscontent == rhscontent && lhsisSharing == rhsisSharing
case (.loaded(let lhsLines, let lhsisSharing), .loaded(let rhsLines, let rhsisSharing)):
lhsLines == rhsLines && lhsisSharing == rhsisSharing
case (.error, .error): true
default: false
}
Expand All @@ -38,8 +38,8 @@ struct ActivityLogDetailView: View {
switch self.state {
case .loading:
self.loadingView
case .loaded(let content, _):
self.loadedView(content: content)
case .loaded(let lines, _):
self.loadedView(lines: lines)
case .error(let error):
self.errorView(error: error)
}
Expand All @@ -54,11 +54,11 @@ struct ActivityLogDetailView: View {
}
}
.sheet(isPresented: self.$isDisplayingShareSheet, onDismiss: {
guard case .loaded(let content, _) = self.state else {
guard case .loaded(let lines, _) = self.state else {
return
}

self.state = .loaded(content, isSharing: false)
self.state = .loaded(lines, isSharing: false)
}, content: {
ActivityLogSharingView(applicationLog: applicationLog) {
AnyView(erasing: Text("TODO: A new support request with the application log attached"))
Expand Down Expand Up @@ -87,15 +87,21 @@ struct ActivityLogDetailView: View {
}

@ViewBuilder
func loadedView(content: String) -> some View {
func loadedView(lines: [String]) -> some View {
ScrollView {
VStack(alignment: .leading) {
TextEditor(text: .constant(content))
.font(.system(.body, design: .monospaced))
.fixedSize(horizontal: false, vertical: true)
.scrollDisabled(true)
.padding()
LazyVStack(alignment: .leading, spacing: 0) {
logLinesContent(lines: lines)
}
.font(.system(.body, design: .monospaced))
.padding()
}
}

@ViewBuilder
private func logLinesContent(lines: [String]) -> some View {
ForEach(Array(lines.enumerated()), id: \.offset) { _, line in
Text(line)
.frame(maxWidth: .infinity, alignment: .leading)
}
}

Expand All @@ -110,19 +116,22 @@ struct ActivityLogDetailView: View {
private func loadLogContent() async {
do {
let content = try await self.dataProvider.readApplicationLog(applicationLog)
let lines = content
.split(separator: "\n", omittingEmptySubsequences: false)
.map(String.init)

self.state = .loaded(content, isSharing: false)
self.state = .loaded(lines, isSharing: false)
} catch {
self.state = .error(error)
}
}

private func startSharing() {
guard case .loaded(let content, _) = self.state else {
guard case .loaded(let lines, _) = self.state else {
return
}

state = .loaded(content, isSharing: true)
state = .loaded(lines, isSharing: true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ struct SupportActivityDetailsView: View {

var body: some View {
ScrollView {
Text(viewModel.logText)
.font(.subheadline)
.frame(maxWidth: .infinity, alignment: .leading)
.padding()
LazyVStack(alignment: .leading, spacing: 0) {
logLinesContent
}
.font(.subheadline)
.padding()
}
.navigationTitle(viewModel.logDate)
.navigationBarTitleDisplayMode(.inline)
Expand All @@ -29,10 +30,18 @@ struct SupportActivityDetailsView: View {
}
}
}

@ViewBuilder
private var logLinesContent: some View {
ForEach(Array(viewModel.logLines.enumerated()), id: \.offset) { _, line in
Text(line)
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}

private final class SupportActivityDetailsViewModel: ObservableObject {
let logText: String
let logLines: [String]
let logDate: String

init(logFile: DDLogFileInfo) {
Expand All @@ -45,15 +54,17 @@ private final class SupportActivityDetailsViewModel: ObservableObject {

guard let logData = try? Data(contentsOf: URL(fileURLWithPath: logFile.filePath)),
let logText = String(data: logData, encoding: .utf8) else {
self.logText = ""
self.logLines = []
return
}
self.logText = logText
self.logLines = logText
.split(separator: "\n", omittingEmptySubsequences: false)
.map(String.init)
}

func buttonShareTapped() {
let activityVC = UIActivityViewController(
activityItems: [logText],
activityItems: [logLines.joined(separator: "\n")],
applicationActivities: nil
)

Expand Down