ToolbarWidgetView.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. //
  2. // ToolbarWidgetView.swift
  3. // Widget
  4. //
  5. // Created by Marino Faggiana on 25/08/22.
  6. // Copyright © 2022 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 WidgetKit
  25. struct ToolbarWidgetView: View {
  26. var entry: ToolbarDataEntry
  27. var body: some View {
  28. GeometryReader { geo in
  29. ZStack(alignment: .topLeading) {
  30. HStack(spacing: 0) {
  31. let sizeButton: CGFloat = 65
  32. let placeholderColor = Color(white: 0.8)
  33. let brandColor = Color(NCBrandColor.shared.brand)
  34. let brandTextColor = Color(NCBrandColor.shared.brandText)
  35. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
  36. Image("buttonAddImage")
  37. .resizable()
  38. .renderingMode(.template)
  39. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  40. .padding(10)
  41. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  42. .clipShape(Circle())
  43. .scaledToFit()
  44. .frame(width: geo.size.width / 4, height: sizeButton)
  45. })
  46. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: {
  47. Image("buttonAddScan")
  48. .resizable()
  49. .renderingMode(.template)
  50. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  51. .padding(10)
  52. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  53. .clipShape(Circle())
  54. .scaledToFit()
  55. .frame(width: geo.size.width / 4, height: sizeButton)
  56. })
  57. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: {
  58. Image("note.text")
  59. .resizable()
  60. .renderingMode(.template)
  61. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  62. .padding(10)
  63. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  64. .clipShape(Circle())
  65. .scaledToFit()
  66. .frame(width: geo.size.width / 4, height: sizeButton)
  67. })
  68. Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: {
  69. Image("microphone")
  70. .resizable()
  71. .renderingMode(.template)
  72. .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
  73. .padding(10)
  74. .background(entry.isPlaceholder ? placeholderColor : brandColor)
  75. .clipShape(Circle())
  76. .scaledToFit()
  77. .frame(width: geo.size.width / 4, height: sizeButton)
  78. })
  79. }
  80. .frame(width: geo.size.width, height: geo.size.height, alignment: .center)
  81. .redacted(reason: entry.isPlaceholder ? .placeholder : [])
  82. HStack {
  83. Image(systemName: entry.footerImage)
  84. .resizable()
  85. .scaledToFit()
  86. .frame(width: 15, height: 15)
  87. .foregroundColor(entry.isPlaceholder ? Color(white: 0.2) : Color(NCBrandColor.shared.brand))
  88. Text(entry.footerText)
  89. .font(.caption2)
  90. .padding(.trailing, 13.0)
  91. }
  92. .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
  93. }.background(ContainerRelativeShape().fill(Color.init(.sRGB, red: 0.89, green: 0.89, blue: 0.89, opacity: 0.75)))
  94. }
  95. }
  96. }
  97. struct ToolbarWidget_Previews: PreviewProvider {
  98. static var previews: some View {
  99. let entry = ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
  100. ToolbarWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemMedium))
  101. }
  102. }