Esempio n. 1
0
        /// <summary>
        /// Selects multiple files using the system file picker
        /// </summary>
        /// <returns>A list with the selected files</returns>
        public static async Task <IReadOnlyList <StorageFile> > SelectMultipleFiles()
        {
            try
            {
                var fileOpenPicker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.List,
                    SuggestedStartLocation = PickerLocationId.ComputerFolder,
                    CommitButtonText       = ResourceService.UiResources.GetString("UI_Upload")
                };
                fileOpenPicker.FileTypeFilter.Add("*");

                return(await fileOpenPicker.PickMultipleFilesAsync());
            }
            catch (Exception e)
            {
                UiService.OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_SelectFileFailed_Title"),
                        string.Format(ResourceService.AppMessages.GetString("AM_SelectFileFailed"), e.Message));
                });

                return(new List <StorageFile>());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Select single file using the system file picker
        /// </summary>
        /// <returns>The selected file</returns>
        public static async Task <StorageFile> SelectSingleFile(IEnumerable <string> fileTypeFilter = null)
        {
            try
            {
                var fileOpenPicker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.List,
                    SuggestedStartLocation = PickerLocationId.ComputerFolder
                };
                if (fileTypeFilter == null)
                {
                    fileOpenPicker.FileTypeFilter.Add("*");
                }
                else
                {
                    foreach (var filter in fileTypeFilter)
                    {
                        fileOpenPicker.FileTypeFilter.Add(filter);
                    }
                }

                return(await fileOpenPicker.PickSingleFileAsync());
            }
            catch (Exception e)
            {
                UiService.OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_SelectFileFailed_Title"),
                        string.Format(ResourceService.AppMessages.GetString("AM_SelectFileFailed"), e.Message));
                });

                return(null);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Display an alert dialog to notify that the user has exceeded or will exceed during
        /// the current operation (pre alert) the storage limit of the account.
        /// </summary>
        /// <param name="isPreAlert">Parameter to indicate if is a pre alert situation.</param>
        public static async void ShowStorageOverquotaAlert(bool isPreAlert)
        {
            if (StorageOverquotaAlertDisplayed)
            {
                return;
            }
            StorageOverquotaAlertDisplayed = true;

            var title = isPreAlert ? ResourceService.AppMessages.GetString("AM_StorageOverquotaPreAlert_Title") :
                        ResourceService.AppMessages.GetString("AM_StorageOverquotaAlert_Title");
            var message = isPreAlert ? ResourceService.AppMessages.GetString("AM_StorageOverquotaPreAlert") :
                          ResourceService.AppMessages.GetString("AM_StorageOverquotaAlert");

            var result = await ShowOkCancelAsync(title, message, TwoButtonsDialogType.YesNo);

            StorageOverquotaAlertDisplayed = false;

            if (!result)
            {
                return;
            }

            UiService.OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Upgrade));
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the user last name attribute
        /// </summary>
        public static async void GetUserLastname()
        {
            var userAttributeRequestListener = new GetUserAttributeRequestListenerAsync();
            var lastname = await userAttributeRequestListener.ExecuteAsync(() =>
                                                                           SdkService.MegaSdk.getOwnUserAttribute((int)MUserAttrType.USER_ATTR_LASTNAME, userAttributeRequestListener));

            UiService.OnUiThread(() => UserData.Lastname = lastname);
        }
Esempio n. 5
0
 /// <summary>
 /// Stops the timer to detect a status change for the debug mode.
 /// </summary>
 private static void StopDebugModeTimer()
 {
     if (_timerDebugMode != null)
     {
         UiService.OnUiThread(() => _timerDebugMode.Stop());
     }
     _changeStatusActionCounter = 0;
 }
Esempio n. 6
0
 public static void Clear()
 {
     UiService.OnUiThread(() =>
     {
         MegaContacts.ItemCollection.Clear();
         IncomingContactRequests.ItemCollection.Clear();
         OutgoingContactRequests.ItemCollection.Clear();
     });
 }
