Fix for JIRA issue N_SE-45124, Fix for gap seen during refreshAdd() after UpdateTabl...
authorkatpaga.a <katpaga.a@samsung.com>
Fri, 12 Jul 2013 06:29:06 +0000 (11:59 +0530)
committerkatpaga.a <katpaga.a@samsung.com>
Mon, 12 Aug 2013 10:16:00 +0000 (15:46 +0530)
Change-Id: I5f61102f653021574c5387d858a094ef8e56719a
Signed-off-by: katpaga.a <katpaga.a@samsung.com>
src/ui/controls/FUiCtrl_TableViewPresenter.cpp
src/ui/inc/FUiCtrl_TableViewPresenter.h

index 69bdc9a..3c24747 100644 (file)
@@ -1185,8 +1185,7 @@ _TableViewPresenter::PreloadItem(int topDrawnGroupIndex, int topDrawnItemIndex,
 
        __pListModel->RestoreItemStatus();
 
-       DeleteItemHeightList();
-       CreateItemHeightList(defaultGroupHeight, defaultItemHeight);
+       RestoreItemHeightList(defaultGroupHeight, defaultItemHeight);
 
        DeleteSectionAlignmentList();
        CreateSectionAlignmentList();
@@ -4057,15 +4056,22 @@ _TableViewPresenter::GetItemHeight(TableViewItemTag itemTag) const
        itemTag.itemIndex++;
        itemTag.itemIndex = startIndex + itemTag.itemIndex;
 
-       __itemHeightList.GetAt(itemTag.itemIndex, itemHeight);
+       _TableViewItemHeight itemHeightListEntry;
+       __itemHeightList.GetAt(itemTag.itemIndex, itemHeightListEntry);
 
-       return itemHeight;
+       return itemHeightListEntry.itemHeight;
 }
 
 float
 _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
 {
        int startIndex = 0;
+       _TableViewItemHeight oldHeightEntry;
+       _TableViewItemHeight itemHeightListEntry;
+
+       itemHeightListEntry.itemHeight = height;
+       itemHeightListEntry.groupIndex = itemTag.groupIndex;
+       itemHeightListEntry.itemIndex = itemTag.itemIndex;
 
        for (int i = 0; i < itemTag.groupIndex; i++)
        {
@@ -4077,13 +4083,14 @@ _TableViewPresenter::SetItemHeight(TableViewItemTag itemTag, float height)
        itemTag.itemIndex++;
        itemTag.itemIndex = startIndex + itemTag.itemIndex;
 
-       float oldHeight = 0.0f;
-       __itemHeightList.GetAt(itemTag.itemIndex, oldHeight);
-       __itemHeightList.SetAt(height, itemTag.itemIndex);
+       __itemHeightList.GetAt(itemTag.itemIndex, oldHeightEntry);
 
-       return oldHeight;
-}
+       itemHeightListEntry.isFooterItem = oldHeightEntry.isFooterItem;
+
+       __itemHeightList.SetAt(itemHeightListEntry, itemTag.itemIndex);
 
+       return oldHeightEntry.itemHeight;
+}
 
 result
 _TableViewPresenter::SetReorderMode(bool enabled)
