Browse Source

coding

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana 2 năm trước cách đây
mục cha
commit
41b891a078

BIN
Widget/Assets.xcassets/nextcloud.imageset/nextcloud-icon29@1x.png


+ 1 - 1
Widget/Assets.xcassets/nextcloud.imageset/Contents.json → Widget/Assets.xcassets/widget.imageset/Contents.json

@@ -1,7 +1,7 @@
 {
 {
   "images" : [
   "images" : [
     {
     {
-      "filename" : "nextcloud-icon29@1x.png",
+      "filename" : "icons8-widgetsmith-250.png",
       "idiom" : "universal"
       "idiom" : "universal"
     }
     }
   ],
   ],

BIN
Widget/Assets.xcassets/widget.imageset/icons8-widgetsmith-250.png


+ 20 - 17
Widget/Dashboard/DashboardData.swift

@@ -53,16 +53,16 @@ struct DashboardDataButton: Hashable {
 }
 }
 
 
 let dashboardDatasTest: [DashboardData] = [
 let dashboardDatasTest: [DashboardData] = [
-    .init(id: 0, title: "title0", subTitle: "subTitle-description0", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 1, title: "title1", subTitle: "subTitle-description1", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 2, title: "title2", subTitle: "subTitle-description2", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 3, title: "title3", subTitle: "subTitle-description3", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 4, title: "title4", subTitle: "subTitle-description4", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 5, title: "title5", subTitle: "subTitle-description5", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 6, title: "title6", subTitle: "subTitle-description6", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 7, title: "title7", subTitle: "subTitle-description7", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 8, title: "title8", subTitle: "subTitle-description8", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil),
-    .init(id: 9, title: "title9", subTitle: "subTitle-description9", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "nextcloud")!, buttons: nil)
+    .init(id: 0, title: "title0", subTitle: "subTitle-description0", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 1, title: "title1", subTitle: "subTitle-description1", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 2, title: "title2", subTitle: "subTitle-description2", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 3, title: "title3", subTitle: "subTitle-description3", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 4, title: "title4", subTitle: "subTitle-description4", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 5, title: "title5", subTitle: "subTitle-description5", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 6, title: "title6", subTitle: "subTitle-description6", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 7, title: "title7", subTitle: "subTitle-description7", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 8, title: "title8", subTitle: "subTitle-description8", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil),
+    .init(id: 9, title: "title9", subTitle: "subTitle-description9", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!, buttons: nil)
 ]
 ]
 
 
 func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: DashboardDataEntry) -> Void) {
 func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: DashboardDataEntry) -> Void) {
@@ -85,11 +85,11 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
     }
     }
     
     
     if isPreview {
     if isPreview {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "nextcloud")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
     }
     }
 
 
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
     guard let account = NCManageDatabase.shared.getActiveAccount() else {
-        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "nextcloud")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+        return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
     }
     }
     
     
     // NETWORKING
     // NETWORKING
@@ -122,8 +122,7 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
     let result = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
     let result = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
     let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
     let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
     let title = result?.title ?? id
     let title = result?.title ?? id
