public async Task <bool> MultipleDeleteContacts() { int count = MegaContactsList.Count(n => n.IsMultiSelected); if (count < 1) { return(false); } var customMessageDialog = new CustomMessageDialog( AppMessages.DeleteMultipleContactsQuestion_Title, String.Format(AppMessages.DeleteMultipleContactsQuestion, count), App.AppInformation, MessageDialogButtons.OkCancel); customMessageDialog.OkOrYesButtonTapped += (sender, args) => { Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.SetProgressIndicator(true, ProgressMessages.RemoveContact)); var helperList = new List <Contact>(count); helperList.AddRange(MegaContactsList.Where(n => n.IsMultiSelected)); foreach (var contact in helperList) { MegaSdk.removeContact(MegaSdk.getContact(contact.Email), new RemoveContactRequestListener(this, contact)); } Deployment.Current.Dispatcher.BeginInvoke(() => ProgressService.SetProgressIndicator(false)); this.IsMultiSelectActive = false; }; return(await customMessageDialog.ShowDialogAsync() == MessageDialogResult.OkYes); }
public void GetMegaContacts() { // User must be online to perform this operation if (!IsUserOnline()) { return; } // First cancel any other loading task that is busy CancelLoad(); // Create the option to cancel CreateLoadCancelOption(); SetEmptyContentTemplate(true); OnUiThread(() => MegaContactsList.Clear()); MUserList contactsList = this.MegaSdk.getContacts(); Task.Factory.StartNew(() => { try { Deployment.Current.Dispatcher.BeginInvoke(() => { for (int i = 0; i < contactsList.size(); i++) { // If the task has been cancelled, stop processing if (LoadingCancelToken.IsCancellationRequested) { LoadingCancelToken.ThrowIfCancellationRequested(); } // To avoid null values if (contactsList.get(i) == null) { continue; } if ((contactsList.get(i).getVisibility() == MUserVisibility.VISIBILITY_VISIBLE)) { var _megaContact = new Contact() { Handle = contactsList.get(i).getHandle(), Email = contactsList.get(i).getEmail(), Timestamp = contactsList.get(i).getTimestamp(), Visibility = contactsList.get(i).getVisibility(), AvatarColor = UiService.GetColorFromHex(SdkService.MegaSdk.getUserAvatarColor(contactsList.get(i))) }; MegaContactsList.Add(_megaContact); MegaSdk.getUserAttribute(contactsList.get(i), (int)MUserAttrType.USER_ATTR_FIRSTNAME, new GetContactDataRequestListener(_megaContact)); MegaSdk.getUserAttribute(contactsList.get(i), (int)MUserAttrType.USER_ATTR_LASTNAME, new GetContactDataRequestListener(_megaContact)); MegaSdk.getUserAvatar(contactsList.get(i), _megaContact.AvatarPath, new GetContactAvatarRequestListener(_megaContact)); } } SetEmptyContentTemplate(false); }); } catch (OperationCanceledException) { // Do nothing. Just exit this background process because a cancellation exception has been thrown } }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current); }