コード例 #1
0
        private async void ThemeDeleteExecute(ThemeCustomInfo theme)
        {
            var confirm = await MessagePopup.ShowAsync(Strings.Resources.DeleteThemeAlert, Strings.Resources.AppName, Strings.Resources.Delete, Strings.Resources.Cancel);

            if (confirm != ContentDialogResult.Primary)
            {
                return;
            }

            try
            {
                var file = await StorageFile.GetFileFromPathAsync(theme.Path);

                await file.DeleteAsync();
            }
            catch { }

            if (Settings.Appearance[Settings.Appearance.RequestedTheme].Custom == theme.Path)
            {
                await SetThemeAsync(new ThemeBundledInfo { Parent = theme.Parent });
            }
            else
            {
                await RefreshThemesAsync();
            }
        }
コード例 #2
0
ファイル: ThemeService.cs プロジェクト: sp1ke77/Unigram
        public static bool Equals(ThemeCustomInfo x, ThemeCustomInfo y)
        {
            if (x.Parent != y.Parent)
            {
                return(false);
            }

            bool equal = false;

            if (x.Values.Count == y.Values.Count) // Require equal count.
            {
                equal = true;
                foreach (var pair in x.Values)
                {
                    if (y.Values.TryGetValue(pair.Key, out Color value))
                    {
                        // Require value be equal.
                        if (!Equals(value, pair.Value))
                        {
                            equal = false;
                            break;
                        }
                    }
                    else
                    {
                        // Require key be present.
                        equal = false;
                        break;
                    }
                }
            }

            return(equal);
        }
コード例 #3
0
        private async void ThemeEditExecute(ThemeCustomInfo theme)
        {
            await SetThemeAsync(theme);

            //NavigationService.Navigate(typeof(SettingsThemePage), theme.Path);
            if (Window.Current.Content is Views.Host.RootPage root)
            {
                root.ShowEditor(theme);
            }
        }
コード例 #4
0
        private async void ThemeCreateExecute(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 InputDialog();

            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 {
                Name = input.Text, Parent = theme.Parent
            };
            var fileName = Client.Execute(new CleanFileName(theme.Name)) as Text;

            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 _themeService.SerializeAsync(file, preparing);

            preparing.Path = file.Path;

            ThemeEditExecute(preparing);
        }
コード例 #5
0
ファイル: Theme.cs プロジェクト: yuezhenglingluan/Unigram
        public void Update(ThemeCustomInfo custom)
        {
            if (custom == null)
            {
                Update(SettingsService.Current.Appearance.RequestedTheme);
                return;
            }

            try
            {
                // Because of Compact, UpdateSource may be executed twice, but there is a bug in XAML and manually clear theme dictionaries here:
                // Prior to RS5, when ResourceDictionary.Source property is changed, XAML forgot to clear ThemeDictionaries.
                ThemeDictionaries.Clear();
                MergedDictionaries.Clear();

                MergedDictionaries.Add(new ResourceDictionary {
                    Source = new Uri("ms-appx:///Themes/ThemeGreen.xaml")
                });

                var dict = new ResourceDictionary();

                foreach (var item in custom.Values)
                {
                    if (item.Key.EndsWith("Brush"))
                    {
                        dict[item.Key] = new SolidColorBrush((Color)item.Value);
                    }
                    else if (item.Key.EndsWith("Color"))
                    {
                        dict[item.Key] = (Color)item.Value;
                    }
                }

                MergedDictionaries[0].MergedDictionaries.Clear();
                MergedDictionaries[0].MergedDictionaries.Add(dict);

                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.StatusBar"))
                {
                    TLWindowContext.GetForCurrentView().UpdateTitleBar();
                }
            }
            catch { }
        }
コード例 #6
0
        public void ShowEditor(ThemeCustomInfo theme)
        {
            var resize = ThemePage == null;

            FindName("ThemePage");
            ThemePage.Load(theme);

            if (resize)
            {
                MainColumn.Width = new GridLength(ActualWidth, GridUnitType.Pixel);

                var view = ApplicationView.GetForCurrentView();
                var size = view.VisibleBounds;

                view.TryResizeView(new Size(size.Width + 320, size.Height));
                ApplicationView.PreferredLaunchViewSize = new Size(size.Width, size.Height);

                MainColumn.Width = new GridLength(1, GridUnitType.Star);
            }
        }
コード例 #7
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);
            }
        }
コード例 #8
0
 public void Load(ThemeCustomInfo theme)
 {
     ViewModel.Initialize(theme);
 }
コード例 #9
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);
        }
コード例 #10
0
 public void Initialize(string path)
 {
     Update(ThemeCustomInfo.FromFile(path));
 }
コード例 #11
0
 private async void ThemeShareExecute(ThemeCustomInfo theme)
 {
     await SharePopup.GetForCurrentView().ShowAsync(new InputMessageDocument(new InputFileLocal(theme.Path), null, false, null));
 }