NCCapabilitiesView.swift 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. //
  2. // NCCapabilitiesView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 19/05/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import SwiftUI
  24. import NextcloudKit
  25. struct NCCapabilitiesView: View {
  26. @ObservedObject var model: NCCapabilitiesModel
  27. var body: some View {
  28. VStack {
  29. List {
  30. Section {
  31. ForEach(model.capabililies, id: \.id) { capability in
  32. HStack {
  33. CapabilityName(text: Binding.constant(capability.text), image: Image(uiImage: capability.image), resize: capability.resize)
  34. CapabilityStatus(available: capability.available)
  35. }
  36. }
  37. }
  38. Section {
  39. CapabilityName(text: $model.homeServer, image: Image(uiImage: NCUtility().loadImage(named: "house")), resize: false)
  40. }
  41. }
  42. }
  43. .navigationBarTitle(NSLocalizedString("_capabilities_", comment: ""))
  44. .frame(maxWidth: .infinity, alignment: .top)
  45. .defaultViewModifier(model)
  46. }
  47. struct CapabilityName: View {
  48. @Binding var text: String
  49. @State var image: Image
  50. @State var resize: Bool
  51. var body: some View {
  52. Label {
  53. Text(text)
  54. .font(.system(size: 15))
  55. } icon: {
  56. if resize {
  57. image
  58. .renderingMode(.template)
  59. .resizable()
  60. .scaledToFill()
  61. .frame(width: 23.0, height: 23.0)
  62. .foregroundColor(.primary)
  63. } else {
  64. image
  65. .renderingMode(.template)
  66. .foregroundColor(.primary)
  67. }
  68. }
  69. .frame(maxWidth: .infinity, alignment: .leading)
  70. }
  71. }
  72. struct CapabilityStatus: View {
  73. @State var available: Bool
  74. var body: some View {
  75. if available {
  76. Image(systemName: "checkmark.circle.fill")
  77. .foregroundColor(.green)
  78. } else {
  79. Image(systemName: "multiply.circle.fill")
  80. .foregroundColor(Color(NCBrandColor.shared.textColor2))
  81. }
  82. }
  83. }
  84. }
  85. #Preview {
  86. return NCCapabilitiesView(model: NCCapabilitiesModel(controller: nil))
  87. }