瀏覽代碼

improved widget

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 年之前
父節點
當前提交
819d2317dd

+ 28 - 18
Widget/Nextcloud/NextcloudWidgetView.swift

@@ -61,6 +61,8 @@ struct NextcloudWidgetView: View {
                                 
                                 HStack {
                                     
+                                    let subTitleColor = Color(white: 0.5)
+                                    
                                     Image(uiImage: element.image)
                                         .resizable()
                                         .scaledToFill()
@@ -76,7 +78,7 @@ struct NextcloudWidgetView: View {
                                         
                                         Text(element.subTitle)
                                             .font(.system(size: CGFloat(10)))
-                                            .foregroundColor(Color(white: 0.5))
+                                            .foregroundColor(subTitleColor)
                                     }
                                     Spacer()
                                 }
@@ -93,52 +95,57 @@ struct NextcloudWidgetView: View {
 
                 HStack(spacing: 0) {
 
-                    Link(destination: URL(string: "nextcloud://open-action?action=upload-asset")!, label: {
+                    let sizeButton: CGFloat = 50
+                    let placeholderColor = Color(white: 0.8)
+                    let brandColor = Color(NCBrandColor.shared.brand)
+                    let brandTextColor = Color(NCBrandColor.shared.brandText)
+                    
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
                         Image("buttonAddImage")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
-                            .frame(width: geo.size.width / 4, height: 50)
+                            .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: URL(string: "nextcloud://open-action?action=add-scan-document")!, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: {
                         Image("buttonAddScan")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
-                            .frame(width: geo.size.width / 4, height: 50)
+                            .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: URL(string: "nextcloud://open-action?action=create-text-document")!, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: {
                         Image("note.text")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
-                            .frame(width: geo.size.width / 4, height: 50)
+                            .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: URL(string: "nextcloud://open-action?action=create-voice-memo")!, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: {
                         Image("microphone")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
-                            .frame(width: geo.size.width / 4, height: 50)
+                            .frame(width: geo.size.width / 4, height: sizeButton)
                     })
                 }
                 .frame(width: geo.size.width, height: geo.size.height - 35, alignment: .bottomTrailing)
@@ -146,11 +153,14 @@ struct NextcloudWidgetView: View {
 
                 HStack {
 
+                    let placeholderColor = Color(white: 0.2)
+                    let brandColor = Color(NCBrandColor.shared.brand)
+
                     Image(systemName: entry.footerImage)
                         .resizable()
                         .scaledToFit()
                         .frame(width: 15, height: 15)
-                        .foregroundColor(entry.isPlaceholder ? Color(white: 0.2) : Color(NCBrandColor.shared.brand))
+                        .foregroundColor(entry.isPlaceholder ? placeholderColor : brandColor)
                     
                     Text(entry.footerText)
                         .font(.caption2)

+ 15 - 15
Widget/Toolbar/ToolbarWidgetView.swift

@@ -37,53 +37,53 @@ struct ToolbarWidgetView: View {
                 HStack(spacing: 0) {
                     
                     let sizeButton: CGFloat = 65
-                    let colorPlaceholder = Color(white: 0.8)
+                    let placeholderColor = Color(white: 0.8)
                     let brandColor = Color(NCBrandColor.shared.brand)
-                    let brandColorText = Color(NCBrandColor.shared.brandText)
+                    let brandTextColor = Color(NCBrandColor.shared.brandText)
 
-                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.actionNoAction : NCGlobal.shared.actionUploadAsset, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
                         Image("buttonAddImage")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? colorPlaceholder : brandColorText)
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? colorPlaceholder : brandColor)
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
                             .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.actionNoAction : NCGlobal.shared.actionScanDocument, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionScanDocument, label: {
                         Image("buttonAddScan")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? colorPlaceholder : brandColorText)
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? colorPlaceholder : brandColor)
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
                             .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.actionNoAction : NCGlobal.shared.actionTextDocument, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionTextDocument, label: {
                         Image("note.text")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? colorPlaceholder : brandColorText)
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? colorPlaceholder : brandColor)
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
                             .frame(width: geo.size.width / 4, height: sizeButton)
                     })
 
-                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.actionNoAction : NCGlobal.shared.actionVoiceMemo, label: {
+                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionVoiceMemo, label: {
                         Image("microphone")
                             .resizable()
                             .renderingMode(.template)
-                            .foregroundColor(entry.isPlaceholder ? colorPlaceholder : brandColorText)
+                            .foregroundColor(entry.isPlaceholder ? placeholderColor : brandTextColor)
                             .padding(10)
-                            .background(entry.isPlaceholder ? colorPlaceholder : brandColor)
+                            .background(entry.isPlaceholder ? placeholderColor : brandColor)
                             .clipShape(Circle())
                             .scaledToFit()
                             .frame(width: geo.size.width / 4, height: sizeButton)
@@ -112,7 +112,7 @@ struct ToolbarWidgetView: View {
 
 struct ToolbarWidget_Previews: PreviewProvider {
     static var previews: some View {
-        let entry = ToolbarDataEntry(date: Date(), isPlaceholder: true, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
+        let entry = ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
         ToolbarWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemMedium))
     }
 }

+ 5 - 5
iOSClient/AppDelegate.swift

@@ -846,7 +846,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                 guard let actionScheme = CCUtility.value(forKey: "action", fromQueryItems: queryItems), let rootViewController = window?.rootViewController else { return false }
                 
                 switch actionScheme {
-                case "upload-asset":
+                case NCGlobal.shared.actionUploadAsset:
 
                     NCAskAuthorization.shared.askAuthorizationPhotoLibrary(viewController: rootViewController) { hasPermission in
                         if hasPermission {
@@ -854,13 +854,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                         }
                     }
                     
-                case "add-scan-document":
+                case NCGlobal.shared.actionScanDocument:
                     
                     if #available(iOS 13.0, *) {
                         NCCreateScanDocument.shared.openScannerDocument(viewController: rootViewController)
                     }
                     
-                case "create-text-document":
+                case NCGlobal.shared.actionTextDocument:
                     
                     guard let navigationController = UIStoryboard(name: "NCCreateFormUploadDocuments", bundle: nil).instantiateInitialViewController(), let directEditingCreators = NCManageDatabase.shared.getDirectEditingCreators(account: account), let directEditingCreator = directEditingCreators.first(where: { $0.editor == NCGlobal.shared.editorText}) else { return false }
                     
@@ -875,7 +875,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
                     rootViewController.present(navigationController, animated: true, completion: nil)
                     
-                case "create-voice-memo":
+                case NCGlobal.shared.actionVoiceMemo:
                     
                     NCAskAuthorization.shared.askAuthorizationAudioRecord(viewController: rootViewController) { hasPermission in
                         if hasPermission {
@@ -892,7 +892,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
                     }
 
                 default:
-                    print("")
+                    print("No action")
                 }
             }
         }

+ 13 - 5
iOSClient/NCGlobal.swift

@@ -384,9 +384,17 @@ class NCGlobal: NSObject {
     
     // ACTION
     //
-    let actionNoAction                                          = URL(string: "nextcloud://open-action?action=no-action")!
-    let actionUploadAsset                                       = URL(string: "nextcloud://open-action?action=upload-asset")!
-    let actionScanDocument                                      = URL(string: "nextcloud://open-action?action=add-scan-document")!
-    let actionTextDocument                                      = URL(string: "nextcloud://open-action?action=create-text-document")!
-    let actionVoiceMemo                                         = URL(string: "nextcloud://open-action?action=create-voice-memo")!
+    let actionNoAction                                          = "no-action"
+    let actionUploadAsset                                       = "upload-asset"
+    let actionScanDocument                                      = "add-scan-document"
+    let actionTextDocument                                      = "create-text-document"
+    let actionVoiceMemo                                         = "create-voice-memo"
+    
+    // WIDGET ACTION
+    //
+    let widgetActionNoAction                                    = URL(string: "nextcloud://open-action?action=no-action")!
+    let widgetActionUploadAsset                                 = URL(string: "nextcloud://open-action?action=upload-asset")!
+    let widgetActionScanDocument                                = URL(string: "nextcloud://open-action?action=add-scan-document")!
+    let widgetActionTextDocument                                = URL(string: "nextcloud://open-action?action=create-text-document")!
+    let widgetActionVoiceMemo                                   = URL(string: "nextcloud://open-action?action=create-voice-memo")!
 }