public override void CmdDispatcher(string CommandName) { int idx; switch (CommandName) { case "SpeechItem": AudioAPI.Play(new Uri(CurrentWord.SoundPath)); break; case "PreviousWord": idx = WordsCollection.IndexOf(CurrentWord); if (idx > 0) SetCurrentWord(WordsCollection[idx - 1]); break; case "NextWord": idx = WordsCollection.IndexOf(CurrentWord); if (idx < WordsCollection.Count - 1) SetCurrentWord(WordsCollection[idx + 1]); break; case "AddToPersonalDictionary": case "Skip": case "TrainingNext": if(CommandName == "AddToPersonalDictionary") { AppSetting.PersonalDictionary.AddOrUpdateWord(CurrentWord); } if(CommandName == "Skip") { AppSetting.PersonalDictionary.AddLearnedWord(CurrentWord); } idx = WordsCollection.IndexOf(CurrentWord); WordsCollection.Remove(CurrentWord); if (WordsCollection.Count == 0) { EFDbContext.SaveChgs(); NavigationService.NavigateBack(); MvxMessenger.Publish(new PlayerEvent(this, PlyaerEventEnum.FoundNewWordsFormClosed, SubItem)); return; } // set the new word if (idx >= WordsCollection.Count) idx = WordsCollection.Count - 1; SetCurrentWord(WordsCollection[idx]); break; case "IDontKnowButtonPressed": PressWordButton_Cmd(new ButtonModel() { IsItTrue = false,Text="IDontKnow" }); break; case "Close": case "Ok": EFDbContext.SaveChgs(); NavigationService.NavigateBack(); break; case "TranslationSelected": CurrentWord.translation_as_string = CurrentTranslation.Translation; break; case "SaveChanges": EFDbContext.SaveChgs(); break; case "Edit": if (IsEditMode) { prevMode = mode; mode = WordsTranslation_parameters.ViewMode.Edit; CmdDispatcher("RightPanel_Button_Properties_Pressed"); } else { mode = prevMode; } SetCurrentWord(CurrentWord); break; case "MergeWords": if(FoundedWord == null) { DialogService.Message(Tx.T("WordsTranslation.Messages.WordForMergeNotFound"), Tx.T("Common.Titles.Error")); return; } CurrentWord.Dictionary.MergeWords(FoundedWord,CurrentWord); EFDbContext.SaveChgs(); NavigationService.NavigateBack(); break; case "FindReferences": NavigationService.OpenDialog(Views.ReferencesToWord, new ReferencesToWord_parameters { Word = CurrentWord }); break; // Right panel case "RightPanel_Button_Translations_Pressed": RightPanel_TranslationButton.IsChecked = !RightPanel_TranslationButton.IsChecked; RightPanel_AllWordsButton.IsChecked = false; RightPanel_Properties.IsChecked = false; break; case "RightPanel_Button_AllWordsButton_Pressed": RightPanel_AllWordsButton.IsChecked = !RightPanel_AllWordsButton.IsChecked; RightPanel_Properties.IsChecked = false; RightPanel_TranslationButton.IsChecked = false; break; case "RightPanel_Button_Properties_Pressed": RightPanel_Properties.IsChecked = !RightPanel_Properties.IsChecked; RightPanel_AllWordsButton.IsChecked = false; RightPanel_TranslationButton.IsChecked = false; break; default: SystemMessage.Show("Unknown command"); break; } }
override async public void OnNavigationOpenPage(ParametersOfForms param_) { WordsTranslation_parameters param = (WordsTranslation_parameters)param_; WordsCollection = param.WordsCollection; SubItem = param.SubtitleItem; LearningItem = param.LearningItem; mode = param.Mode; if (mode == WordsTranslation_parameters.ViewMode.Undefined) throw new NotImplementedException(); if (WordsCollection.Count > 0) { SetCurrentWord(WordsCollection[0]); } else { await DialogService.Message(Tx.T("WordsTranslation.Messages.NoElementForTraining")); NavigationService.NavigateBack(); } }
public WordsTranslation_ViewModel( INavigationService NavigationService_, IDialogService DialogService_, AppSetting AppSetting_, IAudioAPI AudioAPI_, IFolderService FolderService_, IMvxMessenger MvxMessenger_, ILocalization Loc_ ) { // Design mode settings bool isButtonPressed = true; bool isPressedTrueButton = false; if (IsInDesignMode) { //mode = WordsTranslation_parameters.ViewMode.FoundNewWord; mode = WordsTranslation_parameters.ViewMode.Edit; // Subtitle editor //mode = WordsTranslation_parameters.ViewMode.Training; // Training mode //mode = WordsTranslation_parameters.ViewMode.WordTranslation; // Dictionary //mode = WordsTranslation_parameters.ViewMode.Training; //mode = WordsTranslation_parameters.ViewMode.DictionaryItem; } if (!IsInDesignMode) { NavigationService = NavigationService_; DialogService = DialogService_; AppSetting = AppSetting_; AudioAPI = AudioAPI_; FolderService = FolderService_; MvxMessenger = MvxMessenger_; Tx = Loc_; Statuses = new ObservableCollection<WordStatuses>(Enumeration.GetAll<WordStatuses>()); CommandDispatcher = new MvxCommand<string>(CmdDispatcher); PressWordButton_Command = new MvxCommand<ButtonModel>(PressWordButton_Cmd); Command_SelectLanguageService = new MvxCommand<LanguageService>(PressLanguageServiceButton_Cmd); PropertyChanged += WordsTranslation_ViewModel_PropertyChanged; } WordsForSelection_Buttons = new ObservableCollection<ButtonModel>(); LanguageServiceCollection = new ObservableCollection<LanguageService>(); btnNextButton = new ButtonModel(); btnPreviousButton = new ButtonModel(); btnAddToDictionary = new ButtonModel(); btnSkip = new ButtonModel(); WordsCollection_ListModel = new List_Model(); btnTrainingNext = new ButtonModel(); btnOk = new ButtonModel(); Header_LabelModel = new Label_Model(); Header2_LabelModel = new Label_Model(); btnAllWordsList = new ButtonModel(); MergeButton = new ButtonModel { IsEnabled = false }; RightPanel_TranslationButton = new ButtonModel(); RightPanel_Properties = new ButtonModel(); RightPanel_AllWordsButton = new ButtonModel(); SpeechParts = new ObservableCollection<Domain.SpeechParts>(Domain.SpeechParts.GetAll<SpeechParts>()); if (IsInDesignMode) { //Statuses = WordOfDictionary.WordStatuses.Statuses; Header_LabelModel.Text = "This is a Header"; Header2_LabelModel.Text = "second header"; Tx = new LocalizationForDesignMode(); CurrentWord = new WordOfDictionary(); CurrentWord.word_of_dictionary = "White"; CurrentWord.translation_as_string = "Белый"; CurrentWord.transcription = "[wʌɪt]"; CurrentWord.commentary = "Белый цвет, не черный, не зеленый, а [b]именно белый[/b]. \nСовершенно белый.\nНу может с [i]желтоватым отливом[/i]"; CurrentWord.pictures_url = "http://d144fqpiyasmrr.cloudfront.net/uploads/picture/295623.png"; CurrentWord.context = "of the color of milk or fresh snow, due to the reflection of most wavelengths of visible light; the opposite of black."; CurrentWord.SpeechPart = Domain.SpeechParts.Pronoun; CurrentWord.translations.Add(new TranslationOfWord {Translation="белый",Votes=150 }); CurrentWord.translations.Add(new TranslationOfWord {Translation="беловатый",Votes=50 }); CurrentWord.translations.Add(new TranslationOfWord {Translation="беленький, беловатый, бледноватный, беловатенькая, серобуромалиновенькая, ярко белая в крапинку",Votes=15 }); WordsForSelection_Buttons.Add(new ButtonModel { Text="Зелёный"}); WordsForSelection_Buttons.Add(new ButtonModel { Text="Белый"}); WordsForSelection_Buttons.Add(new ButtonModel { Text="Черный"}); WordsForSelection_Buttons.Add(new ButtonModel { Text="Пурпурный"}); WordsForSelection_Buttons.Add(new ButtonModel { Text="Фиолетовый"}); WordsCollection = new ObservableCollection<WordOfDictionary>(); WordsCollection.Add(new WordOfDictionary {word_of_dictionary = "everybody"}); WordsCollection.Add(new WordOfDictionary {word_of_dictionary = "likes"}); WordsCollection.Add(new WordOfDictionary {word_of_dictionary = "cakes"}); LanguageServiceCollection.Add(new LanguageService { Name = "Google translate"}); LanguageServiceCollection.Add(new LanguageService { Name = "Yandex translate"}); LanguageServiceCollection.Add(new LanguageService { Name = "LinguaLeo"}); LanguageServiceCollection.Add(new LanguageService { Name = "Macmillan dictionary"}); SetCurrentWord(CurrentWord); MergeWithStr = "I am"; FoundedWord = new WordOfDictionary { word_of_dictionary = MergeWithStr }; SpeechParts = new ObservableCollection<SpeechParts> { Domain.SpeechParts.Adverb, Domain.SpeechParts.Article, Domain.SpeechParts.Conjuction, Domain.SpeechParts.Pronoun }; } if (IsInDesignMode) { if (mode == WordsTranslation_parameters.ViewMode.Training || mode == WordsTranslation_parameters.ViewMode.FoundNewWord) { if (isButtonPressed) { PressWordButton_Cmd(new ButtonModel { IsItTrue = isPressedTrueButton}); } } } }