Esempio n. 1
0
        private async void OnAcceptClick(object sender, System.EventArgs e)
        {
            if (LstMediaItems.CheckedItems == null || LstMediaItems.CheckedItems.Count < 1)
            {
                new CustomMessageDialog(
                    AppMessages.MinimalPictureSelection_Title,
                    AppMessages.MinimalPictureSelection,
                    App.AppInformation,
                    MessageDialogButtons.Ok).ShowDialog();
                return;
            }

            ProgressService.SetProgressIndicator(true, ProgressMessages.PrepareUploads);
            SetControlState(false);

            // Set upload directory only once for speed improvement and if not exists, create dir
            var uploadDir = AppService.GetUploadDirectoryPath(true);

            foreach (var checkedItem in LstMediaItems.CheckedItems)
            {
                var item = (BaseMediaViewModel <Picture>)checkedItem;
                if (item == null)
                {
                    continue;
                }

                try
                {
                    string fileName = Path.GetFileName(item.Name);
                    if (fileName != null)
                    {
                        string newFilePath = Path.Combine(uploadDir, fileName);
                        using (var fs = new FileStream(newFilePath, FileMode.Create))
                        {
                            await item.BaseObject.GetImage().CopyToAsync(fs);

                            await fs.FlushAsync();

                            fs.Close();
                        }
                        var uploadTransfer = new TransferObjectModel(SdkService.MegaSdk, App.CloudDrive.CurrentRootNode, MTransferType.TYPE_UPLOAD, newFilePath);
                        TransfersService.MegaTransfers.Add(uploadTransfer);
                        uploadTransfer.StartTransfer();
                    }
                }
                catch (Exception)
                {
                    new CustomMessageDialog(
                        AppMessages.PrepareImageForUploadFailed_Title,
                        String.Format(AppMessages.PrepareImageForUploadFailed, item.Name),
                        App.AppInformation,
                        MessageDialogButtons.Ok).ShowDialog();
                }
            }

            ProgressService.SetProgressIndicator(false);
            SetControlState(true);

            App.CloudDrive.NoFolderUpAction = true;

            if (NavigateService.CanGoBack())
            {
                NavigateService.GoBack();
            }
            else
            {
                NavigateService.NavigateTo(typeof(MainPage), NavigationParameter.Normal);
            }
        }
