UIView CreateBackgroundView (CellTableViewCell cell, FullScheduleCellViewModel viewModel) { return new UIView { AutoresizingMask = UIViewAutoresizing.FlexibleHeight, Frame = cell.Bounds, BackgroundColor = ((Xamarin.Forms.Color)new TrackBackgroundColorConverter () .Convert (viewModel.Track, typeof(Xamarin.Forms.Color), null, CultureInfo.CurrentCulture)) .ToUIColor () }; }
void SetupTrack(View view, FullScheduleCellViewModel viewModel, Color textColor, bool visible) { TextView track = view.FindViewById<TextView>(Resource.Id.fs_track); if (visible) { track.Visibility = ViewStates.Visible; track.Text = new TrackValueConverter ().Convert (viewModel.Track, typeof(string), null, CultureInfo.CurrentCulture) as string; track.SetTextColor (textColor); track.Typeface = regular; track.TextSize = 12; } else { track.Visibility = ViewStates.Gone; } }
void SetupLocation(View view, FullScheduleCellViewModel viewModel, Color textColor, bool visible) { TextView location = view.FindViewById<TextView>(Resource.Id.fs_location); if (visible) { location.Visibility = ViewStates.Visible; location.Text = viewModel.Location.ToUpper (); location.SetTextColor (textColor); location.Typeface = bold; location.TextSize = 12; } else { location.Visibility = ViewStates.Gone; } }
void SetupTitle(View view, FullScheduleCellViewModel viewModel, Color textColor, bool visible) { TextView title = view.FindViewById<TextView>(Resource.Id.fs_title); if (visible) { title.Visibility = ViewStates.Visible; title.Text = viewModel.Title; title.SetTextColor (textColor); title.Typeface = light; title.TextSize = 14; } else { title.Visibility = ViewStates.Gone; } }
void AddSubviews (FullScheduleCellViewModel viewModel, CellTableViewCell cellTableViewCell) { var textColor = ((Xamarin.Forms.Color)new TrackTextColorConverter () .Convert (viewModel.Track, typeof(Xamarin.Forms.Color), null, CultureInfo.CurrentCulture)) .ToUIColor (); cellTableViewCell.AddSubview (CreateBackgroundView (cellTableViewCell, viewModel)); cellTableViewCell.AddSubview (CreateTitleLabel (viewModel, textColor)); cellTableViewCell.AddSubview (CreateLocationLabel (viewModel, textColor)); cellTableViewCell.AddSubview (CreateTrackLabel (viewModel, textColor)); if (viewModel.IsOptional) cellTableViewCell.AddSubview ( CreateSelectButton (viewModel, textColor, cellTableViewCell)); }
UIView CreateLocationLabel (FullScheduleCellViewModel viewModel, UIColor textColor) { var label = new UILabel { Text = viewModel.Location.ToUpper (), TextColor = textColor, Frame = new RectangleF { X = Padding, Y = Padding + TitleHeight, Width = TitleWidth / 2, Height = 20 }, Font = UIFont.FromName (Fonts.OpenSansBold, 12) }; return label; }
UIView CreateTitleLabel (FullScheduleCellViewModel viewModel, UIColor textColor) { var label = new UILabel { Text = viewModel.Title, TextColor = textColor, Frame = new RectangleF { X = Padding, Y = Padding, Width = TitleWidth, Height = TitleHeight }, Font = UIFont.FromName (Fonts.OpenSansLight, 14), UserInteractionEnabled = false, LineBreakMode = UILineBreakMode.WordWrap, Lines = 0 }; return label; }
static void UpdateButtonTitle (UIButton button, FullScheduleCellViewModel viewModel) { button.SetTitle (viewModel.IsSelected ? "✓" : "○", UIControlState.Normal); }
UIView CreateSelectButton ( FullScheduleCellViewModel viewModel, UIColor textColor, UITableViewCell cell) { const int ButtonWidth = 50; var button = new UIButton { Frame = new RectangleF { X = cell.Bounds.Width - ButtonWidth, Y = 0, Height = cell.Bounds.Height, Width = ButtonWidth }, AutoresizingMask = UIViewAutoresizing.FlexibleHeight, TintColor = textColor, Font = UIFont.FromName (Fonts.OpenSansLight, 22) }; UpdateButtonTitle (button, viewModel); button.SetTitleColor (textColor, UIControlState.Normal); button.TouchUpInside += (object sender, EventArgs e) => { viewModel.ToggleSelection.Execute (null); }; viewModel.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { if (e.PropertyName == "IsSelected") { UpdateButtonTitle (button, viewModel); } }; return button; }
UIView CreateTrackLabel (FullScheduleCellViewModel viewModel, UIColor textColor) { var label = new UILabel { Text = new TrackValueConverter().Convert(viewModel.Track, typeof(string), null, CultureInfo.CurrentCulture) as string, TextColor = textColor, Frame = new RectangleF { X = Padding + TitleWidth / 2, Y = Padding + TitleHeight, Width = TitleWidth / 2, Height = 20 }, Font = UIFont.FromName (Fonts.OpenSansLight, 12) }; return label; }
void SetupSelectButton(View view, FullScheduleCellViewModel viewModel, Color textColor) { Button selector = view.FindViewById<Button> (Resource.Id.fs_select); UpdateButtonTitle (selector, viewModel); selector.SetTextColor (textColor); selector.Click += (object sender, EventArgs e) => { viewModel.ToggleSelection.Execute (null); }; viewModel.PropertyChanged += (object sender, PropertyChangedEventArgs e) => { if (e.PropertyName == "IsSelected") { UpdateButtonTitle (selector, viewModel); } }; }
static void UpdateButtonTitle (Button button, FullScheduleCellViewModel viewModel) { button.SetTextSize (global::Android.Util.ComplexUnitType.Dip, viewModel.IsSelected ? 24 : 48); button.SetText (viewModel.IsSelected ? "✓" : "○", TextView.BufferType.Normal); }