Example #1
0
        public static int SortByDateDescending(LearnedData a, LearnedData b)
        {
            if (a.Date > b.Date)
            {
                return(-1);
            }

            return(1);
        }
Example #2
0
        public static int SortByIndexDescending(LearnedData a, LearnedData b)
        {
            if (a.Index > b.Index)
            {
                return(-1);
            }

            return(1);
        }
        private void SortList(int direction, List <LearnedData> dataList)
        {
            for (int i = 0; i < listLayout.Children.Count; i++)
            {
                int firstWord = direction == 1 ? i * 10 : (VocabHandler.Instance.Words.Count / 10 - i) * 10;
                int lastWord  = firstWord + 10;

                if (lastWord > VocabHandler.Instance.Words.Count)
                {
                    lastWord = VocabHandler.Instance.Words.Count;
                }

                StackLayout stackLayout      = (StackLayout)listLayout.Children[i];
                Label       wordIndexLabel   = (Label)stackLayout.Children[0];
                Label       lastLearnedLabel = (Label)stackLayout.Children[1];
                Label       accuracyLabel    = (Label)stackLayout.Children[2];

                wordIndexLabel.Text = String.Format("{0} - {1}", firstWord + 1, lastWord);

                stackLayout.GestureRecognizers.Clear();

                if (direction == 1)
                {
                    if (i < dataList.Count)
                    {
                        LearnedData learnedData = dataList[i];
                        firstWord = learnedData.Index * 10;
                        lastWord  = firstWord + 10;

                        if (lastWord > VocabHandler.Instance.Words.Count)
                        {
                            lastWord = VocabHandler.Instance.Words.Count;
                        }

                        wordIndexLabel.Text        = String.Format("{0} - {1}", firstWord + 1, lastWord);
                        lastLearnedLabel.Text      = String.Format("Last learned: {0}", learnedData.Date.ToString());
                        accuracyLabel.Text         = String.Format("Accuracy: {0}%", learnedData.Accuracy);
                        wordIndexLabel.TextColor   = Color.Black;
                        lastLearnedLabel.TextColor = Color.Black;
                        accuracyLabel.TextColor    = Color.Black;
                        TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
                        tapGestureRecognizer.Tapped += async(s, e) =>
                        {
                            await Application.Current.MainPage.Navigation.PushAsync(new VocabTest(firstWord, lastWord - firstWord));
                        };
                        stackLayout.GestureRecognizers.Add(tapGestureRecognizer);
                    }
                    else
                    {
                        wordIndexLabel.Text        = String.Format("{0} - {1}", firstWord + 1, lastWord);
                        lastLearnedLabel.Text      = "Last learned: -";
                        accuracyLabel.Text         = "Accuracy: -";
                        wordIndexLabel.TextColor   = Color.Gray;
                        lastLearnedLabel.TextColor = Color.Gray;
                        accuracyLabel.TextColor    = Color.Gray;
                    }
                }
                else
                {
                    if (dataList.Count >= listLayout.Children.Count - i)
                    {
                        int index = Math.Abs(listLayout.Children.Count - i - dataList.Count);

                        LearnedData learnedData = dataList[index];
                        firstWord = learnedData.Index * 10;
                        lastWord  = firstWord + 10;

                        if (lastWord > VocabHandler.Instance.Words.Count)
                        {
                            lastWord = VocabHandler.Instance.Words.Count;
                        }

                        wordIndexLabel.Text        = String.Format("{0} - {1}", firstWord + 1, lastWord);
                        lastLearnedLabel.Text      = String.Format("Last learned: {0}", learnedData.Date.ToString());
                        accuracyLabel.Text         = String.Format("Accuracy: {0}%", learnedData.Accuracy);
                        wordIndexLabel.TextColor   = Color.Black;
                        lastLearnedLabel.TextColor = Color.Black;
                        accuracyLabel.TextColor    = Color.Black;
                        TapGestureRecognizer tapGestureRecognizer = new TapGestureRecognizer();
                        tapGestureRecognizer.Tapped += async(s, e) =>
                        {
                            await Application.Current.MainPage.Navigation.PushAsync(new VocabTest(firstWord, lastWord - firstWord));
                        };
                        stackLayout.GestureRecognizers.Add(tapGestureRecognizer);
                    }
                    else
                    {
                        lastLearnedLabel.Text      = "Last learned: -";
                        accuracyLabel.Text         = "Accuracy: -";
                        wordIndexLabel.TextColor   = Color.Gray;
                        lastLearnedLabel.TextColor = Color.Gray;
                        accuracyLabel.TextColor    = Color.Gray;
                    }
                }
            }
        }
Example #4
0
        public VocabTest(int startIndex, int count)
        {
            InitializeComponent();
            testWords = new List <WordPair>();
            testWords.AddRange(VocabHandler.Instance.Words.GetRange(startIndex, count));
            Util.ShuffleList <WordPair>(ref testWords);
            cardContent.Text = testWords[wordIndex].Translation;
            popupLayout.GestureRecognizers.Add(new TapGestureRecognizer
            {
                Command = new Command(() => {
                    popupLayout.IsVisible = false;
                    wordIndex++;
                    if (wordIndex < testWords.Count)
                    {
                        cardContent.Text = testWords[wordIndex].Translation;
                        userEntry.Text   = String.Empty;
                    }
                    else
                    {
                        testLayout.IsVisible   = false;
                        resultLayout.IsVisible = true;
                        answers.Text           = String.Format("Correct answers: {0}/{1}", correctAnswers, testWords.Count);
                        int acc       = correctAnswers * 100 / testWords.Count;
                        accuracy.Text = String.Format("Accuracy: {0}%", acc);

                        int index = startIndex / 10;

                        if (acc >= 80)
                        {
                            int maxMastered = -1;

                            if (Application.Current.Properties.ContainsKey("MaxMastered"))
                            {
                                maxMastered = (int)Application.Current.Properties["MaxMastered"];
                            }

                            if (index > maxMastered)
                            {
                                Application.Current.Properties["MaxMastered"] = index;
                            }
                        }

                        Dictionary <int, LearnedData> testData;
                        if (Application.Current.Properties.ContainsKey("TestData"))
                        {
                            string json = (string)Application.Current.Properties["TestData"];

                            testData = JsonConvert.DeserializeObject <Dictionary <int, LearnedData> >(json);
                        }
                        else
                        {
                            testData = new Dictionary <int, LearnedData>();
                        }

                        testData[index] = new LearnedData(index, DateTime.Now, acc);
                        Application.Current.Properties["TestData"] = JsonConvert.SerializeObject(testData);
                        Application.Current.SavePropertiesAsync();
                    }
                    //userEntry.Focus();
                }),
                NumberOfTapsRequired = 1
            });
        }