Esempio n. 2
0
 protected void InitializeMenu(HamburgerMenuItemType activeItem)
 {
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.CloudDrive,
         DisplayName  = UiResources.CloudDriveName.ToLower(),
         IconPathData = VisualResources.CloudDriveMenuPathData,
         IconWidth    = 48,
         IconHeight   = 34,
         Margin       = new Thickness(36, 0, 35, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(MainPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.CloudDrive
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.SavedForOffline,
         DisplayName  = UiResources.SavedForOffline.ToLower(),
         IconPathData = VisualResources.SavedOfflineIcoData,
         IconWidth    = 44,
         IconHeight   = 44,
         Margin       = new Thickness(38, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(SavedForOfflinePage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.SavedForOffline
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.CameraUploads,
         DisplayName  = UiResources.CameraUploads.ToLower(),
         IconPathData = VisualResources.CameraUploadsPathData,
         IconWidth    = 46,
         IconHeight   = 36,
         Margin       = new Thickness(37, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(CameraUploadsPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.CameraUploads
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.SharedItems,
         DisplayName  = UiResources.SharedItems.ToLower(),
         IconPathData = VisualResources.SharedItemsPathData,
         IconWidth    = 45,
         IconHeight   = 36,
         Margin       = new Thickness(37, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(SharedItemsPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.SharedItems
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.Contacts,
         DisplayName  = UiResources.Contacts.ToLower(),
         IconPathData = VisualResources.ContactsPathData,
         IconWidth    = 45,
         IconHeight   = 33,
         Margin       = new Thickness(37, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(ContactsPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.Contacts
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.Transfers,
         DisplayName  = UiResources.Transfers.ToLower(),
         IconPathData = VisualResources.TransfersPathData,
         IconWidth    = 44,
         IconHeight   = 44,
         Margin       = new Thickness(38, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(TransferPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.Transfers
     });
     this.MenuItems.Add(new HamburgerMenuItem()
     {
         Type         = HamburgerMenuItemType.Settings,
         DisplayName  = UiResources.Settings.ToLower(),
         IconPathData = VisualResources.SettingsPathData,
         IconWidth    = 45,
         IconHeight   = 45,
         Margin       = new Thickness(37, 0, 36, 0),
         TapAction    = () =>
         {
             NavigateService.NavigateTo(typeof(SettingsPage), NavigationParameter.Normal);
         },
         IsActive = activeItem == HamburgerMenuItemType.Settings
     });
 }
Esempio n. 3
0
 private void OnItemTap(object sender, ListBoxItemTapEventArgs e)
 {
     NavigateService.NavigateTo(typeof(MediaAlbumPage), NavigationParameter.Normal, LstMediaAlbums.SelectedItem);
 }
Esempio n. 4
0
 private void btnCreateAccount_Click(object sender, RoutedEventArgs e)
 {
     NavigateService.NavigateTo(typeof(LoginPage), NavigationParameter.Normal, new Dictionary <string, string> {
         { "Pivot", "1" }
     });
 }
Esempio n. 5
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            // Remove the main page from the stack. If user presses back button it will then exit the application
            // Also removes the login page and the create account page after the user has created the account succesful
            while (NavigationService.CanGoBack)
            {
                NavigationService.RemoveBackEntry();
            }

            NavigationParameter navParam = NavigateService.ProcessQueryString(NavigationContext.QueryString);

            // Try to avoid display duplicate alerts
            if (isAlertAlreadyDisplayed)
            {
                return;
            }
            isAlertAlreadyDisplayed = true;

            switch (navParam)
            {
            case NavigationParameter.CreateAccount:
                // Show the success message
                new CustomMessageDialog(
                    AppMessages.ConfirmNeeded_Title,
                    AppMessages.ConfirmNeeded,
                    App.AppInformation,
                    MessageDialogButtons.Ok).ShowDialog();
                break;

            case NavigationParameter.API_ESID:
                // Show a message notifying the error
                new CustomMessageDialog(
                    AppMessages.SessionIDError_Title,
                    AppMessages.SessionIDError,
                    App.AppInformation,
                    MessageDialogButtons.Ok).ShowDialog();
                break;

            case NavigationParameter.API_EBLOCKED:
                string message;
                switch ((AccountBlockedReason)Convert.ToInt32(NavigationContext.QueryString["Number"]))
                {
                case AccountBlockedReason.Copyright:
                    message = AppMessages.AM_AccountBlockedCopyright;
                    break;

                case AccountBlockedReason.OtherReason:
                default:
                    message = AppMessages.AM_AccountBlocked;
                    break;
                }

                // Show a message notifying the error
                new CustomMessageDialog(
                    AppMessages.AM_AccountBlocked_Title,
                    message,
                    App.AppInformation,
                    MessageDialogButtons.Ok).ShowDialog();
                break;
            }
        }
Esempio n. 6
0
        public void onEvent(MegaSDK api, MEvent ev)
        {
            switch (ev.getType())
            {
            // If the account has been blocked
            case MEventType.EVENT_ACCOUNT_BLOCKED:
                LogService.Log(MLogLevel.LOG_LEVEL_ERROR, "Blocked account: " + ev.getText());

                // A blocked account automatically triggers a logout
                AppService.LogoutActions();

                // Show the login page with the corresponding navigation parameter
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    NavigateService.NavigateTo(typeof(InitTourPage), NavigationParameter.API_EBLOCKED,
                                               new Dictionary <string, string>
                    {
                        { "Number", ev.getNumber().ToString() },
                        { "Text", ev.getText() }
                    });
                });
                break;

            case MEventType.EVENT_STORAGE:
                bool notifyChange = false;
                var  storageState = (MStorageState)ev.getNumber();
                switch (storageState)
                {
                case MStorageState.STORAGE_STATE_GREEN:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE GREEN");
                    if (storageState == AccountService.AccountDetails.StorageState)
                    {
                        notifyChange = true;
                    }
                    AccountService.AccountDetails.StorageState = storageState;
                    break;

                case MStorageState.STORAGE_STATE_ORANGE:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE ORANGE");
                    if (storageState > AccountService.AccountDetails.StorageState)
                    {
                        notifyChange = true;
                    }
                    AccountService.AccountDetails.StorageState = storageState;
                    break;

                case MStorageState.STORAGE_STATE_RED:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE RED");
                    if (storageState > AccountService.AccountDetails.StorageState)
                    {
                        UiService.OnUiThread(() => DialogService.ShowStorageOverquotaAlert(false));
                        notifyChange = true;
                    }
                    AccountService.AccountDetails.StorageState = storageState;
                    break;

                case MStorageState.STORAGE_STATE_CHANGE:
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO, "STORAGE STATE CHANGE");
                    AccountService.GetAccountDetails();
                    break;
                }

                if (notifyChange)
                {
                    OnStorageStateChanged();
                }
                break;
            }
        }
 private void OnSettingsClick(object sender, EventArgs e)
 {
     NavigateService.NavigateTo(typeof(SettingsPage), NavigationParameter.Normal);
 }
Esempio n. 8
0
        public virtual void onRequestFinish(MegaSDK api, MRequest request, MError e)
        {
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                ProgressService.ChangeProgressBarBackgroundColor((Color)Application.Current.Resources["PhoneChromeColor"]);
                ProgressService.SetProgressIndicator(false);
            });

            switch (e.getErrorCode())
            {
            case MErrorType.API_OK:
                if (ShowSuccesMessage)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        new CustomMessageDialog(
                            SuccessMessageTitle,
                            SuccessMessage,
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });
                }

                if (ActionOnSucces)
                {
                    OnSuccesAction(api, request);
                }

                if (NavigateOnSucces)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => NavigateService.NavigateTo(NavigateToPage, NavigationParameter));
                }
                break;

            case MErrorType.API_EGOINGOVERQUOTA: // Not enough quota
            case MErrorType.API_EOVERQUOTA:      //Storage overquota error
                // Stop all upload transfers
                LogService.Log(MLogLevel.LOG_LEVEL_INFO,
                               string.Format("Storage quota exceeded ({0}) - Canceling uploads", e.getErrorCode().ToString()));
                api.cancelTransfers((int)MTransferType.TYPE_UPLOAD);

                // Disable the "camera upload" service if is enabled
                if (MediaService.GetAutoCameraUploadStatus())
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_INFO,
                                   string.Format("Storage quota exceeded ({0}) - Disabling CAMERA UPLOADS service", e.getErrorCode().ToString()));
                    MediaService.SetAutoCameraUpload(false);
                    SettingsService.SaveSetting(SettingsResources.CameraUploadsIsEnabled, false);
                }

                Deployment.Current.Dispatcher.BeginInvoke(() => DialogService.ShowOverquotaAlert());
                break;

            default:
                if (e.getErrorCode() != MErrorType.API_EINCOMPLETE)
                {
                    if (ShowErrorMessage)
                    {
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            new CustomMessageDialog(
                                ErrorMessageTitle,
                                String.Format(ErrorMessage, e.getErrorString()),
                                App.AppInformation,
                                MessageDialogButtons.Ok).ShowDialog();
                        });
                    }
                }
                break;
            }
        }
        public override Uri MapUri(Uri uri)
        {
            string tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

            // URI association launch for MEGA.
            if (tempUri.Contains("mega://"))
            {
                App.LinkInformation.Reset();

                // Process the URI
                tempUri = tempUri.Replace(@"/Protocol?encodedLaunchUri=", String.Empty);
                tempUri = UriService.ReformatUri(tempUri);

                App.LinkInformation.ActiveLink = tempUri;

                //File link - Open file link to import or download
                if (tempUri.Contains("https://mega.nz/#!"))
                {
                    var extraParams = new Dictionary <string, string>(1)
                    {
                        {
                            "filelink",
                            System.Net.HttpUtility.UrlEncode(tempUri)
                        }
                    };

                    // Needed to get the file link properly
                    if (tempUri.EndsWith("/"))
                    {
                        tempUri = tempUri.Remove(tempUri.Length - 1, 1);
                    }

                    App.LinkInformation.ActiveLink = tempUri;
                    App.LinkInformation.UriLink    = UriLinkType.File;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.FileLinkLaunch, extraParams));
                }
                // Confirm account link
                else if (tempUri.Contains("https://mega.nz/#confirm"))
                {
                    // Go the confirm account page and add the confirm string as parameter
                    var extraParams = new Dictionary <string, string>(1)
                    {
                        {
                            "confirm",
                            System.Net.HttpUtility.UrlEncode(tempUri)
                        }
                    };

                    App.LinkInformation.UriLink = UriLinkType.Confirm;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.UriLaunch, extraParams));
                }
                //Folder link - Open folder link to import or download
                else if (tempUri.Contains("https://mega.nz/#F!"))
                {
                    var extraParams = new Dictionary <string, string>(1)
                    {
                        {
                            "folderlink",
                            System.Net.HttpUtility.UrlEncode(tempUri)
                        }
                    };

                    App.LinkInformation.ActiveLink = tempUri;
                    App.LinkInformation.UriLink    = UriLinkType.Folder;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.FolderLinkLaunch, extraParams));
                }
                //Recovery Key backup link
                else if (tempUri.Contains("https://mega.nz/#backup"))
                {
                    App.LinkInformation.UriLink = UriLinkType.Backup;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.UriLaunch,
                                                              new Dictionary <string, string>(1)
                    {
                        { "backup", String.Empty }
                    }));
                }
                //New sign up link - Incoming share or contact request (no MEGA account)
                else if (tempUri.Contains("https://mega.nz/#newsignup"))
                {
                    App.LinkInformation.UriLink = UriLinkType.NewSignUp;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.UriLaunch,
                                                              new Dictionary <string, string>(1)
                    {
                        { "newsignup", System.Net.HttpUtility.UrlEncode(tempUri) }
                    }));
                }
                //Confirm cancel a MEGA account
                else if (tempUri.Contains("https://mega.nz/#cancel"))
                {
                    App.LinkInformation.UriLink = UriLinkType.Cancel;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.Normal));
                }
                //Recover link - Recover the password with the Recovery Key or park the account
                else if (tempUri.Contains("https://mega.nz/#recover"))
                {
                    App.LinkInformation.UriLink = UriLinkType.Recover;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.Normal));
                }
                //Verify the change of the email address of the MEGA account
                else if (tempUri.Contains("https://mega.nz/#verify"))
                {
                    App.LinkInformation.UriLink = UriLinkType.Verify;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.Normal));
                }
                //Contact request to an email with an associated account of MEGA
                else if (tempUri.Contains("https://mega.nz/#fm/ipc"))
                {
                    App.LinkInformation.UriLink = UriLinkType.FmIpc;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.UriLaunch,
                                                              new Dictionary <string, string>(1)
                    {
                        { "fm/ipc", String.Empty }
                    }));
                }
                //Internal node link
                else if (tempUri.Contains("https://mega.nz/#"))
                {
                    var extraParams = new Dictionary <string, string>(1)
                    {
                        {
                            "localfolderlink",
                            System.Net.HttpUtility.UrlEncode(tempUri)
                        }
                    };

                    // Needed to get the file link properly
                    if (tempUri.EndsWith("/"))
                    {
                        tempUri = tempUri.Remove(tempUri.Length - 1, 1);
                    }

                    App.LinkInformation.ActiveLink = tempUri;
                    App.LinkInformation.UriLink    = UriLinkType.InternalNode;
                    return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.InternalNodeLaunch, extraParams));
                }
                //Invalid link
                else
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        new CustomMessageDialog(
                            AppMessages.AM_LoadFailed_Title,
                            AppMessages.AM_InvalidLink,
                            App.AppInformation,
                            MessageDialogButtons.Ok).ShowDialog();
                    });

                    App.LinkInformation.Reset();
                    return(new Uri("/Pages/MainPage.xaml", UriKind.Relative));
                }
            }

            // User has selected a folder shortcut
            if (tempUri.Contains("ShortCutBase64Handle"))
            {
                App.ShortCutBase64Handle = tempUri.Replace(@"/Pages/MainPage.xaml?ShortCutBase64Handle=", String.Empty);
            }

            // User has selected MEGA app for operating system auto upload function
            if (tempUri.Contains("ConfigurePhotosUploadSettings"))
            {
                // Launch to the auto-upload settings page.
                App.AppInformation.IsStartedAsAutoUpload = true;

                var extraParams = new Dictionary <string, string>(1)
                {
                    {
                        "ConfigurePhotosUploadSettings",
                        System.Net.HttpUtility.UrlEncode(tempUri.Replace(@"?Action=ConfigurePhotosUploadSettings", String.Empty))
                    }
                };

                return(NavigateService.BuildNavigationUri(typeof(MainPage), NavigationParameter.AutoCameraUpload, extraParams));
            }

            // Otherwise perform normal launch.
            return(uri);
        }
