Example #1
0
            /**
             * Reloads a list section within the long list selector items source.
             */
            public void ReloadListSection(ListViewSection section)
            {
                if (mListSections.Count > section.ItemsSourceSectionIndex)
                {
                    ListSection<ListItem> sectionToReload = mListSections[section.ItemsSourceSectionIndex];
                    sectionToReload.Title = section.Title;
                    sectionToReload.Header = section.Header;
                    sectionToReload.HeaderColor = section.GetHeaderBackgroundColor();
                    sectionToReload.HeaderFontColor = section.GetHeaderFontColor();
                    sectionToReload.HeaderFontFamily = section.GetHeaderFontFamily();
                    sectionToReload.HeaderFontSize = section.GetHeaderFontSize();
                    sectionToReload.HeaderFontStyle = section.GetHeaderFontStyle();
                    sectionToReload.HeaderFontWeight = section.GetHeaderFontWeight();
                    sectionToReload.HeaderTextHorizontalAlignment = section.GetHeaderHorizontalAlignment();
                    sectionToReload.HeaderTextVerticalAlignment = section.GetHeaderVerticalAlignment();
                    sectionToReload.Footer = section.Footer;
                    sectionToReload.FooterColor = section.GetFooterBackgroundColor();
                    sectionToReload.FooterFontColor = section.GetFooterFontColor();
                    sectionToReload.FooterFontFamily = section.GetFooterFontFamily();
                    sectionToReload.FooterFontSize = section.GetFooterFontSize();
                    sectionToReload.FooterFontStyle = section.GetFooterFontStyle();
                    sectionToReload.FooterFontWeight = section.GetFooterFontWeight();
                    sectionToReload.FooterTextHorizontalAlignment = section.GetFooterHorizontalAlignment();
                    sectionToReload.FooterTextVerticalAlignment = section.GetFooterVerticalAlignment();
                    sectionToReload.GroupHeaderColor = section.GetGroupHeaderBackgroundColor();

                    mListSections[section.ItemsSourceSectionIndex] = sectionToReload;
                }
            }
Example #2
0
            /**
             * Reloads a list item within the long list selector items source.
             */
            public void ReloadListItem(ListViewSection section, ListViewItem item)
            {
                if (mListSections.Count > section.ItemsSourceSectionIndex)
                {
                    ListSection<ListItem> sectionToReload = mListSections[section.ItemsSourceSectionIndex];
                    if (sectionToReload.Count > item.ItemsSourceItemIndex)
                    {
                        ListItem itemToReload = sectionToReload[item.ItemsSourceItemIndex];
                        itemToReload.Height = item.Height;
                        itemToReload.Width = item.Width;
                        itemToReload.Title = item.Text;
                        itemToReload.Subtitle = item.Subtitle;
                        itemToReload.FontSize = item.GetFontSize();
                        itemToReload.FontColor = item.GetFontColor();
                        itemToReload.SubtitleFontColor = item.GetSubtitleFontColor();
                        if (mListViewStyle == ListViewStyle.NoSubtitle)
                        {
                            itemToReload.SubtitleVisibility = Visibility.Collapsed;
                        }
                        else
                        {
                            itemToReload.SubtitleVisibility = Visibility.Visible;
                        }
                        itemToReload.ImageSource = item.IconImageSource;

                        sectionToReload[item.ItemsSourceItemIndex] = itemToReload;
                    }
                }
            }