@@ -4561,25 +4568,40 @@ _TableViewPresenter::CreateItemHeightList(float defaultGroupItemHeight, float de
 {
        int groupCount = GetGroupCount();
 
+       _TableViewItemHeight itemHeightEntry;
+
        result r = __itemHeightList.SetCapacity(GetItemCount());
        SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
 
        for (int i = 0; i < groupCount; i++)
        {
                int itemCount = GetItemCountAt(i);
-
+               itemHeightEntry.groupIndex = i;
                if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
                {
-                       __itemHeightList.Add(0.0f);
+                       itemHeightEntry.itemIndex = -1;
+                       itemHeightEntry.itemHeight = 0.0f;
+                       itemHeightEntry.isFooterItem = false;
+                       __itemHeightList.Add(itemHeightEntry);
                }
                else
                {
-                       __itemHeightList.Add(defaultGroupItemHeight);
+                       itemHeightEntry.itemIndex = -1;
+                       itemHeightEntry.itemHeight = defaultGroupItemHeight;
+                       itemHeightEntry.isFooterItem = false;
+                       __itemHeightList.Add(itemHeightEntry);
                }
 
                for (int j = 0; j < itemCount; j++)
                {
-                       __itemHeightList.Add(defaultItemHeight);
+                       itemHeightEntry.itemIndex = j;
+                       itemHeightEntry.itemHeight = defaultItemHeight;
+                       itemHeightEntry.isFooterItem = false;
+                       if (HasSectionFooter(i) && j == (itemCount - 1))
+                       {
+                               itemHeightEntry.isFooterItem = true;
+                       }
+                       __itemHeightList.Add(itemHeightEntry);
                }
        }
 
@@ -4591,6 +4613,125 @@ CATCH:
        return false;
 }
 
+bool
+_TableViewPresenter::RestoreItemHeightList(float defaultGroupHeight, float defaultItemHeight)
+{
+       _TableViewItemHeight backupItem;
+       _TableViewItemHeight currentItem;
+       _TableViewItemHeight itemHeightEntry;
+       int groupCount = GetGroupCount();
+       bool isGroupItem = true;
+       int itemCount = 0;
+       int groupIndex = 0;
+       int itemIndex = 0;
+
+       ArrayListT<_TableViewItemHeight> backupItemHeightList;
+       backupItemHeightList.Construct();
+
+       result r = backupItemHeightList.SetCapacity(__itemHeightList.GetCapacity());
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       for (int index = 0; index < __itemHeightList.GetCount(); index++)
+       {
+               __itemHeightList.GetAt(index, backupItem);
+               backupItemHeightList.Add(backupItem);
+       }
+
+       DeleteItemHeightList();
+
+       r = __itemHeightList.SetCapacity(GetItemCount());
+       SysTryCatch(NID_UI_CTRL, r == E_SUCCESS, , r, "[%s] Propagating.", GetErrorMessage(r));
+
+       for (int backUpListIndex = 0, actualListIndex = 0; actualListIndex < GetItemCount() && groupIndex < groupCount; )
+       {
+               backupItemHeightList.GetAt(backUpListIndex, backupItem);
+               if (groupIndex < groupCount)
+               {
+                       itemCount = GetItemCountAt(groupIndex);
+                       if (isGroupItem)
+                       {
+                               isGroupItem = false;
+                               itemHeightEntry.groupIndex = groupIndex;
+                               itemIndex = 0;
+                               if (__pTableView->GetTableViewStyle() == TABLE_VIEW_STYLE_SIMPLE)
+                               {
+                                       itemHeightEntry.itemHeight = 0.0f;
+                               }
+                               else
+                               {
+                                       itemHeightEntry.itemHeight = defaultGroupHeight;
+                               }
+
+                               itemHeightEntry.itemIndex = -1;
+                               itemHeightEntry.isFooterItem = false;
+                               __itemHeightList.Add(itemHeightEntry);
+                               if (itemCount == 0)
+                               {
+                                       isGroupItem = true;
+                                       groupIndex++;
+                               }
+                       }
+                       else
+                       {
+                               itemHeightEntry.itemIndex = itemIndex;
+                               itemHeightEntry.itemHeight = defaultItemHeight;
+                               itemHeightEntry.isFooterItem = false;
+
+                               if (HasSectionFooter(groupIndex) && itemIndex == (itemCount - 1))
+                               {
+                                       itemHeightEntry.isFooterItem = true;
+                               }
+                               __itemHeightList.Add(itemHeightEntry);
+                               itemIndex++;
+
+                               if (itemIndex == itemCount)
+                               {
+                                       isGroupItem = true;
+                                       groupIndex++;
+                               }
+                       }
+               }
+               if (actualListIndex < GetItemCount() && backUpListIndex < backupItemHeightList.GetCount())
+               {
+                       __itemHeightList.GetAt(actualListIndex, currentItem);
+                       if (backupItem.isFooterItem)
+                       {
+                               backUpListIndex++;
+                               continue;
+                       }
+
+                       if(backupItem.groupIndex == currentItem.groupIndex && backupItem.itemIndex == currentItem.itemIndex)
+                       {
+                               currentItem.itemHeight = backupItem.itemHeight;
+                               __itemHeightList.SetAt(currentItem, actualListIndex);
+                               actualListIndex++;
+                               backUpListIndex++;
+                       }
+                       else if (backupItem.groupIndex > currentItem.groupIndex)
+                       {
+                               actualListIndex++;
+                       }
+                       else if (backupItem.groupIndex < currentItem.groupIndex)
+                       {
+                               backUpListIndex++;
+                       }
+                       else
+                       {
+                               SysLog(NID_UI_CTRL, "System error has occurred. Failed to restore the height values.");
+                       }
+               }
+       }
+       backupItemHeightList.RemoveAll();
+
+       return true;
+
+CATCH:
+       backupItemHeightList.RemoveAll();
+       DeleteItemHeightList();
+
+       return false;
+}
+
 void
 _TableViewPresenter::DeleteItemHeightList(void)
 {
@@ -4603,7 +4744,9 @@ _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableV
        float defaultItemHeight = __pProviderAdaptor->GetDefaultItemHeight();
        float defaultGroupItemHeight = __pProviderAdaptor->GetDefaultGroupItemHeight();
 
+       _TableViewItemHeight itemHeightEntry;
        int startIndex = 0;
+
        for (int i = 0; i < groupIndex; i++)
        {
                int itemCount = GetItemCountAt(i);
@@ -4622,15 +4765,59 @@ _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableV
                        int itemCount = GetItemCountAt(groupIndex);
                        for (int i = 0; i < itemCount; i++)
                        {
-                               __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
+                               itemHeightEntry.groupIndex = groupIndex;
+                               itemHeightEntry.itemIndex = (itemCount - 1) - i;
+                               itemHeightEntry.itemHeight = defaultItemHeight;
+                               itemHeightEntry.isFooterItem = false;
+                               if (HasSectionFooter(groupIndex) && i == (itemCount - 1))
+                               {
+                                       itemHeightEntry.isFooterItem = true;
+                               }
+
+                               __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
                        }
 
-                       __itemHeightList.InsertAt(defaultGroupItemHeight, targetIndex);
+                       itemHeightEntry.groupIndex = groupIndex;
+                       itemHeightEntry.itemIndex = itemIndex;
+                       itemHeightEntry.itemHeight = defaultGroupItemHeight;
+                       itemHeightEntry.isFooterItem = false;
+                       __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
 
+                       int updateIndex = targetIndex + itemCount + 1;// Increment the group Index below the added item by 1
+                       int lastIndex = 0;
+                       int groupCount = GetGroupCount();
+
+                       for (int i = 0; i < groupCount; i++)
+                       {
+                               int itemCount = GetItemCountAt(i);
+                               lastIndex = lastIndex + itemCount + 1;
+                       }
+
+                       for (int index = updateIndex; index < lastIndex; index++)
+                       {
+                               __itemHeightList.GetAt(index, itemHeightEntry);
+                               itemHeightEntry.groupIndex = itemHeightEntry.groupIndex + 1;
+                               __itemHeightList.SetAt(itemHeightEntry, index);
+                       }
                }
                else
                {
-                       __itemHeightList.InsertAt(defaultItemHeight, targetIndex);
+                       itemHeightEntry.groupIndex = groupIndex;
+                       itemHeightEntry.itemIndex = itemIndex;
+                       itemHeightEntry.itemHeight = defaultItemHeight;
+                       itemHeightEntry.isFooterItem = false;
+                       __itemHeightList.InsertAt(itemHeightEntry, targetIndex);
+
+                       int itemCount = GetItemCountAt(groupIndex);
+                       int remainingItemCount = (itemCount - itemIndex);
+
+                       for (int i = (targetIndex + 1); i < (targetIndex + remainingItemCount); i++)
+                       {
+                               __itemHeightList.GetAt(i, itemHeightEntry);
+                               itemHeightEntry.groupIndex = groupIndex;
+                               itemHeightEntry.itemIndex = itemHeightEntry.itemIndex + 1;
+                               __itemHeightList.SetAt(itemHeightEntry, i);
+                       }
                }
        }
        else if (refreshType == TABLE_VIEW_REFRESH_TYPE_ITEM_REMOVE)
@@ -4643,10 +4830,36 @@ _TableViewPresenter::RefreshItemHeightList(int groupIndex, int itemIndex, TableV
                        {
                                __itemHeightList.RemoveAt(targetIndex);
                        }
+
+                       int updateIndex = targetIndex;// Decrement the group Index below the added item by 1
+                       int lastIndex = 0;
+
+                       for (int i = 0; i < (GetGroupCount() + 1); i++)
+                       {
+                               int itemCount = GetItemCountAt(i);
+                               lastIndex = lastIndex + itemCount + 1;
+                       }
+
+                       for (int index = updateIndex; index < lastIndex; index++)
+                       {
+                               __itemHeightList.GetAt(index, itemHeightEntry);
+                               itemHeightEntry.groupIndex = itemHeightEntry.groupIndex - 1;
+                               __itemHeightList.SetAt(itemHeightEntry, index);
+                       }
                }
                else
                {
                        __itemHeightList.RemoveAt(targetIndex);
+                       int itemCount = GetItemCountAt(groupIndex);
+                       int remainingItemCount = itemCount - itemIndex;
+
+                       for (int i = targetIndex; i < (targetIndex + remainingItemCount); i++)
+                       {
+                               __itemHeightList.GetAt(i, itemHeightEntry);
+                               itemHeightEntry.groupIndex = groupIndex;
+                               itemHeightEntry.itemIndex = (itemHeightEntry.itemIndex - 1);
+                               __itemHeightList.SetAt(itemHeightEntry, i);
+                       }
                }
        }
 
