Inheritance: NSObject, IHandleNotifyPropertyChanged, IHandleNotifyCollectionChanged
Exemplo n.º 1
0
		public UITableViewSource Parse(DialogViewController controller, object view, MemberInfo member)
		{
			UITableViewSource source = null;
			
			if (view != null)
			{
				view = GetActualView(view);
				controller.RootView = view;

				controller.ToolbarButtons = CheckForToolbarItems(view);
				controller.NavbarButtons = CheckForNavbarItems(view);

				if (member != null)
				{
					using (var memberData = new MemberData(view, member))
					{
						source = ParseList(controller, memberData, null); 
					}
				}
					
				if (source == null)
				{
					source = ParseView(controller, view);
				}

				InitializeSearch(view, source);
			}
			
			return source;
		}
Exemplo n.º 2
0
			protected override void SetDataContext(MemberData value)
			{
				base.SetDataContext(value);
	
				if (DataContext != null)
				{
					var propertyInfo = DataContext.Member as PropertyInfo;
					if (propertyInfo != null)
					{
						EditModeValue = !propertyInfo.CanWrite ? EditMode.ReadOnly : EditModeValue;
					}
	
					SetKeyboard();
				}
			}
Exemplo n.º 3
0
		public UITableViewSource ParseView(DialogViewController controller, object view)
		{
			var members = view.GetType().GetMembers(false);

			var sections = new SortedList<int, Section>();
			var memberLists = new SortedList<int, SortedList<int, MemberData>>();
			var sectionIndex = 0;
			var memberOrder = 0;
			
			foreach (var member in members)
			{
				var attributes = member.GetCustomAttributes(false); 

				var memberData = new MemberData(view, member) { Section = sectionIndex };				

				var defaultValueAttribute = member.GetCustomAttribute<DefaultValueAttribute>();
				if (defaultValueAttribute != null)
				{
					memberData.Value = defaultValueAttribute.Value;
				}

				var pullToRefreshAttribute = member.GetCustomAttribute<PullToRefreshAttribute>();
				if (pullToRefreshAttribute != null)
				{
					((DialogViewController)controller).PullToRefreshCommand = GetCommandForMember(view, member);
					((DialogViewController)controller).RefreshKey = pullToRefreshAttribute.SettingsKey;
					((DialogViewController)controller).EnablePullToRefresh = true;
				}

				var toolbarButtonAttribute = member.GetCustomAttribute<ToolbarButtonAttribute>();
				var navbarButtonAttribute = member.GetCustomAttribute<NavbarButtonAttribute>();
				var skipAttribute = member.GetCustomAttribute<SkipAttribute>();

				if (skipAttribute != null || 
					toolbarButtonAttribute != null || 
					navbarButtonAttribute != null || 	
					pullToRefreshAttribute != null || 
					(attributes.Length == 0 && typeof(MethodInfo) == memberData.Type))
				{
					memberData.Dispose();
					continue;
				}
				
				var themeAttribute = member.GetCustomAttribute<ThemeAttribute>();
				if (themeAttribute != null)
				{
					var theme = Theme.CreateTheme(themeAttribute.ThemeType);
					if (theme != null && theme.CellHeight > 0)
					{
						memberData.RowHeight = theme.CellHeight;
						theme.Dispose();
					}
				}
				else
				{
					var themeable = view as IThemeable;
					if (themeable != null && themeable.Theme != null && themeable.Theme.CellHeight > 0)
					{
						memberData.RowHeight = themeable.Theme.CellHeight;
					}
				}

				var rowHeightAttribute = member.GetCustomAttribute<RowHeightAttribute>();
				if (rowHeightAttribute != null)
					memberData.RowHeight = rowHeightAttribute.RowHeight;
				
				var listAttribute = member.GetCustomAttribute<ListAttribute>();
				var isList = (listAttribute != null && listAttribute.DisplayMode == DisplayMode.List) && 
					!typeof(string).IsAssignableFrom(memberData.Type) && 
					(typeof(IEnumerable).IsAssignableFrom(memberData.Type) || 
					typeof(Enum).IsAssignableFrom(memberData.Type));
				
				var orderAttribute = member.GetCustomAttribute<OrderAttribute>();
				if (orderAttribute != null)
				{
					// make sure assigned order is an even number to fit in between the default order 
					// allowing the values int.MinValue and int.MaxValue for the first and Last positions
					memberData.Order = orderAttribute.Order > int.MaxValue / 2 ? int.MaxValue : orderAttribute.Order * 2;
				}
				else
				{				
					// make sure all default memberOrder is odd;
					memberOrder = memberOrder + (memberOrder % 2) + 1;
					memberData.Order = memberOrder;
				}

				var sectionAttribute = member.GetCustomAttribute<SectionAttribute>();
				if (sectionAttribute != null || isList)
				{
					if (sections.Count > 0)
					{
						sectionIndex++;
					}

					memberData.Section = sectionIndex;

					if (sectionAttribute != null && orderAttribute != null)
					{
						memberData.Section = orderAttribute.Order == 0 ? sectionIndex : orderAttribute.Order;
					}
					else
					{
						memberData.Section = sectionIndex;
					}
				}
				
				var viewTypes = GetViewTypes(memberData);

				if (!sections.ContainsKey(memberData.Section))
				{
					var section = CreateSection(controller, memberData, viewTypes);
					sections.Add(memberData.Section, section);
				}
				else
				{ 
					if (viewTypes != null)
					{
						IList<Type> list = null;
						var key = memberData.Id.ToString();
	
						var viewTypesList = sections[memberData.Section].ViewTypes;
						if (viewTypesList.ContainsKey(key))
						{
							list = viewTypesList[key];
						}
						else
						{
							list = new List<Type>();
							viewTypesList.Add(key, list);
						}
	
						foreach(var viewType in viewTypes)
						{
							if (!list.Contains(viewType))
							{
								list.Add(viewType);
							}	
						}
					}
				}

				if (memberLists.ContainsKey(memberData.Section))
				{
					memberLists[memberData.Section].Add(memberData.Order, memberData); 
				}
				else
				{
					var sortedList = new SortedList<int, MemberData>();
					sortedList.Add(memberData.Order, memberData);
					memberLists.Add(memberData.Section, sortedList);
				}
			}
			
			foreach(var kvp in memberLists)
			{
				var listSources = new SortedList<int, ListSource>();	

				var index = 0;
				var list = kvp.Value.Values.ToList();
				list.ForEach(data => data.Order = index++);

				foreach(var memberData in list)
				{
					var viewTypes = GetViewTypes(memberData);

					if ((!typeof(string).IsAssignableFrom(memberData.Type) && typeof(IEnumerable).IsAssignableFrom(memberData.Type)) || typeof(Enum).IsAssignableFrom(memberData.Type))
					{
						var listSource = ParseList(controller, memberData, viewTypes) as ListSource; 

						listSource.MemberData = memberData;
						listSource.Sections[0].Index = memberData.Section;

						listSources.Add(memberData.Order, listSource);
					}
					else
						listSources.Add(memberData.Order, null);
		
					sections[memberData.Section].ListSources = listSources;
					sections[memberData.Section].Index = memberData.Section;

					var lastListSource = listSources.Values.Last();
					if (lastListSource != null)
						memberData.DataContextBinder = new DataContextBinder(controller, lastListSource.Sections[0]);
				}

				sections[kvp.Key].DataContext = list;
			}
			
			var keyIndex = 0;
			var sectionList = sections.Select(kvp => kvp.Value).ToDictionary((value) => keyIndex++);

			// If there is only one list property return the ListSource rather than create a ViewSource
			if (sectionList.Count == 1 && sectionList[0].DataContext.Count == 1 && sectionList[0].ListSources[0] != null && !sectionList[0].ListSources[0].IsRootCell)
			{
				sectionList[0].ListSources[0].TableViewStyle = UITableViewStyle.Plain;
				return sectionList[0].ListSources[0];
			}

			var source = new ViewSource(controller) { Sections = sectionList };

			return source;
		}