Example #3
0
            /**
             * Creates a section model from the added widget.
             */
            private ListSection<ListItem> CreateSectionModelFromWidget(ListViewSection section)
            {
                ListSection<ListItem> currentSection = new ListSection<ListItem>();
                currentSection.Title = section.Title;
                currentSection.Header = section.Header;
                currentSection.Footer = section.Footer;
                currentSection.HeaderColor = section.GetHeaderBackgroundColor();
                currentSection.HeaderFontColor = section.GetHeaderFontColor();
                currentSection.HeaderFontFamily = section.GetHeaderFontFamily();
                currentSection.HeaderFontSize = section.GetHeaderFontSize();
                currentSection.HeaderFontStyle = section.GetHeaderFontStyle();
                currentSection.HeaderFontWeight = section.GetHeaderFontWeight();
                currentSection.HeaderTextHorizontalAlignment = section.GetHeaderHorizontalAlignment();
                currentSection.HeaderTextVerticalAlignment = section.GetHeaderVerticalAlignment();
                currentSection.Footer = section.Footer;
                currentSection.FooterColor = section.GetFooterBackgroundColor();
                currentSection.FooterFontColor = section.GetFooterFontColor();
                currentSection.FooterFontFamily = section.GetFooterFontFamily();
                currentSection.FooterFontSize = section.GetFooterFontSize();
                currentSection.FooterFontStyle = section.GetFooterFontStyle();
                currentSection.FooterFontWeight = section.GetFooterFontWeight();
                currentSection.FooterTextHorizontalAlignment = section.GetFooterHorizontalAlignment();
                currentSection.FooterTextVerticalAlignment = section.GetFooterVerticalAlignment();
                currentSection.GroupHeaderColor = section.GetGroupHeaderBackgroundColor();

                for (int i = 0; i < section.ChildrenCount; i++ )
                {
                    IWidget widget = section.GetChild(i);
                    if (widget is ListViewItem)
                    {
                        ListViewItem listItem = widget as ListViewItem;
                        ListItem newItem = new ListItem();
                        newItem.Height = listItem.Height;
                        newItem.Width = listItem.Width;
                        newItem.Title = listItem.Text;
                        newItem.Subtitle = listItem.Subtitle;
                        newItem.FontSize = listItem.GetFontSize();
                        newItem.FontColor = listItem.GetFontColor();
                        newItem.SubtitleFontColor = listItem.GetSubtitleFontColor();
                        if (mListViewStyle == ListViewStyle.NoSubtitle)
                        {
                            newItem.SubtitleVisibility = Visibility.Collapsed;
                        }
                        else
                        {
                            newItem.SubtitleVisibility = Visibility.Visible;
                        }
                        newItem.ImageSource = listItem.IconImageSource;

                        listItem.ItemsSourceItemIndex = currentSection.Count;

                        currentSection.Add(newItem);

                        mModelToItemWidgetMap.Add(newItem.UniqueID, listItem);
                    }
                }

                return currentSection;
            }
Example #4
0
 /**
  * Asks for the parent section to reload the list view model item.
  */
 public void ReloadParentListItem()
 {
     if (mParent is ListViewSection)
     {
         ListViewSection parentSection = mParent as ListViewSection;
         parentSection.ReloadParentItem(this);
     }
 }
Example #5
0
 /**
  * Reloads all the section items within the long list selector items source.
  */
 public void ReloadListSectionMembers(ListViewSection section)
 {
     if (mListSections.Count > section.ItemsSourceSectionIndex)
     {
         // TODO SA: this could be more performant
         mListSections[section.ItemsSourceSectionIndex] = CreateSectionModelFromWidget(section);
     }
 }
Example #6
0
 /**
  * Adds a ListViewSection to the LongListSelector.
  * @param section The list view section to be added.
  */
 private void AddListSection(ListViewSection section)
 {
     base.AddChild(section);
     MoSync.Util.RunActionOnMainThreadSync(() =>
     {
         section.ListStyle = mListViewStyle;
         ListSection<ListItem> sectionModel = CreateSectionModelFromWidget(section);
         section.ItemsSourceSectionIndex = mListSections.Count;
         mListSections.Add(sectionModel);
         section.SectionIndex = mListSections.Count - 1;
     });
 }
Example #7
0
            /**
             * Rebuilds the list model.
             */
            public void RebuildList()
            {
                mListSections = new ObservableCollection<ListSection<ListItem>>();

                foreach (IWidget widget in mChildren)
                {
                    if (widget is ListViewSection)
                    {
                        ListViewSection section = widget as ListViewSection;
                        ListSection<ListItem> sectionModel = CreateSectionModelFromWidget(section);
                        mListSections.Add(sectionModel);
                    }
                }

                ReloadListData();
            }
