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;
		}
Beispiel #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);
        }