浏览代码

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 年之前
父节点
当前提交
a54606d5d3
共有 2 个文件被更改,包括 17 次插入25 次删除
  1. 6 8
      Widget/Dashboard/DashboardData.swift
  2. 11 17
      Widget/Dashboard/DashboardWidgetView.swift

+ 6 - 8
Widget/Dashboard/DashboardData.swift

@@ -26,7 +26,7 @@ import NextcloudKit
 import Queuer
 import RealmSwift
 
-var dashboaardItems = 5
+let dashboaardItems = 5
 
 struct DashboardDataEntry: TimelineEntry {
     let date: Date
@@ -122,6 +122,7 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
     }
     
     let (tableDashboard, tableButton) = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
+    let existsButton: Int = tableButton == nil ? 0 : 1
     let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
     let title = tableDashboard?.title ?? id
     var titleImage = UIImage(named: "widget")!
@@ -132,11 +133,7 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
             titleImage = image.imageColor(NCBrandColor.shared.label)
         }
     }
-    
-    if tableButton?.count ?? 0 > 0 {
-        dashboaardItems -= 1
-    }
-
+        
     NextcloudKit.shared.getDashboardWidgetsApplication(id, options: options) { account, results, data, error in
         
         var datas = [DashboardData]()
@@ -145,8 +142,8 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
             for result in results {
                 if let items = result.items {
                     var counter: Int = 0
+                    let maxCounter = dashboaardItems - existsButton
                     for item in items {
-                        
                         counter += 1
                         let title = item.title ?? ""
                         let subtitle = item.subtitle ?? ""
@@ -177,7 +174,8 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
                         
                         let data = DashboardData(id: counter, title: title, subTitle: subtitle, link: link, icon: icon)
                         datas.append(data)
-                        if datas.count == dashboaardItems { break}
+                        
+                        if datas.count == maxCounter { break }
                     }
                 }
             }

+ 11 - 17
Widget/Dashboard/DashboardWidgetView.swift

@@ -27,6 +27,8 @@ import WidgetKit
 struct DashboardWidgetView: View {
 
     var entry: DashboardDataEntry
+    let brandColor = Color(NCBrandColor.shared.brand)
+    let brandTextColor = Color(NCBrandColor.shared.brandText)
     
     var body: some View {
         
@@ -40,8 +42,6 @@ struct DashboardWidgetView: View {
                         .resizable()
                         .scaledToFill()
                         .frame(width: 20, height: 20)
-                        .clipped()
-                        .cornerRadius(5)
                     
                     Text(entry.title)
                         .font(.system(size: 15))
@@ -109,30 +109,24 @@ struct DashboardWidgetView: View {
                     
                     HStack(spacing: 0) {
 
-                        let sizeButton: CGFloat = 45
-                        let placeholderColor = Color(white: 0.8)
                         let brandColor = Color(NCBrandColor.shared.brand)
                         let brandTextColor = Color(NCBrandColor.shared.brandText)
 
                         ForEach(tableButton, id: \.index) { element in
-                            Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
+                            Link(destination: URL(string: element.link)! , label: {
                                 
                                 Text(element.text)
-                                    .fontWeight(.bold)
-                                    .font(.title)
-                                    .padding()
-                                    .background(Color.purple)
-                                    .foregroundColor(.white)
-                                    .padding(10)
-                                    .border(Color.purple, width: 5)
-                                    .cornerRadius(40)
+                                    .font(.system(size: 18))
+                                    .padding(7)
+                                    .background(brandColor)
+                                    .foregroundColor(brandTextColor)
+                                    .border(brandColor, width: 1)
+                                    .cornerRadius(16)
                             })
-                            
+                            .frame(width: geo.size.width / 2)
                         }
                     }
-                    .frame(width: geo.size.width, height: geo.size.height - 25, alignment: .bottomTrailing)
-                    .redacted(reason: entry.isPlaceholder ? .placeholder : [])
-                    
+                    .frame(width: geo.size.width, height: geo.size.height - 25, alignment: .bottom)
                 }
                 
                 HStack {