Example #8
0
            /**
             * Inserts a list view section at a certain index.
             * @param child The widget to be added to the list.
             * @param index The index where the widget should be added.
             */
            private void InsertListSection(ListViewSection section, int index)
            {
                base.InsertChild(section, index);
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    section.ListStyle = mListViewStyle;
                    ListSection<ListItem> sectionModel = CreateSectionModelFromWidget(section);
                    section.ItemsSourceSectionIndex = index;
                    mListSections.Insert(index, sectionModel);
                    section.SectionIndex = index;

                    // update the section indexes for all the sections after the inserted one
                    for (int i = index + 1; i < mChildren.Count; i++)
                    {
                        if (mChildren[i] is ListViewSection)
                        {
                            (mChildren[i] as ListViewSection).ItemsSourceSectionIndex++;
                        }
                    }
                });
            }
Example #9
0
 /**
  * Reloads all the section items within the long list selector items source.
  */
 public void ReloadListSectionMembers(ListViewSection section)
 {
     if (mListSections.Count > section.ItemsSourceSectionIndex)
     {
         // TODO SA: this could be more performant
         mListSections[section.ItemsSourceSectionIndex] = CreateSectionModelFromWidget(section);
     }
 }
Example #10
0
            /**
             * Reloads a list item within the long list selector items source.
             */
            public void ReloadListItem(ListViewSection section, ListViewItem item)
            {
                if (mListSections.Count > section.ItemsSourceSectionIndex)
                {
                    ListSection<ListItem> sectionToReload = mListSections[section.ItemsSourceSectionIndex];
                    if (sectionToReload.Count > item.ItemsSourceItemIndex)
                    {
                        ListItem itemToReload = sectionToReload[item.ItemsSourceItemIndex];
                        itemToReload.Height = item.Height;
                        itemToReload.Width = item.Width;
                        itemToReload.Title = item.Text;
                        itemToReload.Subtitle = item.Subtitle;
                        itemToReload.FontSize = item.GetFontSize();
                        itemToReload.FontColor = item.GetFontColor();
                        itemToReload.SubtitleFontColor = item.GetSubtitleFontColor();
                        if (mListViewStyle == ListViewStyle.NoSubtitle)
                        {
                            itemToReload.SubtitleVisibility = Visibility.Collapsed;
                        }
                        else
                        {
                            itemToReload.SubtitleVisibility = Visibility.Visible;
                        }
                        itemToReload.ImageSource = item.IconImageSource;

                        sectionToReload[item.ItemsSourceItemIndex] = itemToReload;
                    }
                }
            }
Example #11
0
            /**
             * Reloads a list section within the long list selector items source.
             */
            public void ReloadListSection(ListViewSection section)
            {
                if (mListSections.Count > section.ItemsSourceSectionIndex)
                {
                    ListSection<ListItem> sectionToReload = mListSections[section.ItemsSourceSectionIndex];
                    sectionToReload.Title = section.Title;
                    sectionToReload.Header = section.Header;
                    sectionToReload.HeaderColor = section.GetHeaderBackgroundColor();
                    sectionToReload.HeaderFontColor = section.GetHeaderFontColor();
                    sectionToReload.HeaderFontFamily = section.GetHeaderFontFamily();
                    sectionToReload.HeaderFontSize = section.GetHeaderFontSize();
                    sectionToReload.HeaderFontStyle = section.GetHeaderFontStyle();
                    sectionToReload.HeaderFontWeight = section.GetHeaderFontWeight();
                    sectionToReload.HeaderTextHorizontalAlignment = section.GetHeaderHorizontalAlignment();
                    sectionToReload.HeaderTextVerticalAlignment = section.GetHeaderVerticalAlignment();
                    sectionToReload.Footer = section.Footer;
                    sectionToReload.FooterColor = section.GetFooterBackgroundColor();
                    sectionToReload.FooterFontColor = section.GetFooterFontColor();
                    sectionToReload.FooterFontFamily = section.GetFooterFontFamily();
                    sectionToReload.FooterFontSize = section.GetFooterFontSize();
                    sectionToReload.FooterFontStyle = section.GetFooterFontStyle();
                    sectionToReload.FooterFontWeight = section.GetFooterFontWeight();
                    sectionToReload.FooterTextHorizontalAlignment = section.GetFooterHorizontalAlignment();
                    sectionToReload.FooterTextVerticalAlignment = section.GetFooterVerticalAlignment();
                    sectionToReload.GroupHeaderColor = section.GetGroupHeaderBackgroundColor();

                    mListSections[section.ItemsSourceSectionIndex] = sectionToReload;
                }
            }
