Beispiel #1
0
        protected override async void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_test);

            mAdView = FindViewById <AdView>(Resource.Id.adView1);
            var adRequest = new AdRequest.Builder().Build();

            mAdView.LoadAd(adRequest);

            Bundle      bundle            = Intent.GetBundleExtra("testParams");
            int         oldQuestionsCount = bundle.GetInt("oldQuestions", 0);
            int         newQuestionsCount = bundle.GetInt("newQuestions", 0);
            List <long> categories        = bundle.GetLongArray("categories").ToList();

            show_testinput = bundle.GetBoolean("show_testinput", false);

            questions = new List <TestHelper.Question>();
            DictionaryDBHelper db_helper = new DictionaryDBHelper();
            List <DictionaryDBHelper.QuestionExt1> db_questions = db_helper.GetNewQuestions(newQuestionsCount, categories);

            db_questions.AddRange(db_helper.GetOldQuestions(oldQuestionsCount, categories));
            foreach (DictionaryDBHelper.QuestionExt1 db_question in db_questions)
            {
                TestHelper.Question       question     = new TestHelper.Question(db_question.Id, db_question.Name, db_question.Is_old);
                DictionaryDBHelper.Answer valid_answer = db_helper.GetAnswerForQuestion(db_question.Id);
                question.AddAnswer(valid_answer.Value, true);
                if (db_question.Is_sealed)
                {
                    List <DictionaryDBHelper.Answer> answers = db_helper.GetAnswersForSealedQuestion(db_question.Id, valid_answer.Id);
                    for (int i = 0; i < answers.Count; i++)
                    {
                        question.AddAnswer(answers[i].Value, false);
                    }
                }
                else
                if (db_question.Category_Is_sealed)
                {
                    List <DictionaryDBHelper.Answer> answers = db_helper.GetAnswersForSealedCategory(3, db_question.Category_id, valid_answer.Id);
                    for (int i = 0; i < answers.Count; i++)
                    {
                        question.AddAnswer(answers[i].Value, false);
                    }
                }
                else
                {
                    //List<DictionaryDBHelper.Answer> answers = db_helper.GetAnswersForCategories(3, categories, valid_answer.Id);
                    List <DictionaryDBHelper.Answer> answers = db_helper.GetAnswersForSealedCategory(3, db_question.Category_id, valid_answer.Id);
                    for (int i = 0; i < answers.Count; i++)
                    {
                        question.AddAnswer(answers[i].Value, false);
                    }
                }
                questions.Add(question);
            }

            if (questions.Count == 0)
            {
                Toast.MakeText(this, "Brak pytań dla wybranych kategorii", ToastLength.Short).Show();
                SetResult(Result.FirstUser);
                Finish();
                return;
            }

            radioGroupAnswers    = FindViewById <RadioGroup>(Resource.Id.rgAnswers);
            questionIndex        = 0;
            questionsAnswered    = 0;
            progressAnswered     = FindViewById <ProgressBar>(Resource.Id.progressAnswered);
            progressAnswered.Max = questions.Count();

            GenerateQuestion();

            ISharedPreferences prefs             = PreferenceManager.GetDefaultSharedPreferences(ApplicationContext);
            string             locale_saved_name = prefs.GetString("localeName", "");
            var locales = await TextToSpeech.GetLocalesAsync();

            locale = locales.FirstOrDefault(l => l.Name == locale_saved_name);

            FindViewById <Button>(Resource.Id.btnVerify).Click += btnVerify_Click;
            FindViewById <Button>(Resource.Id.btnNext).Click   += btnNext_Click;
            FindViewById <Button>(Resource.Id.btnClose).Click  += BtnClose_Click;

            duration_start = DateTime.Now;
        }