Exemplo n.º 4
0
		private static List<Type> GetViewTypes(MemberData memberData)
		{
			List<Type> viewTypeList = new List<Type>();

			var memberInfo = memberData.Member;
			if (memberInfo != null)
			{
				var cellViewAttributes = memberInfo.GetCustomAttributes<CellViewAttribute>();
				if (cellViewAttributes.Length > 0)
				{
					viewTypeList = (from attribute in cellViewAttributes select attribute.ViewType).ToList();
					var viewAttributesList = cellViewAttributes.ToList();
					viewAttributesList.ForEach((attribute) => 
					{
						var sizeable = attribute as ISizeable;
						if (sizeable != null)
						{
							memberData.RowHeight = sizeable.GetRowHeight();
						}
					});
				}

				var cellViewTemplates = memberInfo.GetCustomAttributes<Attribute>().Where(attribute=> typeof(CellViewTemplate).IsAssignableFrom(attribute.GetType())).Cast<CellViewTemplate>().ToList();
				if (cellViewTemplates.Count > 0)
				{
					cellViewTemplates.ForEach(attribute=>viewTypeList.Add(attribute.CellViewType));
				}
			}

			if (viewTypeList.Count == 0)
				return null;

			return viewTypeList;
		}
Exemplo n.º 5
0
		private static Section CreateSection(DialogViewController controller, MemberData memberData, List<Type> viewTypes)
		{
			var listSources = new SortedList<int, ListSource>();
			listSources.Add(memberData.Order, null);

			var memberOrder = 0;
			memberData.Order = memberOrder;

			var sectionMembers = new List<MemberData>();
					
			var section = new Section(controller) { DataContext = sectionMembers };
			
			var sectionAttribute = memberData.Member.GetCustomAttribute<SectionAttribute>();
			if (sectionAttribute != null)
			{
				section.HeaderText = sectionAttribute.Caption;
				section.FooterText = sectionAttribute.Footer;
			}
			section.ViewTypes.Add(memberData.Id.ToString(), viewTypes);
			return section;
		}
