private void LoadDaySelectorButtons(int type = 1)
        {
            layoutButtons = FindViewById <LinearLayout>(Resource.Id.layout_buttons);
            layoutButtons.RemoveAllViews();
            var layoutButtonParams = new LinearLayoutCompat.LayoutParams(
                (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics))
            {
                Width     = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                Height    = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 40, Resources.DisplayMetrics),
                MarginEnd = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 5, Resources.DisplayMetrics)
            };
            int      dayIndex = ReturnDayIndex();
            DateTime baseDate = DateTime.Today;

//            var today = baseDate;
//            var yesterday = baseDate.AddDays(-1);
            DateTime thisWeekStart = baseDate.AddDays(-dayIndex);
//            var thisWeekEnd = thisWeekStart.AddDays(7).AddSeconds(-1);
//            var lastWeekStart = thisWeekStart.AddDays(-7);
//            var lastWeekEnd = thisWeekStart.AddSeconds(-1);
            DateTime thisMonthStart = baseDate.AddDays(1 - baseDate.Day);

//            var thisMonthEnd = thisMonthStart.AddMonths(1).AddSeconds(-1);
//            var lastMonthStart = thisMonthStart.AddMonths(-1);
//            var lastMonthEnd = thisMonthStart.AddSeconds(-1);

            switch (type)
            {
            case 1:
                GetDataForChart(thisWeekStart, _dataType == "BloodPressure");
                break;

            case 2:
                GetDataForChart(thisMonthStart, _dataType == "BloodPressure");
                break;

            case 3:
                GetDataForChart(new DateTime(DateTime.Now.Year, 1, 1), _dataType == "BloodPressure");
                break;

            default:
                return;
            }

            if (type != 3)
            {
                string[] days                = { "L", "M", "M", "J", "V", "S", "D" };
                int      dayOfMonth          = DateTime.Now.Day;
                int      numberOfDaysInMonth = DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);
                int      size                = type == 1 && type != 3 ? days.Length : numberOfDaysInMonth;

                var activeButton = new AppCompatButton(this);
                for (var i = 0; i < size; i++)
                {
                    bool            isActive = type == 1 && type != 3 ? i == dayIndex : i + 1 == dayOfMonth;
                    AppCompatButton btn      = DaySelectorButton(isActive);
                    btn.Id               = i + 1;
                    btn.Text             = type == 1 && type != 3 ? i < days.Length ? days[i] : i.ToString() : (i + 1).ToString();
                    btn.LayoutParameters = layoutButtonParams;
                    if (type == 1 && type != 3 && i > dayIndex)
                    {
                        btn.Enabled = false;
                        btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme));
                    }
                    else
                    if (i + 1 > dayOfMonth)
                    {
                        btn.Enabled = false;
                        btn.SetTextColor(Resources.GetColor(Resource.Color.colorSecondary, Theme));
                    }
                    if (isActive)
                    {
                        activeButton = btn;
                    }
                    layoutButtons.AddView(btn);
                }

                if (type == 2)
                {
                    _scrollViewButtons.PostDelayed(delegate { _scrollViewButtons.SmoothScrollTo(activeButton.Left - 5, 0); }, 30);
                }
            }
            else
            {
                Drawable img = Resources.GetDrawable(Resource.Drawable.calendar_date, Theme);
                img.SetBounds(0, 0, 50, 50);
                var btn = new AppCompatButton(this)
                {
                    Id   = 1,
                    Text = "Data"
                           //Background = buttonBackgroundA,
                           //LayoutParameters = layoutButtonParams
                };
                btn.SetTextColor(Color.White);
                btn.Background = buttonBackgroundDatePicker;
                btn.SetAllCaps(false);
                btn.SetCompoundDrawables(img, null, null, null);
                btn.SetPadding((int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics),
                               (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 8, Resources.DisplayMetrics));

                btn.Click += (sender, args) =>
                {
                    var frag = SharingDatePickerFragment.NewInstance(delegate(DateTime time)
                    {
                        //_tbDate.Text = time.ToShortDateString();
                        _tvDate.Text = time.ToShortDateString();
                        switch (_dataType)
                        {
                        case "BloodPressure":
                            verticalScrollLinearLayout.RemoveAllViewsInLayout();
                            horizontalScrollLinearLayout.RemoveAllViewsInLayout();
                            LoadDataInScrollLayouts(time);
                            break;

                        case "BloodGlucose":
                            verticalScrollLinearLayout.RemoveAllViewsInLayout();
                            LoadDataInScrollLayouts(time, false);
                            break;
                        }
                    });
                    frag.Show(SupportFragmentManager, SharingDatePickerFragment.TAG);
                };
                layoutButtons.AddView(btn);
            }
        }
