2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://floralicense.org/license/
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.
18 * @file CtGroupListPanel.cpp
19 * @brief This is the implementation file for the GroupListPanel class.
23 #include "CtContactListItem.h"
24 #include "CtGroupListPanel.h"
25 #include "CtGroupListPresentationModel.h"
26 #include "CtContactsApp.h"
27 #include "CtMainForm.h"
28 #include "CtResourceManager.h"
29 #include "CtSceneRegister.h"
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;
41 static const int IDA_FOOTER_CREATE = 1;
42 static const int IDA_MORE_EDIT = 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_LIST_ELEMENT_MESSAGE = 40;
47 static const int IDA_LIST_ELEMENT_EMAIL = 41;
48 static const int IDA_LIST_ELEMENT_ADD_MEMEBER = 42;
50 static const wchar_t* IDB_NO_GROUP = L"00_Nocontents_unnamed.png";
52 static const unsigned int COLOR_ITEM_TEXT_NORMAL = Color32<0, 0, 0>::Value;
53 static const unsigned int COLOR_ITEM_TEXT_PRESSED = Color32<255, 255, 255>::Value;
54 static const unsigned int COLOR_EMPTY_COMMENT = Color32<102, 102, 102>::Value;
56 static const int H_GROUP_ITEM = 76;
57 static const int W_INITIAL_PANEL = 10;
58 static const int H_INITIAL_PANEL = 10;
59 static const int W_THUMBNAIL = 108;
60 static const int H_THUMBNAIL = 108;
61 static const int X_TEXT = 26;
62 static const int W_ELEMENT_GAP = 16;
64 static const int X_EMPTY_IMAGE = 220;
65 static const int Y_EMPTY_IMAGE = 300;
66 static const int W_EMPTY_IMAGE = 280;
67 static const int H_EMPTY_IMAGE = 280;
68 static const int Y_EMPTY_COMMENT = 618;
69 static const int H_EMPTY_COMMENT = 38;
71 static const int FONT_SIZE_EMPTY_COMMENT = 32;
73 GroupListPanel::GroupListPanel(void)
77 , __pEmptyImageLabel(null)
78 , __pEmptyCommentLabel(null)
79 , __pPresentationModel(null)
83 GroupListPanel::~GroupListPanel(void)
88 GroupListPanel::Initialize(void)
90 Construct(Rectangle(0, 0, W_INITIAL_PANEL, H_INITIAL_PANEL));
94 GroupListPanel::OnInitializing(void)
96 const Form* pForm = dynamic_cast<Form*>(GetParent());
99 Rectangle clientBounds = pForm->GetClientAreaBounds();
100 SetBounds(Rectangle(0, 0, clientBounds.width, clientBounds.height));
102 __pPresentationModel = GroupListPresentationModel::GetInstance();
104 __pListView = new (std::nothrow) GroupedListView();
105 __pListView->Construct(Rectangle(0, 0, clientBounds.width, clientBounds.height), GROUPED_LIST_VIEW_STYLE_INDEXED, true, false);
106 __pListView->SetItemProvider(*this);
107 __pListView->AddGroupedListViewItemEventListener(*this);
109 AddControl(__pListView);
111 __pEmptyImageLabel = new (std::nothrow) Label();
112 __pEmptyImageLabel->Construct(Rectangle(X_EMPTY_IMAGE, Y_EMPTY_IMAGE, W_EMPTY_IMAGE, H_EMPTY_IMAGE), L"");
113 Bitmap* pBitmap = ResourceManager::GetBitmapN(IDB_NO_GROUP);
116 __pEmptyImageLabel->SetBackgroundBitmap(*pBitmap);
119 __pEmptyImageLabel->SetShowState(false);
121 AddControl(__pEmptyImageLabel);
123 __pEmptyCommentLabel = new (std::nothrow) Label();
124 __pEmptyCommentLabel->Construct(Rectangle(0, Y_EMPTY_COMMENT, clientBounds.width, H_EMPTY_COMMENT),
125 ResourceManager::GetString(L"IDS_PB_HEADER_NO_GROUP"));
126 __pEmptyCommentLabel->SetTextConfig(FONT_SIZE_EMPTY_COMMENT, LABEL_TEXT_STYLE_NORMAL);
127 __pEmptyCommentLabel->SetTextColor(Color(COLOR_EMPTY_COMMENT));
128 __pEmptyCommentLabel->SetShowState(false);
130 AddControl(__pEmptyCommentLabel);
132 __pOptionMenu = new (std::nothrow) OptionMenu();
133 __pOptionMenu->Construct();
134 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_SK_EDIT"), IDA_MORE_EDIT);
135 __pOptionMenu->AddActionEventListener(*this);
136 __pOptionMenu->SetShowState(false);
141 GroupListPanel::OnTerminating(void)
143 result r = E_SUCCESS;
145 if (__pPresentationModel != null)
147 __pPresentationModel->RemoveGroupChangeListener(*this);
150 delete __pOptionMenu;
156 GroupListPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
158 SceneManager* pSceneManager = SceneManager::GetInstance();
159 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
163 case IDA_HEADER_CONTACTS:
165 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
167 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
169 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
171 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
173 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST_EDITOR));
178 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_LIST));
182 case IDA_HEADER_GROUPS:
184 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST));
187 case IDA_HEADER_FAVORITES:
189 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
191 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_SINGLE)
193 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
195 else if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
197 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST_EDITOR));
202 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_FAVORITE_LIST));
206 case IDA_FOOTER_CREATE:
208 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
213 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_LIST_EDITOR));
222 GroupListPanel::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
224 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
225 if(__pPresentationModel->GetCategoryCount() > 0 && pContactsApp->GetOperationId() != OPERATION_ID_PICK)
227 __pOptionMenu->SetShowState(true);
228 __pOptionMenu->Show();
233 GroupListPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
234 const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
236 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
238 if (previousSceneId.Equals(IDSCN_CONTACT_SELECTOR, true))
240 __pPresentationModel->AddContactToCategory(__sweptItemIndex, pArgs);
243 Form* pForm = dynamic_cast<Form*>(GetParent());
245 Form *pEventForm = const_cast<Form*>(pForm);
246 pEventForm->SetFormMenuEventListener(this);
248 Header* pHeader = pForm->GetHeader();
249 pHeader->AddActionEventListener(*this);
251 Footer* pFooter = pForm->GetFooter();
252 pFooter->AddActionEventListener(*this);
254 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
256 pFooter->SetShowState(false);
257 SetBounds(Rectangle(0, 0, pForm->GetClientAreaBounds().width, pForm->GetClientAreaBounds().height));
258 __pListView->SetSize(__pListView->GetWidth(), pForm->GetClientAreaBounds().height);
261 if (__pPresentationModel->GetCategoryCount() == 0)
263 pForm->SetFormMenuEventListener(null);
264 __pListView->SetShowState(false);
265 __pEmptyImageLabel->SetShowState(true);
266 __pEmptyCommentLabel->SetShowState(true);
270 __pListView->SetShowState(true);
271 __pEmptyImageLabel->SetShowState(false);
272 __pEmptyCommentLabel->SetShowState(false);
277 FooterItem footerItemCreate;
278 footerItemCreate.Construct(IDA_FOOTER_CREATE);
279 footerItemCreate.SetText(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"));
280 int count = pFooter->GetItemCount();
283 pFooter->AddItem(footerItemCreate);
287 pFooter->SetItemAt(0, footerItemCreate);
291 pFooter->SetItemAt(0, footerItemCreate);
292 pFooter->RemoveItemAt(1);
293 pFooter->RemoveButtonAt(BUTTON_POSITION_LEFT);
295 pFooter->SetItemEnabled(0,true);
296 pForm->SetFormMenuEventListener(null);
298 if (__pPresentationModel->GetCategoryCount() > 0)
300 pForm->SetFormMenuEventListener(this);
302 __pListView->SetShowState(true);
303 __pEmptyImageLabel->SetShowState(false);
304 __pEmptyCommentLabel->SetShowState(false);
306 else if (__pPresentationModel->GetContactCount() > 0)
308 __pListView->SetShowState(true);
309 __pEmptyImageLabel->SetShowState(false);
310 __pEmptyCommentLabel->SetShowState(false);
314 __pListView->SetShowState(false);
315 __pEmptyImageLabel->SetShowState(true);
316 __pEmptyCommentLabel->SetShowState(true);
320 __pListView->UpdateList();
321 __pPresentationModel->AddGroupChangeListener(*this);
325 pArgs->RemoveAll(true);
331 GroupListPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
332 const Tizen::Ui::Scenes::SceneId& nextSceneId)
334 const Form* pForm = dynamic_cast<Form*>(GetParent());
337 Form *pEventForm = const_cast<Form*>(pForm);
338 pEventForm->SetFormMenuEventListener(null);
340 Header* pHeader = pForm->GetHeader();
341 pHeader->RemoveActionEventListener(*this);
343 Footer* pFooter = pForm->GetFooter();
344 pFooter->RemoveActionEventListener(*this);
346 __pPresentationModel->RemoveGroupChangeListener(*this);
350 GroupListPanel::GetGroupCount(void)
356 GroupListPanel::GetItemCount(int groupIndex)
358 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
359 int count = __pPresentationModel->GetCategoryCount();
361 if (__pPresentationModel->GetContactCountInNotAssignedCategory(pContactsApp->GetReturnType()))
369 Tizen::Ui::Controls::ListItemBase*
370 GroupListPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth)
372 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
373 String groupNameString;
374 int contactCount = 0;
375 String contactCountString;
376 Bitmap* pThumbnail = null;
377 bool isNotAssinged = false;
378 int adjustedNameWidth;
380 Dimension groupNameSize;
383 CustomItem* pItem = new (std::nothrow) CustomItem();
384 pItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()), LIST_ANNEX_STYLE_NORMAL);
386 result r = __pPresentationModel->UpdatePersonList(itemIndex);
387 TryReturn(r == E_SUCCESS, null, "[%s] Unable to update person list", GetErrorMessage(r));
389 if (__pPresentationModel->GetCategoryCount() == itemIndex)
391 isNotAssinged = true;
392 groupNameString = ResourceManager::GetString(L"IDS_PB_BODY_NOT_ASSIGNED");
393 contactCount = __pPresentationModel->GetContactCountInNotAssignedCategory(pContactsApp->GetReturnType());
394 contactCountString = L"(" + Integer::ToString(contactCount) + L")";
398 groupNameString = __pPresentationModel->GetCategoryName(itemIndex);
399 contactCount = __pPresentationModel->GetContactCountInCategory(itemIndex, pContactsApp->GetReturnType());
400 contactCountString = L"(" + Integer::ToString(contactCount) + L")";
403 font.Construct(FONT_STYLE_PLAIN, pContactsApp->GetFontSize());
404 font.GetTextExtent(contactCountString, contactCountString.GetLength(), countSize);
405 font.GetTextExtent(groupNameString, groupNameString.GetLength(), groupNameSize);
407 adjustedNameWidth = itemWidth - (W_THUMBNAIL + (X_TEXT * 2) + (countSize.width + W_ELEMENT_GAP * 2));
408 if (groupNameSize.width < adjustedNameWidth)
410 adjustedNameWidth = groupNameSize.width + 1;
413 pItem->AddElement(Rectangle(X_TEXT, 0, adjustedNameWidth, pContactsApp->GetListItemSingleLineHeight()), 1, groupNameString, pContactsApp->GetFontSize(), COLOR_ITEM_TEXT_NORMAL, COLOR_ITEM_TEXT_PRESSED, COLOR_ITEM_TEXT_PRESSED, true);
414 pItem->AddElement(Rectangle(X_TEXT + adjustedNameWidth + W_ELEMENT_GAP, 0, countSize.width + 1, pContactsApp->GetListItemSingleLineHeight()), 2, contactCountString, pContactsApp->GetFontSize(), COLOR_ITEM_TEXT_NORMAL, COLOR_ITEM_TEXT_PRESSED, COLOR_ITEM_TEXT_PRESSED, true);
416 pThumbnail = __pPresentationModel->GetThumbnailN(itemIndex);
417 if (pThumbnail != null)
419 pItem->AddElement(Rectangle(itemWidth - W_THUMBNAIL - X_TEXT, (pContactsApp->GetListItemSingleLineHeight() - H_THUMBNAIL)/2, W_THUMBNAIL, H_THUMBNAIL), 0, *pThumbnail);
423 if (pContactsApp->GetOperationId().IsEmpty() == false)
428 ListContextItem* pItemContext = new (std::nothrow) ListContextItem();
429 pItemContext->Construct();
430 if (contactCount == 0)
432 pItemContext->AddElement(IDA_LIST_ELEMENT_MESSAGE, ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"), false);
433 pItemContext->AddElement(IDA_LIST_ELEMENT_EMAIL, ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"), false);
437 pItemContext->AddElement(IDA_LIST_ELEMENT_MESSAGE, ResourceManager::GetString(L"IDS_COM_BODY_MESSAGE"));
438 pItemContext->AddElement(IDA_LIST_ELEMENT_EMAIL, ResourceManager::GetString(L"IDS_COM_BODY_EMAIL"));
441 if (isNotAssinged == false && __pPresentationModel->GetContactCount() > __pPresentationModel->GetContactCountInCategory(itemIndex))
443 pItemContext->AddElement(IDA_LIST_ELEMENT_ADD_MEMEBER, ResourceManager::GetString(L"IDS_PB_SK_ADD_MEMBER"));
446 pItem->SetContextItem(pItemContext);
451 Tizen::Ui::Controls::GroupItem*
452 GroupListPanel::CreateGroupItem(int groupIndex, int itemWidth)
454 GroupItem* pItem = new (std::nothrow) GroupItem();
455 pItem->Construct(Dimension(itemWidth, H_GROUP_ITEM));
456 pItem->SetElement(ResourceManager::GetString(L"IDS_PB_BODY_PHONE"));
462 GroupListPanel::DeleteItem(int groupIndex, int itemIndex, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
464 CustomItem* pCustomItem = static_cast<CustomItem *>(pItem);
465 pCustomItem->RemoveAllElements();
474 GroupListPanel::DeleteGroupItem(int groupIndex, Tizen::Ui::Controls::GroupItem* pItem, int itemWidth)
483 GroupListPanel::OnContactsChanged(void)
485 __pListView->UpdateList();
489 GroupListPanel::OnCategoriesChanged(void)
491 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
493 Form* pForm = dynamic_cast<Form*>(GetParent());
496 if (__pPresentationModel->GetCategoryCount()> 0)
498 pForm->SetFormMenuEventListener(this);
502 pForm->SetFormMenuEventListener(null);
505 if (pContactsApp->GetOperationId() == OPERATION_ID_PICK)
507 if (__pPresentationModel->GetCategoryCount() == 0)
509 __pListView->SetShowState(false);
510 __pEmptyImageLabel->SetShowState(true);
511 __pEmptyCommentLabel->SetShowState(true);
515 __pListView->SetShowState(true);
516 __pEmptyImageLabel->SetShowState(false);
517 __pEmptyCommentLabel->SetShowState(false);
522 if (__pPresentationModel->GetCategoryCount() > 0)
524 __pListView->SetShowState(true);
525 __pEmptyImageLabel->SetShowState(false);
526 __pEmptyCommentLabel->SetShowState(false);
528 else if (__pPresentationModel->GetContactCount() > 0)
530 __pListView->SetShowState(true);
531 __pEmptyImageLabel->SetShowState(false);
532 __pEmptyCommentLabel->SetShowState(false);
536 __pListView->SetShowState(false);
537 __pEmptyImageLabel->SetShowState(true);
538 __pEmptyCommentLabel->SetShowState(true);
542 __pListView->UpdateList();
546 GroupListPanel::OnGroupedListViewContextItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
548 SceneManager* pSceneManager = SceneManager::GetInstance();
552 case IDA_LIST_ELEMENT_MESSAGE:
554 ArrayList* pList = new (std::nothrow) ArrayList();
557 if (__pPresentationModel->GetCategoryCount() == itemIndex)
559 pList->Add(*(new (std::nothrow) Integer(ID_GROUP_CONTACT_NOT_ASSIGNED)));
563 pList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId(itemIndex))));
565 pList->Add(*(new (std::nothrow) Integer(ID_GROUP_CONTACT_SELECT_MESSAGE)));
566 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_CONTACT_LIST_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
569 case IDA_LIST_ELEMENT_EMAIL:
571 ArrayList* pList = new (std::nothrow) ArrayList();
574 if (__pPresentationModel->GetCategoryCount() == itemIndex)
576 pList->Add(*(new (std::nothrow) Integer(ID_GROUP_CONTACT_NOT_ASSIGNED)));
580 pList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId(itemIndex))));
582 pList->Add(*(new (std::nothrow) Integer(ID_GROUP_CONTACT_SELECT_EMAIL)));
583 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_CONTACT_LIST_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
586 case IDA_LIST_ELEMENT_ADD_MEMEBER:
588 IList* pArgList = __pPresentationModel->GetContactIdListInCategory(itemIndex);
590 __sweptItemIndex = itemIndex;
592 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_CONTACT_SELECTOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgList);
601 GroupListPanel::OnGroupedListViewItemStateChanged(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, int elementId, Tizen::Ui::Controls::ListItemStatus state)
603 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
605 ArrayList* pList = new (std::nothrow) ArrayList();
608 if (__pPresentationModel->GetCategoryCount() == itemIndex)
610 pList->Add(*(new (std::nothrow) Integer(ID_GROUP_CONTACT_NOT_ASSIGNED)));
614 pList->Add(*(new (std::nothrow) Integer(__pPresentationModel->GetCategoryId(itemIndex))));
617 if (pContactsApp->GetSelectionMode() == APP_CONTROL_SELECTION_MODE_MULTI)
619 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_GROUP_CONTACT_LIST_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
623 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_GROUP_CONTACT_LIST, SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
628 GroupListPanel::OnGroupedListViewItemSwept(Tizen::Ui::Controls::GroupedListView& listView, int groupIndex, int itemIndex, Tizen::Ui::Controls::SweepDirection direction)