NCCapabilitiesView.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. import SwiftUI
  9. @objc class NCHostingCapabilitiesView: NSObject {
  10. @objc func makeShipDetailsUI() -> UIViewController {
  11. let capabilitiesStatus = NCCapabilitiesStatus()
  12. let view = NCCapabilitiesView(capabilitiesStatus: capabilitiesStatus)
  13. let vc = UIHostingController(rootView: view)
  14. vc.title = NSLocalizedString("_capabilities_", comment: "")
  15. return vc
  16. }
  17. }
  18. class NCCapabilitiesStatus: ObservableObject {
  19. struct Capability: Identifiable, Hashable {
  20. let id = UUID()
  21. let text: String
  22. let image: UIImage
  23. let available: Bool
  24. }
  25. @Published var capabililies: [Capability] = []
  26. init(preview: Bool = false) {
  27. // if preview {
  28. capabililies = [Capability(text: "File sharing", image: UIImage(named: "share")!, available: true),
  29. Capability(text: "Externa site", image: UIImage(systemName: "network")!, available: false)
  30. ]
  31. // }
  32. }
  33. }
  34. struct NCCapabilitiesView: View {
  35. @ObservedObject var capabilitiesStatus: NCCapabilitiesStatus
  36. init(capabilitiesStatus: NCCapabilitiesStatus) {
  37. self.capabilitiesStatus = capabilitiesStatus
  38. }
  39. var body: some View {
  40. ScrollView {
  41. VStack {
  42. ForEach(capabilitiesStatus.capabililies, id: \.id) { capability in
  43. HStack {
  44. Capability(text: capability.text, image: Image(uiImage: capability.image))
  45. CapabilityAvailable(available: capability.available)
  46. }
  47. }
  48. }
  49. .frame(maxWidth: .infinity, alignment: .top)
  50. //.padding(EdgeInsets(top: 0, leading: 10, bottom: 0, trailing: 10))
  51. }
  52. }
  53. }
  54. struct Capability: View {
  55. @State var text: String = ""
  56. @State var image: Image
  57. var body: some View {
  58. Label {
  59. Text(text)
  60. .font(.system(size: 15))
  61. .foregroundColor(Color(UIColor.systemGray))
  62. } icon: {
  63. image
  64. .renderingMode(.template)
  65. .resizable()
  66. .frame(width: 25.0, height: 25.0)
  67. .foregroundColor(Color(UIColor.systemGray))
  68. }
  69. .frame(maxWidth: .infinity, alignment: .leading)
  70. }
  71. }
  72. struct CapabilityAvailable: View {
  73. @State private var text: String
  74. init(available: Bool) {
  75. if available {
  76. _text = State(initialValue: NSLocalizedString("_available_", comment: ""))
  77. } else {
  78. _text = State(initialValue: NSLocalizedString("_not_available_", comment: ""))
  79. }
  80. }
  81. var body: some View {
  82. Text(text)
  83. .frame(width: 100)
  84. .font(.system(size: 12))
  85. .padding(EdgeInsets(top: 7, leading: 12, bottom: 7, trailing: 12))
  86. .foregroundColor(.primary)
  87. .background(
  88. RoundedRectangle(cornerRadius: 20)
  89. .stroke(Color(UIColor.systemGray), lineWidth: 0.5)
  90. .background(
  91. RoundedRectangle(cornerRadius: 20)
  92. .fill(Color(UIColor.secondarySystemBackground))
  93. )
  94. )
  95. .frame(maxWidth: .infinity, alignment: .trailing)
  96. }
  97. }
  98. struct NCCapabilitiesView_Previews: PreviewProvider {
  99. static var previews: some View {
  100. NCCapabilitiesView(capabilitiesStatus: NCCapabilitiesStatus(preview: true))
  101. }
  102. }