Esempio n. 10
0
        public async void Download(TransferQueu transferQueu, string downloadPath = null)
        {
            // User must be online to perform this operation
            if (!IsUserOnline())
            {
                return;
            }

            if (AppInformation.PickerOrAsyncDialogIsOpen)
            {
                return;
            }

            if (downloadPath == null)
            {
                if (!await FolderService.SelectDownloadFolder(this))
                {
                    return;
                }
                else
                {
                    downloadPath = AppService.GetSelectedDownloadDirectoryPath();
                }
            }

            OnUiThread(() => ProgressService.SetProgressIndicator(true, ProgressMessages.PrepareDownloads));

            // Extra check to try avoid null values
            if (String.IsNullOrWhiteSpace(downloadPath))
            {
                OnUiThread(() => ProgressService.SetProgressIndicator(false));
                await new CustomMessageDialog(AppMessages.SelectFolderFailed_Title,
                                              AppMessages.SelectFolderFailedNoErrorCode, App.AppInformation,
                                              MessageDialogButtons.Ok).ShowDialogAsync();
                return;
            }

            // Check for illegal characters in the download path
            if (FolderService.HasIllegalChars(downloadPath))
            {
                OnUiThread(() => ProgressService.SetProgressIndicator(false));
                await new CustomMessageDialog(AppMessages.SelectFolderFailed_Title,
                                              String.Format(AppMessages.InvalidFolderNameOrPath, downloadPath),
                                              this.AppInformation).ShowDialogAsync();
                return;
            }

            if (!await CheckDownloadPath(downloadPath))
            {
                OnUiThread(() => ProgressService.SetProgressIndicator(false));
                return;
            }

            // If selected file is a folder then also select it childnodes to download
            bool result;

            if (this.IsFolder)
            {
                result = await RecursiveDownloadFolder(transferQueu, downloadPath, this);
            }
            else
            {
                result = await DownloadFile(transferQueu, downloadPath, this);
            }

            OnUiThread(() => ProgressService.SetProgressIndicator(false));

            // TODO Remove this global declaration in method
            App.CloudDrive.NoFolderUpAction = true;
            if (!result || !transferQueu.Any(t => t.IsAliveTransfer()))
            {
                return;
            }
            NavigateService.NavigateTo(typeof(TransferPage), NavigationParameter.Downloads);
        }
