浏览代码

coding

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 年之前
父节点
当前提交
4c5a65c3cc

+ 8 - 5
Widget/Nextcloud/NextcloudData.swift

@@ -32,6 +32,7 @@ struct NextcloudDataEntry: TimelineEntry {
     let date: Date
     let recentDatas: [RecentData]
     let isPlaceholder: Bool
+    let footerImage: String
     let footerText: String
 }
 
@@ -55,11 +56,11 @@ let recentDatasTest: [RecentData] = [
 func getDataEntry(isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: NextcloudDataEntry) -> Void) {
 
     if isPreview {
-        return completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerText: ""))
+        return completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerImage: "", footerText: NCBrandOptions.shared.brand + " widget"))
     }
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
 
     func isLive(file: NCCommunicationFile, files: [NCCommunicationFile]) -> Bool {
@@ -194,14 +195,16 @@ func getDataEntry(isPreview: Bool, displaySize: CGSize, completion: @escaping (_
             }
 
             let fileInUpload = NCManageDatabase.shared.getNumMetadatasInUpload()
+            let footerText = (fileInUpload == 0) ? "last update \(Date().formatted())"  : "\(fileInUpload) files in uploading"
+            let footerImage = (fileInUpload == 0) ? "checkmark.icloud" : "arrow.triangle.2.circlepath"
 
             // Completion
             if errorCode != 0 {
-                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerText: errorDescription))
+                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerImage: "xmark.icloud", footerText: errorDescription))
             } else if recentDatas.isEmpty {
-                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerText: "\(Date().formatted())"))
+                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerImage: footerImage, footerText: footerText))
             } else {
-                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatas, isPlaceholder: false, footerText: "\(Date().formatted())"))
+                completion(NextcloudDataEntry(date: Date(), recentDatas: recentDatas, isPlaceholder: false, footerImage: footerImage, footerText: footerText))
             }
         }
     }

+ 1 - 1
Widget/Nextcloud/NextcloudWidgetProvider.swift

@@ -29,7 +29,7 @@ struct NextcloudWidgetProvider: TimelineProvider {
     typealias Entry = NextcloudDataEntry
 
     func placeholder(in context: Context) -> Entry {
-        return Entry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerText: "Nextcloud")
+        return Entry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: true, footerImage: "", footerText: NCBrandOptions.shared.brand + " widget")
     }
 
     func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {

+ 14 - 6
Widget/Nextcloud/NextcloudWidgetView.swift

@@ -69,6 +69,7 @@ struct NextcloudWidgetView: View {
                     }
                     Spacer()
                         .frame(width: geo.size.width, height: 16.0)
+                    /*
                     HStack(spacing: 5) {
                         Image(systemName: "arrow.triangle.2.circlepath")
                             .foregroundColor(Color(NCBrandColor.shared.brand))
@@ -80,14 +81,21 @@ struct NextcloudWidgetView: View {
                     HStack(spacing: spacingImageUpload) {
                     }
                     .frame(width: geo.size.width, alignment: .center)
+                    */
                 }
                 .padding(.top, 45)
                 .redacted(reason: entry.isPlaceholder ? .placeholder : [])
-                Text(entry.footerText)
-                    .font(.caption2)
-                    .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottomTrailing)
-                    .padding(.trailing, 10.0)
-                    .padding(.bottom, 5.0)
+                HStack {
+                    Image(systemName: entry.footerImage)
+                        .resizable()
+                        .scaledToFit()
+                        .frame(width: 15, height: 15)
+                        .foregroundColor(Color(NCBrandColor.shared.brand))
+                    Text(entry.footerText)
+                        .font(.caption2)
+                        .padding(.trailing, 10.0)
+                }
+                .frame(maxWidth: geo.size.width, maxHeight: geo.size.height, alignment: .bottomTrailing)
             }
         }
     }
@@ -95,7 +103,7 @@ struct NextcloudWidgetView: View {
 
 struct NextcloudWidget_Previews: PreviewProvider {
     static var previews: some View {
-        let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: false, footerText: NCBrandOptions.shared.brand + " widget")
+        let entry = NextcloudDataEntry(date: Date(), recentDatas: recentDatasTest, isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
         NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }