private void OnBackKeyPressed(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if (ProgressBarOverlay.IsOpen() && longRunningOperation != null)
            {
                longRunningOperation.Dispose();
                longRunningOperation = null;
                e.Cancel             = true;
            }
            else
            {
                switch (PageType)
                {
                case LibraryModel.LibraryLevel.Catalogue:
                    //list of cataloue's, means that we are in library
                    App.Engine.StatisticsManager.LogLibraryBack(ContentId);
                    break;

                case LibraryModel.LibraryLevel.Category:
                    // list of category means that we are in catalogue
                    App.Engine.StatisticsManager.LogCatalogueBack(ContentId);
                    break;

                case LibraryModel.LibraryLevel.MediaItemsList:
                    // list of media items, means that we are in category
                    App.Engine.StatisticsManager.LogCategoryBack(ContentId);
                    break;
                }
            }
            base.OnBackKeyPress(e);
        }
Example #2
0
        private void OnLibraryClicked(object sender, SelectionChangedEventArgs args)
        {
            if (AllLibrariesList.SelectedIndex != -1)
            {
                Library clickedLib = AllLibrariesList.SelectedItem as Library;
                Debug.Assert(clickedLib != null);

                if (clickedLib.CatalogueCount == -1)
                {
                    ProgressBarOverlay.Show(FileLanguage.MainPage_DownloadingLib);

                    longRunningOperation = App.Engine.DownloadLibrary(clickedLib)
                                           .Finally(ProgressBarOverlay.Close)
                                           .Subscribe <Library>(
                        library =>
                    {
                        // keep ProgressBarOverlay.Close() call here despite it's also in Finally,
                        // because it has to be called before NavigateToLibrary, i.e. before
                        // ApplicationBar for new page is loaded.
                        ProgressBarOverlay.Close();
                        NavigateToLibrary(library);
                    },
                        Utils.StandardErrorHandler
                        );
                }
                else
                {
                    NavigateToLibrary(clickedLib);
                }

                // set selected index to -1 to enable repeated clicks on item
                AllLibrariesList.SelectedIndex = -1;
            }
        }
Example #3
0
        private void Login(object sender, RoutedEventArgs e)
        {
            ProgressBarOverlay.Show(FileLanguage.CONNECTING);

            longRunningOperation = App.Engine.Login(UsernameBoxText, PasswordBoxText)
                                   .Subscribe <Unit>(
                result =>
            {
                Dispatcher.BeginInvoke(() =>
                {
                    ProgressBarOverlay.Close();
                    App.Engine.RememberUsernameAndPassword(UsernameBoxText, PasswordBoxText);
                    App.Engine.RequestMotdUpdate();
                    MainMenuScreen.SelectedItem = Libraries;
                    if (App.Engine.ApplicationSettings.ShowTipsStartup)
                    {
                        GoForwardToScreen(Screen.TipsAndTricks);
                    }
                    else
                    {
                        GoForwardToScreen(Screen.MainMenu);
                    }
                });
            },
                error =>
            {
                ProgressBarOverlay.Close();
                Utils.StandardErrorHandler(error);
            }
                );
        }
Example #4
0
        private void UpdateLanguages()
        {
            ProgressBarOverlay.Show(FileLanguage.ProgressOverlay_UpdatingLibrary);

            longRunningOperation = App.Engine.RequestLanguageListUpdate()
                                   .ObserveOnDispatcher()
                                   .Finally(
                () =>
            {
                ProgressBarOverlay.Close();

                longRunningOperation = null;
                PhoneApplicationService.Current.State.Remove(KLanguagesPageUpdateInProgress);

                // leave this page if library contents were deleted (for example
                // on failed update or after user interruption)
                if (App.Engine.ApplicationSettings.AvailableLanguages.LanguageList.Count == -1)
                {
                    MessageBox.Show(FileLanguage.LibraryUnavailableAfterFailedUpdate);
                    NavigationService.GoBack();
                }
            })
                                   .Subscribe <List <LanguageInfo> >(
                languageList => ReloadLanguages(languageList),
                Utils.StandardErrorHandler
                );
        }
        private void UpdateLibrary(Library library)
        {
            ProgressBarOverlay.Show(FileLanguage.ProgressOverlay_UpdatingLibrary);

            longRunningOperation = App.Engine.UpdateLibrary(library)
                                   .Finally(
                () =>
            {
                ProgressBarOverlay.Close();

                longRunningOperation = null;
                PhoneApplicationService.Current.State.Remove(KCataloguePageUpdateInProgress);

                // leave this page if library contents were deleted (for example
                // on failed update or after user interruption)
                if (library.CatalogueCount == -1)
                {
                    MessageBox.Show(FileLanguage.LibraryUnavailableAfterFailedUpdate);
                    NavigationService.GoBack();
                }
            })
                                   .Subscribe <Library>(
                _ => ReloadLibrary(true),
                Utils.StandardErrorHandler
                );
        }
