Exemplo n.º 1
0
        public static ImageSource GetChat(Chat chat, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                if (chat.Type is ChatTypePrivate privata)
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(privata.UserId % _colors.Length)], InitialNameStringConverter.Convert(chat), stream);
                }
                else if (chat.Type is ChatTypeSecret secret)
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(secret.UserId % _colors.Length)], InitialNameStringConverter.Convert(chat), stream);
                }
                else if (chat.Type is ChatTypeBasicGroup basic)
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(basic.BasicGroupId % _colors.Length)], InitialNameStringConverter.Convert(chat), stream);
                }
                else if (chat.Type is ChatTypeSupergroup super)
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(super.SupergroupId % _colors.Length)], InitialNameStringConverter.Convert(chat), stream);
                }

                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 2
0
        public static LoadedImageSurface GetVectorSurface(IProtoService protoService, File file, Color foreground)
        {
            if (file.Local.IsDownloadingCompleted)
            {
                var text = GetSvgXml(file);

                var bitmap = default(LoadedImageSurface);
                using (var stream = new InMemoryRandomAccessStream())
                {
                    try
                    {
                        var size = PlaceholderImageHelper.GetForCurrentView().DrawSvg(text, foreground, stream);
                        bitmap = LoadedImageSurface.StartLoadFromStream(stream, new Windows.Foundation.Size(size.Width / 3, size.Height / 3));
                    }
                    catch { }
                }

                return(bitmap);
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && protoService != null)
            {
                protoService.DownloadFile(file.Id, 1);
            }

            return(null);
        }
Exemplo n.º 3
0
        public static ImageSource GetVector(IProtoService protoService, File file, Color foreground)
        {
            if (file.Local.IsDownloadingCompleted)
            {
                var text = GetSvgXml(file);

                var bitmap = new BitmapImage();
                using (var stream = new InMemoryRandomAccessStream())
                {
                    try
                    {
                        PlaceholderImageHelper.GetForCurrentView().DrawSvg(text, foreground, stream);

                        bitmap.SetSource(stream);
                    }
                    catch { }
                }

                return(bitmap);
            }
            else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive)
            {
                protoService.DownloadFile(file.Id, 1);
            }

            return(null);
        }
Exemplo n.º 4
0
        public static ImageSource GetIdenticon(IList <byte> hash)
        {
            var bitmap = new BitmapImage();

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawIdenticon(hash, stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 5
0
        public static ImageSource GetBlurred(string path)
        {
            var bitmap = new BitmapImage();

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawThumbnailPlaceholder(path, 3, stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 6
0
        public static ImageSource GetQr(string data, Color foreground, Color background)
        {
            var bitmap = new BitmapImage();

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawQr(data, foreground, background, stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 7
0
        public static ImageSource GetChat(ChatInviteLinkInfo chat, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[0], InitialNameStringConverter.Convert(chat), stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 8
0
        public static ImageSource GetUser(User user, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[Math.Abs(user.Id % _colors.Length)], InitialNameStringConverter.Convert(user), stream);
                try
                {
                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 9
0
        public static ImageSource GetGlyph(string glyph, int id, int side)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawGlyph(glyph, _colors[Math.Abs(id % _colors.Length)], stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 10
0
        public static ImageSource GetNameForChat(string title, int side, int color = 5)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(_colors[color], InitialNameStringConverter.Convert(title), stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 11
0
        public static ImageSource GetBadge(string text, Color color, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawProfilePlaceholder(color, InitialNameStringConverter.Convert(text), stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 12
0
        public static ImageSource GetSavedMessages(int id, int width, int height)
        {
            var bitmap = new BitmapImage {
                DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical
            };

            using (var stream = new InMemoryRandomAccessStream())
            {
                try
                {
                    PlaceholderImageHelper.GetForCurrentView().DrawSavedMessages(_colors[Math.Abs(id % _colors.Length)], stream);

                    bitmap.SetSource(stream);
                }
                catch { }
            }

            return(bitmap);
        }
Exemplo n.º 13
0
        public TLWindowContext(Window window, int id)
            : base(window)
        {
            _id = id;

            _window            = window;
            _window.Activated += OnActivated;

            _lifetime = TLContainer.Current.Lifetime;

            _placeholderHelper = PlaceholderImageHelper.GetForCurrentView();

            Windows.UI.ViewManagement.ApplicationView.GetForCurrentView().SetPreferredMinSize(new Size(320, 500));
            SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed;

            UpdateTitleBar();

            var app = App.Current as App;

            app.UISettings.ColorValuesChanged += UISettings_ColorValuesChanged;

            _window.CoreWindow.Closed += (s, e) =>
            {
                try
                {
                    _placeholderHelper = null;
                    app.UISettings.ColorValuesChanged -= UISettings_ColorValuesChanged;
                }
                catch { }
            };
            _window.Closed += (s, e) =>
            {
                try
                {
                    _placeholderHelper = null;
                    app.UISettings.ColorValuesChanged -= UISettings_ColorValuesChanged;
                }
                catch { }
            };
        }