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;
        }
예제 #2
0
        public void Update(IProtoService protoService, ChatTheme theme)
        {
            _protoService = protoService;
            _theme        = theme;

            Name.Text = theme?.Name ?? string.Empty;

            var settings = ActualTheme == ElementTheme.Light ? theme.LightSettings : theme.DarkSettings;

            if (settings == null)
            {
                NoTheme.Visibility = Visibility.Visible;

                Preview.Unload();
                Outgoing.Fill = null;
                Incoming.Fill = null;
                return;
            }

            NoTheme.Visibility = Visibility.Collapsed;

            Preview.UpdateSource(protoService, settings.Background, true);
            Outgoing.Fill = settings.OutgoingMessageFill;
            Incoming.Fill = new SolidColorBrush(ThemeAccentInfo.Colorize(ActualTheme == ElementTheme.Light ? TelegramThemeType.Day : TelegramThemeType.Tinted, settings.AccentColor.ToColor(), "MessageBackgroundBrush"));
        }
예제 #3
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();
            }
        }
예제 #4
0
        // This is for global theme
        private void Update(TelegramTheme requested, ChatTheme theme)
        {
            var settings = requested == TelegramTheme.Light ? theme?.LightSettings : theme?.DarkSettings;

            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();

            Update(ThemeAccentInfo.FromAccent(tint, accent, outgoing));
        }
예제 #5
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);
            }
        }
예제 #6
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));
                }
            }
        }
예제 #7
0
        private void Update(TelegramTheme requested, ThemeAccentInfo info = null)
        {
            try
            {
                ThemeOutgoing.Update(requested, info?.Values);
                ThemeIncoming.Update(requested, info?.Values);

                var values = info?.Values;
                var shades = info?.Shades;

                var target = MergedDictionaries[0].ThemeDictionaries[requested == TelegramTheme.Light ? "Light" : "Dark"] as ResourceDictionary;
                var lookup = ThemeService.GetLookup(requested);

                if (shades != null && shades.TryGetValue(AccentShade.Default, out Color accentResource))
                {
                    target["Accent"] = accentResource;
                }
                else
                {
                    target["Accent"] = ThemeInfoBase.Accents[TelegramThemeType.Day][AccentShade.Default];
                }

                foreach (var item in lookup)
                {
                    if (target.TryGet(item.Key, out SolidColorBrush brush))
                    {
                        Color value;
                        if (item.Value is AccentShade shade)
                        {
                            if (shades != null && shades.TryGetValue(shade, out Color accent))
                            {
                                value = accent;
                            }
                            else
                            {
                                value = ThemeInfoBase.Accents[TelegramThemeType.Day][shade];
                            }
                        }
                        else if (values != null && values.TryGetValue(item.Key, out Color themed))
                        {
                            value = themed;
                        }
                        else if (item.Value is Color color)
                        {
                            value = color;
                        }

                        if (brush.Color == value)
                        {
                            continue;
                        }

                        try
                        {
                            brush.Color = value;
                        }
                        catch (UnauthorizedAccessException)
                        {
                            // Some times access denied is thrown,
                            // this seems to happen after the application
                            // is resumed, but unfortunately I can't see
                            // any fix to this. The exception is going
                            // to be thrown any time - even minutes after
                            // the resume - if the theme changes.

                            // The exception MIGHT be related to StaticResources
                            // but I'm not able to confirm this.
                        }
                    }
                }

                int GetColor(string key)
                {
                    if (target.TryGet(key, out SolidColorBrush brush))
                    {
                        return(brush.Color.ToValue());
                    }

                    return(0);
                }

                Parameters = new ThemeParameters
                {
                    BackgroundColor = GetColor("ContentDialogBackground"),
                    TextColor       = GetColor("ContentDialogForeground"),
                    ButtonColor     = GetColor("ButtonBackground"),
                    ButtonTextColor = GetColor("ButtonForeground"),
                    HintColor       = GetColor("SystemControlDisabledChromeDisabledLowBrush"),
                    LinkColor       = GetColor("HyperlinkForeground")
                };
            }
            catch { }
        }
예제 #8
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);
        }