Ejemplo n.º 1
0
        private async void EditCamera_Click(object sender, RoutedEventArgs e)
        {
            var capture = new CameraCaptureUI();

            capture.VideoSettings.AllowTrimming        = true;
            capture.VideoSettings.Format               = CameraCaptureUIVideoFormat.Mp4;
            capture.VideoSettings.MaxResolution        = CameraCaptureUIMaxVideoResolution.StandardDefinition;
            capture.VideoSettings.MaxDurationInSeconds = 9f;
            capture.PhotoSettings.AllowCropping        = true;
            capture.PhotoSettings.Format               = CameraCaptureUIPhotoFormat.Jpeg;
            capture.PhotoSettings.MaxResolution        = CameraCaptureUIMaxPhotoResolution.HighestAvailable;

            var file = await capture.CaptureFileAsync(CameraCaptureUIMode.PhotoOrVideo);

            if (file != null)
            {
                var media = await StorageMedia.CreateAsync(file);

                var dialog = new EditMediaPopup(media, ImageCropperMask.Ellipse);

                var confirm = await dialog.ShowAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    ViewModel.EditPhotoCommand.Execute(media);
                }
            }
        }
Ejemplo n.º 2
0
        public static async Task <StorageMedia> PickSingleMediaAsync(this FileOpenPicker picker)
        {
            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return(null);
            }

            return(await StorageMedia.CreateAsync(file));
        }
