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_MORE = 10;
41 static const int IDA_FOOTER_DONE = 11;
42 static const int IDA_FOOTER_CANCEL = 12;
43 static const int IDA_MORE_CREATE_GROUP = 13;
45 static const int H_ITEM = 112;
46 static const int X_MORE = 55;
47 static const int X_LIST_ITEM_TEXT_MARGIN = 32;
49 GroupSelectorForm::GroupSelectorForm(void)
50 : __pGroupListPresentationModel(null)
52 , __pBottomLabel(null)
54 , __pGroupIndexMap(null)
55 , __pGroupIdList(null)
59 GroupSelectorForm::~GroupSelectorForm(void)
64 GroupSelectorForm::Initialize(void)
66 Construct(L"IDL_GROUP_SELECTOR_FORM");
70 GroupSelectorForm::OnInitializing(void)
72 Footer* pFooter = GetFooter();
73 pFooter->SetItemEnabled(0, false);
74 pFooter->AddActionEventListener(*this);
75 SetFormBackEventListener(this);
77 __pGroupListPresentationModel = GroupListPresentationModel::GetInstance();
78 __pGroupListPresentationModel->AddGroupChangeListener(*this);
80 __pListView = static_cast<ListView*>(GetControl(L"IDC_LISTVIEW", false));
81 __pListView->SetItemProvider(*this);
82 __pListView->AddListViewItemEventListener(*this);
84 __pBottomLabel = static_cast<Label*>(GetControl(L"IDC_LABEL", false));
86 __pGroupIndexMap = new (std::nothrow) HashMapT<int, bool>();
87 __pGroupIndexMap->Construct(__pGroupListPresentationModel->GetCategoryCount());
89 __pOptionMenu = new (std::nothrow) OptionMenu();
90 __pOptionMenu->Construct();
91 __pOptionMenu->AddItem(ResourceManager::GetString(L"IDS_COM_BODY_CREATE"), IDA_MORE_CREATE_GROUP);
92 __pOptionMenu->AddActionEventListener(*this);
93 __pOptionMenu->SetShowState(false);
99 GroupSelectorForm::OnTerminating(void)
101 result r = E_SUCCESS;
103 if (__pGroupIndexMap)
105 __pGroupIndexMap->RemoveAll();
106 delete __pGroupIndexMap;
111 __pGroupIdList->RemoveAll(true);
112 delete __pGroupIdList;
115 if (__pGroupListPresentationModel != null)
117 __pGroupListPresentationModel->RemoveGroupChangeListener(*this);
120 delete __pOptionMenu;
126 GroupSelectorForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
128 result r = E_SUCCESS;
130 SceneManager* pSceneManager = SceneManager::GetInstance();
131 ArrayList* pList = null;
135 case IDA_MORE_CREATE_GROUP:
137 r = pSceneManager->GoForward(ForwardSceneTransition(IDSCN_GROUP_EDITOR, SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
138 TryCatch(r == E_SUCCESS, , "[%s] Unable to go forward", GetErrorMessage(r));
141 case IDA_FOOTER_DONE:
143 pList = new (std::nothrow) ArrayList();
144 pList->Construct(__pGroupIndexMap->GetCount());
146 for (int i = 0; i < __pGroupListPresentationModel->GetCategoryCount(); i++)
148 bool categoryValue = false;
149 RecordId categoryId = __pGroupListPresentationModel->GetCategoryId(i);
151 __pGroupIndexMap->GetValue(categoryId, categoryValue);
155 pList->Add(*(new (std::nothrow) Integer(categoryId)));
159 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT), pList);
160 TryCatch(r == E_SUCCESS, , "[%s] Unable to go backward", GetErrorMessage(r));
163 case IDA_FOOTER_CANCEL:
165 r = pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
166 TryCatch(r == E_SUCCESS, ,"[%s] Unable to go backward", GetErrorMessage(r));
178 pList->RemoveAll(true);
186 GroupSelectorForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId, const Tizen::Ui::Scenes::SceneId& currentSceneId, Tizen::Base::Collection::IList* pArgs)
188 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
189 pContactsApp->AddContactsAppChangeEventListener(*this);
191 SetFormMenuEventListener(this);
193 Footer *pFooter = GetFooter();
194 pFooter->SetMenuButton();
201 if (__pGroupIdList != null)
203 __pGroupIdList->RemoveAll(true);
204 delete __pGroupIdList;
207 __pGroupIdList = pArgs;
209 __pGroupIndexMap->RemoveAll();
211 int categoryCount = __pGroupListPresentationModel->GetCategoryCount();
212 for (int index = 0; index < categoryCount; index++)
214 if (__pGroupListPresentationModel->IsContactInCategory(*__pGroupIdList, index) == true)
216 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), true);
220 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), false);
224 __pListView->UpdateList();
226 for (int index = 0; index < __pListView->GetItemCount(); index++)
228 bool isChecked = false;
230 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
232 if (isChecked == true)
234 result r = __pListView->SetItemChecked(index, true);
235 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
243 GroupSelectorForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId, const Tizen::Ui::Scenes::SceneId& nextSceneId)
245 ContactsApp* pContactsApp = static_cast<ContactsApp*>(ContactsApp::GetInstance());
246 pContactsApp->RemoveContactsAppChangeEventListener(*this);
247 SetFormMenuEventListener(null);
251 GroupSelectorForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
253 SceneManager *pSceneManager = SceneManager::GetInstance();
254 pSceneManager->GoBackward(BackwardSceneTransition(SCENE_TRANSITION_ANIMATION_TYPE_RIGHT));
258 GroupSelectorForm::OnFormMenuRequested(Tizen::Ui::Controls::Form& source)
260 __pOptionMenu->SetShowState(true);
261 __pOptionMenu->Show();
264 Tizen::Ui::Controls::ListItemBase*
265 GroupSelectorForm::CreateItem(int index, int itemWidth)
267 result r = E_SUCCESS;
270 CustomItem* pItem = new (std::nothrow) CustomItem();
271 pItem->Construct(Dimension(itemWidth, H_ITEM), LIST_ANNEX_STYLE_MARK);
273 name = __pGroupListPresentationModel->GetCategoryName(index);
275 r = pItem->AddElement(Rectangle(0, 0, itemWidth - (ListItemBase::GetAnnexWidth(LIST_ANNEX_STYLE_MARK) + X_LIST_ITEM_TEXT_MARGIN), H_ITEM), index, name);
276 TryCatch(r == E_SUCCESS, , "[%s] Unable to add element", GetErrorMessage(r));
288 GroupSelectorForm::DeleteItem(int index, Tizen::Ui::Controls::ListItemBase* pItem, int itemWidth)
296 GroupSelectorForm::GetItemCount(void)
298 return __pGroupListPresentationModel->GetCategoryCount();
302 GroupSelectorForm::OnListViewContextItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListContextItemStatus state)
307 GroupSelectorForm::OnListViewItemStateChanged(Tizen::Ui::Controls::ListView& listView, int index, int elementId, Tizen::Ui::Controls::ListItemStatus status)
309 result r = E_SUCCESS;
311 if (status == LIST_ITEM_STATUS_CHECKED)
313 r = listView.SetItemChecked(index, true);
314 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
316 r = __pGroupIndexMap->SetValue(__pGroupListPresentationModel->GetCategoryId(index), true);
317 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set value", GetErrorMessage(r));
319 else if (status == LIST_ITEM_STATUS_UNCHECKED)
321 r = listView.SetItemChecked(index, false);
322 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
324 r = __pGroupIndexMap->SetValue(__pGroupListPresentationModel->GetCategoryId(index), false);
325 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set value", GetErrorMessage(r));
328 Footer* pFooter = GetFooter();
330 int modifiedItems = 0;
331 int itemCount = listView.GetItemCount();
332 for(int count = 0; count < itemCount; count++)
334 if(__pGroupListPresentationModel->IsContactInCategory(*__pGroupIdList, count) != listView.IsItemChecked(count))
340 if(modifiedItems > 0)
342 pFooter->SetItemEnabled(0, true);
346 pFooter->SetItemEnabled(0, false);
348 pFooter->Invalidate(true);
353 GroupSelectorForm::OnListViewItemSwept(Tizen::Ui::Controls::ListView& listView, int index, Tizen::Ui::Controls::SweepDirection direction)
358 GroupSelectorForm::UpdateBottomLabel(void)
360 int itemCount = __pListView->GetItemCount();
361 int selectedCount = 0;
362 bool isChecked = false;
364 for (int index = 0; index < itemCount; index++)
366 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
368 if (isChecked == true)
374 String selected = ResourceManager::GetString(L"IDS_COM_POP_SELECTED");
375 selected.Append(L" (");
376 selected.Append(selectedCount);
377 selected.Append(L")");
378 __pBottomLabel->SetText(selected);
381 if (selectedCount > 0)
383 __pBottomLabel->SetShowState(true);
384 __pListView->SetSize(__pListView->GetSize().width, GetClientAreaBounds().height - __pBottomLabel->GetHeight());
388 __pBottomLabel->SetShowState(false);
389 __pListView->SetSize(__pListView->GetSize().width, GetClientAreaBounds().height);
392 __pBottomLabel->Invalidate(false);
398 GroupSelectorForm::OnContactsChanged(void)
403 GroupSelectorForm::OnCategoriesChanged(void)
405 __pListView->UpdateList();
407 for (int index = 0; index < __pListView->GetItemCount(); index++)
409 bool isChecked = false;
411 __pGroupIndexMap->GetValue(__pGroupListPresentationModel->GetCategoryId(index), isChecked);
413 if (isChecked == true)
415 result r = __pListView->SetItemChecked(index, true);
416 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item checked", GetErrorMessage(r));
420 result r = __pListView->SetItemChecked(index, false);
421 TryReturnVoid(r == E_SUCCESS, "[%s] Unable to set item unchecked", GetErrorMessage(r));
423 __pGroupIndexMap->Add(__pGroupListPresentationModel->GetCategoryId(index), false);
427 __pListView->Invalidate(true);
431 GroupSelectorForm::OnForeground(void)
437 GroupSelectorForm::OnBackground(void)