diff options
Diffstat (limited to 'Widget/Files/FilesWidgetView.swift')
-rw-r--r-- | Widget/Files/FilesWidgetView.swift | 113 |
1 files changed, 69 insertions, 44 deletions
diff --git a/Widget/Files/FilesWidgetView.swift b/Widget/Files/FilesWidgetView.swift index 0cd1fb963..9b0c6c05a 100644 --- a/Widget/Files/FilesWidgetView.swift +++ b/Widget/Files/FilesWidgetView.swift @@ -27,11 +27,33 @@ import WidgetKit struct FilesWidgetView: View { var entry: FilesDataEntry - + var body: some View { - + + let parameterLink = "&user=\(entry.userId)&url=\(entry.url)" + let linkNoAction: URL = URL(string: NCGlobal.shared.widgetActionNoAction + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionNoAction + parameterLink)! : URL(string: NCGlobal.shared.widgetActionNoAction)! + let linkActionUploadAsset: URL = URL(string: NCGlobal.shared.widgetActionUploadAsset + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionUploadAsset + parameterLink)! : URL(string: NCGlobal.shared.widgetActionUploadAsset)! + let linkActionScanDocument: URL = URL(string: NCGlobal.shared.widgetActionScanDocument + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionScanDocument + parameterLink)! : URL(string: NCGlobal.shared.widgetActionScanDocument)! + let linkActionTextDocument: URL = URL(string: NCGlobal.shared.widgetActionTextDocument + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionTextDocument + parameterLink)! : URL(string: NCGlobal.shared.widgetActionTextDocument)! + let linkActionVoiceMemo: URL = URL(string: NCGlobal.shared.widgetActionVoiceMemo + parameterLink) != nil ? URL(string: NCGlobal.shared.widgetActionVoiceMemo + parameterLink)! : URL(string: NCGlobal.shared.widgetActionVoiceMemo)! + GeometryReader { geo in - + + if entry.isEmpty { + VStack(alignment: .center) { + Image(systemName: "checkmark") + .resizable() + .scaledToFit() + .frame(width: 50, height: 50) + Text(NSLocalizedString("_no_items_", comment: "")) + .font(.system(size: 25)) + .padding() + Text(NSLocalizedString("_check_back_later_", comment: "")) + .font(.system(size: 15)) + } + .frame(width: geo.size.width, height: geo.size.height) + } + ZStack(alignment: .topLeading) { HStack() { @@ -45,52 +67,54 @@ struct FilesWidgetView: View { } .frame(width: geo.size.width - 20) .padding([.top, .leading, .trailing], 10) - - VStack(alignment: .leading) { - - VStack(spacing: 0) { - - ForEach(entry.datas, id: \.id) { element in - - Link(destination: element.url) { - - HStack { - - Image(uiImage: element.image) - .resizable() - .scaledToFill() - .frame(width: 35, height: 35) - .clipped() - .cornerRadius(5) - - VStack(alignment: .leading, spacing: 2) { - - Text(element.title) - .font(.system(size: 12)) - .fontWeight(.regular) - - Text(element.subTitle) - .font(.system(size: CGFloat(10))) - .foregroundColor(Color(.systemGray)) + + if !entry.isEmpty { + VStack(alignment: .leading) { + + VStack(spacing: 0) { + + ForEach(entry.datas, id: \.id) { element in + + Link(destination: element.url) { + + HStack { + + Image(uiImage: element.image) + .resizable() + .scaledToFill() + .frame(width: 35, height: 35) + .clipped() + .cornerRadius(5) + + VStack(alignment: .leading, spacing: 2) { + + Text(element.title) + .font(.system(size: 12)) + .fontWeight(.regular) + + Text(element.subTitle) + .font(.system(size: CGFloat(10))) + .foregroundColor(Color(.systemGray)) + } + Spacer() } - Spacer() + .padding(.leading, 10) + .frame(height: 50) } - .padding(.leading, 10) - .frame(height: 50) + Divider() + .padding(.leading, 54) } - Divider() - .padding(.leading, 54) } } + .padding(.top, 30) + .redacted(reason: entry.isPlaceholder ? .placeholder : []) } - .padding(.top, 30) - .redacted(reason: entry.isPlaceholder ? .placeholder : []) HStack(spacing: 0) { let sizeButton: CGFloat = 40 - Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: { + Link(destination: entry.isPlaceholder ? linkNoAction : linkActionUploadAsset, label: { Image("addImage") .resizable() .renderingMode(.template) @@ -102,7 +126,7 @@ struct FilesWidgetView: View { .frame(width: geo.size.width / 4, height: sizeButton) }) - Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: { + Link(destination: entry.isPlaceholder ? linkNoAction : linkActionScanDocument, label: { Image("scan") .resizable() .renderingMode(.template) @@ -114,7 +138,7 @@ struct FilesWidgetView: View { .frame(width: geo.size.width / 4, height: sizeButton) }) - Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: { + Link(destination: entry.isPlaceholder ? linkNoAction : linkActionTextDocument, label: { Image("note.text") .resizable() .renderingMode(.template) @@ -126,7 +150,7 @@ struct FilesWidgetView: View { .frame(width: geo.size.width / 4, height: sizeButton) }) - Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: { + Link(destination: entry.isPlaceholder ? linkNoAction : linkActionVoiceMemo, label: { Image("microphone") .resizable() .renderingMode(.template) @@ -151,10 +175,11 @@ struct FilesWidgetView: View { Text(entry.footerText) .font(.caption2) - .padding(.trailing, 13.0) + .lineLimit(1) .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brand)) } - .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing) + .padding(.horizontal, 15.0) + .frame(maxWidth: geo.size.width, maxHeight: geo.size.height - 2, alignment: .bottomTrailing) } } } @@ -163,7 +188,7 @@ struct FilesWidgetView: View { struct FilesWidget_Previews: PreviewProvider { static var previews: some View { let datas = Array(filesDatasTest[0...4]) - let entry = FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files") + let entry = FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, isEmpty: true, userId: "", url: "", tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files") FilesWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge)) } } |