private async void Answer(object sender, EventArgs args, RecyclerView QuestionsRecView) { //if correct var userAns = Tickets.ElementAt(Position).Answers.FirstOrDefault(o => o.Ans == (sender as TextView).Text); (sender as TextView).SetBackgroundColor(userAns.Correct ? Color.Green : Color.Red); //if not correct QuestionsRecView.GetChildAt(Tickets.ElementAt(Position).Answers.IndexOf(Tickets.ElementAt(Position).Answers.First(o => o.Correct))).FindViewById <TextView>(Resource.Id.AnsTxt).SetBackgroundColor(Color.Green); //add user answer Answers.Add(userAns.Ans); //if not correct //correct or incorect count detect _ = Tickets.ElementAt(Position).Answers.FirstOrDefault(o => o.Ans == (sender as TextView).Text).Correct ? CorrectAns++ : FailedAns++; //disable all answers for (int i = 0; i < QuestionsRecView.ChildCount; i++) { QuestionsRecView.GetChildAt(i).FindViewById <TextView>(Resource.Id.AnsTxt).Enabled = false; } //cor ans CorAns.Text = CorrectAns.ToString(); //incor ans FilAns.Text = FailedAns.ToString(); // if incorect answers limit set limit -> int MaxIncorectCount = 3 default if (FailedAns == MaxIncorrectCount) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); // alert.SetTitle("არადა კაი იყო 😁"); alert.SetMessage($"შენ ვერ ჩააბარე გამოცდა იმითომ რომ {MaxIncorrectCount} შეკითხვას გაეცი არასწორი პასუხი"); Dialog dialog = alert.Create(); dialog.Show(); } Position++; NextQuestion.Text = (Position + 1).ToString(); if (AutoChange.Checked) { TicketPager.SetCurrentItem(Position, true); } if (Position == TicketsCount) { await new AnsweredService().SaveUserAnswersAsync(Tickets, Answers); var endUi = new Intent(this, typeof(EndActivity)); endUi.PutExtra("TicketsCount", TicketsCount); StartActivity(endUi); ClearUi(); } }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.activity_testing); try { //getting tickets. if (Intent.GetBooleanExtra("Online", false)) { var tmp = await new GetTopicService(Animations).GetAllOnlineCategoryAsync(); if (Intent.GetStringArrayListExtra("Topics") != null) { Tickets = tmp.First(o => o.Name == Intent.GetStringExtra("Category")).Topics.Where(o => Intent.GetStringArrayListExtra("Topics").Any(i => i == o.Name)).SelectMany(o => o.TicketsDb).ToList().Shuffle().Take(TicketsCount); } else { Tickets = tmp.First(o => o.Name == Intent.GetStringExtra("Category")).Topics.SelectMany(o => o.TicketsDb).ToList().Shuffle().Take(TicketsCount); } } else { var tmp = await new GetTopicService().GetAllOfflineCategoryAsync(); if (Intent.GetStringArrayListExtra("Topics") != null) { Tickets = tmp.First(o => o.Name == Intent.GetStringExtra("Category")).Topics.Where(o => Intent.GetStringArrayListExtra("Topics").Any(i => i == o.Name)).SelectMany(o => o.TicketsDb).ToList().Shuffle().Take(TicketsCount); } else { Tickets = tmp.First(o => o.Name == Intent.GetStringExtra("Category")).Topics.SelectMany(o => o.TicketsDb).ToList().Shuffle().Take(TicketsCount); } } TicketsCount = Tickets.Count(); } catch (Java.Net.UnknownHostException) { Android.Support.V7.App.AlertDialog.Builder alert = new Android.Support.V7.App.AlertDialog.Builder(this); alert.SetTitle("ინტერნეტის კავშირი"); alert.SetMessage("ეს აპლიკაცია ირთვება პირვლად იმისთვის რომ ჩაირთოს საჭიროა ინტერნეტთან კავშირი შეკითხვების გადმოსაწერათ ერთჯერადი კავშირია."); Dialog dialog = alert.Create(); dialog.Show(); } //getting taked tickets count. TicketsCount = Tickets.Count(); //tst.Dispose(); //UI. TimerTxt = FindViewById <TextView>(Resource.Id.TimeTxt); HelpImg = FindViewById <ImageView>(Resource.Id.HelpImg); CorAns = FindViewById <TextView>(Resource.Id.CorrectAnswers); FilAns = FindViewById <TextView>(Resource.Id.FiledAnswers); QuestionCount = FindViewById <TextView>(Resource.Id.AllQuestions); NextQuestion = FindViewById <TextView>(Resource.Id.NextQuest); AutoChange = FindViewById <CheckBox>(Resource.Id.AutoChange); //_________ QuestionCount.Text = Tickets.Count().ToString(); NextQuestion.Text = (Position + 1).ToString(); TicketPager = FindViewById <Android.Support.V4.View.ViewPager>(Resource.Id.TicketsPager); TicketPager.Adapter = new TicketFragmentAdapter(Tickets.ToList(), Answer, SupportFragmentManager); HelpImg.Click += HelpForAns; TicketPager.Touch += (object sender, View.TouchEventArgs e) => { TicketPager.SetCurrentItem((Position + 1), true); TicketPager.SetCurrentItem((Position), true); }; //start timer. TimerStart(); }