diff options
author | Marino Faggiana <marino@marinofaggiana.com> | 2022-11-02 20:32:24 +0300 |
---|---|---|
committer | Marino Faggiana <marino@marinofaggiana.com> | 2022-11-02 20:32:24 +0300 |
commit | f567cee143234e598464cb8b1cb5890b04aca860 (patch) | |
tree | 71a10ab313295b8124e375a8a32a7b04dd733e28 | |
parent | 4e67087b98a90bffcdfe9a9e32ea5dd515794f13 (diff) |
Improve
Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
-rw-r--r-- | Nextcloud.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | Widget/Lockscreen/LockscreenData.swift | 97 | ||||
-rw-r--r-- | Widget/Lockscreen/LockscreenWidgetProvider.swift | 6 | ||||
-rw-r--r-- | Widget/Lockscreen/LockscreenWidgetView.swift | 28 |
4 files changed, 79 insertions, 56 deletions
diff --git a/Nextcloud.xcodeproj/project.pbxproj b/Nextcloud.xcodeproj/project.pbxproj index cd951134d..e617f1c78 100644 --- a/Nextcloud.xcodeproj/project.pbxproj +++ b/Nextcloud.xcodeproj/project.pbxproj @@ -3619,7 +3619,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; @@ -3682,7 +3682,7 @@ CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 8; + CURRENT_PROJECT_VERSION = 9; DEVELOPMENT_TEAM = NKUJUXUJ3B; ENABLE_STRICT_OBJC_MSGSEND = YES; ENABLE_TESTABILITY = YES; diff --git a/Widget/Lockscreen/LockscreenData.swift b/Widget/Lockscreen/LockscreenData.swift index 26332de1c..6dbbcdbd8 100644 --- a/Widget/Lockscreen/LockscreenData.swift +++ b/Widget/Lockscreen/LockscreenData.swift @@ -32,14 +32,17 @@ struct LockscreenData: TimelineEntry { let quotaRelative: Float let quotaUsed: String let quotaTotal: String + let error: Bool } -func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, completion: @escaping (_ entry: LockscreenData) -> Void) { +func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, family: WidgetFamily, completion: @escaping (_ entry: LockscreenData) -> Void) { var account: tableAccount? + var quotaRelative: Float = 0 + let options = NKRequestOptions(timeout: 15, queue: NKCommon.shared.backgroundQueue) if isPreview { - return completion(LockscreenData(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "")) + return completion(LockscreenData(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: false)) } let accountIdentifier: String = configuration?.accounts?.identifier ?? "active" @@ -50,55 +53,63 @@ func getLockscreenDataEntry(configuration: AccountIntent?, isPreview: Bool, comp } guard let account = account else { - return completion(LockscreenData(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "")) + return completion(LockscreenData(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: false)) } - var quotaRelative: Float = 0 - if account.quotaRelative > 0 { - quotaRelative = Float(account.quotaRelative) / 100 + let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor) + if serverVersionMajor < NCGlobal.shared.nextcloudVersion25 { + completion(LockscreenData(date: Date(), isPlaceholder: false, activity: NSLocalizedString("_widget_available_nc25_", comment: ""), link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: true)) } - let quotaUsed: String = CCUtility.transformedSize(account.quotaUsed) - var quotaTotal: String = "" - switch account.quotaTotal { - case -1: - quotaTotal = "" - case -2: - quotaTotal = "" - case -3: - quotaTotal = "" - default: - quotaTotal = CCUtility.transformedSize(account.quotaTotal) - } + // NETWORKING + let password = CCUtility.getPassword(account.account)! + NKCommon.shared.setup( + account: account.account, + user: account.user, + userId: account.userId, + password: password, + urlBase: account.urlBase, + userAgent: CCUtility.getUserAgent(), + nextcloudVersion: 0, + delegate: NCNetworking.shared) - let serverVersionMajor = NCManageDatabase.shared.getCapabilitiesServerInt(account: account.account, elements: NCElementsJSON.shared.capabilitiesVersionMajor) - if serverVersionMajor >= NCGlobal.shared.nextcloudVersion25 { + if #available(iOSApplicationExtension 16.0, *) { + if family == .accessoryCircular { + NextcloudKit.shared.getUserProfile(options: options) { _, userProfile, _, error in + if error == .success, let userProfile = userProfile, let account = NCManageDatabase.shared.setAccountUserProfile(userProfile) { + if account.quotaRelative > 0 { + quotaRelative = Float(account.quotaRelative) / 100 + } + let quotaUsed: String = CCUtility.transformedSize(account.quotaUsed) + var quotaTotal: String = "" - // NETWORKING - let password = CCUtility.getPassword(account.account)! - NKCommon.shared.setup( - account: account.account, - user: account.user, - userId: account.userId, - password: password, - urlBase: account.urlBase, - userAgent: CCUtility.getUserAgent(), - nextcloudVersion: 0, - delegate: NCNetworking.shared) - - let options = NKRequestOptions(timeout: 15, queue: NKCommon.shared.backgroundQueue) - NextcloudKit.shared.getDashboardWidgetsApplication("activity", options: options) { _, results, _, error in - var activity: String = NSLocalizedString("_no_data_available_", comment: "") - var link = URL(string: "https://")! - if error == .success, let result = results?.first { - if let item = result.items?.first { - if let title = item.title { activity = title } - if let itemLink = item.link, let url = URL(string: itemLink) { link = url } + switch account.quotaTotal { + case -1: + quotaTotal = "" + case -2: + quotaTotal = "" + case -3: + quotaTotal = "" + default: + quotaTotal = CCUtility.transformedSize(account.quotaTotal) + } + completion(LockscreenData(date: Date(), isPlaceholder: false, activity: "", link: URL(string: "https://")!, quotaRelative: quotaRelative, quotaUsed: quotaUsed, quotaTotal: quotaTotal, error: false)) + } else { + completion(LockscreenData(date: Date(), isPlaceholder: false, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: true)) + } + } + } else if family == .accessoryRectangular { + NextcloudKit.shared.getDashboardWidgetsApplication("activity", options: options) { _, results, _, error in + var activity: String = NSLocalizedString("_no_data_available_", comment: "") + var link = URL(string: "https://")! + if error == .success, let result = results?.first { + if let item = result.items?.first { + if let title = item.title { activity = title } + if let itemLink = item.link, let url = URL(string: itemLink) { link = url } + } } + completion(LockscreenData(date: Date(), isPlaceholder: false, activity: activity, link: link, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: false)) } - completion(LockscreenData(date: Date(), isPlaceholder: false, activity: activity, link: link, quotaRelative: quotaRelative, quotaUsed: quotaUsed, quotaTotal: quotaTotal)) } - } else { - completion(LockscreenData(date: Date(), isPlaceholder: false, activity: NSLocalizedString("_widget_available_nc25_", comment: ""), link: URL(string: "https://")!, quotaRelative: quotaRelative, quotaUsed: quotaUsed, quotaTotal: quotaTotal)) } } diff --git a/Widget/Lockscreen/LockscreenWidgetProvider.swift b/Widget/Lockscreen/LockscreenWidgetProvider.swift index a18ae09c6..6d3ac5b89 100644 --- a/Widget/Lockscreen/LockscreenWidgetProvider.swift +++ b/Widget/Lockscreen/LockscreenWidgetProvider.swift @@ -31,17 +31,17 @@ struct LockscreenWidgetProvider: IntentTimelineProvider { typealias Intent = AccountIntent func placeholder(in context: Context) -> Entry { - return Entry(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "") + return Entry(date: Date(), isPlaceholder: true, activity: "", link: URL(string: "https://")!, quotaRelative: 0, quotaUsed: "", quotaTotal: "", error: false) } func getSnapshot(for configuration: AccountIntent, in context: Context, completion: @escaping (Entry) -> Void) { - getLockscreenDataEntry(configuration: configuration, isPreview: false) { entry in + getLockscreenDataEntry(configuration: configuration, isPreview: false, family: context.family) { entry in completion(entry) } } func getTimeline(for configuration: AccountIntent, in context: Context, completion: @escaping (Timeline<Entry>) -> Void) { - getLockscreenDataEntry(configuration: configuration, isPreview: context.isPreview) { entry in + getLockscreenDataEntry(configuration: configuration, isPreview: context.isPreview, family: context.family) { entry in let timeLine = Timeline(entries: [entry], policy: .atEnd) completion(timeLine) } diff --git a/Widget/Lockscreen/LockscreenWidgetView.swift b/Widget/Lockscreen/LockscreenWidgetView.swift index de03865c0..c252806f3 100644 --- a/Widget/Lockscreen/LockscreenWidgetView.swift +++ b/Widget/Lockscreen/LockscreenWidgetView.swift @@ -33,13 +33,25 @@ struct LockscreenWidgetView: View { var body: some View { switch family { case .accessoryCircular: - Gauge( - value: entry.quotaRelative, - label: { Text(" " + entry.quotaTotal + " ") }, - currentValueLabel: { Text(entry.quotaUsed) } - ) - .gaugeStyle(.accessoryCircular) - .redacted(reason: entry.isPlaceholder ? .placeholder : []) + if entry.error { + Gauge( + value: 0, + label: {}, + currentValueLabel: { + Image(systemName: "xmark.icloud") + .font(.system(size: 25.0)) + } + ) + .gaugeStyle(.accessoryCircularCapacity) + } else { + Gauge( + value: entry.quotaRelative, + label: { Text(" " + entry.quotaTotal + " ") }, + currentValueLabel: { Text(entry.quotaUsed) } + ) + .gaugeStyle(.accessoryCircular) + .redacted(reason: entry.isPlaceholder ? .placeholder : []) + } case .accessoryRectangular: VStack(alignment: .leading, spacing: 1) { HStack(spacing: 1) { @@ -68,7 +80,7 @@ struct LockscreenWidgetView: View { @available(iOSApplicationExtension 16.0, *) struct LockscreenWidgetView_Previews: PreviewProvider { static var previews: some View { - let entry = LockscreenData(date: Date(), isPlaceholder: false, activity: "Alba Mayoral changed Marketing / Regional Marketing / Agenda Meetings / Q4 2022 / OCTOBER / 13.11 Afrah Kahlid.md", link: URL(string: "https://")!, quotaRelative: 0.5, quotaUsed: "22 GB", quotaTotal: "50 GB") + let entry = LockscreenData(date: Date(), isPlaceholder: false, activity: "Alba Mayoral changed Marketing / Regional Marketing / Agenda Meetings / Q4 2022 / OCTOBER / 13.11 Afrah Kahlid.md", link: URL(string: "https://")!, quotaRelative: 0.5, quotaUsed: "22 GB", quotaTotal: "50 GB", error: true) LockscreenWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .accessoryRectangular)).previewDisplayName("Rectangular") LockscreenWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .accessoryCircular)).previewDisplayName("Circular") } |