Exemple #1
0
        public static void Map(ClipViewModel source, Clip target)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            byte[] data;

            if (source.Format == DataFormats.Bitmap)
            {
                data = Utils.ImageSourceToByteArray((ImageSource)source.Data);
            }
            else if (source.Format == DataFormats.Text)
            {
                data = Encoding.UTF8.GetBytes((string)source.Data);
            }
            else
            {
                data = Utils.ObjectToByteArray(source.Data);
            }

            target.Id           = source.Id;
            target.Data         = data;
            target.Format       = source.Format;
            target.AddedDate    = source.AddedDate;
            target.LastUsedDate = source.LastUsedDate;
        }
Exemple #2
0
        public static ClipViewModel Map(Clip source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            object data;

            if (source.Format == DataFormats.Bitmap)
            {
                data = Utils.ByteArrayToImageSource(source.Data);
            }
            else if (source.Format == DataFormats.Text)
            {
                data = Encoding.UTF8.GetString(source.Data);
            }
            else
            {
                data = Utils.ByteArrayToObject(source.Data);
            }

            var target = new ClipViewModel(data, source.Format);

            target.Id           = source.Id;
            target.AddedDate    = source.AddedDate;
            target.LastUsedDate = source.LastUsedDate;

            return(target);
        }
        protected ContentScreen(IContentPresenter creator, ClipViewModel owner, Action <ContentScreen> releaseFn)
        {
            ContentPresenter = creator;
            Clip             = owner;

            this.releaseFn = releaseFn;
            this.ConductWith(owner);
        }
 public ContentScreen CreateContentScreen(ClipViewModel clip)
 {
     return(contentScreenFactory.CreateTextScreen(
                creator: this,
                owner: clip,
                releaseFn: contentScreenFactory.Release
                ));
 }
Exemple #5
0
        public MockClipList()
        {
            AddClip(new Clipboard.Clip("AlternationCount=\"{Binding Items.Count, RelativeSource={RelativeSource Self}}\""));
            var pinnedClip = new Clipboard.Clip("rgba(255, 2, 50, .3)");
            var clipVM     = new ClipViewModel(pinnedClip);

            clipVM.Pinned = true;
            Clips.Add(clipVM);
            AddClip(new Clipboard.Clip("#0bb"));
        }
Exemple #6
0
        public static Clip Map(ClipViewModel source)
        {
            if (source == null)
            {
                throw new ArgumentNullException(nameof(source));
            }

            var target = new Clip();

            Map(source, target);

            return(target);
        }
Exemple #7
0
        private void AddClip(ISearchResultViewModel album, ClipViewModel clip)
        {
            var existing = album.Clips.Where(x => x.Id == clip.Id).FirstOrDefault();

            if (existing != null)
            {
                return;
            }

            Action action = () => album.AddClip(clip);

            Dispatcher.Invoke(action, DispatcherPriority.DataBind);
        }
        public ImageContentScreenViewModel(
            IContentPresenter creator, ClipViewModel owner, Action <ContentScreen> releaseFn,
            ActionButtonViewModel actionButton) : base(creator, owner, releaseFn)
        {
            // Create export image button
            exportImageButton             = actionButton;
            exportImageButton.ToolTip     = "Save as file";
            exportImageButton.Icon        = (Geometry)Application.Current.FindResource("IconExport");
            exportImageButton.ClickAction = ExportImage;
            exportImageButton.ConductWith(this);

            // Add export button to side controls of the clip
            Clip.SideControls.Add(exportImageButton);
        }
Exemple #9
0
        protected override async void OnKeyboardClipAdded(ClipViewModel newClip)
        {
            base.OnKeyboardClipAdded(newClip);

            // When new clip is added and user is not scrolling, we try to keep loaded clip count at size of one batch
            // This prevents from having too many items slowing down deactivation and switching between pages
            if (Items.Count <= DataProvider.BatchSize || !(Math.Abs(VerticalScrollOffset) < 4))
            {
                return;
            }

            ClipViewModel lastClip = Items.Last();
            await lastClip.TryCloseAsync();

            vmFactory.Release(lastClip);
        }
 public LinkContentScreenViewModel(IContentPresenter creator, ClipViewModel owner, Action <ContentScreen> releaseFn) : base(creator, owner, releaseFn)
 {
 }
