From 3706abf384bc6afdd928cc3591bda884bd3d97f6 Mon Sep 17 00:00:00 2001 From: marcosrdz Date: Tue, 16 Feb 2021 21:58:01 -0500 Subject: [PATCH] ADD: graphicRectangular complication --- .../ComplicationController.swift | 16 ++++++++++------ ios/BlueWalletWatch Extension/Info.plist | 1 + .../Widgets/Shared/WidgetDataStore.swift | 11 +++++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/ios/BlueWalletWatch Extension/ComplicationController.swift b/ios/BlueWalletWatch Extension/ComplicationController.swift index 2c29daef5..9b6bf389c 100644 --- a/ios/BlueWalletWatch Extension/ComplicationController.swift +++ b/ios/BlueWalletWatch Extension/ComplicationController.swift @@ -40,10 +40,11 @@ class ComplicationController: NSObject, CLKComplicationDataSource { let date: Date let valueLabel: String let currencySymbol: String - - if let price = marketData?.formattedRateForComplication, let marketDatadata = marketData?.date { + let timeLabel: String + if let price = marketData?.formattedRateForComplication, let marketDatadata = marketData?.date, let lastUpdated = marketData?.formattedDate { date = marketDatadata valueLabel = price + timeLabel = lastUpdated if let preferredFiatCurrency = UserDefaults.standard.string(forKey: "preferredFiatCurrency"), let preferredFiatUnit = fiatUnit(currency: preferredFiatCurrency) { currencySymbol = preferredFiatUnit.symbol } else { @@ -51,6 +52,7 @@ class ComplicationController: NSObject, CLKComplicationDataSource { } } else { valueLabel = "--" + timeLabel = "--" currencySymbol = fiatUnit(currency: "USD")!.symbol date = Date() } @@ -131,7 +133,7 @@ class ComplicationController: NSObject, CLKComplicationDataSource { case .modularLarge: let template = CLKComplicationTemplateModularLargeStandardBody() if #available(watchOSApplicationExtension 6.0, *) { - template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price") + template.headerTextProvider = CLKTextProvider(format: "Bitcoin Price") template.body1TextProvider = CLKTextProvider(format: "%@%@", currencySymbol, valueLabel) entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template) handler(entry) @@ -143,8 +145,9 @@ class ComplicationController: NSObject, CLKComplicationDataSource { case .graphicRectangular: let template = CLKComplicationTemplateGraphicRectangularStandardBody() if #available(watchOSApplicationExtension 6.0, *) { - template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price") + template.headerTextProvider = CLKTextProvider(format: "Bitcoin Price") template.body1TextProvider = CLKTextProvider(format: "%@%@", currencySymbol, valueLabel) + template.body2TextProvider = CLKTextProvider(format: "%@", timeLabel) entry = CLKComplicationTimelineEntry(date: date, complicationTemplate: template) handler(entry) } else { @@ -248,7 +251,7 @@ func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler case .modularLarge: let template = CLKComplicationTemplateModularLargeStandardBody() if #available(watchOSApplicationExtension 6.0, *) { - template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price") + template.headerTextProvider = CLKTextProvider(format: "Bitcoin Price") template.body1TextProvider = CLKTextProvider(format: "%@%@", "$S", "46,000") handler(template) @@ -260,8 +263,9 @@ func getLocalizableSampleTemplate(for complication: CLKComplication, withHandler case .graphicRectangular: let template = CLKComplicationTemplateGraphicRectangularStandardBody() if #available(watchOSApplicationExtension 6.0, *) { - template.headerTextProvider = CLKTextProvider(format: "Bitcoin Market Price") + template.headerTextProvider = CLKTextProvider(format: "Bitcoin Price") template.body1TextProvider = CLKTextProvider(format: "%@%@", "$S", "46,000") + template.body2TextProvider = CLKTextProvider(format: "%@", Date().description) handler(template) } else { handler(nil) diff --git a/ios/BlueWalletWatch Extension/Info.plist b/ios/BlueWalletWatch Extension/Info.plist index 482d6017b..bc9bf43e1 100644 --- a/ios/BlueWalletWatch Extension/Info.plist +++ b/ios/BlueWalletWatch Extension/Info.plist @@ -27,6 +27,7 @@ CLKComplicationFamilyCircularSmall CLKComplicationFamilyGraphicBezel CLKComplicationFamilyGraphicCircular + CLKComplicationFamilyGraphicRectangular CLKComplicationFamilyGraphicCorner CLKComplicationFamilyModularLarge CLKComplicationFamilyModularSmall diff --git a/ios/WalletInformationWidget/Widgets/Shared/WidgetDataStore.swift b/ios/WalletInformationWidget/Widgets/Shared/WidgetDataStore.swift index bfbe35c87..740d4f530 100644 --- a/ios/WalletInformationWidget/Widgets/Shared/WidgetDataStore.swift +++ b/ios/WalletInformationWidget/Widgets/Shared/WidgetDataStore.swift @@ -43,6 +43,17 @@ struct WidgetDataStore: Codable { return isoDateFormatter.date(from: lastUpdate) } + var formattedDate: String? { + let isoDateFormatter = ISO8601DateFormatter() + let dateFormatter = DateFormatter() + dateFormatter.locale = Locale.current + dateFormatter.timeStyle = .short + + if let date = isoDateFormatter.date(from: lastUpdate) { + return dateFormatter.string(from: date) + } + return nil + } } class WidgetData {