Skip to content

Commit

Permalink
Select a random theme by default
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchalmers committed Jan 21, 2021
1 parent aea7c21 commit 232af71
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DesktopClock/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public partial class App : Application
public static string Title { get; } = Assembly.GetCustomAttribute<AssemblyTitleAttribute>().Title;

// https://www.materialui.co/colors
public static IReadOnlyCollection<Theme> Themes { get; } = new Theme[]
public static IReadOnlyList<Theme> Themes { get; } = new Theme[]
{
new Theme("White", "#FFFFFF", "#000000"),
new Theme("Black", "#000000", "#9E9E9E"),
Expand Down
9 changes: 1 addition & 8 deletions DesktopClock/MainViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Windows.Input;
using System.Windows.Media;
using DesktopClock.Properties;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf;
Expand Down Expand Up @@ -36,7 +35,7 @@ public MainViewModel()
/// <summary>
/// Sets app theme to parameter's value.
/// </summary>
public ICommand SetThemeCommand { get; } = new RelayCommand<Theme>(SetTheme);
public ICommand SetThemeCommand { get; } = new RelayCommand<Theme>((t) => Settings.Default.Theme = t);

/// <summary>
/// Sets format string in settings to parameter's string.
Expand Down Expand Up @@ -79,11 +78,5 @@ private void SystemClockTimer_SecondChanged(object sender, EventArgs e)
}

private void UpdateTimeString() => RaisePropertyChanged(nameof(CurrentTimeOrCountdownString));

private static void SetTheme(Theme theme)
{
Settings.Default.TextColor = (Color)ColorConverter.ConvertFromString(theme.PrimaryColor);
Settings.Default.OuterColor = (Color)ColorConverter.ConvertFromString(theme.SecondaryColor);
}
}
}
19 changes: 17 additions & 2 deletions DesktopClock/Properties/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public sealed class Settings : INotifyPropertyChanged

private Settings()
{
var random = new Random();

// Random default theme.
Theme = App.Themes[random.Next(0, App.Themes.Count)];
}

public event PropertyChangedEventHandler PropertyChanged;
Expand All @@ -37,11 +41,22 @@ private Settings()
public string Format { get; set; } = "dddd, MMM dd, HH:mm:ss";
public bool BackgroundEnabled { get; set; } = false;
public double BackgroundOpacity { get; set; } = 0.90;
public Color OuterColor { get; set; } = Colors.DarkGray;
public Color TextColor { get; set; } = Colors.Black;
public Color OuterColor { get; set; }
public Color TextColor { get; set; }
public string FontFamily { get; set; } = "Arial";
public DateTimeOffset CountdownTo { get; set; } = DateTimeOffset.MinValue;

[JsonIgnore]
public Theme Theme
{
get => new Theme("Custom", TextColor.ToString(), OuterColor.ToString());
set
{
TextColor = (Color)ColorConverter.ConvertFromString(value.PrimaryColor);
OuterColor = (Color)ColorConverter.ConvertFromString(value.SecondaryColor);
}
}

#endregion "Properties"

/// <summary>
Expand Down

0 comments on commit 232af71

Please sign in to comment.