mirror of
https://github.com/Ranchero-Software/NetNewsWire
synced 2026-11-30 09:18:18 +00:00
Add iOS Activity Log screen. Create shared view model and use it on iOS and Mac.
This commit is contained in:
1 parent
7c69ab0587
commit
a1e45c056f
6 files changed
+327
-89
No files matched your search
@@ -0,0 +1,127 @@
|
||||
//
|
||||
// ActivityLogView.swift
|
||||
// NetNewsWire-iOS
|
||||
//
|
||||
// Created by Brent Simmons on 6/11/26.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Account
|
||||
import ActivityLog
|
||||
import RSCore
|
||||
|
||||
struct ActivityLogView: View {
|
||||
|
||||
@State private var entries = [Activity]()
|
||||
@State private var plainText = ""
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if entries.isEmpty {
|
||||
ContentUnavailableView("No Activity Logged", systemImage: "checkmark.circle")
|
||||
} else {
|
||||
VStack(spacing: 0) {
|
||||
privacyWarning
|
||||
Divider()
|
||||
ScrollView {
|
||||
Text(buildAttributedString(entries))
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.textSelection(.enabled)
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle("Activity Log")
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("Copy Contents") {
|
||||
UIPasteboard.general.string = plainText
|
||||
}
|
||||
.disabled(entries.isEmpty)
|
||||
}
|
||||
}
|
||||
.task {
|
||||
reload()
|
||||
}
|
||||
.onReceive(NotificationCenter.default.publisher(for: .activityDidChange)) { _ in
|
||||
reload()
|
||||
}
|
||||
}
|
||||
|
||||
private var privacyWarning: some View {
|
||||
Text("Activity may contain feed URLs and other information you may not want to share publicly.")
|
||||
.font(.footnote)
|
||||
.foregroundStyle(.secondary)
|
||||
.padding()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private extension ActivityLogView {
|
||||
|
||||
func reload() {
|
||||
entries = ActivityLog.shared.completedActivities
|
||||
plainText = buildPlainText(entries)
|
||||
}
|
||||
|
||||
func buildAttributedString(_ entries: [Activity]) -> AttributedString {
|
||||
var result = AttributedString()
|
||||
for entry in entries {
|
||||
result.append(attributedString(for: entry))
|
||||
result.append(AttributedString("\n\n"))
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func attributedString(for activity: Activity) -> AttributedString {
|
||||
var result = AttributedString()
|
||||
for segment in ActivityLogViewModel.segments(for: activity) {
|
||||
var piece = AttributedString(segment.text)
|
||||
piece.foregroundColor = color(for: segment.color)
|
||||
piece.font = .system(.body, design: .monospaced).weight(fontWeight(for: segment.weight))
|
||||
result.append(piece)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func buildPlainText(_ entries: [Activity]) -> String {
|
||||
var result = ""
|
||||
for entry in entries {
|
||||
result += ActivityLogViewModel.plainText(for: entry)
|
||||
result += "\n\n"
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func color(for color: ActivityLogTextColor) -> Color {
|
||||
switch color {
|
||||
case .primary:
|
||||
return .primary
|
||||
case .secondary:
|
||||
return .secondary
|
||||
case .success:
|
||||
return .green
|
||||
case .failure:
|
||||
return .red
|
||||
case .account(let accountID):
|
||||
guard let accountID, let account = AccountManager.shared.existingAccount(accountID: accountID) else {
|
||||
return .secondary
|
||||
}
|
||||
return account.type.logColor
|
||||
}
|
||||
}
|
||||
|
||||
func fontWeight(for weight: ActivityLogTextWeight) -> Font.Weight {
|
||||
switch weight {
|
||||
case .regular:
|
||||
return .regular
|
||||
case .medium:
|
||||
return .medium
|
||||
case .bold:
|
||||
return .bold
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -533,6 +533,23 @@
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" accessoryType="disclosureIndicator" indentationWidth="10" textLabel="aLg-lb-4bR" style="IBUITableViewCellStyleDefault" id="aLg-mN-7rY" customClass="VibrantTableViewCell" customModule="NetNewsWire" customModuleProvider="target">
|
||||
<rect key="frame" x="20" y="1463" width="374" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="aLg-mN-7rY" id="aLg-cV-2mN">
|
||||
<rect key="frame" x="0.0" y="0.0" width="343.5" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Activity Log" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontForContentSizeCategory="YES" adjustsFontSizeToFit="NO" id="aLg-lb-4bR">
|
||||
<rect key="frame" x="20" y="0.0" width="315.5" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
</subviews>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
<tableViewSection headerTitle="Help" id="CS8-fJ-ghn">
|
||||
|
||||
@@ -33,6 +33,7 @@ final class SettingsViewController: UITableViewController {
|
||||
case accountStats = 1
|
||||
case dinosaurs = 2
|
||||
case cloudKitZoneStats = 3
|
||||
case activityLog = 4
|
||||
}
|
||||
|
||||
private enum FeedsRow: Int {
|
||||
@@ -282,6 +283,8 @@ final class SettingsViewController: UITableViewController {
|
||||
return UIHostingController(rootView: AccountStatsView())
|
||||
case .cloudKitZoneStats:
|
||||
return UIHostingController(rootView: CloudKitStatsView())
|
||||
case .activityLog:
|
||||
return UIHostingController(rootView: ActivityLogView())
|
||||
case .dinosaurs:
|
||||
return UIHostingController(rootView: DinosaursView(dismissAndPresent: { [weak self] dinosaur in
|
||||
guard let self else {
|
||||
|
||||
Reference in new issue
Block a user