Exemple #1
0
        public ThemeSettingsBase this[TelegramTheme type]
        {
            get
            {
                if (type == TelegramTheme.Light)
                {
                    return(_themeLight = _themeLight ?? new ThemeSettingsBase(_container, TelegramTheme.Light));
                }

                return(_themeDark = _themeDark ?? new ThemeSettingsBase(_container, TelegramTheme.Dark));
            }
        }
Exemple #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();
            }
        }
Exemple #3
0
        public Color GetDefaultColor(TelegramTheme flags, string key)
        {
            var resources = flags == TelegramTheme.Dark ? _defaultDark : _defaultLight;

            while (resources.TryGetValue(key, out object value))
            {
                if (value is string)
                {
                    key = value as string;
                }
                else if (value is Color color)
                {
                    return(color);
                }
            }

            return(default);
Exemple #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));
        }
Exemple #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);
            }
        }
 public ThemeCustomInfo(TelegramTheme parent, Color accent, string name)
     : base(TelegramThemeType.Custom, accent, null, null)
 {
     Parent = parent;
     Name   = name;
 }
Exemple #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 { }
        }
Exemple #8
0
 public Dictionary <string, string[]> GetMapping(TelegramTheme flags)
 {
     return(flags == TelegramTheme.Dark ? _mappingDark : _mapping);
 }
Exemple #9
0
 public static Dictionary <string, object> GetLookup(TelegramTheme flags)
 {
     return(flags == TelegramTheme.Dark ? _defaultDark : _defaultLight);
 }