Initialize Tizen 2.3
[apps/osp/Contacts.git] / src / CtGroupListEditorPanel.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.1 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //     http://floralicense.org/license/
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an AS IS BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16
17 /**
18  * @file        CtGroupListEditorPanel.cpp
19  * @brief       This is the implementation file for the GroupListEditorPanel class.
20  */
21
22 #include <FSocial.h>
23 #include "CtContactListItem.h"
24 #include "CtGroupListEditorPanel.h"
25 #include "CtGroupListPresentationModel.h"
26 #include "CtContactsApp.h"
27 #include "CtMainForm.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
30 #include "CtTypes.h"
31
32 using namespace Tizen::App;
33 using namespace Tizen::Base;
34 using namespace Tizen::Base::Collection;
35 using namespace Tizen::Graphics;
36 using namespace Tizen::Ui;
37 using namespace Tizen::Ui::Controls;
38 using namespace Tizen::Ui::Scenes;
39 using namespace Tizen::Social;
40
41 static const int IDA_FOOTER_REMOVE = 1;
42 static const int IDA_FOOTER_CANCEL = 2;
43 static const int IDA_HEADER_CONTACTS = 10;
44 static const int IDA_HEADER_GROUPS = 11;
45 static const int IDA_HEADER_FAVORITES = 12;
46 static const int IDA_BUTTON_EDIT_GROUP = 20;
47 static const int IDA_CHECK_SELECT_ALL_CHECKED = 30;
48 static const int IDA_CHECK_SELECT_ALL_UNCHECKED = 31;
49
50 static const wchar_t* IDB_BUTTON_CIRCLE_NORMAL = L"00_circle_button.png";
51 static const wchar_t* IDB_BUTTON_CIRCLE_PRESSED = L"00_circle_button_press.png";
52 static const wchar_t* IDB_BUTTON_RENAME_NORMAL = L"00_button_rename.png";
53 static const wchar_t* IDB_BUTTON_RENAME_PRESSED = L"00_button_rename_press.png";
54
55 static const unsigned int COLOR_CHECK_LABEL_BG = Color32<220, 218, 211>::Value;
56 static const unsigned int COLOR_BOTTOM_LABEL_BG = Color32<68, 68, 68>::Value;
57 static const unsigned int COLOR_BOTTOM_LABEL_FONT = Color32<255, 255, 255>::Value;
58
59 static const int FONT_SIZE_BOTTOM_LABEL = 32;
60
61 static const int H_SELECT_ALL = 112;
62 static const int H_ITEM = 112;
63 static const int H_GROUP_ITEM = 84;
64 static const int W_INITIAL_PANEL = 10;
65 static const int H_INITIAL_PANEL = 10;
66 static const int W_THUMBNAIL = 112;
67 static const int W_BUTTON_EDIT_GROUP = 72;
68 static const int H_BUTTON_EDIT_GROUP = 72;
69 static const int Y_BUTTON_GAP = 20;
70 static const int X_THUMBNAIL_GAP = 16;
71 static const int X_LIST_ITEM_TEXT_MARGIN = 64;
72 static const int H_BOTTOM_LABEL = 48;
73 static const int W_ELEMENT_GAP = 16;
74
75 GroupListEditorPanel::GroupListEditorPanel(void)
76 : __pSelectAll(null)
77 , __pTableView(null)
78 , __pCheckLabel(null)
79 , __pBottomLabel(null)
80 , __pPresentationModel(null)
81 , __pSavedCategoryList(null)
82 {
83 }
84
85 GroupListEditorPanel::~GroupListEditorPanel(void)
86 {
87 }
88
89 void
90 GroupListEditorPanel::Initialize(void)
91 {
92         Construct(Rectangle(0, 0, W_INITIAL_PANEL, H_INITIAL_PANEL));
93 }
94
95 result
96 GroupListEditorPanel::OnInitializing(void)
97 {
98         const Form* pForm = dynamic_cast<Form*>(GetParent());
99         AppAssert(pForm);
100
101         FloatRectangle clientBounds = pForm->GetClientAreaBoundsF();
102         SetBounds(FloatRectangle(0, 0, clientBounds.width, clientBounds.height));
103
104         __pPresentationModel = GroupListPresentationModel::GetInstance();
105
106         __pCheckLabel = new (std::nothrow) Label();
107         __pCheckLabel->Construct(Rectangle(0, Y_BUTTON_GAP, clientBounds.width, H_BUTTON_EDIT_GROUP), L"");
108         __pCheckLabel->SetBackgroundColor(COLOR_CHECK_LABEL_BG);
109         AddControl(__pCheckLabel);
110
111         __pSelectAll = new (std::nothrow) CheckButton();
112         __pSelectAll->Construct(Rectangle(0, 0, clientBounds.width, H_SELECT_ALL), CHECK_BUTTON_STYLE_MARK, BACKGROUND_STYLE_NONE);
113         __pSelectAll->SetText(ResourceManager::GetString(L"IDS_COM_BODY_SELECT_ALL"));
114         __pSelectAll->SetActionId(IDA_CHECK_SELECT_ALL_CHECKED, IDA_CHECK_SELECT_ALL_UNCHECKED);
115         __pSelectAll->AddActionEventListener(*this);
116         AddControl(__pSelectAll);
117
118         __pTableView = new (std::nothrow) GroupedTableView();
119         __pTableView->Construct(Rectangle(0, H_SELECT_ALL, clientBounds.width, clientBounds.height - H_SELECT_ALL - H_BOTTOM_LABEL), true, TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
120         __pTableView->SetItemProvider(this);
121         __pTableView->AddGroupedTableViewItemEventListener(*this);
122         AddControl(__pTableView);
123
124         __pBottomLabel = new (std::nothrow) Label();
125         __pBottomLabel->Construct(FloatRectangle(0, clientBounds.height - H_BOTTOM_LABEL, clientBounds.width, H_BOTTOM_LABEL),
126                                                                                                         ResourceManager::GetString(L"IDS_COM_POP_SELECTED") + INITIAL_SELECTED_COUNT);
127         __pBottomLabel->SetBackgroundColor(Color(COLOR_BOTTOM_LABEL_BG));
128         __pBottomLabel->SetTextColor(Color(COLOR_BOTTOM_LABEL_FONT));
129         __pBottomLabel->SetTextConfig(FONT_SIZE_BOTTOM_LABEL, LABEL_TEXT_STYLE_BOLD);
130         __pBottomLabel->SetTextVerticalAlignment(ALIGNMENT_MIDDLE);
131         __pBottomLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
132         AddControl(__pBottomLabel);
133
134         if (__pSavedCategoryList == null)
135         {
136                 __pSavedCategoryList = new (std::nothrow) ArrayList();
137                 __pSavedCategoryList->Construct();
138         }
139
140         return E_SUCCESS;
141 }
142
143 result
144 GroupListEditorPanel::OnTerminating(void)
145 {
146         result r = E_SUCCESS;
147
148         if (__pPresentationModel != null)
149         {
150                 __pPresentationModel->RemoveGroupChangeListener(*this);
151         }
152
153         if (__pSavedCategoryList != null)
154         {
155                 __pSavedCategoryList->RemoveAll(true);
156                 delete __pSavedCategoryList;
157                 __pSavedCategoryList = null;
158         }
159
160         return r;
161 }
162
163 void
164 GroupListEditorPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
165 {
166         SceneManager* pSceneManager = SceneManager::GetInstance();
167         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
168
169         switch (actionId)
170         {
171         case IDA_HEADER_CONTACTS:
172                 {
173                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
174                         {
175                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
176                                 {
177                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
178                                 }
179                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
180                                 {
181                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
182                                 }
183                         }
184                         else
185                         {
186                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
187                         }
188                 }
189                 break;
190         case IDA_HEADER_GROUPS:
191                 {
192                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
193                 }
194                 break;
195         case IDA_HEADER_FAVORITES:
196                 {
197                         if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
198                         {
199                                 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
200                                 {
201                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
202                                 }
203                                 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
204                                 {
205                                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
206                                 }
207                         }
208                         else
209                         {
210                                 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
211                         }
212                 }
213                 break;
214         case IDA_FOOTER_REMOVE:
215                 {
216                         int categoryCount = __pTableView->GetItemCountAt(0);
217
218                         for (int index = categoryCount - 1; index >= 0; index--)
219                         {
220                                 if (__pTableView->IsItemChecked(0, index) == true)
221                                 {
222                                         __pPresentationModel->RemoveCategory(index);
223                                 }
224                         }
225                         __pPresentationModel->UpdateCategoryList();
226
227                         pSceneManager->GoBackward(BackwardSceneTransition(IDSCN_GROUP_LIST));
228                 }
229                 break;
230         case IDA_FOOTER_CANCEL:
231                 {
232                         pSceneManager->GoBackward(BackwardSceneTransition());
233                 }
234                 break;
235         case IDA_BUTTON_EDIT_GROUP:
236                 {
237                         int index = -1;
238                         ArrayList* pList = new (std::nothrow) ArrayList();
239                         pList->Construct();
240
241                         Integer::Parse(source.GetName(), index);
242                         pList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId(index))));
243                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
244                 }
245                 break;
246         case IDA_CHECK_SELECT_ALL_CHECKED:
247                 {
248                         for (int i = 0; i < __pTableView->GetItemCountAt(0); i++)
249                         {
250                                 __pTableView->SetItemChecked(0, i, true);
251                         }
252                         __pTableView->Invalidate(true);
253                         UpdateBottomLabel();
254                 }
255                 break;
256         case IDA_CHECK_SELECT_ALL_UNCHECKED:
257                 {
258                         for (int i = 0; i < __pTableView->GetItemCountAt(0); i++)
259                         {
260                                 __pTableView->SetItemChecked(0, i, false);
261                         }
262                         __pTableView->Invalidate(true);
263                         UpdateBottomLabel();
264                 }
265                 break;
266         default:
267                 break;
268         }
269 }
270
271 void
272 GroupListEditorPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
273                                                                    const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
274 {
275         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
276         pContactsApp->AddContactsAppChangeEventListener(*this);
277         Form* pForm = dynamic_cast<Form*>(GetParent());
278         AppAssert(pForm);
279
280         Header* pHeader = pForm->GetHeader();
281         pHeader->AddActionEventListener(*this);
282
283         Footer* pFooter = pForm->GetFooter();
284         pFooter->RemoveAllItems();
285         pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
286         pForm->SetFormMenuEventListener(null);
287         pFooter->AddActionEventListener(*this);
288
289         FooterItem footerCancel;
290         footerCancel.Construct(IDA_FOOTER_CANCEL);
291         footerCancel.SetText(ResourceManager::GetString(L"IDS_PB_SK_CANCEL"));
292         pFooter->AddItem(footerCancel);
293
294         FooterItem footerRemove;
295         footerRemove.Construct(IDA_FOOTER_REMOVE);
296         footerRemove.SetText(ResourceManager::GetString(L"IDS_COM_BODY_REMOVE"));
297         pFooter->AddItem(footerRemove);
298
299         __pTableView->UpdateTableView();
300
301         if (previousSceneId.Equals(IDSCN_GROUP_EDITOR, true) == false)
302         {
303                 __pSelectAll->SetSelected(false);
304                 for (int i = 0; i < __pTableView->GetItemCountAt(0); i++)
305                 {
306                         __pTableView->SetItemChecked(0, i, false);
307                 }
308         }
309         else if (previousSceneId.Equals(IDSCN_GROUP_EDITOR, true) == true)
310         {
311                 ResetSelectedItems();
312         }
313
314         __pPresentationModel->AddGroupChangeListener(*this);
315         UpdateBottomLabel();
316
317         if (pArgs != null)
318         {
319                 pArgs->RemoveAll(true);
320                 delete pArgs;
321         }
322 }
323
324 void
325 GroupListEditorPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
326                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
327 {
328         ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
329         pContactsApp->RemoveContactsAppChangeEventListener(*this);
330
331         const Form* pForm = dynamic_cast<Form*>(GetParent());
332         AppAssert(pForm);
333
334         Header* pHeader = pForm->GetHeader();
335         pHeader->RemoveActionEventListener(*this);
336
337         Footer* pFooter = pForm->GetFooter();
338         pFooter->RemoveActionEventListener(*this);
339
340         __pPresentationModel->RemoveGroupChangeListener(*this);
341
342         if (__pSavedCategoryList != null)
343         {
344                 __pSavedCategoryList->RemoveAll(true);
345                 SaveCategoryList();
346         }
347 }
348
349 Tizen::Ui::Controls::TableViewGroupItem*
350 GroupListEditorPanel::CreateGroupItem(int groupIndex, int itemWidth)
351 {
352         TableViewSimpleGroupItem* pItem = new (std::nothrow) TableViewSimpleGroupItem();
353         pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
354         pItem->SetItemContents(ResourceManager::GetString(L"IDS_PB_BODY_PHONE"));
355         pItem->SetEnabled(false);
356
357         return pItem;
358 }
359
360 Tizen::Ui::Controls::TableViewItem*
361 GroupListEditorPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth)
362 {
363         String groupNameString;
364         String contactCountString;
365         Bitmap* pThumbnail = null;
366         Bitmap* pBgBitmap = null;
367         Bitmap* pBitmap = null;
368         bool isNotAssinged = false;
369         int adjustedNameWidth;
370         Dimension countSize;
371         Dimension groupNameSize;
372         Font font;
373         IList* pList = null;
374
375         ContactsApp *pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
376         TableViewItem* pItem = new (std::nothrow) TableViewItem();
377         pItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()), TABLE_VIEW_ANNEX_STYLE_MARK);
378
379         result r = __pPresentationModel->UpdatePersonList(itemIndex);
380         TryReturn(r == E_SUCCESS, null, "[%s] Unable to update person list", GetErrorMessage(r));
381
382         if (__pPresentationModel->GetCategoryCount() == itemIndex)
383         {
384                 isNotAssinged = true;
385                 groupNameString = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
386                 contactCountString = L"(" + Integer::ToString(__pPresentationModel->GetContactCountInNotAssignedCategory()) + L")";
387         }
388         else
389         {
390                 groupNameString = __pPresentationModel->GetCategoryName(itemIndex);
391                 contactCountString = L"(" + Integer::ToString(__pPresentationModel->GetContactCountInCategoryN(itemIndex, pList)) + L")";
392         }
393
394         font.Construct(FONT_STYLE_PLAIN, pContactsApp->GetFontSize());
395         font.GetTextExtent(contactCountString, contactCountString.GetLength(), countSize);
396         font.GetTextExtent(groupNameString, groupNameString.GetLength(), groupNameSize);
397
398         adjustedNameWidth = itemWidth - (TableViewItem::GetAnnexWidth(TABLE_VIEW_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN + W_BUTTON_EDIT_GROUP + W_THUMBNAIL + (X_THUMBNAIL_GAP * 2) + (countSize.width + W_ELEMENT_GAP * 2));
399         if (groupNameSize.width < adjustedNameWidth)
400         {
401                 adjustedNameWidth = groupNameSize.width + W_ELEMENT_GAP + 1;
402         }
403
404         Label* pLabelGroupName = new (std::nothrow) Label();
405         pLabelGroupName->Construct(Rectangle(0, Y_BUTTON_GAP, adjustedNameWidth, H_BUTTON_EDIT_GROUP + pContactsApp->GetFontHeightOffset()), groupNameString);
406         pLabelGroupName->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
407         pLabelGroupName->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
408         pLabelGroupName->SetMargin(0, 0);
409         pItem->AddControl(pLabelGroupName);
410
411         Label* pLabelCount = new (std::nothrow) Label();
412         pLabelCount->Construct(Rectangle(adjustedNameWidth, Y_BUTTON_GAP, countSize.width + W_ELEMENT_GAP + 1, H_BUTTON_EDIT_GROUP + pContactsApp->GetFontHeightOffset()), contactCountString);
413         pLabelCount->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
414         pLabelCount->SetTextConfig(pContactsApp->GetFontSize(), LABEL_TEXT_STYLE_NORMAL);
415         pLabelCount->SetMargin(0, 0);
416         pItem->AddControl(pLabelCount);
417
418         int editButtonX = itemWidth - (TableViewItem::GetAnnexWidth(TABLE_VIEW_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN + X_THUMBNAIL_GAP + W_BUTTON_EDIT_GROUP);
419         Button* pButtonEdit = new (std::nothrow) Button();
420         pButtonEdit->Construct(Rectangle(editButtonX, (pContactsApp->GetListItemSingleLineHeight() - H_BUTTON_EDIT_GROUP)/2, W_BUTTON_EDIT_GROUP, H_BUTTON_EDIT_GROUP));
421         pButtonEdit->SetActionId(IDA_BUTTON_EDIT_GROUP);
422         pButtonEdit->AddActionEventListener(*this);
423         pButtonEdit->SetName(Integer::ToString(itemIndex));
424         pItem->AddControl(pButtonEdit);
425
426         Label* pLabelThumbnail = new (std::nothrow) Label();
427         pLabelThumbnail->Construct(Rectangle(editButtonX - (X_THUMBNAIL_GAP + W_THUMBNAIL), 0, W_THUMBNAIL, H_ITEM), L"");
428         pItem->AddControl(pLabelThumbnail);
429
430         pThumbnail = __pPresentationModel->GetThumbnailN(itemIndex, pList);
431
432         if(pThumbnail != null)
433         {
434                 pLabelThumbnail->SetBackgroundBitmap(*pThumbnail);
435                 delete pThumbnail;
436         }
437
438         pBgBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_CIRCLE_NORMAL);
439         if (pBgBitmap != null)
440         {
441                 pButtonEdit->SetNormalBackgroundBitmap(*pBgBitmap);
442                 delete pBgBitmap;
443         }
444         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RENAME_NORMAL);
445         if (pBitmap != null)
446         {
447                 pButtonEdit->SetNormalBitmap(Point(0, 0), *pBitmap);
448                 delete pBitmap;
449         }
450
451         pBgBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_CIRCLE_PRESSED);
452         if (pBgBitmap != null)
453         {
454                 pButtonEdit->SetPressedBackgroundBitmap(*pBgBitmap);
455                 delete pBgBitmap;
456         }
457         pBitmap = ResourceManager::GetBitmapN(IDB_BUTTON_RENAME_PRESSED);
458         if (pBitmap != null)
459         {
460                 pButtonEdit->SetPressedBitmap(Point(0, 0), *pBitmap);
461                 delete pBitmap;
462         }
463         pItem->SetIndividualSelectionEnabled(pButtonEdit, true);
464
465         if (pList != null)
466         {
467                 pList->RemoveAll(true);
468                 pList = null;
469         }
470
471         return pItem;
472 }
473
474 bool
475 GroupListEditorPanel::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem* pItem)
476 {
477         delete pItem;
478         pItem = null;
479
480         return true;
481 }
482
483 bool
484 GroupListEditorPanel::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
485 {
486         delete pItem;
487         pItem = null;
488
489         return true;
490 }
491
492 int
493 GroupListEditorPanel::GetDefaultGroupItemHeight(void)
494 {
495         return H_GROUP_ITEM;
496 }
497
498 int
499 GroupListEditorPanel::GetDefaultItemHeight(void)
500 {
501         return H_ITEM;
502 }
503
504 int
505 GroupListEditorPanel::GetGroupCount(void)
506 {
507         int count  = __pPresentationModel->GetCategoryCount();
508         if(count == 0)
509         {
510                 __pSelectAll->SetShowState(false);
511                 __pCheckLabel->SetShowState(false);
512                 __pTableView->SetBounds(0, 0, GetWidth(), GetHeight());
513                 return 0;
514         }
515         else
516         {
517                 __pSelectAll->SetShowState(true);
518                 __pCheckLabel->SetShowState(true);
519                 if (__pBottomLabel->GetShowState() == false)
520                 {
521                         __pTableView->SetBounds(0, __pSelectAll->GetY() + __pSelectAll->GetHeight(), GetWidth(), GetHeight() - __pSelectAll->GetHeight());
522                 }
523                 else
524                 {
525                         __pTableView->SetBounds(0, __pSelectAll->GetY() + __pSelectAll->GetHeight(), GetWidth(), GetHeight() - __pSelectAll->GetHeight() - __pBottomLabel->GetHeight());
526                 }
527                 return 1;
528         }
529 }
530
531 int
532 GroupListEditorPanel::GetItemCount(int groupIndex)
533 {
534         return __pPresentationModel->GetCategoryCount();
535 }
536
537 void
538 GroupListEditorPanel::UpdateGroupItem(int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem)
539 {
540 }
541
542 void
543 GroupListEditorPanel::UpdateItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem)
544 {
545 }
546
547 result
548 GroupListEditorPanel::UpdateBottomLabel(void)
549 {
550         int selectedCount = 0;
551         for (int i = 0; i < __pTableView->GetItemCountAt(0); i++)
552         {
553                 if (__pTableView->IsItemChecked(0, i) == true)
554                 {
555                         selectedCount++;
556                 }
557         }
558
559         String selected = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
560         selected.Append(L" (");
561         selected.Append(selectedCount);
562         selected.Append(L")");
563         __pBottomLabel->SetText(selected);
564         __pBottomLabel->Invalidate(false);
565
566         Form* pForm = dynamic_cast<Form*>(GetParent());
567         AppAssert(pForm);
568
569         Footer* pFooter = pForm->GetFooter();
570         if (selectedCount > 0)
571         {
572                 if(__pBottomLabel->GetShowState() == false)
573                 {
574                         __pBottomLabel->SetShowState(true);
575                         __pTableView->SetSize(__pTableView->GetSize().width, __pTableView->GetSize().height - H_BOTTOM_LABEL);
576                 }
577                 pFooter->SetItemEnabled(1, true);
578         }
579         else if (selectedCount == 0 )
580         {
581                 if (__pBottomLabel->GetShowState() == true)
582                 {
583                         __pBottomLabel->SetShowState(false);
584                         __pTableView->SetSize(__pTableView->GetSize().width, __pTableView->GetSize().height + H_BOTTOM_LABEL);
585                 }
586                 pFooter->SetItemEnabled(1, false);
587         }
588
589         pFooter->Invalidate(true);
590
591         return E_SUCCESS;
592 }
593
594 void
595 GroupListEditorPanel::ResetSelectedItems(void)
596 {
597         for (int index = 0; index < __pTableView->GetItemCountAt(0); index++)
598         {
599                 __pTableView->SetItemChecked(0, index, false);
600                 __pTableView->Invalidate(true);
601         }
602
603         if (__pPresentationModel != null)
604         {
605                 if (__pSavedCategoryList != null)
606                 {
607                         for (int i = 0; i < __pSavedCategoryList->GetCount(); i++)
608                         {
609                                 Integer* pCategoryId = static_cast<Integer*>(__pSavedCategoryList->GetAt(i));
610
611                                 bool isCategoryFound = false;
612                                 if (pCategoryId != null)
613                                 {
614                                         RecordId recordId =     pCategoryId->ToInt();
615                                         for (int index = 0; index < __pTableView->GetItemCountAt(0); index++)
616                                         {
617                                                 if (recordId == __pPresentationModel->GetCategoryId(index))
618                                                 {
619                                                         __pTableView->SetItemChecked(0, index, true);
620                                                         isCategoryFound = true;
621                                                 }
622                                         }
623                                         if (isCategoryFound == false)
624                                         {
625                                                 __pSavedCategoryList->RemoveAt(i);
626                                                 i--;
627                                         }
628                                 }
629                         }
630
631                         __pTableView->Invalidate(true);
632
633                         if (__pSavedCategoryList->GetCount() == __pTableView->GetItemCountAt(0))
634                         {
635                                 __pSelectAll->SetSelected(true);
636                         }
637                         else
638                         {
639                                 __pSelectAll->SetSelected(false);
640                         }
641
642                         __pSelectAll->Invalidate(true);
643                         UpdateBottomLabel();
644                 }
645         }
646 }
647
648 void
649 GroupListEditorPanel::OnGroupedTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewContextItem *pContextItem, bool activated)
650 {
651 }
652
653 void
654 GroupListEditorPanel::OnGroupedTableViewGroupItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, Tizen::Ui::Controls::TableViewGroupItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
655 {
656 }
657
658 void
659 GroupListEditorPanel::OnGroupedTableViewItemStateChanged(Tizen::Ui::Controls::GroupedTableView &tableView, int groupIndex, int itemIndex, Tizen::Ui::Controls::TableViewItem *pItem, Tizen::Ui::Controls::TableViewItemStatus status)
660 {
661         if (tableView.IsItemChecked(groupIndex, itemIndex) == true)
662         {
663                 bool isChecked = true;
664                 for (int i = 0; i < tableView.GetItemCountAt(groupIndex); i++)
665                 {
666                         if (tableView.IsItemChecked(groupIndex, i) == false)
667                         {
668                                 isChecked = false;
669                                 break;
670                         }
671                 }
672                 __pSelectAll->SetSelected(isChecked);
673         }
674         else if (tableView.IsItemChecked(groupIndex, itemIndex) == false)
675         {
676                 __pSelectAll->SetSelected(false);
677         }
678
679         UpdateBottomLabel();
680 }
681
682 void
683 GroupListEditorPanel::OnContactsChanged(void)
684 {
685         __pTableView->UpdateTableView();
686 }
687
688 void
689 GroupListEditorPanel::OnCategoriesChanged(void)
690 {
691         __pTableView->UpdateTableView();
692         ResetSelectedItems();
693 }
694
695 void
696 GroupListEditorPanel::OnForeground(void)
697 {
698 }
699
700 void
701 GroupListEditorPanel::OnBackground(void)
702 {
703         if (__pSavedCategoryList != null)
704         {
705                 __pSavedCategoryList->RemoveAll(true);
706                 SaveCategoryList();
707         }
708 }
709
710 void
711 GroupListEditorPanel::SaveCategoryList(void)
712 {
713         for (int index = 0; index < __pTableView->GetItemCountAt(0); index++)
714         {
715                 if (__pTableView->IsItemChecked(0, index) == true)
716                 {
717                         __pSavedCategoryList->Add((new (std::nothrow) Integer(__pPresentationModel->GetCategoryId(index))));
718                 }
719         }
720 }