Ejemplo n.º 1
0
		private static IRoot CreateViewEnumerableRoot(IRoot root)
		{
			IRoot newRoot = null;

			Type elementType = root.ViewBinding.ElementType;
			if (elementType == null)
				elementType = typeof(RootElement);

			newRoot = new RootElement() { Opaque = false, ViewBinding = root.ViewBinding };
			IElement element = null;
			
			var items = (IEnumerable)root.DataContext;
			var section = new Section() { Opaque = false, ViewBinding = root.ViewBinding, Parent = newRoot as IElement };

			newRoot.Sections.Add(section);

			foreach (var e in items)
			{
				var caption = e.ToString();
				if (string.IsNullOrEmpty(caption))
				{
					caption = MakeCaption(root.ViewBinding.ViewType.Name);
				}
				
				element = Activator.CreateInstance(elementType) as IElement;
				((RootElement)element).Opaque = false;
				element.Caption = caption;
				element.ViewBinding.DataContextCode = DataContextCode.Object;
				element.ViewBinding.ViewType = root.ViewBinding.ViewType;
				element.ViewBinding.MemberInfo = root.ViewBinding.MemberInfo;

				if (e is UIView)
					element.ViewBinding.View = e as UIView;
				else
					element.DataContext = e;

				if (element.ViewBinding.ViewType == null)
					element.ViewBinding.ViewType = e.GetType();

				section.Add(element);
			}
		
			ThemeHelper.ApplyElementTheme(root.Theme, newRoot, null);

			return newRoot;
		}
Ejemplo n.º 2
0
		private List<ISection> CreateSectionList(UIView view, IRoot root)
		{
			var memberFuncMap = new List<Func<object, MemberInfo[]>>() 
			{
				(T)=>GetFields(T),
				(T)=>GetProperties(T),
				(T)=>GetMethods(T)
			};

			ISection lastSection = new Section() { Order = -1, Parent = root as IElement };

			var sectionList = new List<ISection>() { lastSection };

			IElement newElement = null;
			Theme theme = null;
			var themeable = root as IThemeable;
			if (themeable != null)
			{
				ThemeHelper.ApplyRootTheme(view, themeable);
				theme = themeable.Theme;
				ThemeHelper.ApplyElementTheme(theme, lastSection, null);
			}
			
			if (!(view is IView))
			{
				newElement = new UIViewElement(null, view, false);
				lastSection.Add(newElement);
			}
			else
			{
				foreach(var memberFunc in memberFuncMap)
				{
					var members = memberFunc(view);
		
					foreach (var member in members)
					{
						var isList = member.GetCustomAttribute<ListAttribute>() != null;

						var pullToRefreshAttribute = member.GetCustomAttribute<PullToRefreshAttribute>();
						if (pullToRefreshAttribute != null)
						{
							root.PullToRefreshCommand = GetCommandForMember(view, member);
							root.DefaultSettingsKey = pullToRefreshAttribute.SettingsKey;
						}
						var skipAttribute = member.GetCustomAttribute<SkipAttribute>(true);
						if (skipAttribute != null) continue;
						
						var sectionAttribute = member.GetCustomAttribute<SectionAttribute>();
		
						if (sectionAttribute != null)
						{	
							Theme sectionTheme = null;
							if (sectionAttribute.ThemeType != null)
								 sectionTheme = Activator.CreateInstance(sectionAttribute.ThemeType) as Theme;
							
							lastSection = new Section(sectionAttribute.Caption, sectionAttribute.Footer) { Order = sectionAttribute.Order };
							lastSection.Parent = root as IElement;

							ThemeHelper.ApplyElementTheme(root.Theme, lastSection, null); 
							ThemeHelper.ApplyElementTheme(sectionTheme, lastSection, null);

							sectionList.Add(lastSection);
						}
		
						var bindings = GetBindings(view, member);
	
						newElement = GetElementForMember(root.Theme, view, member, bindings);
						
						ThemeHelper.ApplyElementTheme(theme, newElement, member);
						
						IBindable bindable = null;
						
						if (newElement is ISection)
						{
							lastSection.Add(((ISection)newElement).Elements);
							bindable = lastSection as IBindable;
						}
						else if (newElement != null)
						{
							bindable = newElement as IBindable;

							if ((isList) && newElement is IRoot)
							{
								var sections = ((IRoot)newElement).Sections;

								var firstSection = sections.FirstOrDefault();
								if (firstSection.Elements.Count > 0)
									lastSection.Add(firstSection.Elements);

								for(var index=1; index < sections.Count; index++)
								{
									sectionList.Add(sections[index]);
								}
							}
							else
							{
								lastSection.Add(newElement);
							}
						}
			
						if (bindable != null && bindable != _NoElement && bindings.Count != 0)
						{
							foreach (Binding binding in bindings)
							{
								if (binding.TargetPath == null)
								{
									binding.TargetPath = "DataContext";
								}
			
								BindingOperations.SetBinding(bindable, binding.TargetPath, binding);
							}
						}
					}
				}
			}

			foreach (var section in sectionList)
			{
				var orderedList = section.Elements.OrderBy(e=>e.Order).Where((e)=>e != _NoElement).ToList();
				section.Elements = new System.Collections.ObjectModel.ObservableCollection<MonoMobile.MVVM.IElement>(orderedList);
			}

			var orderedSections = sectionList.Where(s=>s.Elements.Count > 0).OrderBy(section=>section.Order).ToList();
			return orderedSections;
		}
		public void PerformFilter(string text)
		{
			if (_OriginalSections == null)
				return;
			
			OnSearchTextChanged(text);
			
			var newSections = new List<ISection>();
			
			var searchable = Root as ISearchBar;
			if (searchable != null)
			{
				if (searchable.SearchCommand == null)
				{
					for (int sidx = 0; sidx < _OriginalSections.Length; sidx++)
					{
						ISection newSection = null;
						var section = _OriginalSections[sidx];
						IElement[] elements = _OriginalElements[sidx];
						
						for (int eidx = 0; eidx < elements.Length; eidx++)
						{
							var searchableView = elements[eidx] as ISearchable;
							
							if ((searchableView != null && searchableView.Matches(text)) || (elements[eidx].Caption != null) && elements[eidx].Caption.Contains(text))
							{
								if (newSection == null)
								{
									newSection = new Section(section.HeaderText, section.FooterText) { FooterView = section.FooterView, HeaderView = section.HeaderView };
									newSections.Add(newSection);
								}
								newSection.Add(elements[eidx]);
							}
						}
					}
				}
				else
				{
					newSections = searchable.SearchCommand.Execute(_OriginalSections, text);
				}
			}
			
			Root.Sections = newSections;

			ReloadData();
		}