Exemplo n.º 6
0
		public static UITableViewSource ParseList(DialogViewController controller, MemberData memberData, List<Type> viewTypes)
		{
			object memberValue = memberData.Value;
			var member = memberData.Member;
			var type = memberData.Type;

			var isList = typeof(IEnumerable).IsAssignableFrom(type) || typeof(Enum).IsAssignableFrom(type);
			if (isList)
			{
				var data = type.CreateGenericListFromEnumerable(memberValue);
				var source = new ListSource(controller, (IList)data, viewTypes);

				if (source != null)
				{
					if (type.IsEnum)
					{
						source.SelectedItem = memberValue;
						source.SelectedItems.Add(source.SelectedItem);
					}
					else if (data != null && data.Count == 1)
					{
						source.SelectedItem = data[0];
						source.SelectedItems.Add(source.SelectedItem);
					}

					source.Caption = GetCaption(member);

					var listAttribute = member.GetCustomAttribute<ListAttribute>();
					if (listAttribute != null)
					{
						source.DisplayMode = listAttribute.DisplayMode;
						source.SelectionAction = listAttribute.SelectionAction;

						source.IsMultiselect = listAttribute.SelectionAction == SelectionAction.Multiselection;
						source.IsSelectable = source.SelectionAction != SelectionAction.NavigateToView;
						source.IsNavigable = listAttribute.DisplayMode != DisplayMode.Collapsable || listAttribute.SelectionAction == SelectionAction.NavigateToView;

						source.SelectedAccessoryViewType = listAttribute.SelectedAccessoryViewType;
						source.UnselectedAccessoryViewType = listAttribute.UnselectedAccessoryViewType;
						source.UnselectionBehavior = listAttribute.UnselectionBehavior;

						source.ReplaceCaptionWithSelection = listAttribute.ReplaceCaptionWithSelection;
						
						if (!string.IsNullOrEmpty(listAttribute.SelectedItemMemberName)) 
						{
							source.SelectedItemMemberName = listAttribute.SelectedItemMemberName;
						}
						if (!string.IsNullOrEmpty(listAttribute.SelectedItemsMemberName))
						{
							source.SelectedItemsMemberName = listAttribute.SelectedItemsMemberName;
						}
					}						
	
					source.PopOnSelection = source.SelectionAction == SelectionAction.PopOnSelection;
					
					var memberAttributes = member.GetCustomAttributes(false);
					foreach(var memberAttribute in memberAttributes)
					{
						var navigable = memberAttribute as INavigable;
						if (navigable != null)
						{
							source.IsSelectable = false;
							source.NavigationViewType = navigable.NavigateToViewType;

							source.IsNavigable = navigable.NavigateToViewType != null;
						}
					}

					source.IsRootCell = source.DisplayMode != DisplayMode.List;

					return source;
				}
			}

			return null;
		}
Exemplo n.º 7
0
		public static Type GetView(MemberData memberData)
		{
			var attributes = memberData.Member.GetCustomAttributes(false);

			foreach(Attribute attribute in attributes)
			{
				var attributeType = attribute.GetType();

				if (_TypeViewMap.ContainsKey(attributeType))
				{
					return _TypeViewMap[attributeType];
				}
			}
			
			var type = memberData.Member.GetMemberType();

			return GetView(type);
		}