private async Task RefreshThemesAsync()
        {
            Items.ReplaceWith(_themeService.GetThemes());
            Custom.ReplaceWith(await _themeService.GetCustomThemesAsync());

            var type = Settings.Appearance.RequestedThemeType;

            if (ThemeAccentInfo.IsAccent(type))
            {
                var accent = Settings.Appearance.Accents[type];
                if (_defaultAccents[type].Contains(accent))
                {
                    Accents.ReplaceWith(_defaultAccents[type]
                                        .Select(x => ThemeAccentInfo.FromAccent(type, x)));
                }
                else
                {
                    Accents.ReplaceWith(_defaultAccents[type]
                                        .Take(_defaultAccents[type].Length - 1)
                                        .Union(new[] { accent })
                                        .Select(x => ThemeAccentInfo.FromAccent(type, x)));
                }
            }
            else
            {
                Accents.Clear();
            }

            AreCustomThemesAvailable = Custom.Count > 0;
        }
Ejemplo n.º 2
0
        public void Initialize(TelegramTheme requested)
        {
            var settings = SettingsService.Current.Appearance;

            if (settings[requested].Type == TelegramThemeType.Custom && File.Exists(settings[requested].Custom))
            {
                UpdateCustom(settings[requested].Custom);
            }
            else if (ThemeAccentInfo.IsAccent(settings[requested].Type))
            {
                Update(ThemeAccentInfo.FromAccent(settings[requested].Type, settings.Accents[settings[requested].Type]));
            }
            else
            {
                Update();
            }
        }
Ejemplo n.º 3
0
        public void Initialize(TelegramTheme requested)
        {
            var settings = SettingsService.Current.Appearance;

            if (settings.ChatTheme != null)
            {
                Update(requested, settings.ChatTheme);
            }
            else if (settings[requested].Type == TelegramThemeType.Custom && System.IO.File.Exists(settings[requested].Custom))
            {
                Update(ThemeCustomInfo.FromFile(settings[requested].Custom));
            }
            else if (ThemeAccentInfo.IsAccent(settings[requested].Type))
            {
                Update(ThemeAccentInfo.FromAccent(settings[requested].Type, settings.Accents[settings[requested].Type]));
            }
            else
            {
                Update(requested);
            }
        }
Ejemplo n.º 4
0
        private async void AccentThemeExecute()
        {
            var type = Settings.Appearance[Settings.Appearance.RequestedTheme].Type;

            if (ThemeAccentInfo.IsAccent(type))
            {
                var accent = Settings.Appearance.Accents[type];
                if (accent == default)
                {
                    accent = BootStrapper.Current.UISettings.GetColorValue(UIColorType.Accent);
                }

                var dialog = new SelectColorPopup();
                dialog.Color = accent;

                var confirm = await dialog.ShowAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    await SetThemeAsync(ThemeAccentInfo.FromAccent(type, dialog.Color));
                }
            }
        }
Ejemplo n.º 5
0
        // This is for chat specific theme
        public bool Update(ElementTheme elementTheme, ChatTheme theme)
        {
            var updated   = false;
            var requested = elementTheme == ElementTheme.Dark ? TelegramTheme.Dark : TelegramTheme.Light;

            var settings = requested == TelegramTheme.Light ? theme?.LightSettings : theme?.DarkSettings;

            if (settings != null)
            {
                if (_lastAccent != settings.AccentColor)
                {
                    _lastTheme = theme;

                    var tint = SettingsService.Current.Appearance[requested].Type;
                    if (tint == TelegramThemeType.Classic || (tint == TelegramThemeType.Custom && requested == TelegramTheme.Light))
                    {
                        tint = TelegramThemeType.Day;
                    }
                    else if (tint == TelegramThemeType.Custom)
                    {
                        tint = TelegramThemeType.Tinted;
                    }

                    var accent   = settings.AccentColor.ToColor();
                    var outgoing = settings.OutgoingMessageAccentColor.ToColor();

                    var info = ThemeAccentInfo.FromAccent(tint, accent, outgoing);
                    ThemeOutgoing.Update(info.Parent, info.Values);
                    ThemeIncoming.Update(info.Parent, info.Values);
                }
                if (_lastBackground != settings.Background?.Id)
                {
                    updated = true;
                }

                _lastAccent     = settings.AccentColor;
                _lastBackground = settings.Background?.Id;
            }
            else
            {
                if (_lastAccent != null)
                {
                    _lastTheme = null;

                    var options = SettingsService.Current.Appearance;
                    if (options[requested].Type == TelegramThemeType.Custom && System.IO.File.Exists(options[requested].Custom))
                    {
                        var info = ThemeCustomInfo.FromFile(options[requested].Custom);
                        ThemeOutgoing.Update(info.Parent, info.Values);
                        ThemeIncoming.Update(info.Parent, info.Values);
                    }
                    else if (ThemeAccentInfo.IsAccent(options[requested].Type))
                    {
                        var info = ThemeAccentInfo.FromAccent(options[requested].Type, options.Accents[options[requested].Type]);
                        ThemeOutgoing.Update(info.Parent, info.Values);
                        ThemeIncoming.Update(info.Parent, info.Values);
                    }
                    else
                    {
                        ThemeOutgoing.Update(requested);
                        ThemeIncoming.Update(requested);
                    }
                }
                if (_lastBackground != null)
                {
                    updated = true;
                }

                _lastAccent     = null;
                _lastBackground = null;
            }

            return(updated);
        }