Ejemplo n.º 4
0
		private ISection CreateEnumCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);
			
			object context = view;
			var dataContext = view as IDataContext;

			if (dataContext != null)
			{
				context = dataContext.DataContext;
			}
			
			SetDefaultConverter(view, member, "DataContext", new EnumCollectionConverter(), null, bindings);

			member = GetMemberFromDataContext(member, ref context);

			var csection = new Section() { IsMultiselect = true, Opaque = false };

			var collection = member.GetValue(view);
			if (collection == null)
			{
				var collectionType = typeof(EnumCollection<>);
				var enumType = memberType.GetGenericArguments().FirstOrDefault();
				Type[] generic = { enumType };

				collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
				member.SetValue(view, collection);
			}

			var index = 0;
			var items = (EnumCollection)collection;
			foreach (var item in items.Items)
			{
				var checkboxElement = new CheckboxElement(item.Description) 
				{ 
					Item = item, 
					Index = index, 
					DataContext = item.IsChecked, 
					Group = item.GroupName
				};

				csection.Add(checkboxElement);				
				index++;
			}
			
			csection.DataContext = memberType;
			csection.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

			return csection;
		}
Ejemplo n.º 5
0
		private ISection CreateSelectCollectionSection(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			object context = view;

			var csection = new Section() { IsMultiselect = false, Opaque = false };
			var index = 0;

			SetDefaultConverter(view, member, "DataContext", new EnumerableConverter(), null, bindings);
		
			var dataContextMember = GetMemberFromDataContext(member, ref context);

			var collection = dataContextMember.GetValue(context) as IEnumerable;

			foreach (var item in collection)
			{
				var radioElement = new RadioElement(item.ToString()) { Item = item, Index = index, DataContext = false};
				
				csection.Add(radioElement);
				index++;
			}
			
			csection.ViewBinding.DataContextCode = DataContextCode.Enumerable;
			csection.ViewBinding.ViewType = null;

			return csection;
		}
Ejemplo n.º 6
0
		private ISection CreateEnumSection(Theme theme, MemberInfo member, IEnumerable values, object currentValue, bool popOnSelection, List<Binding> bindings)
		{
			var csection = new Section() { Opaque = false };

			int index = 0;
			int selected = -1; 

			foreach(var value in values)
			{
				if (currentValue != null && currentValue.Equals(value))
					selected = index;
				
				var description = value.ToString();
				
				if (value.GetType().IsEnum)
					description = ((Enum)value).GetDescription();
				
				var radioElement = new RadioElement(description) { Item = value };
				radioElement.Index = index;
				radioElement.PopOnSelect = popOnSelection;
				radioElement.DataContext = selected == index;
				radioElement.Opaque = false;

				csection.Add(radioElement);
				index++;
			}

			csection.ViewBinding.DataContextCode = DataContextCode.Enum;

			return csection;
		}
