InfoDisplaySettingsViewModel.swift 905 B

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