InfoDisplaySettingsViewModel.swift 879 B

123456789101112131415161718192021222324252627282930313233
  1. // LoopFollow
  2. // InfoDisplaySettingsViewModel.swift
  3. import Foundation
  4. import SwiftUI
  5. class InfoDisplaySettingsViewModel: ObservableObject {
  6. @Published var infoSort: [Int]
  7. @Published var infoVisible: [Bool]
  8. init() {
  9. infoSort = Storage.shared.infoSort.value
  10. infoVisible = Storage.shared.infoVisible.value
  11. }
  12. func toggleVisibility(for sortedIndex: Int) {
  13. infoVisible[sortedIndex].toggle()
  14. Storage.shared.infoVisible.value = infoVisible
  15. }
  16. func move(from source: IndexSet, to destination: Int) {
  17. infoSort.move(fromOffsets: source, toOffset: destination)
  18. Storage.shared.infoSort.value = infoSort
  19. }
  20. func getName(for index: Int) -> String {
  21. guard let infoType = InfoType(rawValue: index) else {
  22. return String(localized: "Unknown")
  23. }
  24. return infoType.name
  25. }
  26. }