Пример #2
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.ReservaSalaJuntasLayout);
            Toolbar toolbar = FindViewById <Toolbar>(Resource.Id.toolbar);

            SetActionBar(toolbar);
            ActionBar.Title = Resources.GetString(Resource.String.str_meeting_room_reservation);
            ActionBar.SetDisplayHomeAsUpEnabled(true);
            /*_viewPager = FindViewById<ViewPager>(Resource.Id.vpSucursal);*/
            salas = SalasController.GetSalaJuntas(Intent.GetStringExtra("sucursal_id"));

            /*niveles = SalasController.GetNivelesSucursal(Intent.GetStringExtra("sucursal_id"));
             * _viewPager.Adapter = new SalaJuntasAdapter(this, salas);*/
            //tlSalasJuntas = FindViewById<TableLayout>(Resource.Id.tlSalasJuntas);
            Horarios.Add(fecha_seleccionada, new List <double>());
            ListView lvSalasJuntas = FindViewById <ListView>(Resource.Id.lvSalasJuntas);

            lvSalasJuntas.Adapter       = new SalasJuntasListAdapter(salas);
            lvSalasJuntas.ChoiceMode    = ChoiceMode.Single;
            lvSalasJuntas.ItemSelected += (sender, e) =>
            {
                Console.WriteLine(((ListView)sender).ChildCount);
            };

            /*salas.ForEach(sala =>
             * {
             *  LayoutInflater liView = LayoutInflater;
             *  View SucursalView = liView.Inflate(Resource.Layout.SalasJuntasLayout, null, true);
             *  SucursalView.FindViewById<LinearLayout>(Resource.Id.llSalaJunta).Click += delegate
             *  {
             *      SucursalView.FindViewById<LinearLayout>(Resource.Id.llReserva).Visibility = ViewStates.Visible;
             *  };
             *  SucursalView.FindViewById<TextView>(Resource.Id.lblSalaJunta).Text = sala.Sala_Descripcion;
             *  SucursalView.FindViewById<TextView>(Resource.Id.tvCapacidad).Text = sala.Sala_Capacidad + "-" + (Convert.ToInt32(sala.Sala_Capacidad) + 2).ToString();
             *  SucursalView.FindViewById<TextView>(Resource.Id.tvNivel).Text = "Nivel " + Convert.ToInt32(sala.Sala_Nivel).ToString("00");
             *  TableRow row = new TableRow(this);
             *  row.AddView(SucursalView);
             *  tlSalasJuntas.AddView(row);
             * });*/
            FindViewById <TextView>(Resource.Id.lblCreditosDisponibles).Text   = SalasController.GetCreditosDisponibles(storage.Get("Usuario_Id")).ToString();
            FindViewById <LinearLayout>(Resource.Id.llSeleccionarFecha).Click += (sender, e) =>
            {
                DatePickerMinFragment frag = DatePickerMinFragment.NewInstance(delegate(DateTime time)
                {
                    FindViewById <TextView>(Resource.Id.lblDiaFecha).Text  = time.DayOfWeek.ToString().Substring(0, 3);
                    FindViewById <TextView>(Resource.Id.lblDiaNumero).Text = time.Day.ToString();
                    fecha_seleccionada = time.ToString("d");
                    Horarios.Clear();
                    Horarios.Add(fecha_seleccionada, new List <double>());
                    UpdateHorasNoDisponibles();
                });
                frag.Show(FragmentManager, Resources.GetString(Resource.String.str_meeting_room_reservation));
            };
            FindViewById <TextView>(Resource.Id.lblDiaFecha).Text       = DateTime.Parse(fecha_seleccionada).DayOfWeek.ToString().Substring(0, 3);
            FindViewById <TextView>(Resource.Id.lblDiaNumero).Text      = DateTime.Parse(fecha_seleccionada).Day.ToString();
            FindViewById <TextView>(Resource.Id.lblHorasTotal).Text     = Horarios[fecha_seleccionada].Count.ToString();
            FindViewById <TextView>(Resource.Id.lblCreditosUsados).Text = creditos.ToString();

            /*Spinner spNivel = FindViewById<Spinner>(Resource.Id.spNivel);
             * spNivel.Adapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleSpinnerItem, niveles.Keys.ToList());
             * spNivel.SetSelection(niveles.Count - 1);
             * spNivel.ItemSelected += (sender, e) =>
             * {
             *  salas = SalasController.GetSalaJuntas(Intent.GetStringExtra("sucursal_id"), niveles[((Spinner)sender).SelectedItem.ToString()]);
             *  _viewPager.Adapter = new SalaJuntasAdapter(this, salas);
             * };*/
            llhHorario = FindViewById <LinearLayout>(Resource.Id.llhHorario);
            SalasController.GetHorasNoDisponibles(fecha_seleccionada, salas[SalaSeleccionada].Sala_Id).ForEach(horas =>
            {
                HorasNoDisponibles.Add(DateTime.Parse(horas.Sala_Hora_Fin).Hour);
                UpdateHorasNoDisponibles();
            });

            /*_viewPager.PageSelected += (sender, e) =>
             * {
             *  HorasNoDisponibles.Clear();
             *  SalasController.GetHorasNoDisponibles(fecha_seleccionada, salas[_viewPager.CurrentItem].Sala_Id).ForEach(horas =>
             *  {
             *      HorasNoDisponibles.Add(DateTime.Parse(horas.Sala_Hora_Fin).Hour);
             *  });
             *  if (!Horarios.ContainsKey(salas[_viewPager.CurrentItem].Sala_Id))
             *      Horarios.Add(salas[_viewPager.CurrentItem].Sala_Id, new Dictionary<string, List<double>>());
             *  if (!Horarios[salas[_viewPager.CurrentItem].Sala_Id].ContainsKey(fecha_seleccionada))
             *      Horarios[salas[_viewPager.CurrentItem].Sala_Id].Add(fecha_seleccionada, new List<double>());
             *  UpdateHorasNoDisponibles();
             *  FillHorario();
             * };*/
            FindViewById <RelativeLayout>(Resource.Id.rlAgendar).Click += (sender, e) => ShowConfirmacion();
            UpdateHorasNoDisponibles();
            FillHorario();
            HorizontalScrollView scrollHoras = FindViewById <HorizontalScrollView>(Resource.Id.hsvHorario);

            scrollHoras.PostDelayed(delegate
            {
                if (Convert.ToInt32(Build.VERSION.Sdk) < 23)
                {
                    scrollHoras.ScrollTo(DateTime.Now.Hour * 200, 0);
                }
                else
                {
                    scrollHoras.ScrollTo(DateTime.Now.Hour * 400, 0);
                }
            }, 100);
        }