Ejemplo n.º 1
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            var vacationViewModel   = ((AndroidApp)Application).VacationViewModel;
            var localizationService = ((AndroidApp)Application).LocalizationService;

            vacationViewModel.PropertyChanged += ViewModelOnPropertyChanged;
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.Delail);

            Android.Support.V7.Widget.Toolbar toolbar =
                FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);
            SetSupportActionBar(toolbar);
            SupportActionBar.SetDisplayShowTitleEnabled(true);


            Button saveButton = FindViewById <Button>(Resource.Id.saveButton);
            Button startDate  = FindViewById <Button>(Resource.Id.startDate);
            Button endDate    = FindViewById <Button>(Resource.Id.endDate);

            string vacId = Intent.GetStringExtra("Vacation");

            if (vacId == null)
            {
                _vacation                  = new Vacation();
                _vacation.Id               = new Guid();
                _vacation.Created          = DateTime.Now;
                _vacation.CreatedBy        = "Name";
                _vacation.Start            = _vacation.Created;
                _vacation.End              = _vacation.Created.AddDays(1);
                _vacation.VacationTypeId   = 1;
                _vacation.VacationStatusId = 3;
            }
            else
            {
                _vacation = vacationViewModel.FindVacation(vacId);
            }

            startDate.Text = _vacation.Start.ToString("d MMM yyyy");
            endDate.Text   = _vacation.End.ToString("d MMM yyyy");

            RadioButton approved = FindViewById <RadioButton>(Resource.Id.approved);

            approved.Text = localizationService.Localize("Open");
            RadioButton closed = FindViewById <RadioButton>(Resource.Id.closed);

            closed.Text = localizationService.Localize("Close");
            if (_vacation.VacationStatusId == 3)
            {
                approved.Checked = true;
            }
            else
            {
                closed.Checked = true;
            }
            approved.Click += (sender, e) =>
            {
                if (((RadioButton)sender).Id == Resource.Id.approved)
                {
                    _vacation.VacationStatusId = 3;
                }
                else
                {
                    _vacation.VacationStatusId = 5;
                }
            };
            closed.Click += (sender, e) =>
            {
                if (((RadioButton)sender).Id == Resource.Id.closed)
                {
                    _vacation.VacationStatusId = 5;
                }
                else
                {
                    _vacation.VacationStatusId = 3;
                }
            };


            startDate.Click += (sender, eventArgs) =>
            {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                {
                    _vacation.Start = time;
                    startDate.Text  = time.ToString("d MMM yyyy");
                });
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            };

            endDate.Click += (sender, eventArgs) =>
            {
                DatePickerFragment frag = DatePickerFragment.NewInstance(delegate(DateTime time)
                {
                    _vacation.End = time;
                    endDate.Text  = time.ToString("d MMM yyyy");
                });
                frag.Show(FragmentManager, DatePickerFragment.TAG);
            };

            ViewPager viewPager;
            DetailFragmentStatePagerAdapter detailFragmentPagerAdapter;

            viewPager = FindViewById <ViewPager>(Resource.Id.viewPager);
            detailFragmentPagerAdapter = new DetailFragmentStatePagerAdapter(SupportFragmentManager);
            detailFragmentPagerAdapter.addFragmentView((arg1, arg2, arg3) =>
            {
                var view      = arg1.Inflate(Resource.Layout.ImageViewLayout, arg2, false);
                var imageView = view.FindViewById <ImageView>(Resource.Id.imageView);
                imageView.SetImageResource(Resource.Drawable.Icon_Request_Green);
                var vacationType  = view.FindViewById <TextView>(Resource.Id.vacationType);
                vacationType.Text = localizationService.Localize("Regular");
                return(view);
            });
            detailFragmentPagerAdapter.addFragmentView((arg1, arg2, arg3) =>
            {
                var view      = arg1.Inflate(Resource.Layout.ImageViewLayout, arg2, false);
                var imageView = view.FindViewById <ImageView>(Resource.Id.imageView);
                imageView.SetImageResource(Resource.Drawable.Icon_Request_Plum);
                var vacationType  = view.FindViewById <TextView>(Resource.Id.vacationType);
                vacationType.Text = localizationService.Localize("Sick");
                return(view);
            });
            detailFragmentPagerAdapter.addFragmentView((arg1, arg2, arg3) =>
            {
                var view      = arg1.Inflate(Resource.Layout.ImageViewLayout, arg2, false);
                var imageView = view.FindViewById <ImageView>(Resource.Id.imageView);
                imageView.SetImageResource(Resource.Drawable.Icon_Request_Gray);
                var vacationType  = view.FindViewById <TextView>(Resource.Id.vacationType);
                vacationType.Text = localizationService.Localize("Exceptional");
                return(view);
            });
            detailFragmentPagerAdapter.addFragmentView((arg1, arg2, arg3) =>
            {
                var view      = arg1.Inflate(Resource.Layout.ImageViewLayout, arg2, false);
                var imageView = view.FindViewById <ImageView>(Resource.Id.imageView);
                imageView.SetImageResource(Resource.Drawable.Icon_Request_Dark);
                var vacationType  = view.FindViewById <TextView>(Resource.Id.vacationType);
                vacationType.Text = localizationService.Localize("LeaveWithoutPay");
                return(view);
            });
            detailFragmentPagerAdapter.addFragmentView((arg1, arg2, arg3) =>
            {
                var view      = arg1.Inflate(Resource.Layout.ImageViewLayout, arg2, false);
                var imageView = view.FindViewById <ImageView>(Resource.Id.imageView);
                imageView.SetImageResource(Resource.Drawable.Icon_Request_Blue);
                var vacationType  = view.FindViewById <TextView>(Resource.Id.vacationType);
                vacationType.Text = localizationService.Localize("Overtime");
                return(view);
            });

            viewPager.Adapter = detailFragmentPagerAdapter;
            viewPager.SetCurrentItem(_vacation.VacationTypeId - 1, false);

            saveButton.Click += async(sender, a) =>
            {
                if (vacId == null)
                {
                    _vacation.VacationTypeId = viewPager.CurrentItem + 1;
                    await vacationViewModel.AddVacation(_vacation);
                }
                _vacation.VacationTypeId = viewPager.CurrentItem + 1;
                _vacation.Created        = DateTime.Now;
                Intent intent = new Intent(this, typeof(MainActivity));
                intent.PutExtra("Filter", "ALL");
                StartActivity(intent);
            };

            vacationViewModel.PropertyChanged -= ViewModelOnPropertyChanged;
        }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.detail_layout);

            _startDatePickerDialog = new DatePickerDialog(this);
            _startDatePickerDialog.DatePicker.Tag = StartDatePicker;
            _startDatePickerDialog.SetOnDateSetListener(this);

            _endDatePickerDialog = new DatePickerDialog(this);
            _endDatePickerDialog.DatePicker.Tag = EndDatePicker;
            _endDatePickerDialog.SetOnDateSetListener(this);

            _startVac       = FindViewById <TextView>(Resource.Id.dayStart);
            _startDateMonth = FindViewById <TextView>(Resource.Id.monthStart);
            _startDateYear  = FindViewById <TextView>(Resource.Id.yearStart);

            _endVac       = FindViewById <TextView>(Resource.Id.dayEnd);
            _endDateMonth = FindViewById <TextView>(Resource.Id.monthEnd);
            _endDateYear  = FindViewById <TextView>(Resource.Id.yearEnd);

            _saveButton = FindViewById <Button>(Resource.Id.saveButton);

            _recyclerView = FindViewById <RecyclerView>(Resource.Id.recyclerViewDetail);
            _adapter      = new RadioButtonAdapter(_recyclerView);
            _recyclerView.SetAdapter(_adapter);

            _linearLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.Horizontal, false);
            _recyclerView.SetLayoutManager(_linearLayoutManager);
            _recyclerView.StopNestedScroll();

            _viewPager = FindViewById <ViewPager>(Resource.Id.viewPager);
            DetailFragmentStatePagerAdapter detailFragmentPagerAdapter = new DetailFragmentStatePagerAdapter(SupportFragmentManager);

            detailFragmentPagerAdapter.AddFragmentView((arg1, arg2, arg3) =>
            {
                return(SetViewPagerFragment(arg1, arg2, "Regular", Resource.Drawable.Icon_Request_Green));
            });
            detailFragmentPagerAdapter.AddFragmentView((arg1, arg2, arg3) =>
            {
                return(SetViewPagerFragment(arg1, arg2, "Sick", Resource.Drawable.Icon_Request_Plum));
            });
            detailFragmentPagerAdapter.AddFragmentView((arg1, arg2, arg3) =>
            {
                return(SetViewPagerFragment(arg1, arg2, "Exceptional", Resource.Drawable.Icon_Request_Gray));
            });
            detailFragmentPagerAdapter.AddFragmentView((arg1, arg2, arg3) =>
            {
                return(SetViewPagerFragment(arg1, arg2, "LeaveWithoutPay", Resource.Drawable.Icon_Request_Dark));
            });
            detailFragmentPagerAdapter.AddFragmentView((arg1, arg2, arg3) =>
            {
                return(SetViewPagerFragment(arg1, arg2, "OverTime", Resource.Drawable.Icon_Request_Blue));
            });

            _viewPager.Adapter = detailFragmentPagerAdapter;

            var dots = FindViewById <TabLayout>(Resource.Id.dot);

            dots.SetupWithViewPager(_viewPager, true);

            var startDateEditText = FindViewById <RelativeLayout>(Resource.Id.relative1);

            startDateEditText.Click += (s, e) =>
            {
                _startDatePickerDialog.UpdateDate(StartDatePickerTime.Year, StartDatePickerTime.Month - 1, StartDatePickerTime.Day);
                _startDatePickerDialog.Show();
            };

            var endDateEditText = FindViewById <RelativeLayout>(Resource.Id.relative2);

            endDateEditText.Click += (s, e) =>
            {
                _endDatePickerDialog.UpdateDate(EndDatePickerTime.Year, EndDatePickerTime.Month - 1, EndDatePickerTime.Day);
                _endDatePickerDialog.Show();
            };
        }