Esempio n. 7
0
        /// <summary>
        /// Creates a destination download path external to the app.
        /// </summary>
        /// <param name="downloadPath">The external download folder path.</param>
        /// <returns>TRUE if all went well or FALSE in other case.</returns>
        private static async Task <bool> CreateExternalDownloadPathAsync(string downloadPath)
        {
            string rootPath         = Path.GetPathRoot(downloadPath);
            string tempDownloadPath = downloadPath;

            List <string> foldersNames = new List <string>(); //Folders that will be needed create
            List <string> foldersPaths = new List <string>(); //Paths where will needed create the folders

            //Loop to follow the reverse path to search the first missing folder
            while (string.Compare(tempDownloadPath, rootPath) != 0)
            {
                try { await StorageFolder.GetFolderFromPathAsync(tempDownloadPath); }
                catch (UnauthorizedAccessException)
                {
                    //The folder exists, but probably is a restricted access system folder in the download path.
                    break;                    // Exit the loop.
                }
                catch (FileNotFoundException) //Folder not exists
                {
                    //Include the folder name that will be needed create and the corresponding path
                    foldersNames.Insert(0, Path.GetFileName(tempDownloadPath));
                    foldersPaths.Insert(0, new DirectoryInfo(tempDownloadPath).Parent.FullName);
                }
                finally
                {
                    //Upgrade to the next path to check (parent folder)
                    tempDownloadPath = new DirectoryInfo(tempDownloadPath).Parent.FullName;
                }
            }

            // Create each necessary folder of the download path
            for (int i = 0; i < foldersNames.Count; i++)
            {
                try
                {
                    StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(foldersPaths.ElementAt(i));

                    await folder.CreateFolderAsync(Path.GetFileName(foldersNames.ElementAt(i)), CreationCollisionOption.OpenIfExists);
                }
                catch (Exception e)
                {
                    UiService.OnUiThread(async() =>
                    {
                        await DialogService.ShowAlertAsync(
                            ResourceService.AppMessages.GetString("AM_DownloadFailed_Title"),
                            string.Format(ResourceService.AppMessages.GetString("AM_CreateDownloadPathError"),
                                          e.GetType().Name + " - " + e.Message));
                    });
                    return(false);
                }
            }

            return(true);
        }