@@ -4672,7 +4885,6 @@ _TableViewPresenter::CreateSectionAlignmentList(void)
 
        for (int i = 0; i < groupCount; i++)
        {
-
                __sectionAlignmentList.Add(alignment);
        }
 
@@ -5937,4 +6149,25 @@ _TableViewSectionStringAlignment::operator!= (const _TableViewSectionStringAlign
        return true;
 }
 
+bool
+_TableViewItemHeight::operator!= (const _TableViewItemHeight& rhs) const
+{
+       if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
+       {
+               return false;
+       }
+
+       return true;
+}
+
+bool
+_TableViewItemHeight::operator== (const _TableViewItemHeight& rhs) const
+{
+       if (groupIndex == rhs.groupIndex && itemIndex == rhs.itemIndex && itemHeight == rhs.itemHeight && isFooterItem == rhs.isFooterItem)
+       {
+               return true;
+       }
+
+       return false;
+}
 }}} // Tizen::Ui::Controls
index 446b5f5..00acdee 100644 (file)
@@ -101,6 +101,25 @@ struct _TableViewSectionStringAlignment
        bool operator!= (const _TableViewSectionStringAlignment& rhs) const;
 };
 
+struct _TableViewItemHeight
+{
+       int groupIndex;
+       int itemIndex;
+       float itemHeight;
+       bool isFooterItem;
+
+       _TableViewItemHeight(void)
+               : groupIndex(0)
+               , itemIndex(-1)
+               , itemHeight(0)
+               , isFooterItem(false)
+       {
+       }
+
+       bool operator== (const _TableViewItemHeight& rhs) const;
+       bool operator!= (const _TableViewItemHeight& rhs) const;
+};
+
 struct _TableViewScrollToItemTag
 {
        int groupIndex;
@@ -364,6 +383,7 @@ private:
        float GetItemHeight(TableViewItemTag itemTag) const;
        float SetItemHeight(TableViewItemTag itemTag, float height);
        bool CreateItemHeightList(float defaultGroupItemHeight, float defaultItemHeight);
+       bool RestoreItemHeightList(float defaultGroupItemHeight, float defaultItemHeight);
        void DeleteItemHeightList(void);
        void PresetItemHeightList(void);
        bool RefreshItemHeightList(int groupIndex, int itemIndex, TableViewRefreshType refreshType);
@@ -420,7 +440,7 @@ private:
 
        _TableViewReorderInfo __reorderInfo;
 
-       Tizen::Base::Collection::ArrayListT<float> __itemHeightList;
+       Tizen::Base::Collection::ArrayListT<_TableViewItemHeight> __itemHeightList;
        Tizen::Base::Collection::ArrayListT<_TableViewSectionStringAlignment> __sectionAlignmentList;
        float __itemTotalHeight;