import SwiftUI import FlixyDesign import FlixyDownloads import MediaKit /// Was beim Herunterladen gilt. /// /// Die Löschfrist steht bewusst mit ausgeschriebenen Fristen da statt mit /// einem Schieberegler: „Nach 7 Tagen" ist eine Entscheidung, die man bewusst /// trifft — beim Löschen von Filmen soll niemand versehentlich auf „sofort" /// rutschen. struct DownloadSettingsView: View { @Environment(DownloadCoordinator.self) private var downloads @Environment(\.flixyAccent) private var accent var body: some View { @Bindable var downloads = downloads Form { SettingsHeader( symbol: "arrow.down.circle", colour: SettingsPalette.downloads, title: "sidebar.downloads", explanation: "settings.downloadsHeaderExplanation" ) Section { Toggle("downloads.wifiOnly", isOn: $downloads.isWiFiOnly) Picker("settings.storageLimit", selection: storageLimitBinding) { Text("settings.storageUnlimited").tag(Int64(0)) ForEach([Int64(5), 10, 20, 30, 50, 100], id: \.self) { gigabytes in Text("\(gigabytes) GB").tag(gigabytes * 1_000_000_000) } } } footer: { Text("settings.downloadsExplanation") } Section { Stepper(value: $downloads.maximumConcurrentDownloads, in: 1...5) { LabeledContent( "settings.concurrent", value: downloads.maximumConcurrentDownloads.formatted() ) } } header: { Text("settings.concurrentHeader") } footer: { // Zwei statt aller auf einmal: eine ganze Staffel parallel zu // laden teilt die Bandbreite so auf, dass keine Folge fertig // wird — und unterwegs ist eine fertige Folge mehr wert als // zehn halbe. Text("settings.concurrentExplanation") } Section { Picker("settings.deleteWatched", selection: deleteAfterBinding) { Text("settings.deleteNever").tag(Double(-1)) Text("settings.deleteImmediately").tag(Double(0)) Text("settings.deleteAfterDay").tag(Duration.afterOneDay.seconds) Text("settings.deleteAfterWeek").tag(Duration.afterOneWeek.seconds) } Picker("settings.keepUnwatched", selection: keepUnwatchedBinding) { Text("settings.keepOff").tag(0) ForEach([1, 2, 3, 5], id: \.self) { count in Text("settings.keepCount \(count)").tag(count) } } } header: { Text("settings.episodes") } } .tint(accent) .flixyForm() .scrollContentBackground(.hidden) .background(Color.flixyCanvas) .navigationTitle(Text("sidebar.downloads")) .flixyInlineTitle() } private var storageLimitBinding: Binding { Binding( get: { downloads.storageLimitBytes ?? 0 }, set: { downloads.storageLimitBytes = $0 > 0 ? $0 : nil } ) } private var deleteAfterBinding: Binding { Binding( get: { downloads.rules.deleteWatchedAfter?.seconds ?? -1 }, set: { downloads.rules.deleteWatchedAfter = $0 >= 0 ? .seconds($0) : nil } ) } private var keepUnwatchedBinding: Binding { Binding( get: { downloads.rules.keepUnwatchedEpisodes ?? 0 }, set: { downloads.rules.keepUnwatchedEpisodes = $0 > 0 ? $0 : nil } ) } }