Example #6
0
 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs args)
 {
     if (ProgressBarOverlay.IsOpen())
     {
         args.Cancel = true;
     }
     base.OnBackKeyPress(args);
 }
Example #7
0
 private void SaveServer()
 {
     ProgressBarOverlay.Show(FileLanguage.CONNECTING);
     longRunningOperation = App.Engine.SaveServer(ServerUrl.Text)
                            .Finally(() => ProgressBarOverlay.Close())
                            .Subscribe <Unit>(
         result => GoForwardToScreen(Screen.Login),
         Utils.StandardErrorHandler
         );
 }
Example #8
0
 private void OnBackKeyPressed(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (ProgressBarOverlay.IsOpen() && longRunningOperation != null)
     {
         longRunningOperation.Dispose();
         longRunningOperation = null;
         e.Cancel             = true;
     }
     base.OnBackKeyPress(e);
 }
Example #9
0
        private void RequestAddingLibrary()
        {
            ProgressBarOverlay.Show(FileLanguage.MainPage_AddingLibrary);

            longRunningOperation = App.Engine.AddLibrary(NewLibraryId.Text)
                                   .Finally(() => ProgressBarOverlay.Close())
                                   .Subscribe <Unit>(
                result => { /*no implementation needed*/ },
                Utils.StandardErrorHandler
                );
        }
Example #10
0
        private void OnFactoryResetButtonClicked(object sender, RoutedEventArgs e)
        {
            _operationsState = OperationsStates.FactoryReseting;
            MessageBoxResult result = MessageBox.Show(FileLanguage.SettingsPage_FactoryResetInfoMessage, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                ProgressBarOverlay.Show(FileLanguage.SettingsPage_ClearingData);
                App.Engine.FactoryReset()
                .Finally(() => { try { NavigationService.GoBack(); } catch (InvalidOperationException) { } })
                .Finally(ProgressBarOverlay.Close)
                .Subscribe();
            }
        }
Example #11
0
        private void OnLogoutButtonClicked(object sender, RoutedEventArgs e)
        {
            _operationsState = OperationsStates.LoggingOut;
            MessageBoxResult result = MessageBox.Show(FileLanguage.QUESTION_LOGOUT_USER, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                ProgressBarOverlay.Show(FileLanguage.SettingsPage_LoggingOut);
                App.Engine.Logout()
                .Finally(() => { try { NavigationService.GoBack(); } catch (InvalidOperationException) { } })
                .Finally(ProgressBarOverlay.Close)
                .Subscribe();
            }
        }
Example #12
0
        private void OnFactoryResetButtonClicked(object sender, EventArgs e)
        {
            MessageBoxResult result = MessageBox.Show(FileLanguage.SettingsPage_FactoryResetInfoMessage, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                ProgressBarOverlay.Show(FileLanguage.SettingsPage_ClearingData);
                App.Engine.FactoryReset()
                .Finally(() =>
                {
                    VisibleScreen = Screen.SelectServer;
                })
                .Finally(ProgressBarOverlay.Close)
                .Subscribe();
            }
        }
Example #13
0
        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            App.RecursiveBack = false;

            if (App.Engine.ApplicationSettings.ServerUrl == null)
            {
                VisibleScreen = Screen.SelectServer;
            }
            else if (App.Engine.LoggedUser == null)
            {
                VisibleScreen = Screen.Login;
            }
            else
            {
                VisibleScreen = Screen.MainMenu;
            }
            if (!ApplicationBar.IsVisible)  // Do not remove unless Settings Page workaround is removed
            {
                ApplicationBar.IsVisible = true;
            }
            ProgressBarOverlay.Close();

            bool pivot = this.NavigationContext.QueryString.ContainsKey("MainMenuScreen.SelectedIndex");

            int index = 0;

            if (pivot && int.TryParse(this.NavigationContext.QueryString["MainMenuScreen.SelectedIndex"], out index))
            {
                backToContentLists           = true;
                MainMenuScreen.SelectedIndex = index;
                if (e.NavigationMode == System.Windows.Navigation.NavigationMode.New)
                {
                    if (PhoneApplicationService.Current.State.ContainsKey(SelectedPivotItemIndexKey))
                    {
                        PhoneApplicationService.Current.State[SelectedPivotItemIndexKey] = index;
                    }
                }
                else
                {
                    if (PhoneApplicationService.Current.State.ContainsKey(SelectedPivotItemIndexKey))
                    {
                        PhoneApplicationService.Current.State[SelectedPivotItemIndexKey] = 1;
                    }
                }
            }
            base.OnNavigatedTo(e);
        }
