Ejemplo n.º 1
0
        public void ReadQuestionTest()
        {
            Repository.Default.DeleteDatabase();
            Repository.Default.CreateDatabase();

            Category category = new Category();
            category.Name = "bob";
            Category.Save(category);

            Question question = new Question();
            question.Title = "Is Fiona going to the baby?";
            question.Answer = "Yes, of course within seconds";
            question.AskCount = 60;
            question.Category = Category.Read(1);
            question.EasinessFactor = 70.50;
            question.Interval = 80;
            question.LastAsked = DateTime.Today.AddDays(-2);
            question.NextAskOn = DateTime.Today.AddDays(2);
            question.Order = 90;
            question.PreviousInterval = 100;
            question.ResponseQuality = 110;
            Question.Save(question);

            question = Question.Read(1);
            Assert.AreEqual("Is Fiona going to the baby?", question.Title);
            Assert.AreEqual("Yes, of course within seconds", question.Answer);
            Assert.AreEqual(60, question.AskCount);
            Assert.AreEqual(1, question.Category.Id);
            Assert.AreEqual(70.50, question.EasinessFactor);
            Assert.AreEqual(DateTime.Today.AddDays(-2), question.LastAsked);
            Assert.AreEqual(DateTime.Today.AddDays(2), question.NextAskOn);
            Assert.AreEqual(90, question.Order);
            Assert.AreEqual(100, question.PreviousInterval);
            Assert.AreEqual(110, question.ResponseQuality);
        }
        public override void ViewDidLoad()
        {
            // Hide the toolbar
            base.ViewDidLoad();
            NavigationController.SetToolbarHidden(true,true);

            // Error state
            if (_questions.Count < 1)
            {
                Logger.Warn("AnswerQuestionsController was pushed with zero questions for {0}", _category.Name);
                NavigationController.PopViewControllerAnimated(true);
            }

            // Flashcard bg image
            _bgImage = UIImage.FromFile("Assets/Images/flashcardbg.jpg");
            _bgImageView = new UIImageView(_bgImage);
            _bgImageView.Frame = new RectangleF(0,0,320,480);
            View.AddSubview(_bgImageView);

            // The question label
            _labelQuestion = new UILabel();
            _labelQuestion.Text = "";
            _labelQuestion.Font = UIFont.SystemFontOfSize(24f);
            _labelQuestion.TextColor = UIColor.Black;
            _labelQuestion.Frame = new RectangleF(15, 15, 290, 50);
            _labelQuestion.BackgroundColor = UIColor.Clear;
            _labelQuestion.Lines = 2;
            View.AddSubview(_labelQuestion);

            // Show button, triggers the answer being visible
            _buttonShow = new UnderlineButton();
            _buttonShow.Font = UIFont.SystemFontOfSize(16f);
            _buttonShow.SetTitle("Reveal answer...",UIControlState.Normal);
            _buttonShow.SetTitleColor(UIColor.Black,UIControlState.Normal);
            _buttonShow.HorizontalAlignment = UIControlContentHorizontalAlignment.Left;
            _buttonShow.Frame = new RectangleF(15,80,120,25);
            _buttonShow.TouchDown += new EventHandler(ShowAnswer);
            View.AddSubview(_buttonShow);

            // The answer label
            _labelAnswer = new UILabel();
            _labelAnswer.Text = "";
            _labelAnswer.Font = UIFont.SystemFontOfSize(24f);
            _labelAnswer.TextColor = UIColor.Gray;
            _labelAnswer.Frame = new RectangleF(15, 140, 290, 180);
            _labelAnswer.BackgroundColor = UIColor.Clear;
            _labelAnswer.Lines = 7;
            View.AddSubview(_labelAnswer);

            // The 6 score buttons
            AddScoreButtons();

            // The first question, display it in the labels
            _currentQuestion = _questions[_questionIndex];
            BindQuestion(_currentQuestion);
        }
        private void ScoreClick(object sender, EventArgs e)
        {
            ScoreButton button = (ScoreButton)sender;
            int score = button.Score;

            // Update the Question's properties and save it
            QuestionManager.AnswerQuestion(_currentQuestion, score);
            Question.Save(_currentQuestion);

            // Pop the next question, or if there's none left pop the controller
            ++_questionIndex;

            if (_questionIndex < _questions.Count)
            {
                _currentQuestion = _questions[_questionIndex];
                BindQuestion(_currentQuestion);
            }
            else
            {
                NavigationController.PopViewControllerAnimated(true);
            }
        }
        /// <summary>
        /// Sets up the question/answer labels for the provided question.
        /// </summary>
        /// <param name="question"></param>
        private void BindQuestion(Question question)
        {
            DisableScoreButtons();

            // Question and answer text
            _labelQuestion.Text = question.Title;
            _labelAnswer.Alpha = 0;
            _labelAnswer.Text = question.Answer;

            // As UILabel sucks, this verticially aligns it
            NSString nsString = new NSString(_labelAnswer.Text);
            SizeF size = nsString.StringSize(_labelAnswer.Font);
            SizeF requiredSize = new SizeF(size.Width,size.Height * _labelAnswer.Lines);
            _labelAnswer.Frame = new RectangleF(_labelAnswer.Frame.Left, _labelAnswer.Frame.Top, _labelAnswer.Frame.Width, requiredSize.Height);

            for (int i=0;i < requiredSize.Height / size.Height ;i++)
            {
                _labelAnswer.Text += "\n";
            }
        }
 public void DeleteRow(Question question)
 {
     Questions.Remove(question);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Remove this view from the stack

            if (_question == null)
            {
                _question = new Question();
                _question.Category = _category;
                Title = "Add Question";
            }
            else
            {
                Title = "Edit Question";
            }

            View.BackgroundColor = UIColor.GroupTableViewBackgroundColor;

            // Question label
            _labelQuestion = new UILabel();
            _labelQuestion.Text = "Question";
            _labelQuestion.Font = UIFont.BoldSystemFontOfSize(16f);
            _labelQuestion.Frame = new RectangleF(10, 10, 300, 25);
            _labelQuestion.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelQuestion);

            // Question textbox
            _textFieldQuestion = new UITextField();
            _textFieldQuestion.Text = _question.Title;
            _textFieldQuestion.Frame = new RectangleF(10, 35, 300, 30);
            _textFieldQuestion.BorderStyle = UITextBorderStyle.RoundedRect;
            _textFieldQuestion.ShouldReturn = delegate
            {
                    _textFieldQuestion.ResignFirstResponder();
                    return true;
            };
            View.AddSubview(_textFieldQuestion);

            // Answer label
            _labelAnswer = new UILabel();
            _labelAnswer.Text = "Answer";
            _labelAnswer.Font = UIFont.BoldSystemFontOfSize(16f);
            _labelAnswer.Frame = new RectangleF(10, 75, 300, 25);
            _labelAnswer.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelAnswer);

            // Answer textbox
            _textFieldAnswer = new UITextField();
            _textFieldAnswer.Text = _question.Answer;
            _textFieldAnswer.Frame = new RectangleF(10, 100, 300, 120);
            _textFieldAnswer.BorderStyle = UITextBorderStyle.RoundedRect;
            _textFieldAnswer.ShouldReturn = delegate
            {
                    _textFieldAnswer.ResignFirstResponder();
                    return true;
            };
            View.AddSubview(_textFieldAnswer);

            // Tips section
            _labelTipsHeader = new UILabel();
            _labelTipsHeader.Text = "Tips";
            _labelTipsHeader.Font = UIFont.BoldSystemFontOfSize(16f);
            _labelTipsHeader.TextColor = UIColor.Gray;
            _labelTipsHeader.Frame = new RectangleF(15, 225, 300, 25);
            _labelTipsHeader.BackgroundColor = UIColor.Clear;
            View.AddSubview(_labelTipsHeader);

            _labelTipsBody = new UILabel();
            _labelTipsBody.Text = "Make the question title short, make the answer short with " +
                "only a few points. Use acronyms, rhymes and mneumonics where possible. More tips can be found in the help.";
            _labelTipsBody.Font = UIFont.SystemFontOfSize(16f);
            _labelTipsBody.TextColor = UIColor.Gray;
            _labelTipsBody.Frame = new RectangleF(15, 245, 295, 100);
            _labelTipsBody.BackgroundColor = UIColor.Clear;
            _labelTipsBody.Lines = 10;
            View.AddSubview(_labelTipsBody);

            // Cancel
            _cancelButton = new UIBarButtonItem();
            _cancelButton.Title = "Cancel";
            _cancelButton.Clicked += delegate(object sender, EventArgs e)
            {
                NavigationController.PopViewControllerAnimated(true);
            };

            // Save button
            _saveButton = new UIBarButtonItem();
            _saveButton.Title = "Save";
            _saveButton.Clicked += SaveClick;

            // Hide the navigation bar, back button and toolbar.
            NavigationController.SetToolbarHidden(true, true);
            NavigationItem.HidesBackButton = true;
            NavigationItem.SetLeftBarButtonItem(_cancelButton, false);
            NavigationItem.SetRightBarButtonItem(_saveButton, false);
        }
 public AddEditQuestionController(Question question,Category category)
 {
     // Null means new category
     _question = question;
     _category = category;
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Saves the question to the default repository, returning its id.
 /// </summary>
 /// <param name="question"></param>
 /// <returns></returns>
 public static int Save(Question question)
 {
     return Repository.Default.SaveQuestion(question);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Moves the provided question to the new index in the list, and updates all other questions.
 /// </summary>
 /// <param name="question"></param>
 /// <param name="newIndex"></param>
 public static void Move(Question question, int newIndex)
 {
     Repository.Default.MoveQuestion(question, newIndex);
 }