|
@@ -24,6 +24,7 @@
|
|
|
import WidgetKit
|
|
|
import NextcloudKit
|
|
|
import Queuer
|
|
|
+import RealmSwift
|
|
|
|
|
|
let dashboaardItems = 5
|
|
|
|
|
@@ -31,6 +32,7 @@ struct DashboardDataEntry: TimelineEntry {
|
|
|
let date: Date
|
|
|
let datas: [DashboardData]
|
|
|
let tableDashboard: tableDashboardWidget?
|
|
|
+ let tableButton: Results<tableDashboardWidgetButton>?
|
|
|
let isPlaceholder: Bool
|
|
|
let titleImage: UIImage
|
|
|
let title: String
|
|
@@ -44,7 +46,6 @@ struct DashboardData: Identifiable, Hashable {
|
|
|
let subTitle: String
|
|
|
let link: URL
|
|
|
let icon: UIImage
|
|
|
- let buttons: [DashboardDataButton]?
|
|
|
}
|
|
|
|
|
|
struct DashboardDataButton: Hashable {
|
|
@@ -54,16 +55,16 @@ struct DashboardDataButton: Hashable {
|
|
|
}
|
|
|
|
|
|
let dashboardDatasTest: [DashboardData] = [
|
|
|
- .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)
|
|
|
+ .init(id: 0, title: "title0", subTitle: "subTitle-description0", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 1, title: "title1", subTitle: "subTitle-description1", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 2, title: "title2", subTitle: "subTitle-description2", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 3, title: "title3", subTitle: "subTitle-description3", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 4, title: "title4", subTitle: "subTitle-description4", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 5, title: "title5", subTitle: "subTitle-description5", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 6, title: "title6", subTitle: "subTitle-description6", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 7, title: "title7", subTitle: "subTitle-description7", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 8, title: "title8", subTitle: "subTitle-description8", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!),
|
|
|
+ .init(id: 9, title: "title9", subTitle: "subTitle-description9", link: URL(string: "https://nextcloud.com/")!, icon: UIImage(named: "widget")!)
|
|
|
]
|
|
|
|
|
|
func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: CGSize, completion: @escaping (_ entry: DashboardDataEntry) -> Void) {
|
|
@@ -86,11 +87,11 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
|
|
|
}
|
|
|
|
|
|
if isPreview {
|
|
|
- return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
|
|
|
+ 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"))
|
|
|
}
|
|
|
|
|
|
guard let account = NCManageDatabase.shared.getActiveAccount() else {
|
|
|
- return completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: nil, isPlaceholder: true, titleImage: UIImage(named: "widget")!, title: "Dashboard", footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
|
|
|
+ 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_", value: "No account found", comment: "")))
|
|
|
}
|
|
|
|
|
|
// NETWORKING
|
|
@@ -120,7 +121,7 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
|
|
|
NKCommon.shared.writeLog("Start \(NCBrandOptions.shared.brand) dashboard widget session with level \(levelLog) " + versionNextcloudiOS)
|
|
|
}
|
|
|
|
|
|
- let tableDashboard = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
|
|
|
+ let (tableDashboard, tableButton) = NCManageDatabase.shared.getDashboardWidget(account: account.account, id: id)
|
|
|
let options = NKRequestOptions(queue: NKCommon.shared.backgroundQueue)
|
|
|
let title = tableDashboard?.title ?? id
|
|
|
var titleImage = UIImage(named: "widget")!
|
|
@@ -170,7 +171,7 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
|
|
|
semaphore.wait()
|
|
|
}
|
|
|
|
|
|
- let data = DashboardData(id: counter, title: title, subTitle: subtitle, link: link, icon: icon, buttons: nil)
|
|
|
+ let data = DashboardData(id: counter, title: title, subTitle: subtitle, link: link, icon: icon)
|
|
|
datas.append(data)
|
|
|
if datas.count == dashboaardItems { break}
|
|
|
}
|
|
@@ -179,11 +180,11 @@ func getDashboardDataEntry(intent: Applications, isPreview: Bool, displaySize: C
|
|
|
}
|
|
|
|
|
|
if error != .success {
|
|
|
- completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: tableDashboard, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
|
|
|
+ completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: tableDashboard, tableButton: tableButton, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "xmark.icloud", footerText: error.errorDescription))
|
|
|
} else if datas.isEmpty {
|
|
|
- completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: tableDashboard, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NSLocalizedString("_no_data_available_", comment: "")))
|
|
|
+ completion(DashboardDataEntry(date: Date(), datas: datasPlaceholder, tableDashboard: tableDashboard, tableButton: tableButton, isPlaceholder: true, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NSLocalizedString("_no_data_available_", comment: "")))
|
|
|
} else {
|
|
|
- completion(DashboardDataEntry(date: Date(), datas: datas, tableDashboard: tableDashboard, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
|
|
|
+ completion(DashboardDataEntry(date: Date(), datas: datas, tableDashboard: tableDashboard, tableButton: tableButton, isPlaceholder: false, titleImage: titleImage, title: title, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " dashboard"))
|
|
|
}
|
|
|
}
|
|
|
}
|