Esempio n. 8
0
        /// <summary>
        /// Show toast text notification and app logo.
        /// </summary>
        /// <param name="title">Title to show in the notification.</param>
        /// <param name="text">Text to show in the notification.</param>
        /// <param name="duration">
        /// How long (in seconds) will the notification be visible in the
        /// action center. Default is 5 seconds.
        /// To keep the system default value set zero or a negative value.
        /// </param>
        public static void ShowTextNotification(string title, string text, int duration = 5)
        {
            try
            {
                var visual = new ToastVisual
                {
                    BindingGeneric = new ToastBindingGeneric
                    {
                        Children =
                        {
                            new AdaptiveText {
                                Text = title
                            },
                            new AdaptiveText {
                                Text = text
                            }
                        },

                        AppLogoOverride = new ToastGenericAppLogo
                        {
                            Source   = LogoUri,
                            HintCrop = ToastGenericAppLogoCrop.Circle
                        }
                    }
                };

                var toastContent = new ToastContent
                {
                    Visual = visual,
                    Audio  = new ToastAudio()
                    {
                        Silent = true
                    },
                };

                var toast = new ToastNotification(toastContent.GetXml());
                if (duration > 0)
                {
                    toast.ExpirationTime = new DateTimeOffset(DateTime.Now.AddSeconds(duration));
                }

                try { ToastNotificationManager.CreateToastNotifier().Show(toast); }
                catch (Exception e)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Error showing toast notification", e);
                    UiService.OnUiThread(async() => await DialogService.ShowAlertAsync(title, text));
                }
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Error creating toast notification", e);
                UiService.OnUiThread(async() => await DialogService.ShowAlertAsync(title, text));
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Clear all the user data info
 /// </summary>
 public static void ClearUserData()
 {
     UiService.OnUiThread(() =>
     {
         UserData.UserEmail   = string.Empty;
         UserData.AvatarColor = (Color)Application.Current.Resources["MegaRedColor"];
         UserData.AvatarUri   = null;
         UserData.Firstname   = string.Empty;
         UserData.Lastname    = string.Empty;
     });
 }
Esempio n. 10
0
 /// <summary>
 /// Method that should be called when an action required for
 /// change the API URL is started.
 /// </summary>
 public static void ChangeApiUrlActionStarted()
 {
     UiService.OnUiThread(() =>
     {
         if (timerChangeApiUrl == null)
         {
             timerChangeApiUrl          = new DispatcherTimer();
             timerChangeApiUrl.Interval = new TimeSpan(0, 0, 5);
             timerChangeApiUrl.Tick    += (obj, args) => ChangeApiUrl();
         }
         timerChangeApiUrl.Start();
     });
 }
Esempio n. 11
0
        /// <summary>
        /// Gets all the account details info
        /// </summary>
        public static async void GetAccountDetails()
        {
            var accountDetailsRequestListener = new GetAccountDetailsRequestListenerAsync();
            var accountDetails = await accountDetailsRequestListener.ExecuteAsync(() =>
            {
                SdkService.MegaSdk.getAccountDetails(accountDetailsRequestListener);
            });

            if (accountDetails == null)
            {
                return;
            }

            UiService.OnUiThread(() =>
            {
                AccountDetails.AccountType = accountDetails.getProLevel();
                AccountDetails.TotalSpace  = accountDetails.getStorageMax();
                AccountDetails.UsedSpace   = accountDetails.getStorageUsed();

                AccountDetails.CloudDriveUsedSpace     = accountDetails.getStorageUsed(SdkService.MegaSdk.getRootNode().getHandle());
                AccountDetails.IncomingSharesUsedSpace = GetIncomingSharesUsedSpace();
                AccountDetails.RubbishBinUsedSpace     = accountDetails.getStorageUsed(SdkService.MegaSdk.getRubbishNode().getHandle());

                AccountDetails.TransferQuota     = accountDetails.getTransferMax();
                AccountDetails.UsedTransferQuota = accountDetails.getTransferOwnUsed();

                GetTransferOverquotaDetails();

                AccountDetails.PaymentMethod = accountDetails.getSubscriptionMethod();
            });

            // If there is a valid subscription
            if (accountDetails.getSubscriptionStatus() == MSubscriptionStatus.SUBSCRIPTION_STATUS_VALID)
            {
                // If is a valid and active subscription (auto renewable subscription)
                if (accountDetails.getSubscriptionRenewTime() != 0)
                {
                    GetSubscriptionDetails(accountDetails);
                }
                // If is a valid but non active subscription (canceled subscription)
                else if (accountDetails.getProExpiration() != 0)
                {
                    GetNonSubscriptionDetails(accountDetails);
                }
            }
            // If is a pro account without subscription
            else if (accountDetails.getProExpiration() != 0)
            {
                GetNonSubscriptionDetails(accountDetails);
            }
        }
Esempio n. 12
0
 /// <summary>
 /// Gets the specific details related to a transfer over-quota
 /// </summary>
 public static void GetTransferOverquotaDetails()
 {
     UiService.OnUiThread(() =>
     {
         AccountDetails.TransferOverquotaDelay = SdkService.MegaSdk.getBandwidthOverquotaDelay();
         AccountDetails.IsInTransferOverquota  = AccountDetails.TransferOverquotaDelay != 0;
         if (AccountDetails.IsInTransferOverquota)
         {
             AccountDetails.TimerTransferOverquota?.Start();
         }
         else
         {
             AccountDetails.TimerTransferOverquota?.Stop();
         }
     });
 }
Esempio n. 13
0
 /// <summary>
 /// Clear all the account details info
 /// </summary>
 public static void ClearAccountDetails()
 {
     UiService.OnUiThread(() =>
     {
         AccountDetails.AccountType           = MAccountType.ACCOUNT_TYPE_FREE;
         AccountDetails.TotalSpace            = 0;
         AccountDetails.UsedSpace             = 0;
         AccountDetails.CloudDriveUsedSpace   = 0;
         AccountDetails.RubbishBinUsedSpace   = 0;
         AccountDetails.TransferQuota         = 0;
         AccountDetails.UsedTransferQuota     = 0;
         AccountDetails.IsInTransferOverquota = false;
         AccountDetails.PaymentMethod         = string.Empty;
         AccountDetails.SubscriptionRenewDate = string.Empty;
         AccountDetails.ProExpirationDate     = string.Empty;
     });
 }
Esempio n. 14
0
        public static async void ShowOverquotaAlert()
        {
            var result = await ShowOkCancelAsync(
                ResourceService.AppMessages.GetString("AM_OverquotaAlert_Title"),
                ResourceService.AppMessages.GetString("AM_OverquotaAlert"),
                TwoButtonsDialogType.YesNo);

            if (!result)
            {
                return;
            }

            UiService.OnUiThread(() =>
            {
                NavigateService.Instance.Navigate(typeof(MyAccountPage), false,
                                                  NavigationObject.Create(typeof(MainViewModel), NavigationActionType.Upgrade));
            });
        }
Esempio n. 15
0
        /// <summary>
        /// Show toast alert notification with a warning icon.
        /// </summary>
        /// <param name="title">Title to show in the notification.</param>
        /// <param name="text">Text to show in the notification.</param>
        public static void ShowAlertNotification(string title, string text)
        {
            var visual = new ToastVisual
            {
                BindingGeneric = new ToastBindingGeneric
                {
                    Children =
                    {
                        new AdaptiveText {
                            Text = title
                        },
                        new AdaptiveText {
                            Text = text
                        }
                    },

                    AppLogoOverride = new ToastGenericAppLogo
                    {
                        Source   = WarningUri,
                        HintCrop = ToastGenericAppLogoCrop.Circle
                    }
                }
            };

            var toastContent = new ToastContent
            {
                Visual = visual,
                Audio  = new ToastAudio()
                {
                    Silent = false
                },
            };

            var toast = new ToastNotification(toastContent.GetXml());

            try { ToastNotificationManager.CreateToastNotifier().Show(toast); }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Error showing toast notification", e);
                UiService.OnUiThread(async() => await DialogService.ShowAlertAsync(title, text));
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Share a link with other external app
        /// </summary>
        /// <param name="link">Link to share</param>
        public static void ShareLink(string link)
        {
            DataTransferManager.GetForCurrentView().DataRequested += (sender, args) =>
            {
                args.Request.Data.Properties.Title       = ResourceService.AppMessages.GetString("AM_ShareLinkFromMega_Title");
                args.Request.Data.Properties.Description = ResourceService.AppMessages.GetString("AM_ShareLinkFromMega");
                args.Request.Data.SetText(link);
            };

            try { DataTransferManager.ShowShareUI(); }
            catch (Exception)
            {
                UiService.OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_ShareLinkFromMegaFailed_Title"),
                        ResourceService.AppMessages.GetString("AM_ShareLinkFromMegaFailed"));
                });
            }
        }
