From b58b7030cf7f340a02595fbe701d6fadfed45482 Mon Sep 17 00:00:00 2001 From: Valeriy Mironov Date: Tue, 21 Nov 2017 21:32:49 +0200 Subject: [PATCH] Added parsing all known for now types of parameters --- WatchFace/Elements/Activity.cs | 3 +- .../ActivityElements}/FormattedNumber.cs | 4 +- WatchFace/Elements/AnalogDialFace.cs | 38 +++++++++++++++ WatchFace/Elements/Background.cs | 1 + WatchFace/Elements/BasicElements/ClockHand.cs | 45 ++++++++++++++++++ .../Elements/BasicElements/Coordinates.cs | 33 +++++++++++++ .../{ => Elements}/BasicElements/Image.cs | 2 +- .../{ => Elements}/BasicElements/ImageSet.cs | 2 +- .../{ => Elements}/BasicElements/Number.cs | 2 +- WatchFace/Elements/BasicElements/Scale.cs | 33 +++++++++++++ .../{ => Elements}/BasicElements/TwoDigits.cs | 2 +- WatchFace/Elements/Battery.cs | 34 ++++++++++++++ WatchFace/Elements/Date.cs | 3 +- .../{ => DateElements}/MonthAndDay.cs | 7 ++- .../DateElements/OneLineMonthAndDay.cs} | 9 ++-- .../{ => DateElements}/SeparateMonthAndDay.cs | 4 +- WatchFace/Elements/Scales.cs | 30 ++++++++++++ WatchFace/Elements/Status.cs | 42 +++++++++++++++++ WatchFace/Elements/StatusElements/Flag.cs | 34 ++++++++++++++ WatchFace/Elements/StatusElements/Switch.cs | 38 +++++++++++++++ WatchFace/Elements/Time.cs | 7 +-- .../TimeElements/AmPm.cs} | 8 ++-- WatchFace/Elements/Weather.cs | 38 +++++++++++++++ .../Elements/WeatherElements/AirPollution.cs | 30 ++++++++++++ .../WeatherElements/JoinedTemperature.cs | 46 +++++++++++++++++++ .../WeatherElements/SeparateTemperature.cs | 33 +++++++++++++ .../Elements/WeatherElements/SignedNumber.cs | 34 ++++++++++++++ .../Elements/WeatherElements/Temperature.cs | 29 ++++++++++++ .../WeatherElements/TextTemperature.cs | 33 +++++++++++++ .../Elements/WeatherElements/WeatherIcon.cs | 30 ++++++++++++ WatchFace/WatchFace.cs | 32 ++++++++++--- WatchFace/WatchFace.csproj | 2 +- 32 files changed, 656 insertions(+), 32 deletions(-) rename WatchFace/{BasicElements => Elements/ActivityElements}/FormattedNumber.cs (93%) create mode 100644 WatchFace/Elements/AnalogDialFace.cs create mode 100644 WatchFace/Elements/BasicElements/ClockHand.cs create mode 100644 WatchFace/Elements/BasicElements/Coordinates.cs rename WatchFace/{ => Elements}/BasicElements/Image.cs (95%) rename WatchFace/{ => Elements}/BasicElements/ImageSet.cs (96%) rename WatchFace/{ => Elements}/BasicElements/Number.cs (97%) create mode 100644 WatchFace/Elements/BasicElements/Scale.cs rename WatchFace/{ => Elements}/BasicElements/TwoDigits.cs (95%) create mode 100644 WatchFace/Elements/Battery.cs rename WatchFace/Elements/{ => DateElements}/MonthAndDay.cs (86%) rename WatchFace/{BasicElements/JoinedNumber.cs => Elements/DateElements/OneLineMonthAndDay.cs} (77%) rename WatchFace/Elements/{ => DateElements}/SeparateMonthAndDay.cs (92%) create mode 100644 WatchFace/Elements/Scales.cs create mode 100644 WatchFace/Elements/Status.cs create mode 100644 WatchFace/Elements/StatusElements/Flag.cs create mode 100644 WatchFace/Elements/StatusElements/Switch.cs rename WatchFace/{BasicElements/AmPmSwitch.cs => Elements/TimeElements/AmPm.cs} (86%) create mode 100644 WatchFace/Elements/Weather.cs create mode 100644 WatchFace/Elements/WeatherElements/AirPollution.cs create mode 100644 WatchFace/Elements/WeatherElements/JoinedTemperature.cs create mode 100644 WatchFace/Elements/WeatherElements/SeparateTemperature.cs create mode 100644 WatchFace/Elements/WeatherElements/SignedNumber.cs create mode 100644 WatchFace/Elements/WeatherElements/Temperature.cs create mode 100644 WatchFace/Elements/WeatherElements/TextTemperature.cs create mode 100644 WatchFace/Elements/WeatherElements/WeatherIcon.cs diff --git a/WatchFace/Elements/Activity.cs b/WatchFace/Elements/Activity.cs index 6ac7137..46a7461 100644 --- a/WatchFace/Elements/Activity.cs +++ b/WatchFace/Elements/Activity.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using WatchFace.BasicElements; +using WatchFace.Elements.ActivityElements; +using WatchFace.Elements.BasicElements; using WatchFace.Models; namespace WatchFace.Elements diff --git a/WatchFace/BasicElements/FormattedNumber.cs b/WatchFace/Elements/ActivityElements/FormattedNumber.cs similarity index 93% rename from WatchFace/BasicElements/FormattedNumber.cs rename to WatchFace/Elements/ActivityElements/FormattedNumber.cs index c30c7a9..9b39952 100644 --- a/WatchFace/BasicElements/FormattedNumber.cs +++ b/WatchFace/Elements/ActivityElements/FormattedNumber.cs @@ -1,13 +1,13 @@ using System; using System.Collections.Generic; +using WatchFace.Elements.BasicElements; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.ActivityElements { public class FormattedNumber { public Number Number { get; set; } - public long SuffixImageIndex { get; set; } public long DecimalPointImageIndex { get; set; } diff --git a/WatchFace/Elements/AnalogDialFace.cs b/WatchFace/Elements/AnalogDialFace.cs new file mode 100644 index 0000000..aeff183 --- /dev/null +++ b/WatchFace/Elements/AnalogDialFace.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements +{ + public class AnalogDialFace + { + public ClockHand Hours { get; set; } + public ClockHand Minutes { get; set; } + public ClockHand Seconds { get; set; } + + public static AnalogDialFace Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new AnalogDialFace(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Hours = ClockHand.Parse(parameter.Children); + break; + case 2: + result.Minutes = ClockHand.Parse(parameter.Children); + break; + case 3: + result.Seconds = ClockHand.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/Background.cs b/WatchFace/Elements/Background.cs index 9d4ae2d..764d90f 100644 --- a/WatchFace/Elements/Background.cs +++ b/WatchFace/Elements/Background.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using WatchFace.Elements.BasicElements; using WatchFace.Models; namespace WatchFace.Elements diff --git a/WatchFace/Elements/BasicElements/ClockHand.cs b/WatchFace/Elements/BasicElements/ClockHand.cs new file mode 100644 index 0000000..5685c86 --- /dev/null +++ b/WatchFace/Elements/BasicElements/ClockHand.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.BasicElements +{ + public class ClockHand + { + public long Unknown { get; set; } + public long Color { get; set; } + public Coordinates Center { get; set; } + public List Shape { get; set; } + public Image CenterImage { get; set; } + + public static ClockHand Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new ClockHand {Shape = new List()}; + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Unknown = parameter.Value; + break; + case 2: + result.Color = parameter.Value; + break; + case 3: + result.Center = Coordinates.Parse(parameter.Children); + break; + case 4: + result.Shape.Add(Coordinates.Parse(parameter.Children)); + break; + case 5: + result.CenterImage = Image.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/BasicElements/Coordinates.cs b/WatchFace/Elements/BasicElements/Coordinates.cs new file mode 100644 index 0000000..6f4e2be --- /dev/null +++ b/WatchFace/Elements/BasicElements/Coordinates.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.BasicElements +{ + public class Coordinates + { + public long X { get; set; } + public long Y { get; set; } + + public static Coordinates Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Coordinates(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.X = parameter.Value; + break; + case 2: + result.Y = parameter.Value; + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/BasicElements/Image.cs b/WatchFace/Elements/BasicElements/Image.cs similarity index 95% rename from WatchFace/BasicElements/Image.cs rename to WatchFace/Elements/BasicElements/Image.cs index 4372f23..2482300 100644 --- a/WatchFace/BasicElements/Image.cs +++ b/WatchFace/Elements/BasicElements/Image.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using WatchFace.Models; -namespace WatchFace.Elements +namespace WatchFace.Elements.BasicElements { public class Image { diff --git a/WatchFace/BasicElements/ImageSet.cs b/WatchFace/Elements/BasicElements/ImageSet.cs similarity index 96% rename from WatchFace/BasicElements/ImageSet.cs rename to WatchFace/Elements/BasicElements/ImageSet.cs index e46972f..0fe72b5 100644 --- a/WatchFace/BasicElements/ImageSet.cs +++ b/WatchFace/Elements/BasicElements/ImageSet.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.BasicElements { public class ImageSet { diff --git a/WatchFace/BasicElements/Number.cs b/WatchFace/Elements/BasicElements/Number.cs similarity index 97% rename from WatchFace/BasicElements/Number.cs rename to WatchFace/Elements/BasicElements/Number.cs index 4679854..586e343 100644 --- a/WatchFace/BasicElements/Number.cs +++ b/WatchFace/Elements/BasicElements/Number.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.BasicElements { public class Number { diff --git a/WatchFace/Elements/BasicElements/Scale.cs b/WatchFace/Elements/BasicElements/Scale.cs new file mode 100644 index 0000000..399cc20 --- /dev/null +++ b/WatchFace/Elements/BasicElements/Scale.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.BasicElements +{ + public class Scale + { + public long StartImageIndex { get; set; } + public List Segments { get; set; } + + public static Scale Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Scale {Segments = new List()}; + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.StartImageIndex = parameter.Value; + break; + case 2: + result.Segments.Add(Coordinates.Parse(parameter.Children)); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/BasicElements/TwoDigits.cs b/WatchFace/Elements/BasicElements/TwoDigits.cs similarity index 95% rename from WatchFace/BasicElements/TwoDigits.cs rename to WatchFace/Elements/BasicElements/TwoDigits.cs index 67e24df..8c529ce 100644 --- a/WatchFace/BasicElements/TwoDigits.cs +++ b/WatchFace/Elements/BasicElements/TwoDigits.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.BasicElements { public class TwoDigits { diff --git a/WatchFace/Elements/Battery.cs b/WatchFace/Elements/Battery.cs new file mode 100644 index 0000000..2be2b33 --- /dev/null +++ b/WatchFace/Elements/Battery.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements +{ + public class Battery + { + public Number Text { get; set; } + public ImageSet Icon { get; set; } + + public static Battery Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Battery(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Text = Number.Parse(parameter.Children); + break; + case 2: + result.Icon = ImageSet.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/Date.cs b/WatchFace/Elements/Date.cs index 26b239a..0f746cd 100644 --- a/WatchFace/Elements/Date.cs +++ b/WatchFace/Elements/Date.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; -using WatchFace.BasicElements; +using WatchFace.Elements.BasicElements; +using WatchFace.Elements.DateElements; using WatchFace.Models; namespace WatchFace.Elements diff --git a/WatchFace/Elements/MonthAndDay.cs b/WatchFace/Elements/DateElements/MonthAndDay.cs similarity index 86% rename from WatchFace/Elements/MonthAndDay.cs rename to WatchFace/Elements/DateElements/MonthAndDay.cs index 0611d48..df8eee1 100644 --- a/WatchFace/Elements/MonthAndDay.cs +++ b/WatchFace/Elements/DateElements/MonthAndDay.cs @@ -1,14 +1,13 @@ using System; using System.Collections.Generic; -using WatchFace.BasicElements; using WatchFace.Models; -namespace WatchFace.Elements +namespace WatchFace.Elements.DateElements { public class MonthAndDay { public SeparateMonthAndDay Separate { get; set; } - public JoinedNumber Joined { get; set; } + public OneLineMonthAndDay Joined { get; set; } public long Unknown1 { get; set; } public long Unknown2 { get; set; } @@ -25,7 +24,7 @@ namespace WatchFace.Elements result.Separate = SeparateMonthAndDay.Parse(parameter.Children); break; case 2: - result.Joined = JoinedNumber.Parse(parameter.Children); + result.Joined = OneLineMonthAndDay.Parse(parameter.Children); break; case 3: result.Unknown1 = parameter.Value; diff --git a/WatchFace/BasicElements/JoinedNumber.cs b/WatchFace/Elements/DateElements/OneLineMonthAndDay.cs similarity index 77% rename from WatchFace/BasicElements/JoinedNumber.cs rename to WatchFace/Elements/DateElements/OneLineMonthAndDay.cs index 32f22b3..7dab642 100644 --- a/WatchFace/BasicElements/JoinedNumber.cs +++ b/WatchFace/Elements/DateElements/OneLineMonthAndDay.cs @@ -1,20 +1,21 @@ using System; using System.Collections.Generic; +using WatchFace.Elements.BasicElements; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.DateElements { - public class JoinedNumber + public class OneLineMonthAndDay { public Number Number { get; set; } public long DelimiterImageIndex { get; set; } - public static JoinedNumber Parse(List descriptor) + public static OneLineMonthAndDay Parse(List descriptor) { if (descriptor == null) throw new ArgumentNullException(nameof(descriptor)); - var result = new JoinedNumber(); + var result = new OneLineMonthAndDay(); foreach (var parameter in descriptor) switch (parameter.Id) { diff --git a/WatchFace/Elements/SeparateMonthAndDay.cs b/WatchFace/Elements/DateElements/SeparateMonthAndDay.cs similarity index 92% rename from WatchFace/Elements/SeparateMonthAndDay.cs rename to WatchFace/Elements/DateElements/SeparateMonthAndDay.cs index fa9b154..daf2d55 100644 --- a/WatchFace/Elements/SeparateMonthAndDay.cs +++ b/WatchFace/Elements/DateElements/SeparateMonthAndDay.cs @@ -1,9 +1,9 @@ using System; using System.Collections.Generic; -using WatchFace.BasicElements; +using WatchFace.Elements.BasicElements; using WatchFace.Models; -namespace WatchFace.Elements +namespace WatchFace.Elements.DateElements { public class SeparateMonthAndDay { diff --git a/WatchFace/Elements/Scales.cs b/WatchFace/Elements/Scales.cs new file mode 100644 index 0000000..1f39134 --- /dev/null +++ b/WatchFace/Elements/Scales.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements +{ + public class Scales + { + public Scale Steps { get; set; } + + public static Scales Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Scales(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 2: + result.Steps = Scale.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/Status.cs b/WatchFace/Elements/Status.cs new file mode 100644 index 0000000..937dbbf --- /dev/null +++ b/WatchFace/Elements/Status.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.StatusElements; +using WatchFace.Models; + +namespace WatchFace.Elements +{ + public class Status + { + public Switch Switch { get; set; } + public Flag Alarm { get; set; } + public Flag Lock { get; set; } + public Flag DoNotDisturb { get; set; } + + public static Status Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Status(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Switch = Switch.Parse(parameter.Children); + break; + case 2: + result.Alarm = Flag.Parse(parameter.Children); + break; + case 3: + result.Lock = Flag.Parse(parameter.Children); + break; + case 4: + result.DoNotDisturb = Flag.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/StatusElements/Flag.cs b/WatchFace/Elements/StatusElements/Flag.cs new file mode 100644 index 0000000..2715163 --- /dev/null +++ b/WatchFace/Elements/StatusElements/Flag.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.StatusElements +{ + public class Flag + { + public long ImageIndexOn { get; set; } + public Coordinates Coordinates { get; set; } + + public static Flag Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Flag(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Coordinates = Coordinates.Parse(parameter.Children); + break; + case 2: + result.ImageIndexOn = parameter.Value; + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/StatusElements/Switch.cs b/WatchFace/Elements/StatusElements/Switch.cs new file mode 100644 index 0000000..8105291 --- /dev/null +++ b/WatchFace/Elements/StatusElements/Switch.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.StatusElements +{ + public class Switch + { + public long ImageIndexOn { get; set; } + public long ImageIndexOff { get; set; } + public Coordinates Coordinates { get; set; } + + public static Switch Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Switch(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Coordinates = Coordinates.Parse(parameter.Children); + break; + case 2: + result.ImageIndexOn = parameter.Value; + break; + case 3: + result.ImageIndexOff = parameter.Value; + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/Time.cs b/WatchFace/Elements/Time.cs index 9656991..9d5db53 100644 --- a/WatchFace/Elements/Time.cs +++ b/WatchFace/Elements/Time.cs @@ -1,13 +1,14 @@ using System; using System.Collections.Generic; -using WatchFace.BasicElements; +using WatchFace.Elements.BasicElements; +using WatchFace.Elements.TimeElements; using WatchFace.Models; namespace WatchFace.Elements { public class Time { - public AmPmSwitch AmPm { get; set; } + public AmPm AmPm { get; set; } public TwoDigits Hours { get; set; } public TwoDigits Minutes { get; set; } public TwoDigits Seconds { get; set; } @@ -31,7 +32,7 @@ namespace WatchFace.Elements result.Seconds = TwoDigits.Parse(parameter.Children); break; case 4: - result.AmPm = AmPmSwitch.Parse(parameter.Children); + result.AmPm = AmPm.Parse(parameter.Children); break; default: throw new InvalidParameterException(parameter); diff --git a/WatchFace/BasicElements/AmPmSwitch.cs b/WatchFace/Elements/TimeElements/AmPm.cs similarity index 86% rename from WatchFace/BasicElements/AmPmSwitch.cs rename to WatchFace/Elements/TimeElements/AmPm.cs index c662e9f..5c9e27a 100644 --- a/WatchFace/BasicElements/AmPmSwitch.cs +++ b/WatchFace/Elements/TimeElements/AmPm.cs @@ -2,21 +2,21 @@ using System.Collections.Generic; using WatchFace.Models; -namespace WatchFace.BasicElements +namespace WatchFace.Elements.TimeElements { - public class AmPmSwitch + public class AmPm { public long ImageIndexPm { get; set; } public long ImageIndexAm { get; set; } public long X { get; set; } public long Y { get; set; } - public static AmPmSwitch Parse(List descriptor) + public static AmPm Parse(List descriptor) { if (descriptor == null) throw new ArgumentNullException(nameof(descriptor)); - var result = new AmPmSwitch(); + var result = new AmPm(); foreach (var parameter in descriptor) switch (parameter.Id) { diff --git a/WatchFace/Elements/Weather.cs b/WatchFace/Elements/Weather.cs new file mode 100644 index 0000000..a380ae5 --- /dev/null +++ b/WatchFace/Elements/Weather.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.WeatherElements; +using WatchFace.Models; + +namespace WatchFace.Elements +{ + public class Weather + { + public WeatherIcon Icon { get; set; } + public Temperature Temperature { get; set; } + public AirPollution AirPollution { get; set; } + + public static Weather Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Weather(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Icon = WeatherIcon.Parse(parameter.Children); + break; + case 2: + result.Temperature = Temperature.Parse(parameter.Children); + break; + case 3: + result.AirPollution = AirPollution.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/AirPollution.cs b/WatchFace/Elements/WeatherElements/AirPollution.cs new file mode 100644 index 0000000..096facf --- /dev/null +++ b/WatchFace/Elements/WeatherElements/AirPollution.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class AirPollution + { + public ImageSet Icon { get; set; } + + public static AirPollution Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new AirPollution(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 2: + result.Icon = ImageSet.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/JoinedTemperature.cs b/WatchFace/Elements/WeatherElements/JoinedTemperature.cs new file mode 100644 index 0000000..cf4caf1 --- /dev/null +++ b/WatchFace/Elements/WeatherElements/JoinedTemperature.cs @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class JoinedTemperature + { + public Number Number { get; set; } + public long MinusSignImageIndex { get; set; } + public long DelimiterImageIndex { get; set; } + public long Unknown { get; set; } + public long DegreesImageIndex { get; set; } + + public static JoinedTemperature Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new JoinedTemperature(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Number = Number.Parse(parameter.Children); + break; + case 2: + result.MinusSignImageIndex = parameter.Value; + break; + case 3: + result.DelimiterImageIndex = parameter.Value; + break; + case 4: + result.Unknown = parameter.Value; + break; + case 5: + result.DegreesImageIndex = parameter.Value; + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/SeparateTemperature.cs b/WatchFace/Elements/WeatherElements/SeparateTemperature.cs new file mode 100644 index 0000000..49c27f8 --- /dev/null +++ b/WatchFace/Elements/WeatherElements/SeparateTemperature.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class SeparateTemperature + { + public SignedNumber Day { get; set; } + public SignedNumber Night { get; set; } + + public static SeparateTemperature Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new SeparateTemperature(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Day = SignedNumber.Parse(parameter.Children); + break; + case 2: + result.Night = SignedNumber.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/SignedNumber.cs b/WatchFace/Elements/WeatherElements/SignedNumber.cs new file mode 100644 index 0000000..02ab409 --- /dev/null +++ b/WatchFace/Elements/WeatherElements/SignedNumber.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class SignedNumber + { + public Number Number { get; set; } + public long MinusImageIndex { get; set; } + + public static SignedNumber Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new SignedNumber(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Number = Number.Parse(parameter.Children); + break; + case 2: + result.MinusImageIndex = parameter.Value; + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/Temperature.cs b/WatchFace/Elements/WeatherElements/Temperature.cs new file mode 100644 index 0000000..17b670c --- /dev/null +++ b/WatchFace/Elements/WeatherElements/Temperature.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class Temperature + { + public TextTemperature Text { get; set; } + + public static Temperature Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new Temperature(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 2: + result.Text = TextTemperature.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/TextTemperature.cs b/WatchFace/Elements/WeatherElements/TextTemperature.cs new file mode 100644 index 0000000..1393acc --- /dev/null +++ b/WatchFace/Elements/WeatherElements/TextTemperature.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class TextTemperature + { + public SeparateTemperature Separate { get; set; } + public JoinedTemperature Joined { get; set; } + + public static TextTemperature Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new TextTemperature(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Separate = SeparateTemperature.Parse(parameter.Children); + break; + case 2: + result.Joined = JoinedTemperature.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/Elements/WeatherElements/WeatherIcon.cs b/WatchFace/Elements/WeatherElements/WeatherIcon.cs new file mode 100644 index 0000000..1b343c8 --- /dev/null +++ b/WatchFace/Elements/WeatherElements/WeatherIcon.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using WatchFace.Elements.BasicElements; +using WatchFace.Models; + +namespace WatchFace.Elements.WeatherElements +{ + public class WeatherIcon + { + public Coordinates Coordinates { get; set; } + + public static WeatherIcon Parse(List descriptor) + { + if (descriptor == null) + throw new ArgumentNullException(nameof(descriptor)); + + var result = new WeatherIcon(); + foreach (var parameter in descriptor) + switch (parameter.Id) + { + case 1: + result.Coordinates = Coordinates.Parse(parameter.Children); + break; + default: + throw new InvalidParameterException(parameter); + } + return result; + } + } +} \ No newline at end of file diff --git a/WatchFace/WatchFace.cs b/WatchFace/WatchFace.cs index 1d198a5..2b6c9ba 100644 --- a/WatchFace/WatchFace.cs +++ b/WatchFace/WatchFace.cs @@ -7,10 +7,15 @@ namespace WatchFace { public class WatchFace { - public Background Background { get; private set; } - public Time Time { get; private set; } - public Date Date { get; private set; } - public Activity Activity { get; private set; } + public Background Background { get; set; } + public Time Time { get; set; } + public Date Date { get; set; } + public Weather Weather { get; set; } + public Activity Activity { get; set; } + public Scales Scales { get; set; } + public Status Status { get; set; } + public Battery Battery { get; set; } + public AnalogDialFace AnalogDialFace { get; set; } public static WatchFace Parse(List descriptor) { @@ -34,8 +39,23 @@ namespace WatchFace case 5: result.Date = Date.Parse(resource.Children); break; - //default: - // throw new InvalidParameterException(resource); + case 6: + result.Weather = Weather.Parse(resource.Children); + break; + case 7: + result.Scales = Scales.Parse(resource.Children); + break; + case 8: + result.Status = Status.Parse(resource.Children); + break; + case 9: + result.Battery = Battery.Parse(resource.Children); + break; + case 10: + result.AnalogDialFace = AnalogDialFace.Parse(resource.Children); + break; + default: + throw new InvalidParameterException(resource); } return result; } diff --git a/WatchFace/WatchFace.csproj b/WatchFace/WatchFace.csproj index 44c8044..ce17735 100644 --- a/WatchFace/WatchFace.csproj +++ b/WatchFace/WatchFace.csproj @@ -15,7 +15,7 @@ - +