private void PreloadSticker() { var index = _index; if (index >= _stickers.Count) { index = 0; } var sticker = _stickers[index]; _protoService.DownloadFile(sticker.StickerValue.Id, 32); _protoService.DownloadFile(sticker.PremiumAnimation.Id, 32); }
public static ImageSource GetChat(IProtoService protoService, Chat chat, int side) { if (chat.Type is ChatTypePrivate privata && protoService != null && protoService.IsSavedMessages(chat)) { return(GetSavedMessages(privata.UserId, side)); } var file = chat.Photo?.Small; if (file != null) { if (file.Local.IsDownloadingCompleted) { return(new BitmapImage(new Uri("file:///" + file.Local.Path)) { DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical }); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService?.DownloadFile(file.Id, 1); } } else if (protoService.TryGetUser(chat, out User user) && user.Type is UserTypeDeleted) { return(GetDeletedUser(user, side)); } else { return(GetChat(chat, side)); } return(null); }
public static ImageSource GetUser(IProtoService protoService, User user, int side) { var file = user.ProfilePhoto?.Small; if (file != null) { if (file.Local.IsDownloadingCompleted) { return(new BitmapImage(new Uri("file:///" + file.Local.Path)) { DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical }); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService?.DownloadFile(file.Id, 1); } } else if (user.Type is UserTypeDeleted) { return(GetDeletedUser(user, side)); } else { return(GetUser(user, side)); } return(null); }
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); }
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); }
public void UpdateFile(IProtoService protoService, File file) { var size = Math.Max(file.Size, file.ExpectedSize); if (file.Local.IsDownloadingActive) { Transfer.Value = (double)file.Local.DownloadedSize / size; Transfer.Opacity = 1; } else if (file.Remote.IsUploadingActive) { Transfer.Value = (double)file.Remote.UploadedSize / size; Transfer.Opacity = 1; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { Transfer.Value = 0; Transfer.Opacity = 0; protoService.DownloadFile(file.Id, 32); } else { Transfer.Value = 1; Transfer.Opacity = 0; Texture.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); } }
private string GetPhoto(Message message) { if (message.Content is MessagePhoto photo) { var small = photo.Photo.GetBig(); if (small == null || !small.Photo.Local.IsDownloadingCompleted) { _files[small.Photo.Id] = message; _protoService.DownloadFile(small.Photo.Id, 1, 0); return(string.Empty); } var file = new Uri(small.Photo.Local.Path); var folder = new Uri(ApplicationData.Current.LocalFolder.Path + "\\"); var relativePath = Uri.UnescapeDataString( folder.MakeRelativeUri(file) .ToString() ); return("ms-appdata:///local/" + relativePath); } return(string.Empty); }
private void UpdateThumbnail(Message message, PhotoSize photoSize, File file) { if (file.Local.IsDownloadingCompleted) { double ratioX = (double)48 / photoSize.Width; double ratioY = (double)48 / photoSize.Height; double ratio = Math.Max(ratioX, ratioY); var width = (int)(photoSize.Width * ratio); var height = (int)(photoSize.Height * ratio); Texture.Background = new ImageBrush { ImageSource = new BitmapImage(new Uri("file:///" + file.Local.Path)) { DecodePixelWidth = width, DecodePixelHeight = height }, Stretch = Stretch.UniformToFill, AlignmentX = AlignmentX.Center, AlignmentY = AlignmentY.Center }; Button.Style = App.Current.Resources["ImmersiveFileButtonStyle"] as Style; } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { _protoService.DownloadFile(file.Id, 1); Texture.Background = null; Button.Style = App.Current.Resources["InlineFileButtonStyle"] as Style; } }
public static ImageSource GetChat(IProtoService protoService, ChatInviteLinkInfo chat, int side) { var file = chat.Photo?.Small; if (file != null) { if (file.Local.IsDownloadingCompleted) { return(new BitmapImage(new Uri("file:///" + file.Local.Path)) { DecodePixelWidth = side, DecodePixelHeight = side, DecodePixelType = DecodePixelType.Logical }); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService?.DownloadFile(file.Id, 1); } } else { return(GetChat(chat, side)); } return(null); }
public void UpdateLine(IProtoService protoService, MosaicMediaRow line, Action <object> click) { Children.Clear(); foreach (var position in line) { UIElement content = null; object item = position.Item; if (item is InlineQueryResultAnimation inlineAnimation) { item = inlineAnimation.Animation; } else if (item is InlineQueryResultPhoto inlinePhoto) { item = inlinePhoto.Photo; } if (item is Animation animation && animation.Thumbnail != null) { content = new Image { Source = new BitmapImage(new Uri("file:///" + animation.Thumbnail.Photo.Local.Path)), Stretch = Stretch.UniformToFill }; if (!animation.Thumbnail.Photo.Local.IsDownloadingCompleted) { protoService.DownloadFile(animation.Thumbnail.Photo.Id, 1); } }
public static async Task <LoadedImageSurface> GetPatternSurfaceAsync(IProtoService protoService, File file) { using var locked = await _patternSurfaceLock.WaitAsync(); if (file.Local.IsFileExisting()) { var bitmap = default(LoadedImageSurface); var cache = $"{file.Remote.UniqueId}.cache.png"; var relative = System.IO.Path.Combine("wallpapers", cache); var item = await ApplicationData.Current.LocalFolder.TryGetItemAsync(relative) as StorageFile; if (item == null) { item = await ApplicationData.Current.LocalFolder.CreateFileAsync(relative, CreationCollisionOption.ReplaceExisting); using (var stream = await item.OpenAsync(FileAccessMode.ReadWrite)) { try { var text = await GetSvgXml(file); await PlaceholderImageHelper.Current.DrawSvgAsync(text, Colors.White, stream); } catch { } } } if (item != null) { using (var stream = await item.OpenReadAsync()) { try { var props = await item.Properties.GetImagePropertiesAsync(); bitmap = LoadedImageSurface.StartLoadFromStream(stream, new Size(props.Width / 2d, props.Height / 2d)); } catch { } } } return(bitmap); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && protoService != null) { protoService.DownloadFile(file.Id, 1); } return(null); }
public static ImageSource GetBitmap(IProtoService protoService, File file, int width, int height) { if (file.Local.IsFileExisting()) { return(UriEx.ToBitmap(file.Local.Path, width, height)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && protoService != null) { protoService.DownloadFile(file.Id, 1); } return(null); }
public static ImageSource GetBitmap(IProtoService protoService, File file, int width, int height) { if (file.Local.IsDownloadingCompleted) { return(new BitmapImage(new Uri("file:///" + file.Local.Path)) { DecodePixelWidth = width, DecodePixelHeight = height, DecodePixelType = DecodePixelType.Logical }); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService.DownloadFile(file.Id, 1); } return(null); }
private void Binder_Binding(MediaBinder sender, MediaBindingEventArgs args) { var deferral = args.GetDeferral(); if (_mapping.TryGetValue(args.MediaBinder.Token, out PlaybackItem item)) { var file = GetFile(item.Message); if (file.Local.IsDownloadingCompleted) { args.SetUri(new Uri("file:///" + file.Local.Path)); deferral.Complete(); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingCompleted) { _inverse[args.MediaBinder.Token] = deferral; _binders[args.MediaBinder.Token] = args; _protoService.DownloadFile(file.Id, 10); } } }
private void Button_Click(object sender, RoutedEventArgs e) { var data = _message.GetFileAndName(false); if (data.File == null) { return; } var file = data.File; if (file.Local.IsDownloadingActive) { _protoService.Send(new CancelDownloadFile(file.Id, false)); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive && !file.Local.IsDownloadingCompleted) { _protoService.DownloadFile(file.Id, 32); } else { _delegate.OpenFile(file); } }
public void Update(Call call, DateTime started) { if (_disposed) { return; } _call = call; _started = started; //if (_state != call.State) //{ // Debug.WriteLine("[{0:HH:mm:ss.fff}] State changed in app: " + tuple.Item1, DateTime.Now); // _state = tuple.Item1; // StateLabel.Content = StateToLabel(tuple.Item1); // if (tuple.Item1 == TLPhoneCallState.Established) // { // SignalBarsLabel.Visibility = Visibility.Visible; // StartUpdatingCallDuration(); // if (_emojis != null) // { // for (int i = 0; i < _emojis.Length; i++) // { // var imageLarge = FindName($"LargeEmoji{i}") as Image; // var source = Emoji.BuildUri(_emojis[i]); // imageLarge.Source = new BitmapImage(new Uri(source)); // } // } // } //} //if (tuple.Item2 is TLPhoneCallRequested call) //{ //} var user = _cacheService.GetUser(call.UserId); if (user != null) { if (user.ProfilePhoto != null) { var file = user.ProfilePhoto.Big; if (file.Local.IsDownloadingCompleted) { Image.Source = new BitmapImage(new Uri("file:///" + file.Local.Path)); BackgroundPanel.Background = new SolidColorBrush(Colors.Transparent); } else if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { Image.Source = null; BackgroundPanel.Background = PlaceholderHelper.GetBrush(user.Id); _protoService?.DownloadFile(file.Id, 1, 0); } } else { Image.Source = null; BackgroundPanel.Background = PlaceholderHelper.GetBrush(user.Id); } FromLabel.Text = user.GetFullName(); DescriptionLabel.Text = string.Format(Strings.Resources.CallEmojiKeyTooltip, user.FirstName); } if (call.State is CallStateReady ready) { _emojis = ready.Emojis; for (int i = 0; i < ready.Emojis.Count; i++) { var imageLarge = FindName($"LargeEmoji{i}") as Image; var source = Emoji.BuildUri(_emojis[i]); imageLarge.Source = new BitmapImage(new Uri(source)); } } switch (call.State) { case CallStatePending pending: if (call.IsOutgoing) { ResetUI(); } else { Mute.Visibility = Visibility.Collapsed; Close.Visibility = Visibility.Collapsed; Close.Margin = new Thickness(); Accept.Margin = new Thickness(0, 0, 6, 0); Accept.Visibility = Visibility.Visible; Discard.Margin = new Thickness(6, 0, 0, 0); Discard.Visibility = Visibility.Visible; } break; case CallStateDiscarded discarded: if (call.IsOutgoing && discarded.Reason is CallDiscardReasonDeclined) { Mute.Visibility = Visibility.Collapsed; Close.Margin = new Thickness(0, 0, 6, 0); Close.Visibility = Visibility.Visible; Accept.Margin = new Thickness(6, 0, 0, 0); Accept.Visibility = Visibility.Visible; Discard.Visibility = Visibility.Collapsed; Discard.Margin = new Thickness(); } break; default: ResetUI(); break; } switch (call.State) { case CallStatePending pending: StateLabel.Content = call.IsOutgoing ? pending.IsReceived ? Strings.Resources.VoipRinging : pending.IsCreated ? Strings.Resources.VoipWaiting : Strings.Resources.VoipRequesting : Strings.Resources.VoipIncoming; break; case CallStateExchangingKeys exchangingKeys: StateLabel.Content = Strings.Resources.VoipExchangingKeys; break; case CallStateHangingUp hangingUp: StateLabel.Content = Strings.Resources.VoipHangingUp; break; case CallStateDiscarded discarded: StateLabel.Content = discarded.Reason is CallDiscardReasonDeclined ? Strings.Resources.VoipBusy : Strings.Resources.VoipCallEnded; break; } }
public async Task UpdateAsync(bool force) { if (Package.Current.SignatureKind == PackageSignatureKind.Store) { return; } var diff = Environment.TickCount - _lastCheck; var skip = diff < 5 * 60 * 1000 || _checking; if (skip && !force) { return; } _checking = true; _lastCheck = diff; var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("updates", CreationCollisionOption.OpenIfExists); var files = await folder.GetFilesAsync(); var current = Package.Current.Id.Version.ToVersion(); var sets = new List <Version>(); foreach (var file in files) { var split = System.IO.Path.GetFileNameWithoutExtension(file.Name); if (Version.TryParse(split, out Version version)) { sets.Add(version); } } foreach (var version in sets) { // If this isn't the most recent version and it isn't in use, just delete it if (version <= current) { var file = await folder.TryGetItemAsync($"{version}.appxbundle") as StorageFile; if (file != null) { await file.DeleteAsync(); } } // We can safely ignore any other version as next steps will take care of them } var cloud = await GetNextUpdateAsync(); if (cloud != null && cloud.Version > current) { _nextUpdate = cloud; // There's a new version for the current font if (cloud.Document.Local.IsDownloadingCompleted || cloud.File != null) { _aggregator.Publish(new UpdateAppVersion(cloud)); } else if (cloud.Document.Local.CanBeDownloaded && !cloud.Document.Local.IsDownloadingActive) { _protoService.DownloadFile(cloud.Document.Id, 16); } } // This call is needed to delete old updates from disk await GetHistoryAsync(); _checking = false; }
public async Task UpdateAsync() { var folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("emoji", CreationCollisionOption.OpenIfExists); var files = await folder.GetFilesAsync(); var current = _settings.Appearance.EmojiSet; var sets = new Dictionary <string, List <int> >(); foreach (var file in files) { var split = file.Name.Split('.'); if (split.Length == 3 && split[2] == "ttf" && int.TryParse(split[1], out int version)) { if (sets.TryGetValue(split[0], out var versions)) { versions.Add(version); } else { sets[split[0]] = new List <int> { version }; } } } foreach (var set in sets) { var latest = set.Value.Max(); foreach (var version in set.Value) { // If this is the sticker set in use but we have a newer version set it for the next app launch if (set.Key == current.Id && version == current.Version && version < latest) { _settings.Appearance.EmojiSet = current = new InstalledEmojiSet { Id = current.Id, Title = current.Title, Version = latest }; } // If this isn't the most recent version and it isn't in use, just delete it else if (version < latest) { var file = await folder.TryGetItemAsync($"{set.Key}.{version}.ttf") as StorageFile; if (file != null) { await file.DeleteAsync(); } } } } var online = await GetCloudSetsAsync(); foreach (var item in online) { if (sets.TryGetValue(item.Id, out var installed) && item.Version > installed.Max()) { // There's a new version for the current font if (item.Document.Local.CanBeDownloaded && !item.Document.Local.IsDownloadingActive && !item.Document.Local.IsDownloadingCompleted) { _protoService.DownloadFile(item.Document.Id, 16); } if (item.Thumbnail.Local.CanBeDownloaded && !item.Thumbnail.Local.IsDownloadingActive && !item.Thumbnail.Local.IsDownloadingCompleted) { _protoService.DownloadFile(item.Thumbnail.Id, 16); } } } }
public void UpdateFeature(IProtoService protoService) { var reactions = protoService.Reactions.Values.Where(x => x.IsPremium).ToList(); var cols = 4; var rows = (int)Math.Ceiling((double)reactions.Count / cols); Presenter.ColumnDefinitions.Clear(); Presenter.RowDefinitions.Clear(); for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) { var i = x + y * cols; var button = Presenter.Children[i] as HyperlinkButton; if (button == null) { if (i < reactions.Count) { var item = reactions[i]; var view2 = new LottieView(); view2.AutoPlay = false; view2.IsLoopingEnabled = false; view2.FrameSize = new Size(64, 64); view2.DecodeFrameType = DecodePixelType.Logical; view2.Width = 64; view2.Height = 64; protoService.DownloadFile(item.AroundAnimation.StickerValue.Id, 32); var file = item.CenterAnimation.StickerValue; if (file.Local.IsFileExisting()) { view2.Source = UriEx.ToLocal(file.Local.Path); } else { view2.Source = null; UpdateManager.Subscribe(view2, protoService, file, /*UpdateReaction*/ UpdateFile, true); if (file.Local.CanBeDownloaded && !file.Local.IsDownloadingActive) { protoService.DownloadFile(file.Id, 32); } } button = new HyperlinkButton { Tag = reactions[i], Content = view2, Style = BootStrapper.Current.Resources["EmptyHyperlinkButtonStyle"] as Style }; button.Click += Reaction_Click; Presenter.Children.Add(button); } else { continue; } } Grid.SetColumn(button, x); Grid.SetRow(button, y); if (y == 0) { Presenter.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Auto) }); } } Presenter.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Auto) }); } }