Ejemplo n.º 3
0
        private string ConvertCompression(StorageMedia media, double compression)
        {
            var value = (int)compression;

            if (media is StorageVideo video)
            {
                return(video.ToString(value));
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Format the storage madia of the jpeg module
        /// </summary>
        /// <param name="stMedia">the storage media to format</param>
        /// <returns>True if success</returns>
        public bool FormatStorageMedia(StorageMedia stMedia)
        {
            byte returnValue = 1;
            byte writeBuffer = (byte)(stMedia == StorageMedia.Resident ? 0 : 1);

            CreatCommand(1, CMD_FORMAT_STORAGEMEDIA);
            CreatCommand(new byte[] { writeBuffer });

            SendCommand(id_cmd);
            SendCommand(para_cmd);

            if (!ReceiveACK(CMD_FORMAT_STORAGEMEDIA, 100, ref returnValue) || returnValue != 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 5
0
        public EditMediaPopup(StorageMedia media, ImageCropperMask mask = ImageCropperMask.Rectangle)
        {
            InitializeComponent();

            Canvas.Strokes = media.EditState.Strokes;

            Cropper.SetMask(mask);
            Cropper.SetProportions(mask == ImageCropperMask.Ellipse ? BitmapProportions.Square : media.EditState.Proportions);

            if (mask == ImageCropperMask.Ellipse)
            {
                Proportions.IsChecked = true;
                Proportions.IsEnabled = false;
            }

            _file  = media.File;
            _media = media;

            Loaded += async(s, args) =>
            {
                if (mask == ImageCropperMask.Ellipse)
                {
                    await Cropper.SetSourceAsync(media.File, proportions : BitmapProportions.Square);
                }
                else
                {
                    await Cropper.SetSourceAsync(media.File, media.EditState.Rotation, media.EditState.Flip, media.EditState.Proportions, media.EditState.Rectangle);
                }
            };
            Unloaded += (s, args) =>
            {
                Media.Source = null;
            };

            if (mask == ImageCropperMask.Ellipse && string.Equals(media.File.FileType, ".mp4", StringComparison.OrdinalIgnoreCase))
            {
                FindName(nameof(TrimToolbar));
                TrimToolbar.Visibility  = Visibility.Visible;
                BasicToolbar.Visibility = Visibility.Collapsed;

                InitializeVideo(media.File);
            }
        }
Ejemplo n.º 6
0
        public EditMediaPopup(StorageMedia media)
        {
            InitializeComponent();

            Canvas.Strokes = media.EditState.Strokes;

            Cropper.SetMask(ImageCropperMask.Rectangle);
            Cropper.SetProportions(media.EditState.Proportions);

            if (media.EditState.Proportions != BitmapProportions.Custom)
            {
                Proportions.IsChecked = true;
                Proportions.IsEnabled = true;
            }

            _file  = media.File;
            _media = media;

            Loaded += async(s, args) =>
            {
                await Cropper.SetSourceAsync(media.File, media.EditState.Rotation, media.EditState.Flip, media.EditState.Proportions, media.EditState.Rectangle);
            };
        }
Ejemplo n.º 7
0
        private async void More_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.AddRange(Constants.MediaTypes);

            var files = await picker.PickMultipleFilesAsync();

            if (files != null)
            {
                foreach (var file in files)
                {
                    var storage = await StorageMedia.CreateAsync(file, true);

                    if (storage != null)
                    {
                        Items.Add(storage);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            if (SelectedItem != null && Items.Count > 1)
            {
                var index    = Items.IndexOf(SelectedItem);
                var next     = index > 0 ? Items[index - 1] : null;
                var previous = index < Items.Count - 1 ? Items[index + 1] : null;

                var item = Items[index];

                if (next != null)
                {
                    SelectedItem = next;
                }
                else
                {
                    SelectedItem = previous;
                }

                Items.Remove(item);
            }

            Remove.IsEnabled = Items.Count > 1;
        }
Ejemplo n.º 9
0
        public async void EditPhoto_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.AddRange(Constants.MediaTypes);

            var file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                var media = await StorageMedia.CreateAsync(file);

                var dialog = new EditMediaPopup(media, ImageCropperMask.Ellipse);

                var confirm = await dialog.ShowAsync();

                if (confirm == ContentDialogResult.Primary)
                {
                    ViewModel.EditPhotoCommand.Execute(media);
                }
            }
        }
Ejemplo n.º 10
0
 public MediaSelectedEventArgs(StorageMedia item, bool local)
 {
     Item    = item;
     IsLocal = local;
 }
        public async void SendMediaExecute(ObservableCollection <StorageMedia> media, StorageMedia selectedItem)
        {
            var chat = _chat;

            if (chat == null)
            {
                return;
            }

            if (media == null || media.IsEmpty())
            {
                return;
            }

            var dialog = new SendMediaView {
                ViewModel = this, IsTTLEnabled = chat.Type is ChatTypePrivate
            };

            dialog.SetItems(media);
            dialog.SelectedItem = selectedItem;

            var dialogResult = await dialog.ShowAsync();

            TextField?.FocusMaybe(FocusState.Keyboard);

            if (dialogResult == ContentDialogBaseResult.OK)
            {
                var items = dialog.SelectedItems.ToList();
                if (items.Count > 1 && dialog.IsGrouped)
                {
                    var group = new List <StorageMedia>(Math.Min(items.Count, 10));

                    foreach (var item in items)
                    {
                        group.Add(item);

                        if (group.Count == 10)
                        {
                            await SendGroupedAsync(group);

                            group = new List <StorageMedia>(Math.Min(items.Count, 10));
                        }
                    }

                    if (group.Count > 0)
                    {
                        await SendGroupedAsync(group);
                    }
                }
                else
                {
                    foreach (var storage in items)
                    {
                        if (storage is StoragePhoto photo)
                        {
                            var storageFile = await photo.GetFileAsync();
                            await SendPhotoAsync(storageFile, storage.Caption, storage.IsForceFile, storage.Ttl);
                        }
                        else if (storage is StorageVideo video)
                        {
                            await SendVideoAsync(storage.File, storage.Caption, video.IsMuted, storage.IsForceFile, storage.Ttl, await video.GetEncodingAsync(), video.GetTransform());
                        }
                    }
                }
            }
        }
        private async void SendMediaExecute()
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                if (Settings.IsSendGrouped && MediaLibrary.SelectedCount > 1)
                {
                    var items = MediaLibrary.Where(x => x.IsSelected).ToList();
                    var group = new List <StorageMedia>(Math.Min(items.Count, 10));

                    foreach (var item in items)
                    {
                        group.Add(item);

                        if (group.Count == 10)
                        {
                            await SendGroupedAsync(group);

                            group = new List <StorageMedia>(Math.Min(items.Count, 10));
                        }
                    }

                    if (group.Count > 0)
                    {
                        await SendGroupedAsync(group);
                    }
                }
                else
                {
                    foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                    {
                        if (storage is StoragePhoto photo)
                        {
                            var storageFile = await photo.GetFileAsync();
                            await SendPhotoAsync(storageFile, storage.Caption, storage.IsForceFile, storage.Ttl);
                        }
                        else if (storage is StorageVideo video)
                        {
                            await SendVideoAsync(storage.File, storage.Caption, video.IsMuted, storage.IsForceFile, storage.Ttl, await video.GetEncodingAsync(), video.GetTransform());
                        }
                    }
                }

                return;
            }

            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.AddRange(Constants.MediaTypes);

            var files = await picker.PickMultipleFilesAsync();

            if (files != null && files.Count > 0)
            {
                var storages = new ObservableCollection <StorageMedia>();

                foreach (var file in files)
                {
                    var storage = await StorageMedia.CreateAsync(file, true);

                    if (storage != null)
                    {
                        storages.Add(storage);
                    }
                }

                SendMediaExecute(storages, storages[0]);
            }
        }
Ejemplo n.º 13
0
        public EditMediaPopup(StorageMedia media, ImageCropperMask mask = ImageCropperMask.Rectangle, bool ttl = false)
        {
            InitializeComponent();

            Canvas.Strokes = media.EditState.Strokes;
            Cropper.SetMask(mask);
            if (mask == ImageCropperMask.Ellipse)
            {
                _hasMessageContext          = false;
                media.EditState.Proportions = BitmapProportions.Square;
            }
            Cropper.SetProportions(media.EditState.Proportions);

            _file  = media.File;
            _media = media;
            _originalMediaEditState = CopyBitmapEditState(media.EditState);

            Loaded += async(s, args) =>
            {
                await Cropper.SetSourceAsync(media.File, media.EditState.Rotation, media.EditState.Flip, media.EditState.Proportions, media.EditState.Rectangle);

                if (!_hasMessageContext) //TODO: Fix mask bug, remove hack (#2017 references mask position)
                {
                    await Cropper.SetSourceAsync(_media.File, _media.EditState.Rotation, _media.EditState.Flip, _media.EditState.Proportions, _media.EditState.Rectangle);

                    Cropper.SetProportions(_media.EditState.Proportions);
                }
                Cropper.IsCropEnabled = !_hasMessageContext && _media.IsVideo;
            };
            Unloaded += (s, args) =>
            {
                Media.Source = null;
            };

            #region Init UI
            if (mask == ImageCropperMask.Ellipse && string.Equals(media.File.FileType, ".mp4", StringComparison.OrdinalIgnoreCase))
            {
                FindName(nameof(TrimToolbar));
                TrimToolbar.Visibility    = Visibility.Visible;
                BasicToolbar.Visibility   = Visibility.Collapsed;
                SeparatorLeft.Visibility  = Visibility.Collapsed;
                SeparatorRight.Visibility = Visibility.Collapsed;

                InitializeVideo(media.File);
            }

            if (_media is StorageVideo video)
            {
                _originalVideoCompression = video.Compression;
                _originalVideoIsMuted     = video.IsMuted;
                Mute.IsChecked            = video.IsMuted;
                Mute.Visibility           = Visibility.Visible;
                Compress.IsChecked        = video.Compression != video.MaxCompression;
                Compress.Visibility       = video.CanCompress ? Visibility.Visible : Visibility.Collapsed;

                if (video.CanCompress)
                {
                    Compress.Glyph        = new CompressionToGlyphConverter().Convert(video.Compression, typeof(string), null, video.MaxCompression.ToString()).ToString();
                    Compress.CheckedGlyph = Compress.Glyph;
                    Compress.IsChecked    = video.Compression != video.MaxCompression;
                }
            }
            else
            {
                Mute.Visibility     = Visibility.Collapsed;
                Compress.Visibility = Visibility.Collapsed;
            }

            Crop.Visibility = _media is StoragePhoto ? Visibility.Visible : Visibility.Collapsed;
            Draw.Visibility = Crop.Visibility;
            Ttl.Visibility  = ttl ? Visibility.Visible : Visibility.Collapsed;
            Ttl.IsChecked   = _media.Ttl > 0;

            if (_media.EditState is BitmapEditState editSate)
            {
                Crop.IsChecked = editSate.Proportions != BitmapProportions.Custom ||
                                 editSate.Flip != BitmapFlip.None ||
                                 editSate.Rotation != BitmapRotation.None ||
                                 (!editSate.Rectangle.IsEmpty &&
                                  (editSate.Rectangle.X > 0 || editSate.Rectangle.Y > 0 ||
                                   Math.Abs(editSate.Rectangle.Width - 1) > 0.1f || Math.Abs(editSate.Rectangle.Height - 1) > 0.1f));

                Draw.IsChecked = editSate.Strokes != null && editSate.Strokes.Count > 0;
            }
            else
            {
                Crop.IsChecked = false;
                Draw.IsChecked = false;
            }

            if (_hasMessageContext)
            {
                if (!string.IsNullOrWhiteSpace(media.Caption?.Text))
                {
                    CaptionInput.SetText(media.Caption);
                }
            }
            else
            {
                CaptionInput.Visibility = Visibility.Collapsed;
            }
            #endregion
        }
Ejemplo n.º 14
0
 public MediaSelectedEventArgs(StorageMedia item)
 {
     Item = item;
 }
Ejemplo n.º 15
0
 private bool ConvertSelected(StorageMedia media)
 {
     return(SelectedItems.Contains(media));
 }
Ejemplo n.º 16
0
        public async void SendMediaExecute(ObservableCollection <StorageMedia> media, StorageMedia selectedItem)
        {
            var storages = media;

            if (storages != null && storages.Count > 0)
            {
                var dialog = new SendPhotosView {
                    ViewModel = this, Items = storages, SelectedItem = selectedItem, IsTTLEnabled = _peer is TLInputPeerUser
                };
                var dialogResult = await dialog.ShowAsync();

                TextField.FocusMaybe(FocusState.Keyboard);

                if (dialogResult == ContentDialogBaseResult.OK)
                {
                    foreach (var storage in dialog.Items.Where(x => x.IsSelected))
                    {
                        if (storage is StoragePhoto photo)
                        {
                            await SendPhotoAsync(storage.File, storage.Caption, storage.TTLSeconds);
                        }
                        else if (storage is StorageVideo video)
                        {
                            await SendVideoAsync(storage.File, storage.Caption, false, await video.GetEncodingAsync());
                        }
                    }
                }
            }
        }
Ejemplo n.º 17
0
 public override void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia)
 {
     copyMachine.StorageMedia = storageMedia;
     Console.WriteLine($"{storageMedia} is selected as the storage media");
     copyMachine.State = new SelectDocumentState();
 }
Ejemplo n.º 18
0
 public override void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia)
 {
     throw new Exception("You haven't deposited any coins yet");
 }
Ejemplo n.º 19
0
 public virtual void SelectStorageMedia(CopyMachine copyMachine, StorageMedia storageMedia)
 {
     throw new Exception("It's impossible to select storage media now");
 }
Ejemplo n.º 20
0
 public void SelectStorageMedia(StorageMedia storageMedia) => State.SelectStorageMedia(this, storageMedia);