Esempio n. 11
0
        private void ProcessBackstack(Type page, bool navigateTo)
        {
            bool isMainPage = page == typeof(MainPage);
            var  backStack  = ((PhoneApplicationFrame)Application.Current.RootVisual).BackStack;
            var  lastPage   = backStack.FirstOrDefault();
            var  navParam   = NavigateService.ProcessQueryString(NavigationContext.QueryString);

            // In some cases we should remove the last page from the stack
            if (lastPage != null)
            {
                switch (navParam)
                {
                case NavigationParameter.PasswordLogin:
                    // If the previous page is the PasswordPage (PIN lock page)
                    if (lastPage.Source.ToString().Contains(typeof(PasswordPage).Name))
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                    break;

                case NavigationParameter.SecuritySettings:
                case NavigationParameter.MFA_Enabled:
                    // If the previous page is the "MultiFactorAuthAppSetupPage"
                    if (lastPage.Source.ToString().Contains(typeof(MultiFactorAuthAppSetupPage).Name))
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                    break;
                }

                // If the previous page is the "FolderLinkPage" and the
                // current page is not "PreviewImagePage" or "NodeDetailsPage".
                if (page != typeof(PreviewImagePage) || page != typeof(NodeDetailsPage))
                {
                    if (lastPage.Source.ToString().Contains(typeof(FolderLinkPage).Name))
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                }
            }

            if (isMainPage)
            {
                if (navigateTo)
                {
                    if (lastPage == null)
                    {
                        return;
                    }
                    if (lastPage.Source.ToString().Contains(page.Name) || navParam == NavigationParameter.FileLinkLaunch ||
                        navParam == NavigationParameter.FolderLinkLaunch)
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                }
                else
                {
                    if (backStack.Count(p => p.Source.ToString().Contains(page.Name)) > 1)
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                }
            }
            else
            {
                if (navigateTo)
                {
                    return;
                }
                ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
            }
        }
        private void ProcessBackstack(Type page, bool navigateTo)
        {
            bool isMainPage = page == typeof(MainPage);
            var  backStack  = ((PhoneApplicationFrame)Application.Current.RootVisual).BackStack;
            var  lastPage   = backStack.FirstOrDefault();

            // If the previous page is the PasswordPage (PIN lock page), delete it from the stack
            var navParam = NavigateService.ProcessQueryString(NavigationContext.QueryString);

            if (navParam == NavigationParameter.PasswordLogin)
            {
                if (lastPage == null)
                {
                    return;
                }
                if (lastPage.Source.ToString().Contains(typeof(PasswordPage).Name))
                {
                    ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                }
            }

            // If the previous page is the "FolderLinkPage" delete it from the stack if the
            // current page is not "PreviewImagePage" or "NodeDetailsPage".
            if (page != typeof(PreviewImagePage) || page != typeof(NodeDetailsPage))
            {
                if (lastPage == null)
                {
                    return;
                }
                if (lastPage.Source.ToString().Contains(typeof(FolderLinkPage).Name))
                {
                    ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                }
            }

            if (isMainPage)
            {
                if (navigateTo)
                {
                    if (lastPage == null)
                    {
                        return;
                    }
                    if (lastPage.Source.ToString().Contains(page.Name) || navParam == NavigationParameter.FileLinkLaunch ||
                        navParam == NavigationParameter.FolderLinkLaunch)
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                }
                else
                {
                    if (backStack.Count(p => p.Source.ToString().Contains(page.Name)) > 1)
                    {
                        ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
                    }
                }
            }
            else
            {
                if (navigateTo)
                {
                    return;
                }
                ((PhoneApplicationFrame)Application.Current.RootVisual).RemoveBackEntry();
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Log in to a MEGA account.
        /// </summary>
        public async void Login()
        {
            if (!CheckInputParameters())
            {
                return;
            }

            this.ControlState = false;
            this.IsBusy       = true;

            var login  = new LoginRequestListenerAsync();
            var result = await login.ExecuteAsync(() =>
                                                  this.MegaSdk.login(this.Email, this.Password, login));

            if (result == LoginResult.MultiFactorAuthRequired)
            {
                await DialogService.ShowAsyncMultiFactorAuthCodeInputDialogAsync(async (string code) =>
                {
                    result = await login.ExecuteAsync(() =>
                                                      this.MegaSdk.multiFactorAuthLogin(this.Email, this.Password, code, login));

                    if (result == LoginResult.MultiFactorAuthInvalidCode)
                    {
                        DialogService.SetMultiFactorAuthCodeInputDialogWarningMessage();
                        return(false);
                    }

                    return(true);
                });
            }

            if (_loginPage != null)
            {
                Deployment.Current.Dispatcher.BeginInvoke(() => _loginPage.SetApplicationBar(true));
            }

            this.ControlState = true;
            this.IsBusy       = false;

            // Set default error content
            var errorContent = string.Format(Resources.AppMessages.LoginFailed, login.ErrorString);

            switch (result)
            {
            case LoginResult.Success:
                SettingsService.SaveMegaLoginData(this.Email, this.MegaSdk.dumpSession());

                // Validate product subscription license on background thread
                Task.Run(() => LicenseService.ValidateLicenses());

                // Navigate to the main page to load the main application for the user
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                                                          NavigateService.NavigateTo(typeof(MainPage), NavigationParameter.Login));
                return;

            case LoginResult.UnassociatedEmailOrWrongPassword:
                errorContent = Resources.AppMessages.WrongEmailPasswordLogin;
                break;

            case LoginResult.TooManyLoginAttempts:
                // Too many failed login attempts. Wait one hour.
                errorContent = string.Format(Resources.AppMessages.AM_TooManyFailedLoginAttempts,
                                             DateTime.Now.AddHours(1).ToString("HH:mm:ss"));
                break;

            case LoginResult.AccountNotConfirmed:
                errorContent = Resources.AppMessages.AM_AccountNotConfirmed;
                break;

            case LoginResult.MultiFactorAuthRequired:
            case LoginResult.MultiFactorAuthInvalidCode:
            case LoginResult.Unknown:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }



            // Show error message
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                new CustomMessageDialog(
                    AppMessages.LoginFailed_Title, errorContent,
                    App.AppInformation, MessageDialogButtons.Ok).ShowDialog();
            });
        }
 protected NavigationBaseViewModel(TNavigate navigateService)
 {
     NavigateService     = navigateService;
     NavigateBackCommand = ReactiveCommand.CreateFromTask(_ => NavigateService.NavigateBack());
 }
