Exemple #1
0
        /// <summary>
        /// Checks if the user has an active and online session and if need to navigate to a page
        /// depending on the current state or the active link.
        /// </summary>
        /// <param name="byMainPage">The caller of method</param>
        /// <returns>True if the user has an active and online session or false in other case</returns>
        public static async Task <bool> CheckActiveAndOnlineSessionAsync(bool byMainPage = false)
        {
            var hasActiveAndOnlineSession =
                Convert.ToBoolean(SdkService.MegaSdk.isLoggedIn()) ||
                await SettingsService.HasValidSessionAsync();

            if (byMainPage)
            {
                if (!hasActiveAndOnlineSession)
                {
                    UiService.OnUiThread(() =>
                    {
                        NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true);
                    });
                }

                return(hasActiveAndOnlineSession);
            }

            var navigationResult = await CheckSpecialNavigation(hasActiveAndOnlineSession);

            if (!hasActiveAndOnlineSession && navigationResult.HasValue && !navigationResult.Value)
            {
                UiService.OnUiThread(() =>
                {
                    NavigateService.Instance.Navigate(typeof(LoginAndCreateAccountPage), true);
                });
            }

            return(hasActiveAndOnlineSession);
        }