Ejemplo n.º 7
0
        private static IRoot CreateViewEnumerableRoot(IRoot root)
        {
            IRoot newRoot = null;

            Type elementType = root.ViewBinding.ElementType;

            if (elementType == null)
            {
                elementType = typeof(RootElement);
            }

            newRoot = new RootElement()
            {
                Opaque = false, ViewBinding = root.ViewBinding
            };
            IElement element = null;

            var items   = (IEnumerable)root.DataContext;
            var section = new Section()
            {
                Opaque = false, ViewBinding = root.ViewBinding, Parent = newRoot as IElement
            };

            newRoot.Sections.Add(section);

            foreach (var e in items)
            {
                var caption = e.ToString();
                if (string.IsNullOrEmpty(caption))
                {
                    caption = root.ViewBinding.ViewType.Name.Capitalize();
                }

                element = Activator.CreateInstance(elementType) as IElement;
                ((RootElement)element).Opaque = false;
                element.Caption = caption;
                element.ViewBinding.DataContextCode = DataContextCode.Object;
                element.ViewBinding.ViewType        = root.ViewBinding.ViewType;
                element.ViewBinding.MemberInfo      = root.ViewBinding.MemberInfo;

                if (e is UIView)
                {
                    element.ViewBinding.View = e as UIView;
                }
                else
                {
                    element.DataContext = e;
                }

                if (element.ViewBinding.ViewType == null)
                {
                    element.ViewBinding.ViewType = e.GetType();
                }

                section.Add(element);
            }

            ThemeHelper.ApplyElementTheme(root.Theme, newRoot, null);

            return(newRoot);
        }
Ejemplo n.º 8
0
		public IElement CreateEnumCollectionRoot(MemberInfo member, string caption, object view, List<Binding> bindings)
		{
			Type memberType = GetTypeForMember(member);

			SetDefaultConverter(member, "Value", new EnumItemsConverter(), bindings);

			var csection = new Section() { IsMultiselect = true, Opaque = false };
			ApplyRootTheme(view, csection);

			var collection = GetValue(member, view);
			if (collection == null)
			{
				var collectionType = typeof(EnumCollection<>);
				var enumType = memberType.GetGenericArguments()[0];
				Type[] generic = { enumType };

				collection = Activator.CreateInstance(collectionType.MakeGenericType(generic));
				(member as PropertyInfo).SetValue(view, collection, new object[] {});
			}

			var index = 0;
			var items = (EnumCollection)collection;
			foreach (var item in items.AllValues)
			{
				var checkboxElement = new CheckboxElement(item.Description) { Index = index, Value = item.IsChecked, Group = item.GroupName};
				ApplyRootTheme(view, checkboxElement);

				csection.Add(checkboxElement);
				
				index++;
			}
			
			var element = new RootElement(caption) { csection };
			element.ViewBinding.DataContextCode = DataContextCode.EnumCollection;

			element.Theme.CellStyle = UITableViewCellStyle.Value1;

			return element;
		}
Ejemplo n.º 9
0
		public static ISection CreateEnumSection(IRoot root, IEnumerable values, object currentValue, bool popOnSelection)
		{
			var csection = new Section() { Opaque = false };

			int index = 0;
			int selected = 0;
		
			ApplyElementTheme(root.Theme, csection, null); 

			foreach(var value in values)
			{
				if (currentValue == value)
					selected = index;
				
				var description = value.ToString();

				if (value.GetType() == typeof(Enum))
					description = ((Enum)value).GetDescription(); 
				
				var radioElement = new RadioElement(description) { };
				radioElement.Index = index;
				radioElement.PopOnSelect = popOnSelection;
				radioElement.Value = selected == index;
				radioElement.Opaque = false;
				
				ApplyElementTheme(root.Theme, radioElement, null); 

				csection.Add(radioElement);
				index++;
			}

			csection.Parent = root as IElement;

			return csection;
		}