Esempio n. 15
0
 private static void NavigateToAcknowledgements(object obj)
 {
     NavigateService.NavigateTo(typeof(AcknowledgementsPage), NavigationParameter.Normal);
 }
        private void FetchNodesMainPage(MegaSDK api, MRequest request)
        {
            App.AppInformation.HasFetchedNodes = true;

            // If the user is trying to open a shortcut
            if (App.ShortCutBase64Handle != null)
            {
                bool shortCutError = false;

                MNode shortCutMegaNode = api.getNodeByBase64Handle(App.ShortCutBase64Handle);
                App.ShortCutBase64Handle = null;

                if (_mainPageViewModel != null && shortCutMegaNode != null)
                {
                    // Looking for the absolute parent of the shortcut node to see the type
                    MNode parentNode;
                    MNode absoluteParentNode = shortCutMegaNode;
                    while ((parentNode = api.getParentNode(absoluteParentNode)) != null)
                    {
                        absoluteParentNode = parentNode;
                    }

                    if (absoluteParentNode.getType() == MNodeType.TYPE_ROOT)
                    {
                        var newRootNode    = NodeService.CreateNew(api, _mainPageViewModel.AppInformation, shortCutMegaNode, ContainerType.CloudDrive);
                        var autoResetEvent = new AutoResetEvent(false);
                        Deployment.Current.Dispatcher.BeginInvoke(() =>
                        {
                            _mainPageViewModel.ActiveFolderView.FolderRootNode = newRootNode;
                            autoResetEvent.Set();
                        });
                        autoResetEvent.WaitOne();
                    }
                    else
                    {
                        shortCutError = true;
                    }
                }
                else
                {
                    shortCutError = true;
                }

                if (shortCutError)
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() =>
                    {
                        new CustomMessageDialog(AppMessages.ShortCutFailed_Title,
                                                AppMessages.ShortCutFailed, App.AppInformation,
                                                MessageDialogButtons.Ok).ShowDialog();
                    });
                }
            }
            else
            {
                var cloudDriveRootNode = _mainPageViewModel.CloudDrive.FolderRootNode ??
                                         NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRootNode(), ContainerType.CloudDrive);
                var rubbishBinRootNode = _mainPageViewModel.RubbishBin.FolderRootNode ??
                                         NodeService.CreateNew(api, _mainPageViewModel.AppInformation, api.getRubbishNode(), ContainerType.RubbishBin);

                var autoResetEvent = new AutoResetEvent(false);
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    _mainPageViewModel.CloudDrive.FolderRootNode = cloudDriveRootNode;
                    _mainPageViewModel.RubbishBin.FolderRootNode = rubbishBinRootNode;
                    autoResetEvent.Set();
                });
                autoResetEvent.WaitOne();
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                _mainPageViewModel.LoadFolders();
                _mainPageViewModel.GetAccountDetails();

                // Enable MainPage appbar buttons
                _mainPageViewModel.SetCommandStatus(true);

                if (_mainPageViewModel.SpecialNavigation())
                {
                    return;
                }
            });

            // KEEP ALWAYS AT THE END OF THE METHOD, AFTER THE "LoadForlders" call
            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                // If is a newly activated account, navigates to the upgrade account page
                if (App.AppInformation.IsNewlyActivatedAccount)
                {
                    NavigateService.NavigateTo(typeof(MyAccountPage), NavigationParameter.Normal, new Dictionary <string, string> {
                        { "Pivot", "1" }
                    });
                }
                // If is the first login, navigates to the camera upload service config page
                else if (SettingsService.LoadSetting <bool>(SettingsResources.CameraUploadsFirstInit, true))
                {
                    NavigateService.NavigateTo(typeof(InitCameraUploadsPage), NavigationParameter.Normal);
                }
                else if (App.AppInformation.IsStartedAsAutoUpload)
                {
                    NavigateService.NavigateTo(typeof(SettingsPage), NavigationParameter.AutoCameraUpload);
                }
            });
        }
 private void OnMyAccountTap(object sender, GestureEventArgs e)
 {
     NavigateService.NavigateTo(typeof(MyAccountPage), NavigationParameter.Normal);
 }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            if (!NetworkService.IsNetworkAvailable())
            {
                UpdateGUI(false);
                return;
            }

            if (e.NavigationMode == NavigationMode.Reset)
            {
                return;
            }

            _cameraUploadsPageViewModel.Initialize(App.GlobalListener);

            NavigationParameter navParam = NavigateService.ProcessQueryString(NavigationContext.QueryString);

            if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
            {
                // Needed on every UI interaction
                SdkService.MegaSdk.retryPendingConnections();

#if WINDOWS_PHONE_81
                // Check to see if any files have been picked
                var app = Application.Current as App;
                if (app != null && app.FilePickerContinuationArgs != null)
                {
                    this.ContinueFileOpenPicker(app.FilePickerContinuationArgs);
                    return;
                }

                if (app != null && app.FolderPickerContinuationArgs != null)
                {
                    FolderService.ContinueFolderOpenPicker(app.FolderPickerContinuationArgs,
                                                           _cameraUploadsPageViewModel.CameraUploads);
                }
#endif
            }

            // Initialize the application bar of this page
            SetApplicationBarData();

            if (e.NavigationMode == NavigationMode.Back)
            {
                navParam = NavigationParameter.Browsing;
            }


            switch (navParam)
            {
            case NavigationParameter.Normal:
                // Check if nodes has been fetched. Because when starting app from OS photo setting to go to
                // Auto Camera Upload settings fetching has been skipped in the mainpage
                if (Convert.ToBoolean(SdkService.MegaSdk.isLoggedIn()) && !App.AppInformation.HasFetchedNodes)
                {
                    _cameraUploadsPageViewModel.FetchNodes();
                }
                else
                {
                    _cameraUploadsPageViewModel.LoadFolders();
                }
                break;

            case NavigationParameter.Login:
                break;

            case NavigationParameter.PasswordLogin:
                break;

            case NavigationParameter.UriLaunch:
                break;

            case NavigationParameter.Browsing:
                // Check if nodes has been fetched. Because when starting app from OS photo setting to go to
                // Auto Camera Upload settings fetching has been skipped in the mainpage
                if (Convert.ToBoolean(SdkService.MegaSdk.isLoggedIn()) && !App.AppInformation.HasFetchedNodes)
                {
                    _cameraUploadsPageViewModel.FetchNodes();
                }
                break;

            case NavigationParameter.BreadCrumb:
                break;

            case NavigationParameter.Uploads:
                break;

            case NavigationParameter.Downloads:
                break;

            case NavigationParameter.DisablePassword:
                break;

            case NavigationParameter.FileLinkLaunch:
            case NavigationParameter.FolderLinkLaunch:
            case NavigationParameter.None:
            {
                if (!App.AppInformation.HasPinLockIntroduced && SettingsService.LoadSetting <bool>(SettingsResources.UserPinLockIsEnabled))
                {
                    NavigateService.NavigateTo(typeof(PasswordPage), NavigationParameter.Normal, this.GetType());
                    return;
                }
                break;
            }
            }
        }