Example #14
0
 protected override void OnBackKeyPress(System.ComponentModel.CancelEventArgs args)
 {
     if (ProgressBarOverlay.IsOpen() && longRunningOperation != null)
     {
         longRunningOperation.Dispose();
         longRunningOperation = null;
         args.Cancel          = true;
     }
     else
     {
         if (!_closeQuestionMsgBoxLock && !backToContentLists)
         {
             _closeQuestionMsgBoxLock = true;
             if (MessageBox.Show(FileLanguage.MainPage_ClosingApplicationMessage, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel) == MessageBoxResult.Cancel)
             {
                 args.Cancel = true;
             }
             _closeQuestionMsgBoxLock = false;
         }
     }
     backToContentLists = false;
     base.OnBackKeyPress(args);
 }
Example #15
0
        private void OnRemoveUserButtonClicked(object sender, RoutedEventArgs e)
        {
            _operationsState = OperationsStates.RemovingUsers;
            MessageBoxResult result = MessageBox.Show(FileLanguage.SettingsPage_UsersRemovedInfoMessage, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel);

            if (result == MessageBoxResult.OK)
            {
                ProgressBarOverlay.Show(FileLanguage.SettingsPage_RemovingUser);
                User removedUser = App.Engine.LoggedUser;
                App.Engine.Logout()
                .Finally(
                    () =>
                {
                    App.Engine.RemoveUsers(removedUser);
                    ProgressBarOverlay.Close();
                    try
                    {
                        NavigationService.GoBack();
                    }
                    catch (InvalidOperationException) { }
                })
                .Subscribe();
            }
        }
Example #16
0
        private void OnContextMenuActivated(object sender, RoutedEventArgs args)
        {
            MenuItem menuItem = sender as MenuItem;

            Debug.Assert(menuItem != null);
            Library library = menuItem.CommandParameter as Library;

            Debug.Assert(library != null);

            switch (menuItem.Tag.ToString())
            {
            case "DeleteTag":
                if (MessageBox.Show(FileLanguage.QUESTION_REMOVE_LIBRARY, FileLanguage.ARE_YOU_SURE, MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                {
                    App.Engine.DeleteLibrary(library);
                }
                break;

            case "CheckForUpdatesTag":
            {
                ProgressBarOverlay.Show(FileLanguage.ProgressOverlay_UpdatingLibrary);

                longRunningOperation = App.Engine.UpdateLibrary(library)
                                       .Finally(ProgressBarOverlay.Close)
                                       .Subscribe <Library>(
                    result => { /*no implementation needed*/ },
                    Utils.StandardErrorHandler
                    );
            }
            break;

            case "DownloadAllTag":
            {
                string libraryId = library.ServerId;
                if (library.CatalogueCount == -1)
                {
                    ProgressBarOverlay.Show(FileLanguage.MainPage_DownloadingLib);

                    longRunningOperation = App.Engine.DownloadLibrary(library)
                                           .Finally(ProgressBarOverlay.Close)
                                           .Subscribe <Library>(
                        libraryParam =>
                        {
                            ProgressBarOverlay.Close();
                            if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                            {
                                App.Engine.LibraryModel.LoadLibrary(libraryId);
                            }
                            DownloadAllCommand.GetCommand().Execute(libraryId);
                        },
                        Utils.StandardErrorHandler
                        );
                }
                else
                {
                    if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                    {
                        App.Engine.LibraryModel.LoadLibrary(libraryId);
                    }
                    DownloadAllCommand.GetCommand().Execute(libraryId);
                }
            }
            break;

            case "SearchTag":
            {
                string libraryId = library.ServerId;
                if (library.CatalogueCount == -1)
                {
                    ProgressBarOverlay.Show(FileLanguage.MainPage_DownloadingLib);

                    longRunningOperation = App.Engine.DownloadLibrary(library)
                                           .Finally(ProgressBarOverlay.Close)
                                           .Subscribe <Library>(
                        libraryParam =>
                        {
                            ProgressBarOverlay.Close();
                            if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                            {
                                App.Engine.LibraryModel.LoadLibrary(libraryId);
                            }
                            (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/SearchPage.xaml?rootId=" + libraryId, UriKind.Relative));
                        },
                        Utils.StandardErrorHandler
                        );
                }
                else
                {
                    if (!App.Engine.LibraryModel.IsLoaded() || App.Engine.LibraryModel.LibraryId != libraryId)
                    {
                        App.Engine.LibraryModel.LoadLibrary(libraryId);
                    }
                    (Application.Current.RootVisual as PhoneApplicationFrame).Navigate(new Uri("/SearchPage.xaml?rootId=" + libraryId, UriKind.Relative));
                }
            }
            break;
            }
        }