Ejemplo n.º 10
0
		private List<ISection> CreateSectionList(object view, IRoot root)
		{
			var memberFuncMap = new List<Func<object, MemberInfo[]>>() 
			{
				(T)=>GetFields(T),
				(T)=>GetProperties(T),
				(T)=>GetMethods(T)
			};

			ISection lastSection = new Section() { Order = -1, Parent = root as IElement };

			var sectionList = new List<ISection>() { lastSection };

			IElement newElement = null;
			Theme theme = null;
			var themeable = root as IThemeable;
			if (themeable != null)
			{
				ApplyRootTheme(view, themeable);
				theme = themeable.Theme;
				ApplyElementTheme(theme, lastSection, null);
			}

			foreach(var memberFunc in memberFuncMap)
			{
				var members = memberFunc(view);
	
				foreach (var member in members)
				{
					var pullToRefreshAttribute = member.GetCustomAttribute<PullToRefreshAttribute>();
					if (pullToRefreshAttribute != null)
					{
						root.PullToRefreshCommand = GetCommandForMember(view, member);
						root.DefaultSettingsKey = pullToRefreshAttribute.SettingsKey;
					}
					var skipAttribute = member.GetCustomAttribute<SkipAttribute>(true);
					if (skipAttribute != null) continue;
					
					var inline = member.GetCustomAttribute<InlineAttribute>() != null;
				//	var isRoot = member.GetCustomAttribute<RootAttribute>() != null;
					var listAttribute = member.GetCustomAttribute<ListAttribute>();		
					var isList = listAttribute != null;
					var sectionAttribute = member.GetCustomAttribute<SectionAttribute>();
	
					if (sectionAttribute != null)
					{	
						Theme sectionTheme = null;
						if (sectionAttribute.ThemeType != null)
							 sectionTheme = Activator.CreateInstance(sectionAttribute.ThemeType) as Theme;
						
						lastSection = new Section(sectionAttribute.Caption, sectionAttribute.Footer) { Order = sectionAttribute.Order };
						lastSection.Parent = root as IElement;
						ApplyElementTheme(root.Theme, lastSection, null); 

						ApplyElementTheme(sectionTheme, lastSection, null);
						sectionList.Add(lastSection);
					}
	
					newElement = GetElementForMember(view, member);
					
					if(newElement != null)
					{
						newElement.Theme.MergeTheme(root.Theme);
						ApplyElementTheme(root.Theme, newElement, member);

						//var context = newElement as IView;
					//	var displayInline = (inline || !isRoot) && newElement is IRoot; //&& context != null;
						
						if (isList)
						{
							var newRoot = newElement as IRoot;
							Type viewType = newRoot.ViewBinding.ViewType ?? listAttribute.ViewType;

							string caption = null;
							if (!(view is IDataTemplate))
								caption = newElement.Caption;

							lastSection = new Section(caption,null) { };
							lastSection.Parent = root as IElement;
							ApplyElementTheme(root.Theme, lastSection, null); 
							sectionList.Add(lastSection);
			
							IEnumerable datacontext = null;
							if (view is IDataTemplate)
								datacontext = ((IDataTemplate)view).Items;
							else 
								datacontext = (IEnumerable)GetValue(member, view);

							foreach (var e in datacontext)
							{
								IElement element = null;

								if (e is IViewModel)
								{
									element = new RootElement(e.ToString());
									element.ViewBinding.ViewType = viewType;
									element.ViewBinding.DataContext = e;
									
									((IRoot)element).Theme = Theme.CreateTheme(root.Theme); 
									element.Theme = ((IRoot)element).Theme; 

									if (listAttribute.ThemeType != null)
									{
										var listTheme = Activator.CreateInstance(listAttribute.ThemeType) as Theme;
										var rootTheme = Theme.CreateTheme(((IRoot)element).Theme);
										rootTheme.MergeTheme(listTheme);
										((IRoot)element).Theme = rootTheme;
									}
								}
								else
								{
									element = new RadioElement(e.ToString());
									element.Theme = ((IRoot)element).Theme; 
									
								}
		
								lastSection.Add(element);
							}

						}
						else if (inline)
						{	
							var inlineSection = new Section(string.Empty, null) {  };
							ApplyElementTheme(newElement.Theme, inlineSection, null);
							inlineSection.Parent = root as IElement;
							sectionList.Add(inlineSection);
	
							IRoot inlineRoot = newElement as IRoot;
							if (newElement.ViewBinding.DataContextCode == DataContextCode.Object)
							{
								var bindingContext = new BindingContext(newElement.ViewBinding.CurrentView, newElement.Caption, newElement.Theme);
								inlineRoot = bindingContext.Root;
							}

							inlineSection.Caption = newElement.Caption;
	
							foreach(var element in inlineRoot.Sections[0].Elements)
								inlineSection.Add(element);

							//root.Groups.Add(inlineRoot.Groups[0]);
						}
						else
						{
							lastSection.Add(newElement);
						}
					}
				}
			}
			
			foreach (var section in sectionList)
			{
				var orderedList = section.Elements.OrderBy(e=>e.Order).ToList();
				section.Elements = orderedList;
			}

			var orderedSections = sectionList.Where(s=>s.Elements.Count > 0).OrderBy(section=>section.Order).ToList();
			return orderedSections;
		}