InfoDisplaySettingsViewModel.swift 1015 B

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