public static DelenView Create(List<Identity> users, Share share, string path) { var view = (DelenView)Nib.Instantiate(null, null)[0]; view.Layer.ShadowColor = UIColor.FromRGBA(0f, 0f, 0f, .8f).CGColor; view.Layer.ShadowOpacity = 0.7f; view.Users = users; view.Share = share; view.TitelTekst.Text = string.Format("Delen: {0}",path); view.SluitenButton.TouchUpInside += (object sender, EventArgs e) => { view.RemoveFromSuperview(); }; view.OkButton.TouchUpInside += async (object sender, EventArgs e) => { DialogHelper.ShowBlockingProgressDialog("Bezig", "Deelinstellingen worden bijgewerkt. \nEen ogenblik geduld a.u.b."); List<Identity> selectedUsers = view._dataSource.SelectedUsers; bool shareSucceeded = false; string message; if(selectedUsers != null) { if (share == null) { shareSucceeded = await BusinessLayer.Instance.ShareFolder(path, selectedUsers); message = "Map is succesvol gedeeld."; } else { shareSucceeded = await BusinessLayer.Instance.UpdateSettingsSharedFolder(share, selectedUsers); message = "Deelinstellingen zijn succesvol bijgewerkt"; } DialogHelper.HideBlockingProgressDialog(); if(shareSucceeded){ UIAlertView alertSuccess = new UIAlertView("Succesvol", message, null, "OK"); alertSuccess.Show(); view.RemoveFromSuperview(); }else{ DialogHelper.ShowErrorDialog("Fout", "Er is een fout opgetreden bij delen van de map."); } }else{ DialogHelper.HideBlockingProgressDialog(); view.RemoveFromSuperview(); } //if (view.OnUsersSelected != null){ view.OnUsersSelected(view, EventArgs.Empty); //} //view = null; //}); }; view.NaamTextField.ShouldChangeCharacters = (textField, range, replacementString) => { string searchText = string.Empty; if (range.Length == 1 && string.IsNullOrEmpty(replacementString)) { if (textField.Text.Length > 0) { searchText = textField.Text.Substring(0, textField.Text.Length - 1); } } else { searchText = textField.Text + replacementString; } view._dataSource.UpdateData(view.Users.Where(f => f.Title.ToLower().Contains(searchText)).ToList()); view.TableView.ReloadData(); return true; }; if (share != null) { view._dataSource = new DelenDataSource(users, share.Identities); } else{ view._dataSource = new DelenDataSource(users); } view.TableView.Source = view._dataSource; return view; }
public Task<bool> UpdateSettingsSharedFolder (Share share, List<Identity> usersToShareWith) { return Task.Run (() => { LocalBox box = DataLayer.Instance.GetSelectedOrDefaultBox (); var explorer = new RemoteExplorer (box); List<Identity> inBoth = (from local in share.Identities join remote in usersToShareWith on local.Id equals remote.Id select local).ToList (); var toAdd = usersToShareWith.Where (e => inBoth.All (f => f.Id != e.Id)).ToList (); var toRemove = share.Identities.Where (e => inBoth.All (f => f.Id != e.Id)).ToList (); var messages = AddKeys (share.Item.Path, usersToShareWith, toAdd); RemoveKeys (share.Item.Path, toRemove); var result = explorer.UpdateSettingsSharedFolder (share.Id, usersToShareWith); foreach (var message in messages) { var r = explorer.AddAesKey (share.Item.Path, message); } return result; }); }