public override void ViewDidAppear(bool animated) { base.ViewDidAppear(animated); sfImageEditor = new SfImageEditor(new CGRect(View.Frame.Location.X, 60, View.Frame.Size.Width, View.Frame.Size.Height - 60)); sfImageEditor.Image = UIImage.FromBundle("Images/ImageEditor/WhiteImage.png"); var sampleTimer = NSTimer.CreateTimer(TimeSpan.FromSeconds(3.0), delegate { ReadFile(); Dispose(); }); sampleTimer.Fire(); sfImageEditor.ImageSaving += (sender, e) => { e.Cancel = true; var stream = e.Stream; var byteArray = ReadFully(stream); NSData data = NSData.FromArray(byteArray); if (_model.Name == "Create New") { var count = _collectionView.DataSource.Count; SerializationModel item = new SerializationModel() { Name = itemName != "" ? itemName : ValidateName(), ImageAlignment = UIViewContentMode.Center, ImageBackgroundColor = UIColor.FromRGB(255, 255, 255), id = count - 1, EditsStrm = null }; item.EditsStrm = sfImageEditor.SaveEdits(); item.Image = UIImage.LoadFromData(data); item.ImageAlignment = UIViewContentMode.ScaleAspectFit; _serializationViewModel.ModelCollection.Add(item); EditsViewModel.EditsCollection.Add(new EditsModel() { Name = item.Name }); } else { _model.EditsStrm = sfImageEditor.SaveEdits(); _model.Image = UIImage.LoadFromData(data); _model.ImageAlignment = UIViewContentMode.ScaleAspectFit; } _collectionView.DataSource = _serializationViewModel.ModelCollection; }; this.View.Add(sfImageEditor); }
void ValidateItem(SerializationModel model) { if (model.Name == "Create New") { Delete.Alpha = 0; navigationController.PushViewController(new EditorViewController(model, CustomCollectionView, ViewModel), false); foreach (var item1 in ViewModel.ModelCollection) { item1.IsImageSelected = false; item1.IsItemSelectedToDelete = false; } CustomCollectionView.DataSource = ViewModel.ModelCollection; list = new List <SerializationModel>(); } else if (!model.IsImageSelected) { navigationController.PushViewController(new EditorViewController(model, CustomCollectionView, ViewModel), false); } else { if (!model.IsItemSelectedToDelete) { model.IsItemSelectedToDelete = true; list.Add(model); } else { model.IsItemSelectedToDelete = false; if (list.Count != 0) { list.Remove(model); } } CustomCollectionView.DataSource = ViewModel.ModelCollection; } }
internal void OnLongPressed(object sender, SerializationModel args) { this.LongPressed?.Invoke(sender, args); }
internal void OnItemSelected(object sender, SerializationModel args) { this.ItemSelected?.Invoke(sender, args); }
UIView GetItemView(SerializationModel model, CGRect frame) { UIButton button = new UIButton(frame); UIImageView imageView = new UIImageView(new CGRect(0, 5, frame.Width, frame.Height - 20)); imageView.Alpha = 1f; imageView.Image = model.Image; imageView.BackgroundColor = model.ImageBackgroundColor; imageView.ContentMode = model.ImageAlignment; button.AddSubview(imageView); UILabel label = new UILabel(); if (model.Name != "Create New") { label.Frame = new CGRect(0, frame.Height - 40, frame.Width, 25); label.Alpha = 0.5f; label.BackgroundColor = UIColor.LightGray; if (model.IsImageSelected) { UIImageView SelectedView = new UIImageView(new CGRect(frame.Width - 25, 10, 20, 20)); if (!model.IsItemSelectedToDelete) { SelectedView.Image = UIImage.FromBundle("Images/ImageEditor/NotSelected.png"); imageView.Alpha = 1f; } else { SelectedView.Image = UIImage.FromBundle("Images/ImageEditor/Selected.png"); imageView.Alpha = 0.3f; } SelectedView.BackgroundColor = UIColor.Clear; SelectedView.ContentMode = UIViewContentMode.ScaleAspectFit; button.AddSubview(SelectedView); } } else { if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) { label.Frame = new CGRect(0, frame.Height / 2 + 50, frame.Width, 25); } else { label.Frame = new CGRect(0, frame.Height / 2 + 20, frame.Width, 25); } label.Alpha = 1f; label.BackgroundColor = UIColor.Clear; label.TextColor = UIColor.White; } label.Font = UIFont.SystemFontOfSize(18); label.TextAlignment = UITextAlignment.Center; label.Text = model.Name; button.AddSubview(label); UILongPressGestureRecognizer detector = new UILongPressGestureRecognizer((UILongPressGestureRecognizer obj) => { OnLongPressed(this, model); }); button.AddGestureRecognizer(detector); button.TouchUpInside += (sender, e) => { OnItemSelected(this, model); }; return(button); }
public EditorViewController(SerializationModel model, CustomCollectionView collectionView, SerializationViewModel serializationViewModel) { _model = model; _serializationViewModel = serializationViewModel; _collectionView = collectionView; }