Example #12
0
            /**
             * Creates a section model from the added widget.
             */
            private ListSection<ListItem> CreateSectionModelFromWidget(ListViewSection section)
            {
                ListSection<ListItem> currentSection = new ListSection<ListItem>();
                currentSection.Title = section.Title;
                currentSection.Header = section.Header;
                currentSection.Footer = section.Footer;
                currentSection.HeaderColor = section.GetHeaderBackgroundColor();
                currentSection.HeaderFontColor = section.GetHeaderFontColor();
                currentSection.HeaderFontFamily = section.GetHeaderFontFamily();
                currentSection.HeaderFontSize = section.GetHeaderFontSize();
                currentSection.HeaderFontStyle = section.GetHeaderFontStyle();
                currentSection.HeaderFontWeight = section.GetHeaderFontWeight();
                currentSection.HeaderTextHorizontalAlignment = section.GetHeaderHorizontalAlignment();
                currentSection.HeaderTextVerticalAlignment = section.GetHeaderVerticalAlignment();
                currentSection.Footer = section.Footer;
                currentSection.FooterColor = section.GetFooterBackgroundColor();
                currentSection.FooterFontColor = section.GetFooterFontColor();
                currentSection.FooterFontFamily = section.GetFooterFontFamily();
                currentSection.FooterFontSize = section.GetFooterFontSize();
                currentSection.FooterFontStyle = section.GetFooterFontStyle();
                currentSection.FooterFontWeight = section.GetFooterFontWeight();
                currentSection.FooterTextHorizontalAlignment = section.GetFooterHorizontalAlignment();
                currentSection.FooterTextVerticalAlignment = section.GetFooterVerticalAlignment();
                currentSection.GroupHeaderColor = section.GetGroupHeaderBackgroundColor();

                for (int i = 0; i < section.ChildrenCount; i++ )
                {
                    IWidget widget = section.GetChild(i);
                    if (widget is ListViewItem)
                    {
                        ListViewItem listItem = widget as ListViewItem;
                        ListItem newItem = new ListItem();
                        newItem.Height = listItem.Height;
                        newItem.Width = listItem.Width;
                        newItem.Title = listItem.Text;
                        newItem.Subtitle = listItem.Subtitle;
                        newItem.FontSize = listItem.GetFontSize();
                        newItem.FontColor = listItem.GetFontColor();
                        newItem.SubtitleFontColor = listItem.GetSubtitleFontColor();
                        if (mListViewStyle == ListViewStyle.NoSubtitle)
                        {
                            newItem.SubtitleVisibility = Visibility.Collapsed;
                        }
                        else
                        {
                            newItem.SubtitleVisibility = Visibility.Visible;
                        }
                        newItem.ImageSource = listItem.IconImageSource;

                        listItem.ItemsSourceItemIndex = currentSection.Count;

                        currentSection.Add(newItem);

                        mModelToItemWidgetMap.Add(newItem.UniqueID, listItem);
                    }
                }

                return currentSection;
            }
