Browse Source

coding

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

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -127,6 +127,7 @@
 		F710FC84277B7D3500AA9FBF /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F710FC83277B7D3500AA9FBF /* RealmSwift */; };
 		F710FC86277B7D3F00AA9FBF /* Realm in Frameworks */ = {isa = PBXBuildFile; productRef = F710FC85277B7D3F00AA9FBF /* Realm */; };
 		F710FC88277B7D3F00AA9FBF /* RealmSwift in Frameworks */ = {isa = PBXBuildFile; productRef = F710FC87277B7D3F00AA9FBF /* RealmSwift */; };
+		F711D63128F44801003F43C8 /* IntentHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C9739428F17131002C43E2 /* IntentHandler.swift */; };
 		F7134186259747BA00768D21 /* NCPushNotification.m in Sources */ = {isa = PBXBuildFile; fileRef = F7134185259747BA00768D21 /* NCPushNotification.m */; };
 		F713FF002472764100214AF6 /* UIImage+animatedGIF.m in Sources */ = {isa = PBXBuildFile; fileRef = F713FEFF2472764100214AF6 /* UIImage+animatedGIF.m */; };
 		F71459D21D12E3B700CAFEEC /* CCUtility.m in Sources */ = {isa = PBXBuildFile; fileRef = F7053E3D1C639DF500741EA5 /* CCUtility.m */; };
@@ -2821,6 +2822,7 @@
 				F7346E1628B0EF5C006CE2D2 /* Widget.swift in Sources */,
 				F78302F828B4C3E100B84583 /* NCManageDatabase+Activity.swift in Sources */,
 				F783030228B4C4B800B84583 /* NCUtility.swift in Sources */,
+				F711D63128F44801003F43C8 /* IntentHandler.swift in Sources */,
 				F72EA95A28B7BD0D00C88F0C /* FilesWidgetView.swift in Sources */,
 				F78302FE28B4C44700B84583 /* NCBrand.swift in Sources */,
 				F793E5A028B7651B005E4B02 /* NCViewCertificateDetails.swift in Sources */,
@@ -3511,6 +3513,7 @@
 				GENERATE_INFOPLIST_FILE = YES;
 				INFOPLIST_FILE = "$(SRCROOT)/iOSClient/Brand/WidgetDashboardIntentHandler.plist";
 				INFOPLIST_KEY_CFBundleDisplayName = WidgetDashboardIntentHandler;
+				INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Nextcloud. All rights reserved.";
 				MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.WidgetDashboardIntentHandler;
@@ -3545,6 +3548,7 @@
 				GENERATE_INFOPLIST_FILE = YES;
 				INFOPLIST_FILE = "$(SRCROOT)/iOSClient/Brand/WidgetDashboardIntentHandler.plist";
 				INFOPLIST_KEY_CFBundleDisplayName = WidgetDashboardIntentHandler;
+				INFOPLIST_KEY_NSHumanReadableCopyright = "Copyright © 2022 Nextcloud. All rights reserved.";
 				MTL_ENABLE_DEBUG_INFO = NO;
 				MTL_FAST_MATH = YES;
 				PRODUCT_BUNDLE_IDENTIFIER = it.twsweb.Nextcloud.WidgetDashboardIntentHandler;

+ 5 - 20
Widget/Dashboard/DashboardData.swift

@@ -79,25 +79,6 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
 
     let dashboardItems = getDashboardItems(displaySize: displaySize, withButton: false)
     let datasPlaceholder = Array(dashboardDatasTest[0...dashboardItems - 1])
-    
-    var id: String = intent?.identifier ?? "activity"
-
-    /*
-    switch intent {
-    case .unknown:
-        id = "recommendations"
-    case .notes:
-        id = "notes"
-    case .deck:
-        id = "deck"
-    case .recommendations:
-        id = "recommendations"
-    case .activity:
-        id = "activity"
-    case .user_status:
-        id = "user_status"
-    }
-    */
 
     if isPreview {
         return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: nil, tableButton: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
@@ -106,7 +87,11 @@ func getDashboardDataEntry(intent: Applications?, isPreview: Bool, displaySize:
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
         return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: nil, tableButton: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", comment: "")))
     }
-    
+
+    guard let id = intent?.identifier else {
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: nil, tableButton: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_data_available_", comment: "")))
+    }
+
     let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor)
 
     guard serverVersionMajor >= NCGlobal.shared.nextcloudVersion25 else {

+ 2 - 0
Widget/Intent/Base.lproj/Dashboard.intentdefinition

@@ -63,6 +63,8 @@
 							<string>Primary</string>
 						</dict>
 					</array>
+					<key>INIntentParameterSupportsDynamicEnumeration</key>
+					<true/>
 					<key>INIntentParameterTag</key>
 					<integer>7</integer>
 					<key>INIntentParameterType</key>

+ 11 - 12
WidgetDashboardIntentHandler/IntentHandler.swift

@@ -11,23 +11,22 @@ import RealmSwift
 
 class IntentHandler: INExtension, DashboardIntentHandling {
 
-    override func handler(for intent: INIntent) -> Any {
-        // This is the default implementation.  If you want different objects to handle different intents,
-        // you can override this and return the handler you want for that particular intent.
+    func provideApplicationsOptionsCollection(for intent: DashboardIntent, with completion: @escaping (INObjectCollection<Applications>?, Error?) -> Void) {
+
+        var applications: [Applications] = []
 
         guard let account = NCManageDatabase.shared.getActiveAccount() else {
-            return self
+            completion(nil, nil)
+            return
         }
 
+        let results = NCManageDatabase.shared.getDashboardWidgetApplications(account: account.account)
+        for result in results {
+            let application = Applications(identifier: result.id, display: result.title)
+            applications.append(application)
+        }
 
-        return self
-    }
-
-    func provideCategoryOptionsCollection(for intent: DashboardIntentHandling, with completion: @escaping (INObjectCollection<Applications>?, Error?) -> Void) {
-
-        let eventCategory = Applications(identifier: "ciao", display: "ciao")
-        let collection = INObjectCollection(items: [eventCategory])
-
+        let collection = INObjectCollection(items: applications)
         completion(collection, nil)
     }
 }

+ 5 - 5
iOSClient/Brand/WidgetDashboardIntentHandler.plist

@@ -2,6 +2,11 @@
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
+	<key>NSAppTransportSecurity</key>
+	<dict>
+		<key>NSAllowsArbitraryLoads</key>
+		<true/>
+	</dict>
 	<key>NSExtension</key>
 	<dict>
 		<key>NSExtensionAttributes</key>
@@ -20,10 +25,5 @@
 		<key>NSExtensionPrincipalClass</key>
 		<string>$(PRODUCT_MODULE_NAME).IntentHandler</string>
 	</dict>
-    <key>NSAppTransportSecurity</key>
-    <dict>
-        <key>NSAllowsArbitraryLoads</key>
-        <true/>
-    </dict>
 </dict>
 </plist>

+ 6 - 0
iOSClient/Data/NCManageDatabase+DashboardWidget.swift

@@ -37,6 +37,12 @@ extension NCManageDatabase {
         
         return (resultDashboard, resultsButton)
     }
+
+    func getDashboardWidgetApplications(account: String) -> Results<tableDashboardWidget> {
+
+        let realm = try! Realm()
+        return realm.objects(tableDashboardWidget.self).filter("account == %@", account)
+    }
     
     func addDashboardWidget(account: String, dashboardWidgets: [NCCDashboardWidget]) {