Esempio n. 17
0
        /// <summary>
        /// Open a folder in the file explorer
        /// </summary>
        /// <param name="folderPath">Path of the folder to open</param>
        /// <returns>TRUE if the folder could be opened or FALSE if something failed</returns>
        public static async Task <bool> OpenFolder(string folderPath)
        {
            try
            {
                var folder = await StorageFolder.GetFolderFromPathAsync(folderPath);

                return(await Launcher.LaunchFolderAsync(folder));
            }
            catch (Exception e)
            {
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Error opening folder", e);
                UiService.OnUiThread(async() =>
                {
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_OpenFolderFailed_Title"),
                        ResourceService.AppMessages.GetString("AM_OpenFolderFailed"));
                });

                return(false);
            }
        }
Esempio n. 18
0
        /// <summary>
        /// Gets the user avatar
        /// </summary>
        public static async void GetUserAvatar()
        {
            var userAvatarRequestListener = new GetUserAvatarRequestListenerAsync();
            var userAvatarResult          = await userAvatarRequestListener.ExecuteAsync(() =>
                                                                                         SdkService.MegaSdk.getOwnUserAvatar(UserData.AvatarPath, userAvatarRequestListener));

            if (userAvatarResult)
            {
                UiService.OnUiThread(() =>
                {
                    var img = new BitmapImage()
                    {
                        CreateOptions = BitmapCreateOptions.IgnoreImageCache,
                        UriSource     = new Uri(UserData.AvatarPath)
                    };
                    UserData.AvatarUri = img.UriSource;
                });
            }
            else
            {
                UiService.OnUiThread(() => UserData.AvatarUri = null);
            }
        }
