Browse Source

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 years ago
parent
commit
9c588a4a06

+ 7 - 5
Widget/Files/FilesData.swift

@@ -29,6 +29,8 @@ struct FilesDataEntry: TimelineEntry {
     let date: Date
     let datas: [FilesData]
     let isPlaceholder: Bool
+    let userId: String
+    let url: String
     let tile: String
     let footerImage: String
     let footerText: String
@@ -88,7 +90,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
     var account: tableAccount?
 
     if isPreview {
-        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, tile: getTitleFilesWidget(account: nil), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files"))
+        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files"))
     }
 
     let accountIdentifier: String = configuration?.accounts?.identifier ?? "active"
@@ -99,7 +101,7 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
     }
 
     guard let account = account else {
-        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, tile: getTitleFilesWidget(account: nil), footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: getTitleFilesWidget(account: nil), footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
 
     @Sendable func isLive(file: NKFile, files: [NKFile]) -> Bool {
@@ -254,16 +256,16 @@ func getFilesDataEntry(configuration: AccountIntent?, isPreview: Bool, displaySi
             let footerText = "Files " + NSLocalizedString("_of_", comment: "") +  " " + account.displayName + alias
 
             if error != .success {
-                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, tile: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
+                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: account.userId, url: account.urlBase, tile: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
             } else if datas.isEmpty {
                 var footerText = NSLocalizedString("_no_data_available_", comment: "")
                 let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
                 if serverVersionMajor < NCGlobal.shared.nextcloudVersion25 {
                     footerText = NSLocalizedString("_widget_available_nc25_", comment: "")
                 }
-                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
+                completion(FilesDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: account.userId, url: account.urlBase, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
             } else {
-                completion(FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
+                completion(FilesDataEntry(date: Date(), datas: datas, isPlaceholder: false, userId: account.userId, url: account.urlBase, tile: title, footerImage: "checkmark.icloud", footerText: footerText))
             }
         }
     }

+ 1 - 1
Widget/Files/FilesWidgetProvider.swift

@@ -34,7 +34,7 @@ struct FilesWidgetProvider: IntentTimelineProvider {
         let filesItems = getFilesItems(displaySize: context.displaySize)
         let datasPlaceholder = Array(filesDatasTest[0...filesItems - 1])
         let title = getTitleFilesWidget(account: nil)
-        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, tile: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files")
+        return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, userId: "", url: "", tile: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " files")
     }
 
     func getSnapshot(for configuration: AccountIntent, in context: Context, completion: @escaping (Entry) -> Void) {

+ 14 - 7
Widget/Files/FilesWidgetView.swift

@@ -27,9 +27,16 @@ 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
             
             ZStack(alignment: .topLeading) {
@@ -90,7 +97,7 @@ struct FilesWidgetView: View {
 
                     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 +109,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 +121,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 +133,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)
@@ -163,7 +170,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, userId: "", url: "", tile: "Good afternoon, Marino Faggiana", footerImage: "checkmark.icloud", footerText: "Nextcloud files")
         FilesWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
 }

+ 13 - 3
Widget/Toolbar/ToolbarData.swift

@@ -26,19 +26,29 @@ import WidgetKit
 struct ToolbarDataEntry: TimelineEntry {
     let date: Date
     let isPlaceholder: Bool
+    let userId: String
+    let url: String
     let footerImage: String
     let footerText: String
 }
 
 func getToolbarDataEntry(isPreview: Bool, completion: @escaping (_ entry: ToolbarDataEntry) -> Void) {
 
+    var userId = ""
+    var url = ""
+
+    if let account = NCManageDatabase.shared.getActiveAccount() {
+        userId = account.userId
+        url = account.urlBase
+    }
+
     if isPreview {
-        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
+        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, userId: userId, url: url, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
     }
 
     if NCManageDatabase.shared.getActiveAccount() == nil {
-        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, userId: userId, url: url, footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
 
-    completion(ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
+    completion(ToolbarDataEntry(date: Date(), isPlaceholder: false, userId: userId, url: url, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
 }

+ 1 - 1
Widget/Toolbar/ToolbarWidgetProvider.swift

@@ -29,7 +29,7 @@ struct ToolbarWidgetProvider: TimelineProvider {
     typealias Entry = ToolbarDataEntry
 
     func placeholder(in context: Context) -> Entry {
-        return Entry(date: Date(), isPlaceholder: true, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
+        return Entry(date: Date(), isPlaceholder: true, userId: "", url: "", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
     }
 
     func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {

+ 12 - 5
Widget/Toolbar/ToolbarWidgetView.swift

@@ -30,6 +30,13 @@ struct ToolbarWidgetView: View {
 
     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
 
             ZStack(alignment: .topLeading) {
@@ -41,7 +48,7 @@ struct ToolbarWidgetView: View {
 
                     let sizeButton: CGFloat = 65
 
-                    Link(destination: entry.isPlaceholder ? NCGlobal.shared.widgetActionNoAction : NCGlobal.shared.widgetActionUploadAsset, label: {
+                    Link(destination: entry.isPlaceholder ? linkNoAction : linkActionUploadAsset, label: {
                         Image("addImage")
                             .resizable()
                             .renderingMode(.template)
@@ -53,7 +60,7 @@ struct ToolbarWidgetView: 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)
@@ -65,7 +72,7 @@ struct ToolbarWidgetView: 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)
@@ -77,7 +84,7 @@ struct ToolbarWidgetView: 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()
                             .foregroundColor(entry.isPlaceholder ? Color(.systemGray4) : Color(NCBrandColor.shared.brandText))
@@ -112,7 +119,7 @@ struct ToolbarWidgetView: View {
 
 struct ToolbarWidget_Previews: PreviewProvider {
     static var previews: some View {
-        let entry = ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
+        let entry = ToolbarDataEntry(date: Date(), isPlaceholder: false, userId: "", url: "",  footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
         ToolbarWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemMedium))
     }
 }

+ 1 - 1
iOSClient/AppDelegate.swift

@@ -786,7 +786,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
 
         /*
          Example:
-         nextcloud://open-action?action=create-voice-memo
+         nextcloud://open-action?action=create-voice-memo&url=https://cloud.nextcloud.com&user=marinofaggiana
          */
 
         if scheme == "nextcloud" && action == "open-action" {

+ 5 - 5
iOSClient/NCGlobal.swift

@@ -395,11 +395,11 @@ class NCGlobal: NSObject {
     
     // 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")!
+    let widgetActionNoAction                                    = "nextcloud://open-action?action=no-action"
+    let widgetActionUploadAsset                                 = "nextcloud://open-action?action=upload-asset"
+    let widgetActionScanDocument                                = "nextcloud://open-action?action=add-scan-document"
+    let widgetActionTextDocument                                = "nextcloud://open-action?action=create-text-document"
+    let widgetActionVoiceMemo                                   = "nextcloud://open-action?action=create-voice-memo"
     
     // APPCONFIG
     //