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")); }
public async Task <Tuple <bool, string> > AddChatTheme(AddChatThemeInputModel model) { var targetTheme = await this.db.ChatThemes .FirstOrDefaultAsync(x => x.Name.ToUpper() == model.Name.ToUpper()); if (targetTheme != null) { return(Tuple.Create( false, string.Format(ErrorMessages.ChatThemeAlreadyExist, model.Name.ToUpper()))); } targetTheme = new ChatTheme { Name = model.Name, }; var imageUrl = await ApplicationCloudinary.UploadImage( this.cloudinary, model.Image, string.Format(GlobalConstants.ChatThemeName, targetTheme.Id), GlobalConstants.ChatThemesFolderName); targetTheme.Url = imageUrl; this.db.ChatThemes.Add(targetTheme); await this.db.SaveChangesAsync(); return(Tuple.Create( true, string.Format(SuccessMessages.SuccessfullyAddedChatTheme, model.Name.ToUpper()))); }
public void Decode(IByteBuffer buffer) { Theme = new ChatTheme(); Theme.BackgroundId = ByteBufUtils.ReadUTF8(buffer); Theme.BackgroundBlur = buffer.ReadInt(); Theme.BackgroundColor = buffer.ReadInt(); Theme.Use = (BackgroundType)buffer.ReadInt(); Theme.IconColor = buffer.ReadInt(); }
// 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)); }
// 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); }