Пример #1
0
        private Cell CreateOfficeCell(Office office)
        {
            var containerCell  = new ViewCell();
            var containerStack = new StackLayout();
            var stackLayout    = new StackLayout {
                Margin = new Thickness(20, 0, 0, 0), BackgroundColor = InnerBGColor
            };

            containerCell.View = containerStack;

            {
                Grid grid = new Grid()
                {
                    BindingContext = ContainerBGColor
                };
                var fontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label));
                var label    = new Label {
                    Text = office.Address.FullAddress.Replace(Environment.NewLine, ""), Margin = new Thickness(10, 0, 0, 0), FontAttributes = FontAttributes.Bold, TextColor = Color.CornflowerBlue, FontSize = fontSize
                };
                var gestureRecognizer = new TapGestureRecognizer();
                gestureRecognizer.Tapped += (o, e) => OpenMap(office.Location, Therapist.Therapist.FullName);
                label.GestureRecognizers.Add(gestureRecognizer);
                grid.Children.Add(label);
                containerStack.Children.Add(grid);
            }
            containerStack.Children.Add(stackLayout);
            if (office.TelefoneNumbers.Any())
            {
                var label = new Label {
                    Text = LanguageFile.GetString("contact"), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
                };
                stackLayout.Children.Add(label);

                foreach (var telefoneNumber in office.TelefoneNumbers)
                {
                    var text       = $"{LanguageFile.TranslateContactType(telefoneNumber.Type)}: {telefoneNumber.Number}";
                    var fontSize   = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) + 2;
                    var phoneLabel = new Label {
                        Text = text, TextColor = Blue, FontSize = fontSize
                    };
                    var tapGestureRecognizer = new TapGestureRecognizer();
                    tapGestureRecognizer.Tapped += (o, e) => OpenTelefoneNumber(telefoneNumber);
                    phoneLabel.GestureRecognizers.Add(tapGestureRecognizer);
                    stackLayout.Children.Add(phoneLabel);
                }
            }

            if (office.OfficeHours.Any())
            {
                var label = new Label {
                    Text = LanguageFile.GetString("officehours"), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
                };
                stackLayout.Children.Add(label);

                var grid = new Grid {
                    Margin = new Thickness(20, 0, 0, 0)
                };
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Auto
                });
                grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = GridLength.Star
                });
                for (var i = 0; i < office.OfficeHours.Count; i++)
                {
                    var officeHour = office.OfficeHours[i];
                    grid.RowDefinitions.Add(new RowDefinition {
                        Height = GridLength.Auto
                    });
                    var translateDayOfWeek = LanguageFile.TranslateDayOfWeek(officeHour.DayOfWeek);
                    var text     = $"{officeHour.From:HH:mm} - {officeHour.To:HH:mm}";
                    var fontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) + 2;
                    var dayLabel = new Label {
                        Text = translateDayOfWeek, TextColor = BlueGray, FontSize = fontSize
                    };
                    var timeLabel = new Label {
                        Text = text, TextColor = BlueGray, FontSize = fontSize
                    };
                    grid.Children.Add(dayLabel);
                    grid.Children.Add(timeLabel);
                    Grid.SetRow(dayLabel, i);
                    Grid.SetRow(timeLabel, i);
                    Grid.SetColumn(timeLabel, 1);
                }
                stackLayout.Children.Add(grid);
            }

            if (office.ContactTimes.Any())
            {
                var label = new Label {
                    Text = LanguageFile.GetString("contacttimes"), FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label))
                };

                stackLayout.Children.Add(label);
                foreach (var contactTime in office.ContactTimes)
                {
                    {
                        var text       = $"{LanguageFile.TranslateContactType(contactTime.TelefoneNumber.Type)}: {contactTime.TelefoneNumber.Number}";
                        var fontSize   = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) + 2;
                        var phoneLabel = new Label {
                            Text = text, TextColor = Blue, FontSize = fontSize
                        };
                        var tapGestureRecognizer = new TapGestureRecognizer();
                        tapGestureRecognizer.Tapped += (o, e) => OpenTelefoneNumber(contactTime.TelefoneNumber);
                        phoneLabel.GestureRecognizers.Add(tapGestureRecognizer);

                        stackLayout.Children.Add(phoneLabel);
                    }

                    var grid = new Grid {
                        Margin = new Thickness(20, 0, 0, 0)
                    };
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = GridLength.Auto
                    });
                    grid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = GridLength.Star
                    });

                    for (var i = 0; i < contactTime.OfficeHours.Count; i++)
                    {
                        var officeHour = contactTime.OfficeHours[i];
                        grid.RowDefinitions.Add(new RowDefinition {
                            Height = GridLength.Auto
                        });
                        var translateDayOfWeek = LanguageFile.TranslateDayOfWeek(officeHour.DayOfWeek);
                        var text     = $"{officeHour.From:HH:mm} - {officeHour.To:HH:mm}";
                        var fontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)) + 2;
                        var dayLabel = new Label {
                            Text = translateDayOfWeek, TextColor = BlueGray, FontSize = fontSize
                        };
                        var timeLabel = new Label {
                            Text = text, TextColor = BlueGray, FontSize = fontSize
                        };
                        grid.Children.Add(dayLabel);
                        grid.Children.Add(timeLabel);

                        Grid.SetColumn(timeLabel, 1);
                        Grid.SetRow(timeLabel, i);
                        Grid.SetRow(dayLabel, i);
                    }

                    stackLayout.Children.Add(grid);
                }
            }

            return(containerCell);
        }