71 lines
2.8 KiB
Swift
71 lines
2.8 KiB
Swift
import SwiftUI
|
|
import AppIntents
|
|
|
|
struct MusicActivityCard: View {
|
|
let state: MusicActivityAttributes.ContentState
|
|
let stale: Bool
|
|
var activityID: String = ""
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 10) {
|
|
HStack(spacing: 12) {
|
|
Image(systemName: "waveform").font(.title).foregroundStyle(.indigo)
|
|
TrackLabels(state: state)
|
|
Spacer(minLength: 0)
|
|
Image(systemName: state.playing ? "play.fill" : "pause.fill")
|
|
.accessibilityLabel("Последнее состояние: " + (state.playing ? "воспроизведение" : "пауза"))
|
|
}
|
|
ProgressView(value: state.progress).tint(.indigo)
|
|
ActivityStatus(state: state, stale: stale)
|
|
MusicActivityControls(activityID: activityID)
|
|
}.padding(16)
|
|
}
|
|
}
|
|
|
|
struct TrackLabels: View {
|
|
let state: MusicActivityAttributes.ContentState
|
|
var body: some View {
|
|
VStack(alignment: .leading, spacing: 3) {
|
|
Text(state.title).font(.headline).lineLimit(1)
|
|
Text(state.artist.isEmpty ? "MusicBridge · музыка на ПК" : state.artist)
|
|
.font(.caption).foregroundStyle(.secondary).lineLimit(1)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ActivityStatus: View {
|
|
let state: MusicActivityAttributes.ContentState
|
|
let stale: Bool
|
|
var body: some View {
|
|
if let message = state.message {
|
|
Text(message).font(.caption).lineLimit(2)
|
|
} else if !state.connected {
|
|
Text("Нет связи с ПК · нажмите обновление").font(.caption).foregroundStyle(.secondary)
|
|
} else {
|
|
HStack(spacing: 4) {
|
|
Text("Обновлено в")
|
|
Text(state.updatedAt, style: .time)
|
|
}.font(.caption).foregroundStyle(.secondary)
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MusicActivityControls: View {
|
|
let activityID: String
|
|
var body: some View {
|
|
HStack {
|
|
control(.previous, icon: "backward.end.fill", label: "Предыдущий трек")
|
|
Spacer(minLength: 4)
|
|
control(.toggle, icon: "playpause.fill", label: "Воспроизведение или пауза")
|
|
Spacer(minLength: 4)
|
|
control(.next, icon: "forward.end.fill", label: "Следующий трек")
|
|
Spacer(minLength: 4)
|
|
control(.refresh, icon: "arrow.clockwise", label: "Обновить трек")
|
|
}
|
|
}
|
|
private func control(_ action: MusicRemoteAction, icon: String, label: String) -> some View {
|
|
Button(intent: MusicControlIntent(action, activityID: activityID)) {
|
|
Image(systemName: icon).font(.title3).frame(minWidth: 44, minHeight: 44)
|
|
}.buttonStyle(.plain).accessibilityLabel(label).disabled(activityID.isEmpty)
|
|
}
|
|
}
|