Exemple #11
0
        public void HandleSearchResult(IMetadata result)
        {
            try
            {
                if (result == null)
                {
                    return;
                }

                if (result is IArtist)
                {
                    var artistKey = result.Location.ToString();
                    if (!artistResults.ContainsKey(artistKey))
                    {
                        var artistViewModel = new ArtistViewModel(mediaItemController, result as IArtist); //result.Location, result.Name, result.Summary, result.FromDate, result.ToDate, result.Thumbnail, result.ThumbnailData);
                        var resultViewModel = new SearchResultViewModel(artistViewModel);
                        artistResults.Add(artistKey, resultViewModel);
                        AddResult(resultViewModel);
                    }
                }
                else if (result is IAlbum)
                {
                    var albumViewModel = new AlbumViewModel(mediaItemController, result as IAlbum); //result.Location, result.Name, result.Summary, result.Creator, result.CreatorName, result.FromDate, result.Thumbnail, result.ThumbnailData);

                    var artistKey = result.Creator.ToString();
                    var albumKey  = result.Location.ToString();
                    if (!artistResults.ContainsKey(artistKey))
                    {
                        if (!albumResults.ContainsKey(albumKey))
                        {
                            var resultViewModel = new SearchResultViewModel(albumViewModel);
                            AddResult(resultViewModel);
                            albumResults.Add(albumKey, resultViewModel);
                        }
                    }
                    else
                    {
                        if (!albumResults.ContainsKey(albumKey))
                        {
                            var existing = artistResults[artistKey].Albums.Where(x => x.Id.ToString() == albumViewModel.Id.ToString()).FirstOrDefault();
                            if (existing == null)
                            {
                                AddAlbum(artistResults[artistKey], albumViewModel);
                            }
                        }
                    }
                }
                else if (result is ITrack)
                {
                    var trackViewModel = new TrackViewModel(mediaItemController, result as ITrack); //result.Location, result.Name, result.Summary, result.Number, result.Duration, result.FromDate, result.Creator, result.CreatorName, result.Catalog, result.CatalogName, result.Target, result.TargetType, result.Thumbnail, result.ThumbnailData);

                    var albumKey = result.Catalog.ToString();
                    var trackKey = result.Location.ToString();
                    if (!albumResults.ContainsKey(albumKey))
                    {
                        if (!trackResults.ContainsKey(trackKey))
                        {
                            var resultViewModel = new SearchResultViewModel(trackViewModel);
                            trackResults.Add(trackKey, resultViewModel);
                            AddResult(resultViewModel);
                        }
                    }
                    else
                    {
                        if (!trackResults.ContainsKey(trackKey))
                        {
                            //var existing = albumResults[albumKey].Tracks.Where(x => x.Album.ToString() == trackViewModel.Album.ToString()).FirstOrDefault();
                            //if (existing == null)
                            //{
                            AddTrack(albumResults[albumKey], trackViewModel);
                            //}
                        }
                    }
                }
                else if (result is IClip)
                {
                    var clipViewModel = new ClipViewModel(mediaItemController, result as IClip); //result.Location, result.Name, result.Summary, result.Number, result.Duration, result.Height, result.Width, result.FromDate, result.Creator, result.CreatorName, result.Catalog, result.CatalogName, result.Target, result.TargetType, result.Thumbnail, result.ThumbnailData);

                    var albumKey = result.Catalog.ToString();
                    var clipKey  = result.Location.ToString();
                    if (!albumResults.ContainsKey(albumKey))
                    {
                        if (!clipResults.ContainsKey(clipKey))
                        {
                            var resultViewModel = new SearchResultViewModel(clipViewModel);
                            clipResults.Add(clipKey, resultViewModel);
                            AddResult(resultViewModel);
                        }
                    }
                    else
                    {
                        if (!clipResults.ContainsKey(clipKey))
                        {
                            //var existing = albumResults[albumKey].Tracks.Where(x => x.Album.ToString() == trackViewModel.Album.ToString()).FirstOrDefault();
                            //if (existing == null)
                            //{
                            AddClip(albumResults[albumKey], clipViewModel);
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                logger.Error("  HandleSearchResults", ex);
            }
        }