Example #1
0
        public static ScheduleFilterView NewInstance()
        {
            var fragment = new ScheduleFilterView();

            return(fragment);
        }
Example #2
0
        void SetUpBotomSheet(View view)
        {
            var bottomSheet = view.FindViewById <LinearLayout>(Resource.Id.bottom_sheet);

            this.bottomSheetBehavior       = BottomSheetBehavior.From(bottomSheet);
            this.bottomSheetBehavior.State = BottomSheetBehavior.StateHidden;

            var textGroups = view.FindViewById <TextView>(Resource.Id.text_groups);

            textGroups.Click += (obj, arg) =>
            {
                if (this.Activity == null)
                {
                    return;
                }
                var dialog = ScheduleFilterView.NewInstance();
                dialog.Show(this.Activity.SupportFragmentManager, "qq");
                dialog.SetAdapter(new AdvancedSearchAdapter(
                                      new AdvancedSearchAdapter.SimpleFilter(this.viewModel.GroupList, this.checkedGroups)));
            };
            var textLessonTitles = view.FindViewById <TextView>(Resource.Id.text_lesson_titles);
            var textTeachers     = view.FindViewById <TextView>(Resource.Id.text_teachers);
            var textAuditoriums  = view.FindViewById <TextView>(Resource.Id.text_auditoriums);
            var textLessonTypes  = view.FindViewById <TextView>(Resource.Id.text_lesson_types);
            var applyButton      = view.FindViewById <Button>(Resource.Id.btn_search);

            var progressBar  = bottomSheet.FindViewById <ProgressBar>(Resource.Id.progressBar);
            var progressText = bottomSheet.FindViewById <TextView>(Resource.Id.text_progress);
            var cancelBtn    = bottomSheet.FindViewById <Button>(Resource.Id.btn_cancel);

            cancelBtn.Click += (obj, arg) =>
            {
                this.cts.Cancel();
                cancelBtn.Visibility = ViewStates.Gone;
            };
            this.checkedGroups.CollectionChanged +=
                (obj, arg) =>
            {
                textGroups.Text = string.Join(", ", from index in this.checkedGroups
                                              select this.viewModel.GroupList[index]);
                if (textGroups.Text == string.Empty)
                {
                    textGroups.Text = GetString(Resource.String.all_groups);
                }
                textLessonTitles.Visibility = ViewStates.Gone;
                this.checkedLessonTitles.Clear();
                textTeachers.Visibility = ViewStates.Gone;
                this.checkedTeachers.Clear();
                textAuditoriums.Visibility = ViewStates.Gone;
                this.checkedAuditoriums.Clear();
                textLessonTypes.Visibility = ViewStates.Gone;
                this.checkedLessonTypes.Clear();
                applyButton.Visibility = ViewStates.Gone;
            };
            var downloadShedulesBtn = view.FindViewById <Button>(Resource.Id.btn_acceptGroups);

            downloadShedulesBtn.Click += async(obj, arg) =>
            {
                downloadShedulesBtn.Enabled = false;
                textGroups.Enabled          = false;
                textLessonTitles.Visibility = ViewStates.Gone;
                textTeachers.Visibility     = ViewStates.Gone;
                textAuditoriums.Visibility  = ViewStates.Gone;
                textLessonTypes.Visibility  = ViewStates.Gone;
                applyButton.Visibility      = ViewStates.Gone;
                progressBar.Visibility      = ViewStates.Visible;
                progressText.Visibility     = ViewStates.Visible;
                cancelBtn.Visibility        = ViewStates.Visible;
                this.cts = new CancellationTokenSource();
                try
                {
                    (this.schedules, this.lessonTitles, this.teachers, this.auditoriums, this.lessonTypes) =
                        await this.viewModel.GetAdvancedSearchData(
                            this.checkedGroups.Count == 0?this.viewModel.GroupList :
                            (from index in this.checkedGroups
                             select this.viewModel.GroupList[index]).ToList() as IList <string>,
                            this.cts.Token, progress => Xamarin.Essentials.MainThread.BeginInvokeOnMainThread(() =>
                    {
                        progressBar.Progress = progress;
                        progressText.Text    = progress / 100 + " %";
                    }));

                    Toast.MakeText(this.Context, "Расписания загружены", ToastLength.Short).Show();
                    downloadShedulesBtn.Enabled = true;
                    textGroups.Enabled          = true;
                    textLessonTitles.Visibility = ViewStates.Visible;
                    textTeachers.Visibility     = ViewStates.Visible;
                    textAuditoriums.Visibility  = ViewStates.Visible;
                    textLessonTypes.Visibility  = ViewStates.Visible;
                    applyButton.Visibility      = ViewStates.Visible;

                    progressBar.Visibility  = ViewStates.Gone;
                    progressText.Visibility = ViewStates.Gone;
                    progressBar.Progress    = 0;
                    progressText.Text       = "0 %";
                    cancelBtn.Visibility    = ViewStates.Gone;
                }
                catch (System.OperationCanceledException)
                {
                    this.cts.Dispose();
                    downloadShedulesBtn.Enabled = true;
                    textGroups.Enabled          = true;
                    Toast.MakeText(this.Context, "Загрузка отменена", ToastLength.Short).Show();
                    progressBar.Progress        = 0;
                    progressText.Text           = "0 %";
                    textLessonTitles.Visibility = ViewStates.Gone;
                    textTeachers.Visibility     = ViewStates.Gone;
                    textAuditoriums.Visibility  = ViewStates.Gone;
                    textLessonTypes.Visibility  = ViewStates.Gone;
                    applyButton.Visibility      = ViewStates.Gone;
                    progressBar.Visibility      = ViewStates.Gone;
                    progressText.Visibility     = ViewStates.Gone;
                }
            };



            textLessonTitles.Click += (obj, arg) =>
            {
                if (this.Activity == null)
                {
                    return;
                }
                var dialog = ScheduleFilterView.NewInstance();
                dialog.Show(this.Activity.SupportFragmentManager, "qq");
                dialog.SetAdapter(new AdvancedSearchAdapter(
                                      new AdvancedSearchAdapter.AdvancedFilter(this.lessonTitles, this.checkedLessonTitles)));
            };
            this.checkedLessonTitles.CollectionChanged +=
                (obj, arg) =>
            {
                textLessonTitles.Text = string.Join(", ", from index in this.checkedLessonTitles
                                                    select this.lessonTitles[index]);
                if (textLessonTitles.Text == string.Empty)
                {
                    textLessonTitles.Text = GetString(Resource.String.all_subjects);
                }
            };

            textTeachers.Click += (obj, arg) =>
            {
                if (this.Activity == null)
                {
                    return;
                }
                var dialog = ScheduleFilterView.NewInstance();
                dialog.Show(this.Activity.SupportFragmentManager, "qq");
                dialog.SetAdapter(new AdvancedSearchAdapter(
                                      new AdvancedSearchAdapter.AdvancedFilter(this.teachers, this.checkedTeachers)));
            };
            this.checkedTeachers.CollectionChanged +=
                (obj, arg) =>
            {
                textTeachers.Text = string.Join(", ", from index in this.checkedTeachers
                                                select this.teachers[index]);
                if (textTeachers.Text == string.Empty)
                {
                    textTeachers.Text = GetString(Resource.String.all_teachers);
                }
            };

            textAuditoriums.Click += (obj, arg) =>
            {
                if (this.Activity == null)
                {
                    return;
                }
                var dialog = ScheduleFilterView.NewInstance();
                dialog.Show(this.Activity.SupportFragmentManager, "qq");
                dialog.SetAdapter(new AdvancedSearchAdapter(
                                      new AdvancedSearchAdapter.AdvancedFilter(this.auditoriums, this.checkedAuditoriums)));
            };
            this.checkedAuditoriums.CollectionChanged +=
                (obj, arg) =>
            {
                textAuditoriums.Text = string.Join(", ", from index in this.checkedAuditoriums
                                                   select this.auditoriums[index]);
                if (textAuditoriums.Text == string.Empty)
                {
                    textAuditoriums.Text = GetString(Resource.String.all_auditoriums);
                }
            };

            textLessonTypes.Click += (obj, arg) =>
            {
                if (this.Activity == null)
                {
                    return;
                }
                var dialog = ScheduleFilterView.NewInstance();
                dialog.Show(this.Activity.SupportFragmentManager, "qq");
                dialog.SetAdapter(new AdvancedSearchAdapter(
                                      new AdvancedSearchAdapter.SimpleFilter(this.lessonTypes, this.checkedLessonTypes)));
            };
            this.checkedLessonTypes.CollectionChanged +=
                (obj, arg) =>
            {
                textLessonTypes.Text = string.Join(", ", from index in this.checkedLessonTypes
                                                   select this.lessonTypes[index]);
                if (textLessonTypes.Text == string.Empty)
                {
                    textLessonTypes.Text = GetString(Resource.String.all_lesson_types);
                }
            };
            applyButton.Click += (obj, arg) =>
            {
                SetUpSchedule(null, true);
                var filt        = new Schedule.AdvancedSerach();
                var newSchedule = filt.Filter(this.schedules,
                                              this.checkedLessonTitles.Count == 0 ? this.lessonTitles :
                                              (from index in this.checkedLessonTitles
                                               select this.lessonTitles[index]).ToList() as IList <string>,
                                              this.checkedLessonTypes.Count == 0 ? this.lessonTypes :
                                              (from index in this.checkedLessonTypes
                                               select this.lessonTypes[index]).ToList() as IList <string>,
                                              this.checkedAuditoriums.Count == 0 ? this.auditoriums :
                                              (from index in this.checkedAuditoriums
                                               select this.auditoriums[index]).ToList() as IList <string>,
                                              this.checkedTeachers.Count == 0 ? this.teachers :
                                              (from index in this.checkedTeachers
                                               select this.teachers[index]).ToList() as IList <string>);
                this.viewModel.IsAdvancedSearch = true;
                this.viewModel.SetUpSchedule(newSchedule);
                this.textGroupTitle.Text = "...";
            };
        }