Esempio n. 19
0
        /// <summary>
        /// Method that should be called when an action required for
        /// enable/disable the debug mode is done.
        /// </summary>
        public static void ChangeStatusAction()
        {
            if (_changeStatusActionCounter == 0)
            {
                UiService.OnUiThread(() =>
                {
                    if (_timerDebugMode == null)
                    {
                        _timerDebugMode          = new DispatcherTimer();
                        _timerDebugMode.Interval = new TimeSpan(0, 0, 5);
                        _timerDebugMode.Tick    += (obj, args) => StopDebugModeTimer();
                    }
                    _timerDebugMode.Start();
                });
            }

            _changeStatusActionCounter++;

            if (_changeStatusActionCounter >= 5)
            {
                StopDebugModeTimer();
                DebugSettings.IsDebugMode = !DebugSettings.IsDebugMode;
            }
        }
Esempio n. 20
0
        /// <summary>
        /// Gets the user avatar
        /// </summary>
        public static async void GetUserAvatar()
        {
            var userAvatarRequestListener = new GetUserAvatarRequestListenerAsync();
            var userAvatarResult          = await userAvatarRequestListener.ExecuteAsync(() =>
                                                                                         SdkService.MegaSdk.getOwnUserAvatar(UserData.AvatarPath, userAvatarRequestListener));

            if (userAvatarResult && UserData?.AvatarPath != null)
            {
                UiService.OnUiThread(() =>
                {
                    var img = new BitmapImage()
                    {
                        CreateOptions = BitmapCreateOptions.IgnoreImageCache,
                        UriSource     = new Uri(UserData.AvatarPath)
                    };
                    UserData.AvatarUri = img.UriSource;
                });
            }
            else
            {
                LogService.Log(MLogLevel.LOG_LEVEL_WARNING, "Error getting user avatar");
                UiService.OnUiThread(() => UserData.AvatarUri = null);
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Stops the timer to detect an API URL change.
 /// </summary>
 private static void StopChangeApiUrlTimer() =>
 UiService.OnUiThread(() => timerChangeApiUrl?.Stop());
Esempio n. 22
0
        /// <summary>
        /// Gets the user avatar color
        /// </summary>
        public static void GetUserAvatarColor()
        {
            var avatarColor = UiService.GetColorFromHex(SdkService.MegaSdk.getUserAvatarColor(SdkService.MegaSdk.getMyUser()));

            UiService.OnUiThread(() => UserData.AvatarColor = avatarColor);
        }
Esempio n. 23
0
        public static async void GetAccountAchievements()
        {
            UiService.OnUiThread(() =>
                                 AccountAchievements.IsAchievementsEnabled = SdkService.MegaSdk.isAchievementsEnabled());

            if (!SdkService.MegaSdk.isAchievementsEnabled())
            {
                return;
            }

            var accountAchievementsRequestListener = new GetAccountAchievementsRequestListenerAsync();
            var accountAchievements = await accountAchievementsRequestListener.ExecuteAsync(() =>
            {
                SdkService.MegaSdk.getAccountAchievements(accountAchievementsRequestListener);
            });

            if (accountAchievements == null)
            {
                return;
            }

            var awards = new List <AwardClassViewModel>
            {
                // Add Base storage & transfer
                new AwardClassViewModel(null, true)
                {
                    StorageReward = accountAchievements.getBaseStorage(),
                }
            };

            var awardedClasses = new List <AwardClassViewModel>
            {
                // Add Base storage & transfer
                new AwardClassViewModel(null, true)
                {
                    StorageReward           = accountAchievements.getBaseStorage(),
                    IsTransferAmountVisible = false,
                }
            };


            // Get all the user awards
            var awardsCount = accountAchievements.getAwardsCount();

            for (uint i = 0; i < awardsCount; i++)
            {
                var awardId    = accountAchievements.getAwardId(i);
                var awardClass = (MAchievementClass)accountAchievements.getAwardClass(i);

                var awardedClass = awardedClasses.FirstOrDefault(a => a.AchievementClass == awardClass);
                if (awardedClass == null)
                {
                    awardedClass = new AwardClassViewModel(awardClass)
                    {
                        IsGranted = true
                    };
                    awardedClasses.Add(awardedClass);
                }

                var storageReward  = accountAchievements.getRewardStorageByAwardId(awardId);
                var transferReward = accountAchievements.getRewardTransferByAwardId(awardId);
                var expireDate     = accountAchievements.getAwardExpirationTs(i).ConvertTimestampToDateTime();
                var achievedOnDate = accountAchievements.getAwardTimestamp(i).ConvertTimestampToDateTime();
                var durationInDays = accountAchievements.getClassExpire((int)awardClass);
                awards.Add(new AwardClassViewModel(awardClass)
                {
                    StorageReward  = storageReward,
                    TransferReward = transferReward,
                    ExpireDate     = expireDate,
                    AchievedOnDate = achievedOnDate,
                    DurationInDays = durationInDays,
                    IsGranted      = true
                });


                if (awardClass == MAchievementClass.MEGA_ACHIEVEMENT_INVITE)
                {
                    var mails    = accountAchievements.getAwardEmails(i);
                    var mailSize = mails.size();
                    for (int m = 0; m < mailSize; m++)
                    {
                        var contact = new ContactViewModel(
                            SdkService.MegaSdk.getContact(mails.get(m)), awardedClass.Contacts)
                        {
                            StorageAmount           = storageReward,
                            TransferAmount          = transferReward,
                            ReferralBonusExpireDate = expireDate,
                        };
                        awardedClass.Contacts.ItemCollection.Items.Add(contact);
                        contact.GetContactFirstname();
                        contact.GetContactLastname();
                        contact.GetContactAvatarColor();
                        contact.GetContactAvatar();
                    }

                    if (expireDate <= DateTime.Now)
                    {
                        continue;
                    }

                    awardedClass.StorageReward  += storageReward;
                    awardedClass.TransferReward += transferReward;
                }
                else
                {
                    awardedClass.ExpireDate     = expireDate;
                    awardedClass.StorageReward  = storageReward;
                    awardedClass.TransferReward = transferReward;
                    awardedClass.AchievedOnDate = achievedOnDate;
                    awardedClass.DurationInDays = durationInDays;
                }
            }

            var awardClasses    = Enum.GetValues(typeof(MAchievementClass)).OfType <MAchievementClass>();
            var availableAwards = new List <AwardClassViewModel>();

            foreach (var awardClass in awardClasses)
            {
                switch (awardClass)
                {
                case MAchievementClass.MEGA_ACHIEVEMENT_WELCOME:
                    continue;

                case MAchievementClass.MEGA_ACHIEVEMENT_INVITE:
                {
                    var inviteClass = new AwardClassViewModel(awardClass)
                    {
                        StorageReward  = accountAchievements.getClassStorage((int)awardClass),
                        TransferReward = accountAchievements.getClassTransfer((int)awardClass),
                        DurationInDays = accountAchievements.getClassExpire((int)awardClass),
                    };

                    inviteClass.Contacts.ItemCollection.Items =
                        awardedClasses.FirstOrDefault(a => a.AchievementClass == awardClass)?.Contacts.ItemCollection.Items;
                    availableAwards.Add(inviteClass);

                    continue;
                };
                }

                var available = awards.FirstOrDefault(a => a.AchievementClass == awardClass);

                if (available != null)
                {
                    continue;
                }

                availableAwards.Add(new AwardClassViewModel(awardClass)
                {
                    StorageReward  = accountAchievements.getClassStorage((int)awardClass),
                    TransferReward = accountAchievements.getClassTransfer((int)awardClass),
                    DurationInDays = accountAchievements.getClassExpire((int)awardClass)
                });
            }

            UiService.OnUiThread(() =>
            {
                if (accountAchievements.currentStorage() != -1)
                {
                    AccountAchievements.CurrentStorageQuota = (ulong)accountAchievements.currentStorage();
                }

                if (accountAchievements.currentTransfer() != -1)
                {
                    AccountAchievements.CurrentTransferQuota = (ulong)accountAchievements.currentTransfer();
                }

                AccountAchievements.Awards          = awards;
                AccountAchievements.AwardedClasses  = awardedClasses;
                AccountAchievements.AvailableAwards = availableAwards;
                AccountAchievements.CompletedAwards = awardedClasses.Where(a => a.IsGranted).ToList();
            });
        }
Esempio n. 24
0
        /// <summary>
        /// Navigates to the corresponding page depending on the current state or the active link.
        /// </summary>
        /// <returns>TRUE if navigates or FALSE in other case.</returns>
        private static async Task <bool> SpecialNavigation()
        {
            if (LinkInformationService.ActiveLink.Contains("#newsignup"))
            {
                UiService.OnUiThread(() =>
                                     NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true));
                return(true);
            }

            if (LinkInformationService.ActiveLink.Contains("#confirm"))
            {
                var signUp = new QuerySignUpLinkRequestListenerAsync();
                var result = await signUp.ExecuteAsync(() =>
                {
                    SdkService.MegaSdk.querySignupLink(LinkInformationService.ActiveLink, signUp);
                });

                switch (result)
                {
                case SignUpLinkType.Valid:
                    UiService.OnUiThread(() =>
                                         NavigateService.Instance.Navigate(typeof(ConfirmAccountPage), true,
                                                                           new NavigationObject
                    {
                        Action     = NavigationActionType.Default,
                        Parameters = new Dictionary <NavigationParamType, object>
                        {
                            { NavigationParamType.Email, signUp.EmailAddress },
                            { NavigationParamType.Data, LinkInformationService.ActiveLink },
                        }
                    }));
                    return(true);

                case SignUpLinkType.AutoConfirmed:
                    UiService.OnUiThread(() =>
                                         NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true,
                                                                           new NavigationObject
                    {
                        Action     = NavigationActionType.Login,
                        Parameters = new Dictionary <NavigationParamType, object>
                        {
                            { NavigationParamType.Email, signUp.EmailAddress },
                        }
                    }));
                    return(true);

                case SignUpLinkType.AlreadyConfirmed:
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_AlreadyConfirmedAccount_Title"),
                        ResourceService.AppMessages.GetString("AM_AlreadyConfirmedAccount"));

                    break;

                case SignUpLinkType.Expired:
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_SignUpLinkExpired_Title"),
                        ResourceService.AppMessages.GetString("AM_SignUpLinkExpired"));

                    break;

                case SignUpLinkType.Unknown:
                case SignUpLinkType.Invalid:
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_InvalidSignUpLink_Title"),
                        ResourceService.AppMessages.GetString("AM_InvalidSignUpLink"));

                    break;
                }

                return(false);
            }

            if (LinkInformationService.ActiveLink.Contains("#verify"))
            {
                UiService.OnUiThread(() =>
                                     NavigateService.Instance.Navigate(typeof(ConfirmChangeEmailPage), true));
                return(true);
            }

            if (LinkInformationService.ActiveLink.Contains("#recover"))
            {
                // Check if it is recover or park account
                var query  = new QueryPasswordLinkRequestListenerAsync();
                var result = await query.ExecuteAsync(() =>
                {
                    SdkService.MegaSdk.queryResetPasswordLink(LinkInformationService.ActiveLink, query);
                });

                switch (result)
                {
                case RecoverLinkType.Recovery:
                    UiService.OnUiThread(() => NavigateService.Instance.Navigate(typeof(RecoverPage), true));
                    return(true);

                case RecoverLinkType.ParkAccount:
                    UiService.OnUiThread(() => NavigateService.Instance.Navigate(typeof(ConfirmParkAccountPage), true));
                    return(true);

                case RecoverLinkType.Expired:
                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_RecoveryLinkExpired_Title"),
                        ResourceService.AppMessages.GetString("AM_RecoveryLinkExpired"));

                    break;

                case RecoverLinkType.Unknown:

                    await DialogService.ShowAlertAsync(
                        ResourceService.AppMessages.GetString("AM_InvalidRecoveryLink_Title"),
                        ResourceService.AppMessages.GetString("AM_InvalidRecoveryLink"));

                    break;
                }
            }

            if (LinkInformationService.ActiveLink.Contains("#F!"))
            {
                LinkInformationService.UriLink = UriLinkType.Folder;

                // Navigate to the folder link page
                UiService.OnUiThread(() =>
                                     NavigateService.Instance.Navigate(typeof(FolderLinkPage)));
                return(true);
            }

            if (LinkInformationService.ActiveLink.Contains("#!"))
            {
                LinkInformationService.UriLink = UriLinkType.Folder;

                // Navigate to the file link page
                UiService.OnUiThread(() =>
                                     NavigateService.Instance.Navigate(typeof(FileLinkPage)));
                return(true);
            }

            return(false);
        }