Example #13
0
            /**
             * Inserts a list view section at a certain index.
             * @param child The widget to be added to the list.
             * @param index The index where the widget should be added.
             */
            private void InsertListSection(ListViewSection section, int index)
            {
                base.InsertChild(section, index);
                MoSync.Util.RunActionOnMainThreadSync(() =>
                {
                    section.ListStyle = mListViewStyle;
                    ListSection<ListItem> sectionModel = CreateSectionModelFromWidget(section);
                    section.ItemsSourceSectionIndex = index;
                    mListSections.Insert(index, sectionModel);
                    section.SectionIndex = index;

                    // update the section indexes for all the sections after the inserted one
                    for (int i = index + 1; i < mChildren.Count; i++)
                    {
                        if (mChildren[i] is ListViewSection)
                        {
                            (mChildren[i] as ListViewSection).ItemsSourceSectionIndex++;
                        }
                    }
                });
            }
Example #14
0
 /**
  * Adds a ListViewSection to the LongListSelector.
  * @param section The list view section to be added.
  */
 private void AddListSection(ListViewSection section)
 {
     base.AddChild(section);
     MoSync.Util.RunActionOnMainThreadSync(() =>
     {
         section.ListStyle = mListViewStyle;
         ListSection<ListItem> sectionModel = CreateSectionModelFromWidget(section);
         section.ItemsSourceSectionIndex = mListSections.Count;
         mListSections.Add(sectionModel);
         section.SectionIndex = mListSections.Count - 1;
     });
 }
Example #15
0
            /**
             * Outputs the index of the section in focus and the index of the selected item
             * within that section.
             */
            private void GetSectionAndSelectedItemIndex(out int sectionIndex, out int itemIndex)
            {
                // we need to find the selected item through the LongListSelector
                // items source and through the child widgets aswell in order to
                // set its selected state
                sectionIndex = -1;
                itemIndex = -1;

                // we need to first find the selected item index and its section index
                // within the long list selector items source
                int itemsSourceSectionIndex = -1;
                int itemsSourceItemIndex = -1;

                for (int i = 0; i < mListSections.Count; i++)
                {
                    ListSection<ListItem> section = mListSections[i];

                    int index = section.IndexOf(mLongListSelector.SelectedItem as ListItem);
                    if ( index >= 0)
                    {
                        itemsSourceSectionIndex = i;
                        itemsSourceItemIndex = index;
                    }

                    // deselect all the items
                    for (int j = 0; j < section.Count; j++)
                    {
                        section[j].FontColor = mModelToItemWidgetMap[section[j].UniqueID].GetFontColor();
                        section[j].SubtitleFontColor = mModelToItemWidgetMap[section[j].UniqueID].GetSubtitleFontColor();
                    }
                }

                // select the current item
                SolidColorBrush phoneAccentBrush = Application.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
                (mLongListSelector.SelectedItem as ListItem).FontColor = phoneAccentBrush;
                (mLongListSelector.SelectedItem as ListItem).SubtitleFontColor = phoneAccentBrush;

                // set the coresponding list view item widget selection status
                ListViewItem selectedItem = mModelToItemWidgetMap[(mLongListSelector.SelectedItem as ListItem).UniqueID];
                selectedItem.ItemSelected = true;

                if (mLastSelectedItemWidget != null)
                {
                    mLastSelectedItemWidget.ItemSelected = false;
                }
                mLastSelectedItemWidget = selectedItem;

                // then we need to go through the widget children and find
                // the section/item that match the section/item indexes within
                // the items source
                for (int i = 0; i < mChildren.Count; i++)
                {
                    if (mChildren[i] is ListViewSection)
                    {
                        ListViewSection section = mChildren[i] as ListViewSection;
                        if (section.ItemsSourceSectionIndex == itemsSourceSectionIndex)
                        {
                            for (int j = 0; j < section.ChildrenCount; j++)
                            {
                                if (section.GetChild(j) is ListViewItem)
                                {
                                    ListViewItem item = section.GetChild(j) as ListViewItem;
                                    if (item.ItemsSourceItemIndex == itemsSourceItemIndex)
                                    {
                                        sectionIndex = i;
                                        itemIndex = j;
                                    }
                                }
                            }
                        }
                    }
                }
            }