Skip to content

Instantly share code, notes, and snippets.

@RobertKozak
Created August 10, 2011 22:22
Show Gist options
  • Save RobertKozak/1138443 to your computer and use it in GitHub Desktop.
Save RobertKozak/1138443 to your computer and use it in GitHub Desktop.
namespace DealerCenter
{
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using MonoMobile.Views;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
[Theme(typeof(GroupedTheme))]
public class InventoryItemView: View, IDataContext, INotifyPropertyChanged
{
private UITableViewCellAccessory DetailAccessory = UITableViewCellAccessory.DisclosureIndicator;
private AutoCheckConfirmationView AutoCheckConfirmation;
private SendActionSheetView SendActionSheetView;
[Section(Order = 0)]
[Root(ElementType=typeof(InventoryMiniView), ViewType=typeof(InventoryItemView))]
public new InventoryItemViewModel DataContext
{
get { return (InventoryItemViewModel)GetDataContext(); }
set { SetDataContext(value); }
}
[Section(Order = 2)]
[Button("CanRunKelleyBook", CommandOption = CommandOption.Disable)]
[Bind("KelleyBooked", "ImageIcon", ValueConverterType = typeof(BookedConverter), BindingMode = BindingMode.OneWay)]
[Bind("DetailAccessory", "Accessory", BindingMode = BindingMode.OneWay)]
public void Kelley()
{
Application.PushView(new KelleyBookView() { DataContext = DataContext.Kelley });
}
[Caption("NADA")]
[Bind("NADABooked", "ImageIcon", ValueConverterType = typeof(BookedConverter), BindingMode = BindingMode.OneWay)]
[Button("CanRunNADABook", CommandOption = CommandOption.Disable)]
[Bind("DetailAccessory", "Accessory", BindingMode = BindingMode.OneWay)]
public void Nada()
{
Application.PushView(new NadaBookView() { DataContext = DataContext.Nada });
}
[Bind("BlackBookBooked", "ImageIcon", ValueConverterType = typeof(BookedConverter), BindingMode = BindingMode.OneWay)]
[Button("CanRunBlackBook", CommandOption = CommandOption.Disable)]
[Bind("DetailAccessory", "Accessory", BindingMode = BindingMode.OneWay)]
public void BlackBook()
{
Application.PushView(new BlackBookView() { DataContext = DataContext.BlackBook });
}
[Section(Order = 3)]
[Button("CanRunAutoCheck", CommandOption = CommandOption.Disable)]
[Caption("AutoCheck")]
[Bind(typeof(AutoCheckDataTemplate))]
public void AutoCheck()
{
if (DataContext.AutoCheckBooked.Value)
{
AutoCheckConfirmation.ShowAutoCheckView();
}
else
AutoCheckConfirmation.ShowInView(Application.NavigationController.View);
}
[NavbarButton(UIBarButtonSystemItem.Action)]
public void Action()
{
SendActionSheetView.ShowInView(Application.NavigationController.View);
}
public InventoryItemView()
{
}
public override void Initialize()
{
var title = "The cost is $5 for a summary report. The report will expire 30 days from today.\n\nDo you want to get the AutoCheck Summary report?";
AutoCheckConfirmation = new AutoCheckConfirmationView(title, DataContext);
SendActionSheetView = new SendActionSheetView(string.Empty, DataContext);
}
public override string ToString()
{
return string.Format ("{0} {1} {2}",DataContext.Year, DataContext.Make, DataContext.VehicleModel);
}
public event PropertyChangedEventHandler PropertyChanged = (s, e) => { };
}
[Preserve(AllMembers = true)]
public class BookedConverter : IValueConverter
{
private UIImage _Booked = UIImage.FromFile("Images/SphereGreen.png");
private UIImage _NotBooked = UIImage.FromFile("Images/SphereRed.png");
private UIImage _NotAvailable = UIImage.FromFile("Images/SphereGrey.png");
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value == null || !((bool?)value).HasValue)
return _NotAvailable;
if (((bool?)value).Value)
{
return _Booked;
}
return _NotBooked;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
[Preserve(AllMembers = true)]
public class AccessoryConverter : IValueConverter
{
public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null && (bool)value)
{
return UITableViewCellAccessory.DisclosureIndicator;
}
return UITableViewCellAccessory.None;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value;
}
}
[Preserve(AllMembers = true)]
public class AutoCheckDataTemplate : DataTemplate
{
public override List<Binding> Bind()
{
var bindings = base.Bind();
bindings.Add(new Binding("AutoCheckBooked", "ImageIcon") { Converter = new BookedConverter(), Mode = BindingMode.OneWay });
bindings.Add(new Binding("CanRunAutoCheck", "Accessory") { Converter= new AccessoryConverter(), Mode = BindingMode.OneWay });
return bindings;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment