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 CtGroupSelectorForm.cpp
19 * @brief This is the implementation file for the GroupSelectorForm class.
24 #include "CtContactsApp.h"
25 #include "CtGroupListPresentationModel.h"
26 #include "CtGroupSelectorForm.h"
27 #include "CtResourceManager.h"
28 #include "CtSceneRegister.h"
31 using namespace Tizen::App;
32 using namespace Tizen::Base;
33 using namespace Tizen::Base::Collection;
34 using namespace Tizen::Graphics;
35 using namespace Tizen::Ui;
36 using namespace Tizen::Ui::Controls;
37 using namespace Tizen::Ui::Scenes;
38 using namespace Tizen::Social;
40 static const int IDA_FOOTER_DONE = 11;
41 static const int IDA_FOOTER_CANCEL = 12;
42 static const int IDA_MORE_CREATE_GROUP = 13;
44 static const int X_LIST_ITEM_TEXT_MARGIN = 36;
46 GroupSelectorForm::GroupSelectorForm(void)
47 :__isDonePressed(false)
48 ,__pGroupListPresentationModel(null)
50 , __pBottomLabel(null)
52 , __pGroupIndexMap(null)
53 , __pGroupIdList(null)
57 GroupSelectorForm::~GroupSelectorForm(void)
62 GroupSelectorForm::Initialize(void)
64 Construct(L"IDL_GROUP_SELECTOR_FORM");
68 GroupSelectorForm::OnInitializing(void)
70 Footer* pFooter = GetFooter();
71 pFooter->SetItemEnabled(1, false);
72 pFooter->AddActionEventListener(*this);
73 SetFormBackEventListener(this);
75 __pGroupListPresentationModel = GroupListPresentationModel::GetInstance();
76 __pGroupListPresentationModel->AddGroupChangeListener(*this);
78 __pListView = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW", false));
79 __pListView->SetItemProvider(*this);
80 __pListView->AddListViewItemEventListener(*this);
82 __pBottomLabel = static_cast<Label*>(GetControl(L"IDC_LABEL", false));
84 __pGroupIndexMap = new (std::nothrow) HashMapT<int, bool>();
85 __pGroupIndexMap->Construct(__pGroupListPresentationModel->GetCategoryCount());
87 __pOptionMenu = new (std::nothrow) OptionMenu();
88 __pOptionMenu->Construct();
89 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"), IDA_MORE_CREATE_GROUP);
90 __pOptionMenu->AddActionEventListener(*this);
91 __pOptionMenu->SetShowState(false);
97 GroupSelectorForm::OnTerminating(void)
101 if (__pGroupIndexMap)
103 __pGroupIndexMap->RemoveAll();
104 delete __pGroupIndexMap;
109 __pGroupIdList->RemoveAll(true);
110 delete __pGroupIdList;
113 if (__pGroupListPresentationModel != null)
115 __pGroupListPresentationModel->RemoveGroupChangeListener(*this);
118 delete __pOptionMenu;
124 GroupSelectorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
126 result r = E_SUCCESS;
128 SceneManager* pSceneManager = SceneManager::GetInstance();
129 ArrayList* pList = null;
133 case IDA_MORE_CREATE_GROUP:
135 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
136 TryCatch(r == E_SUCCESS, , "[%s] Unable to go forward", GetErrorMessage(r));
139 case IDA_FOOTER_DONE:
141 __isDonePressed = true;
142 pList = new (std::nothrow) ArrayList();
143 pList->Construct(__pGroupIndexMap->GetCount());
145 for (int i = 0; i < __pGroupListPresentationModel->GetCategoryCount(); i++)
147 bool categoryValue = false;
148 RecordId categoryId = __pGroupListPresentationModel->GetCategoryId(i);
150 __pGroupIndexMap->GetValue(categoryId, categoryValue);
154 pList->Add(*(new (std::nothrow) Integer(categoryId)));
158 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pList);
159 TryCatch(r == E_SUCCESS, , "[%s] Unable to go backward", GetErrorMessage(r));
162 case IDA_FOOTER_CANCEL:
164 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
165 TryCatch(r == E_SUCCESS, ,"[%s] Unable to go backward", GetErrorMessage(r));
177 pList->RemoveAll(true);
185 GroupSelectorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
187 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
188 pContactsApp->AddContactsAppChangeEventListener(*this);
190 SetFormMenuEventListener(this);
197 if (__pGroupIdList != null)
199 __pGroupIdList->RemoveAll(true);
200 delete __pGroupIdList;
203 __pGroupIdList = pArgs;
205 __pGroupIndexMap->RemoveAll();
207 int categoryCount = __pGroupListPresentationModel->GetCategoryCount();
208 for (int index = 0; index < categoryCount; index++)
210 if (__pGroupListPresentationModel->IsContactInCategory(*__pGroupIdList, index) == true)
212 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), true);
216 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), false);
220 __pListView->UpdateList();
222 for (int index = 0; index < __pListView->GetItemCount(); index++)
224 bool isChecked = false;
226 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
228 if (isChecked == true)
230 result r = __pListView->SetItemChecked(index, true);
231 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
239 GroupSelectorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
241 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
242 pContactsApp->RemoveContactsAppChangeEventListener(*this);
243 SetFormMenuEventListener(null);
247 GroupSelectorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
249 SceneManager *pSceneManager = SceneManager::GetInstance();
250 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
254 GroupSelectorForm::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
256 __pOptionMenu->SetShowState(true);
257 __pOptionMenu->Show();
260 Tizen::Ui::Controls::ListItemBase*
261 GroupSelectorForm::CreateItem(int index, int itemWidth)
263 result r = E_SUCCESS;
265 Color textColor = Color::GetColor(COLOR_ID_BLACK);
267 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
269 CustomItem* pItem = new (std::nothrow) CustomItem();
270 pItem->Construct(Dimension(itemWidth, pContactsApp->GetListItemSingleLineHeight()), LIST_ANNEX_STYLE_MARK);
272 name = __pGroupListPresentationModel->GetCategoryName(index);
274 r = pItem->AddElement(Rectangle(X_LIST_ITEM_TEXT_MARGIN/2, 0, itemWidth - (ListItemBase::GetAnnexWidth(LIST_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN), pContactsApp->GetListItemSingleLineHeight()), index, name, pContactsApp->GetFontSize(), textColor, textColor, textColor);
275 TryCatch(r == E_SUCCESS, , "[%s] Unable to add element", GetErrorMessage(r));
287 GroupSelectorForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
295 GroupSelectorForm::GetItemCount(void)
297 return __pGroupListPresentationModel->GetCategoryCount();
301 GroupSelectorForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
306 GroupSelectorForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
308 result r = E_SUCCESS;
310 if (status == LIST_ITEM_STATUS_CHECKED)
312 r = listView.SetItemChecked(index, true);
313 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
315 r = __pGroupIndexMap->SetValue(__pGroupListPresentationModel->GetCategoryId(index), true);
316 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set value", GetErrorMessage(r));
318 else if (status == LIST_ITEM_STATUS_UNCHECKED)
320 r = listView.SetItemChecked(index, false);
321 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
323 r = __pGroupIndexMap->SetValue(__pGroupListPresentationModel->GetCategoryId(index), false);
324 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set value", GetErrorMessage(r));
327 Footer* pFooter = GetFooter();
329 int modifiedItems = 0;
330 int itemCount = listView.GetItemCount();
331 for(int count = 0; count < itemCount; count++)
333 if(__pGroupListPresentationModel->IsContactInCategory(*__pGroupIdList, count) != listView.IsItemChecked(count))
339 if(modifiedItems > 0)
341 pFooter->SetItemEnabled(1, true);
345 pFooter->SetItemEnabled(1, false);
347 pFooter->Invalidate(true);
352 GroupSelectorForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
357 GroupSelectorForm::UpdateBottomLabel(void)
359 int itemCount = __pListView->GetItemCount();
360 int selectedCount = 0;
361 bool isChecked = false;
363 for (int index = 0; index < itemCount; index++)
365 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
367 if (isChecked == true)
373 String selected = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
374 selected.Append(L" (");
375 selected.Append(selectedCount);
376 selected.Append(L")");
377 __pBottomLabel->SetText(selected);
379 if (selectedCount > 0)
381 __pBottomLabel->SetShowState(true);
382 __pListView->SetSize(__pListView->GetSize().width, GetClientAreaBounds().height - __pBottomLabel->GetHeight());
386 __pBottomLabel->SetShowState(false);
387 __pListView->SetSize(__pListView->GetSize().width, GetClientAreaBounds().height);
390 __pBottomLabel->Invalidate(false);
396 GroupSelectorForm::OnContactsChanged(void)
398 if (__isDonePressed == false)
400 SceneManager *pSceneManager = SceneManager::GetInstance();
401 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
404 __isDonePressed = false;
409 GroupSelectorForm::OnCategoriesChanged(void)
411 __pListView->UpdateList();
413 for (int index = 0; index < __pListView->GetItemCount(); index++)
415 bool isChecked = false;
417 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
419 if (isChecked == true)
421 result r = __pListView->SetItemChecked(index, true);
422 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
426 result r = __pListView->SetItemChecked(index, false);
427 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item unchecked", GetErrorMessage(r));
429 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), false);
433 Footer* pFooter = GetFooter();
435 int modifiedItems = 0;
436 int itemCount = __pListView->GetItemCount();
438 for(int count = 0; count < itemCount; count++)
440 if(__pGroupListPresentationModel->IsContactInCategory(*__pGroupIdList, count) != __pListView->IsItemChecked(count))
448 if(modifiedItems > 0)
450 pFooter->SetItemEnabled(1, true);
454 pFooter->SetItemEnabled(1, false);
457 pFooter->Invalidate(true);
460 __pListView->Invalidate(true);
465 GroupSelectorForm::OnForeground(void)
471 GroupSelectorForm::OnBackground(void)