Merge pull request #2635 from BlueWallet/graphicRectangular

ADD: graphicRectangular complication
This commit is contained in:
GLaDOS 2021-02-18 12:02:26 +00:00 committed by GitHub
commit c4c6ab4cf2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View File

@ -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)

View File

@ -27,6 +27,7 @@
<string>CLKComplicationFamilyCircularSmall</string>
<string>CLKComplicationFamilyGraphicBezel</string>
<string>CLKComplicationFamilyGraphicCircular</string>
<string>CLKComplicationFamilyGraphicRectangular</string>
<string>CLKComplicationFamilyGraphicCorner</string>
<string>CLKComplicationFamilyModularLarge</string>
<string>CLKComplicationFamilyModularSmall</string>

View File

@ -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 {