Exemplo n.º 1
0
        public Wizards_ViewModel()
        {
            btnOK = new ButtonModel { Visibility = VisualState.Collapsed};
            btnBack = new ButtonModel();
            btnNext = new ButtonModel();

            TabItemsCollection = new ObservableCollection<object>();

            SelectedIndex = 0;
            UpdateButtonState();
        }
        public ReferencesToWord_ViewModel(
            ILogger Logger_, 
            INavigationService NavigationService_,
            EFDbContext EFDbContext_,
            IDialogService DialogService_,
            ILocalization Tx_
            )
        {
            if (!IsInDesignMode)
            {
                Logger = Logger_;
                NavigationService = NavigationService_;
                EFDbContext =EFDbContext_;
                DialogService = DialogService_;
                Tx = Tx_;

                CommandDispatcher = new MvxCommand<string>(CmdDispatcher);

                References = new ObservableCollection<ReferenceToWordOfDictionary>();
            }

            ClearButton = new ButtonModel();
                      

            if (IsInDesignMode)
            {
                Word = new WordOfDictionary { word_of_dictionary = "I'm" };

                LearningItem li1 = new LearningItem { Name = "Mazzy collection" };
                LearningItem li2 = new LearningItem { Name = "Futurama season 1" };

                Subtitles st1 = new Subtitles { Name = "English - Russian" };
                Subtitles st2 = new Subtitles { Name = "English - Ukraine" };

                References = new ObservableCollection<ReferenceToWordOfDictionary>()
                {
                    new ReferenceToWordOfDictionary {LearningItem = li1, Subtitles = st1,SubtitleItem =  new SubtitleItem { Text = "I'm Mazzy"},WordOfSubtitleItem = new WordOfSubtitleItem { word = "I'm"} },
                    new ReferenceToWordOfDictionary {LearningItem = li1, Subtitles = st1, SubtitleItem = new SubtitleItem { Text = "I am princess Sylvia" } ,WordOfSubtitleItem = new WordOfSubtitleItem { word = "I am"}},
                    new ReferenceToWordOfDictionary {LearningItem = li2, Subtitles = st2, SubtitleItem = new SubtitleItem { Text = "I'm Nibbler" } ,WordOfSubtitleItem = new WordOfSubtitleItem { word = "I'm"}}
                };

            }

        }
 private void PressWordButton_Cmd(ButtonModel button)
 {
     
     if (button.IsItTrue)
     {
         // Success
         Messenger.Publish(new PlayerEvent(this,PlyaerEventEnum.UnderstandingTestPassed, CurrentSub));
     }
     else
     {
         // False
         Messenger.Publish(new PlayerEvent(this,PlyaerEventEnum.UnderstandingTestFailed, CurrentSub));
     }
     NavigationService.NavigateBack();
 }
        private async void PressCollectWordsButton_Cmd(ButtonModel btnModel)
        {
            if (CurrentPhrase.Words[CurrentPhrase.IndexOfCurrentWord].word_of_phrase.ToLower() == btnModel.WordOfButton.word_of_phrase.ToLower())
            {
                // Success
                btnModel.Visibility = VisualState.Hidden; 
                CollectedPhraseText = CurrentPhrase.Words[CurrentPhrase.IndexOfCurrentWord].phrase;
                CurrentPhrase.IndexOfCurrentWord++;

                foreach (var elm in CollectPhrases_Buttons) if (!elm.IsEnabled) elm.IsEnabled = true;

                StatList.Add(new StatisticsMessage() { Cmd = StatisticsCmd.WordCollected, phrase = CurrentPhrase, word = btnModel.WordOfButton });

                if (CurrentPhrase.IndexOfCurrentWord == CurrentPhrase.Words.Count)
                {
                    Controller(new PlayerEvent(this,PlyaerEventEnum.CollectingWordTestPassed,CurrentPhrase.SubtitleItem));
                }
                CurrentPhrase.Errors = 0;
            }
            else
            {
                // Fail, selected word is invalid

                StatList.Add(new StatisticsMessage() { Cmd = StatisticsCmd.WordFail, phrase = CurrentPhrase, word = btnModel.WordOfButton });

                btnModel.IsEnabled = false;
                CurrentPhrase.Errors++;

                if (CurrentPhrase.Errors > 1)
                {
                    player.isHidden = true;
                    bool res = await DialogService.Ask(Loc.T("Player.Message.CanRepeat"));
                    player.isHidden = false;

                    if (res)
                    {
                        CmdDispatcher("Replay");
                    }
                }

            }
        }
        private void PressWordButton_Cmd(ButtonModel btn)
        {

            if (!IsInDesignMode) {
                if (btn.IsItTrue)
                {
                    if(mode == WordsTranslation_parameters.ViewMode.Training)
                    {
                        AppSetting.LearningWordStrategy.SetNextStep(CurrentWord);
                        EFDbContext.SaveChgs();
                    }
                    AudioAPI.Play(PortablePath.Combine(FolderService.ApplicationFolder.Name, @"Resources\Sounds\tada.wav"));
                }
                else
                {
                    if(mode == WordsTranslation_parameters.ViewMode.Training)
                    {
                        CurrentWord.DateOfRepetition = DateTime.Today.AddDays(1).ConvertToUTC();
                        EFDbContext.SaveChgs();
                        ErrorIconVisibility = VisualState.Visible;
                        if (btn.Text != "IDontKnow")
                        {
                            AudioAPI.Play(PortablePath.Combine(FolderService.ApplicationFolder.Name, @"Resources\Sounds\error.wav"));
                        }
                     }
                }
            }

            switch (mode)
            {
                case WordsTranslation_parameters.ViewMode.Training:
                    TranslatingVisibility = VisualState.Visible;
                    CommentaryVisibilty = string.IsNullOrEmpty(CurrentWord.commentary) ? VisualState.Collapsed : VisualState.Visible;
                    ImagePanelVisibility = VisualState.Visible;
                    btnTrainingNext.Visibility = VisualState.Visible;
                    WordsButtonPanelVisibility = VisualState.Collapsed;
                    ContextVisibility = VisualState.Visible;
                    break;

                case WordsTranslation_parameters.ViewMode.FoundNewWord:
                    TranslatingVisibility = VisualState.Visible;
                    CommentaryVisibilty = string.IsNullOrEmpty(CurrentWord.commentary) ? VisualState.Collapsed : VisualState.Visible;
                    ImagePanelVisibility = VisualState.Visible;
                    BottomButtonsPanelVisibility = VisualState.Visible;
                    WordsButtonPanelVisibility = VisualState.Collapsed;
                    btnSkip.Visibility = btn.IsItTrue ? VisualState.Visible : VisualState.Collapsed;
                    break;

                case WordsTranslation_parameters.ViewMode.WordTranslation:
                    break;

                default:
                    throw new NotImplementedException();
            }

        }
        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});
                    }
                }

            }

            
        }