|
1 | 1 | import CodexBarCore |
2 | 2 | import SwiftUI |
3 | 3 |
|
| 4 | +enum ProviderMetricInlinePresentation: Equatable { |
| 5 | + case progress |
| 6 | + case status(String) |
| 7 | +} |
| 8 | + |
4 | 9 | @MainActor |
5 | 10 | struct ProviderDetailView<SupplementaryContent: View>: View { |
6 | 11 | let provider: UsageProvider |
@@ -63,6 +68,15 @@ struct ProviderDetailView<SupplementaryContent: View>: View { |
63 | 68 | L(UsageMenuCardView.popupMetricTitle(provider: provider, metric: metric)) |
64 | 69 | } |
65 | 70 |
|
| 71 | + static func metricInlinePresentation( |
| 72 | + _ metric: UsageMenuCardView.Model.Metric) -> ProviderMetricInlinePresentation |
| 73 | + { |
| 74 | + if let statusText = metric.statusText { |
| 75 | + return .status(statusText) |
| 76 | + } |
| 77 | + return .progress |
| 78 | + } |
| 79 | + |
66 | 80 | static func planRow(provider: UsageProvider, planText: String?) -> (label: String, value: String)? { |
67 | 81 | guard let rawPlan = planText?.trimmingCharacters(in: .whitespacesAndNewlines), |
68 | 82 | !rawPlan.isEmpty |
@@ -455,50 +469,57 @@ private struct ProviderMetricInlineRow: View { |
455 | 469 | .frame(width: self.labelWidth, alignment: .leading) |
456 | 470 |
|
457 | 471 | VStack(alignment: .leading, spacing: 4) { |
458 | | - UsageProgressBar( |
459 | | - percent: self.metric.percent, |
460 | | - tint: self.progressColor, |
461 | | - accessibilityLabel: self.metric.percentStyle.accessibilityLabel, |
462 | | - pacePercent: self.metric.pacePercent, |
463 | | - paceOnTop: self.metric.paceOnTop, |
464 | | - warningMarkerPercents: self.metric.warningMarkerPercents) |
465 | | - .frame(minWidth: ProviderSettingsMetrics.metricBarWidth, maxWidth: .infinity) |
466 | | - |
467 | | - HStack(alignment: .firstTextBaseline, spacing: 8) { |
468 | | - Text(self.metric.percentLabel) |
| 472 | + switch ProviderDetailView<EmptyView>.metricInlinePresentation(self.metric) { |
| 473 | + case let .status(statusText): |
| 474 | + Text(statusText) |
469 | 475 | .font(.footnote) |
470 | 476 | .foregroundStyle(.secondary) |
471 | | - .monospacedDigit() |
472 | | - Spacer(minLength: 8) |
473 | | - if let resetText = self.metric.resetText, !resetText.isEmpty { |
474 | | - Text(resetText) |
475 | | - .font(.footnote) |
476 | | - .foregroundStyle(.secondary) |
477 | | - } |
478 | | - } |
| 477 | + case .progress: |
| 478 | + UsageProgressBar( |
| 479 | + percent: self.metric.percent, |
| 480 | + tint: self.progressColor, |
| 481 | + accessibilityLabel: self.metric.percentStyle.accessibilityLabel, |
| 482 | + pacePercent: self.metric.pacePercent, |
| 483 | + paceOnTop: self.metric.paceOnTop, |
| 484 | + warningMarkerPercents: self.metric.warningMarkerPercents) |
| 485 | + .frame(minWidth: ProviderSettingsMetrics.metricBarWidth, maxWidth: .infinity) |
479 | 486 |
|
480 | | - let hasLeftDetail = self.metric.detailLeftText?.isEmpty == false |
481 | | - let hasRightDetail = self.metric.detailRightText?.isEmpty == false |
482 | | - if hasLeftDetail || hasRightDetail { |
483 | 487 | HStack(alignment: .firstTextBaseline, spacing: 8) { |
484 | | - if let leftDetail = self.metric.detailLeftText, !leftDetail.isEmpty { |
485 | | - Text(leftDetail) |
486 | | - .font(.footnote) |
487 | | - .foregroundStyle(.secondary) |
488 | | - } |
| 488 | + Text(self.metric.percentLabel) |
| 489 | + .font(.footnote) |
| 490 | + .foregroundStyle(.secondary) |
| 491 | + .monospacedDigit() |
489 | 492 | Spacer(minLength: 8) |
490 | | - if let rightDetail = self.metric.detailRightText, !rightDetail.isEmpty { |
491 | | - Text(rightDetail) |
| 493 | + if let resetText = self.metric.resetText, !resetText.isEmpty { |
| 494 | + Text(resetText) |
492 | 495 | .font(.footnote) |
493 | 496 | .foregroundStyle(.secondary) |
494 | 497 | } |
495 | 498 | } |
496 | | - } |
497 | 499 |
|
498 | | - if let detail = self.detailText, !detail.isEmpty { |
499 | | - Text(detail) |
500 | | - .font(.footnote) |
501 | | - .foregroundStyle(.tertiary) |
| 500 | + let hasLeftDetail = self.metric.detailLeftText?.isEmpty == false |
| 501 | + let hasRightDetail = self.metric.detailRightText?.isEmpty == false |
| 502 | + if hasLeftDetail || hasRightDetail { |
| 503 | + HStack(alignment: .firstTextBaseline, spacing: 8) { |
| 504 | + if let leftDetail = self.metric.detailLeftText, !leftDetail.isEmpty { |
| 505 | + Text(leftDetail) |
| 506 | + .font(.footnote) |
| 507 | + .foregroundStyle(.secondary) |
| 508 | + } |
| 509 | + Spacer(minLength: 8) |
| 510 | + if let rightDetail = self.metric.detailRightText, !rightDetail.isEmpty { |
| 511 | + Text(rightDetail) |
| 512 | + .font(.footnote) |
| 513 | + .foregroundStyle(.secondary) |
| 514 | + } |
| 515 | + } |
| 516 | + } |
| 517 | + |
| 518 | + if let detail = self.detailText, !detail.isEmpty { |
| 519 | + Text(detail) |
| 520 | + .font(.footnote) |
| 521 | + .foregroundStyle(.tertiary) |
| 522 | + } |
502 | 523 | } |
503 | 524 | } |
504 | 525 | .frame(maxWidth: .infinity, alignment: .leading) |
|
0 commit comments