-    var titleImage = UIImage()
-    var fileId = ""
+    var titleImage = UIImage(named: "widget")!
 
 
     if let fileName = result?.iconClass {
     if let fileName = result?.iconClass {
         let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
         let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
@@ -148,16 +147,20 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
                         var link = URL(string: "https://")!
                         var link = URL(string: "https://")!
                         if let entryLink = item.link, let url = URL(string: entryLink){ link = url }
                         if let entryLink = item.link, let url = URL(string: entryLink){ link = url }
                         var icon = UIImage(named: "file")!
                         var icon = UIImage(named: "file")!
-                        
+                        var iconFileName: String?
+
                         if let iconUrl = item.iconUrl, let url = URL(string: iconUrl) {
                         if let iconUrl = item.iconUrl, let url = URL(string: iconUrl) {
                             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
                             if let urlComponents = URLComponents(url: url, resolvingAgainstBaseURL: false) {
                                 let queryItems = urlComponents.queryItems
                                 let queryItems = urlComponents.queryItems
                                 if let item = CCUtility.value(forKey: "fileId", fromQueryItems: queryItems) {
                                 if let item = CCUtility.value(forKey: "fileId", fromQueryItems: queryItems) {
-                                    fileId = item
+                                    iconFileName = item
+                                } else {
+                                    let path = (urlComponents.path as NSString)
+                                    iconFileName = ((path.lastPathComponent) as NSString).deletingPathExtension
                                 }
                                 }
                             }
                             }
                             let semaphore = Semaphore()
                             let semaphore = Semaphore()
-                            NCUtility.shared.getImageUserData(url: url, fileName: fileId , size: 128, write: false) { image in
+                            NCUtility.shared.getImageUserData(url: url, fileName: iconFileName , size: 128) { image in
                                 if let image = image {
                                 if let image = image {
                                     icon = image
                                     icon = image
                                 }
                                 }

+ 1 - 1
Widget/Dashboard/DashboardWidgetProvider.swift

@@ -33,7 +33,7 @@ struct DashboardWidgetProvider: IntentTimelineProvider {
     func placeholder(in context: Context) -> Entry {
     func placeholder(in context: Context) -> Entry {
         let datasPlaceholder = Array(dashboardDatasTest[0...nextcloudItems - 1])
         let datasPlaceholder = Array(dashboardDatasTest[0...nextcloudItems - 1])
         let title = "Dashboard"
         let title = "Dashboard"
-        let titleImage = UIImage(named: "nextcloud")!
+        let titleImage = UIImage(named: "widget")!
         return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
         return Entry(date: Date(), datas: datasPlaceholder, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " widget")
     }
     }
 
 

+ 1 - 1
Widget/Dashboard/DashboardWidgetView.swift

@@ -122,7 +122,7 @@ struct DashboardWidget_Previews: PreviewProvider {
     static var previews: some View {
     static var previews: some View {
         let datas = Array(dashboardDatasTest[0...dashboaardItems - 1])
         let datas = Array(dashboardDatasTest[0...dashboaardItems - 1])
         let title = "Dashboard"
         let title = "Dashboard"
-        let titleImage = UIImage(named: "nextcloud")!
+        let titleImage = UIImage(named: "widget")!
         let entry = DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
         let entry = DashboardDataEntry(date: Date(), datas: datas, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: "Nextcloud widget")
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
         DashboardWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemLarge))
     }
     }

+ 6 - 6
Widget/Nextcloud/NextcloudData.swift

@@ -44,12 +44,12 @@ struct NextcloudRecentData: Identifiable, Hashable {
 }
 }
 
 
 let recentDatasTest: [NextcloudRecentData] = [
 let recentDatasTest: [NextcloudRecentData] = [
-    .init(id: "1", image: UIImage(named: "nextcloud")!, title: "title1", subTitle: "subTitle-description1", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: "2", image: UIImage(named: "nextcloud")!, title: "title2", subTitle: "subTitle-description2", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: "3", image: UIImage(named: "nextcloud")!, title: "title3", subTitle: "subTitle-description3", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: "4", image: UIImage(named: "nextcloud")!, title: "title4", subTitle: "subTitle-description4", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: "5", image: UIImage(named: "nextcloud")!, title: "title5", subTitle: "subTitle-description5", url: URL(string: "https://nextcloud.com/")!),
-    .init(id: "6", image: UIImage(named: "nextcloud")!, title: "title6", subTitle: "subTitle-description6", url: URL(string: "https://nextcloud.com/")!)
+    .init(id: "1", image: UIImage(named: "widget")!, title: "title1", subTitle: "subTitle-description1", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: "2", image: UIImage(named: "widget")!, title: "title2", subTitle: "subTitle-description2", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: "3", image: UIImage(named: "widget")!, title: "title3", subTitle: "subTitle-description3", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: "4", image: UIImage(named: "widget")!, title: "title4", subTitle: "subTitle-description4", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: "5", image: UIImage(named: "widget")!, title: "title5", subTitle: "subTitle-description5", url: URL(string: "https://nextcloud.com/")!),
+    .init(id: "6", image: UIImage(named: "widget")!, title: "title6", subTitle: "subTitle-description6", url: URL(string: "https://nextcloud.com/")!)
 ]
 ]
 
 
 func getTitleNextcloudWidget() -> String {
 func getTitleNextcloudWidget() -> String {

+ 26 - 23
iOSClient/Utility/NCUtility.swift

@@ -1023,35 +1023,38 @@ class NCUtility: NSObject {
         return imagePreview
         return imagePreview
     }
     }
     
     
-    func getImageUserData(url: URL, fileName: String, size: CGFloat, write: Bool = true,completition: @escaping (_ image: UIImage?) -> () = { _ in }) {
+    func getImageUserData(url: URL, fileName: String?, size: CGFloat, completition: @escaping (_ image: UIImage?) -> () = { _ in }) {
         
         
-        let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
         let size = CGSize(width: size, height: size)
         let size = CGSize(width: size, height: size)
         let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
         let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
+
+        if let fileName = fileName {
+            let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
+            if FileManager().fileExists(atPath: fileNamePath) {
+                return completition(UIImage(contentsOfFile: fileNamePath))
+            }
+        }
         
         
-        if !FileManager().fileExists(atPath: fileNamePath) {
-            NextcloudKit.shared.getPreview(url: url, options: options) { account, data, error in
-                var image: UIImage?
-                if error == .success {
-                    guard let data = data else { return completition(nil) }
-                    if let uiImage = UIImage(data: data) {
-                        image = uiImage.resizeImage(size: size)
-                    } else if let svgImage = SVGKImage(data: data) {
-                        svgImage.size = size
-                        image = svgImage.uiImage
-                    } else {
-                        print("error")
-                    }
-                    if let image = image, write {
-                        do {
-                            try image.pngData()?.write(to: URL(fileURLWithPath: fileNamePath), options: .atomic)
-                        } catch { }
-                    }
+        NextcloudKit.shared.getPreview(url: url, options: options) { account, data, error in
+            var image: UIImage?
+            if error == .success {
+                guard let data = data else { return completition(nil) }
+                if let uiImage = UIImage(data: data) {
+                    image = uiImage.resizeImage(size: size)
+                } else if let svgImage = SVGKImage(data: data) {
+                    svgImage.size = size
+                    image = svgImage.uiImage
+                } else {
+                    print("error")
+                }
+                if let image = image, let fileName = fileName {
+                    do {
+                        let fileNamePath: String = CCUtility.getDirectoryUserData() + "/" + fileName + ".png"
+                        try image.pngData()?.write(to: URL(fileURLWithPath: fileNamePath), options: .atomic)
+                    } catch { }
                 }
                 }
-                completition(image)
             }
             }
-        } else {
-            completition(UIImage(contentsOfFile: fileNamePath))
+            completition(image)
         }
         }
     }
     }
 }
 }