InfoDisplaySettingsViewModel.swift 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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. // Update UserDefaults
  20. UserDefaultsRepository.infoVisible.value = infoVisible
  21. }
  22. func move(from source: IndexSet, to destination: Int) {
  23. infoSort.move(fromOffsets: source, toOffset: destination)
  24. // Update UserDefaults
  25. UserDefaultsRepository.infoSort.value = infoSort
  26. }
  27. func getName(for index: Int) -> String {
  28. guard let infoType = InfoType(rawValue: index) else {
  29. return "Unknown"
  30. }
  31. return infoType.name
  32. }
  33. }