public void SetTheme(ThemeInfoBase info, bool apply) { if (apply) { _settingsService.Appearance.RequestedTheme = info.Parent; } if (info is ThemeCustomInfo custom) { _settingsService.Appearance[info.Parent].Type = TelegramThemeType.Custom; _settingsService.Appearance[info.Parent].Custom = custom.Path; } else if (info is ThemeAccentInfo accent) { _settingsService.Appearance[info.Parent].Type = accent.Type; _settingsService.Appearance.Accents[accent.Type] = accent.AccentColor; } else { _settingsService.Appearance[info.Parent].Type = info.Parent == TelegramTheme.Light ? TelegramThemeType.Classic : TelegramThemeType.Night; } var flags = _settingsService.Appearance.GetCalculatedElementTheme(); var theme = flags == ElementTheme.Dark ? TelegramTheme.Dark : TelegramTheme.Light; if (theme != info.Parent && !apply) { return; } _settingsService.Appearance.UpdateNightMode(); }
public async Task CreateThemeAsync(ThemeInfoBase theme) { var confirm = await MessagePopup.ShowAsync(Strings.Resources.CreateNewThemeAlert, Strings.Resources.NewTheme, Strings.Resources.CreateTheme, Strings.Resources.Cancel); if (confirm != ContentDialogResult.Primary) { return; } var input = new InputPopup(); input.Title = Strings.Resources.NewTheme; input.Header = Strings.Resources.EnterThemeName; input.Text = $"{theme.Name} #2"; input.IsPrimaryButtonEnabled = true; input.IsSecondaryButtonEnabled = true; input.PrimaryButtonText = Strings.Resources.OK; input.SecondaryButtonText = Strings.Resources.Cancel; confirm = await input.ShowQueuedAsync(); if (confirm != ContentDialogResult.Primary) { return; } var preparing = new ThemeCustomInfo(theme.Parent, theme.AccentColor, input.Text); var fileName = Client.Execute(new CleanFileName(theme.Name)) as Text; var lookup = ThemeService.GetLookup(theme.Parent); foreach (var value in lookup) { if (value.Value is Color color) { preparing.Values[value.Key] = color; } } if (theme is ThemeCustomInfo custom) { foreach (var item in custom.Values) { preparing.Values[item.Key] = item.Value; } } else if (theme is ThemeAccentInfo accent) { foreach (var item in accent.Values) { preparing.Values[item.Key] = item.Value; } } var file = await ApplicationData.Current.LocalFolder.CreateFileAsync("themes\\" + fileName.TextValue + ".unigram-theme", CreationCollisionOption.GenerateUniqueName); await SerializeAsync(file, preparing); preparing.Path = file.Path; SetTheme(preparing, true); if (Window.Current.Content is Views.Host.RootPage root) { root.ShowEditor(preparing); } }