/// <summary> /// Clear the outgoing shared folders list. /// </summary> public void ClearOutgoingSharedFolders() { OutShares.ClearChildNodes(); OnUiThread(() => { OnPropertyChanged("HasOutSharedFolders"); OnPropertyChanged("NumberOfOutSharedFolders"); OnPropertyChanged("NumberOfOutSharedFoldersText"); }); }
/// <summary> /// Gets the outgoing shared folders and fills the list. /// </summary> public void GetOutgoingSharedFolders() { // 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(); OutShares.SetProgressIndication(true); // Process is started so we can set the empty content template to loading already OutShares.SetEmptyContentTemplate(true); MShareList outSharesList = MegaSdk.getOutShares(); if (outSharesList == null) { OnUiThread(() => { new CustomMessageDialog( AppMessages.AM_LoadFailed_Title, AppMessages.AM_LoadOutSharesFailed, App.AppInformation, MessageDialogButtons.Ok).ShowDialog(); OutShares.SetEmptyContentTemplate(false); }); return; } OnUiThread(() => OutShares.ChildNodes.Clear()); Task.Factory.StartNew(() => { try { ulong lastFolderHandle = 0; int outSharesListSize = outSharesList.size(); for (int i = 0; i < outSharesListSize; i++) { // If the task has been cancelled, stop processing if (LoadingCancelToken.IsCancellationRequested) { LoadingCancelToken.ThrowIfCancellationRequested(); } MShare outSharedFolder = outSharesList.get(i); // To avoid null values and public links if ((outSharedFolder != null) && MegaSdk.isOutShare(MegaSdk.getNodeByHandle(outSharedFolder.getNodeHandle()))) { // To avoid repeated values, folders shared with more than one user if (lastFolderHandle != outSharedFolder.getNodeHandle()) { lastFolderHandle = outSharedFolder.getNodeHandle(); var _outSharedFolder = NodeService.CreateNew(this.MegaSdk, this.AppInformation, MegaSdk.getNodeByHandle(lastFolderHandle), ContainerType.OutShares, OutShares.ChildNodes); if (_outSharedFolder != null) { _outSharedFolder.DefaultImagePathData = VisualResources.FolderTypePath_shared; OnUiThread(() => OutShares.ChildNodes.Add(_outSharedFolder)); } } } } OnUiThread(() => { OnPropertyChanged("HasOutSharedFolders"); OnPropertyChanged("NumberOfOutSharedFolders"); OnPropertyChanged("NumberOfOutSharedFoldersText"); }); } catch (OperationCanceledException) { // Do nothing. Just exit this background process because a cancellation exception has been thrown } finally { // Show the user that processing the childnodes is done OutShares.SetProgressIndication(false); // Set empty content to folder instead of loading view OutShares.SetEmptyContentTemplate(false); } }, LoadingCancelToken, TaskCreationOptions.PreferFairness, TaskScheduler.Current); }