2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Flora License, Version 1.0 (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 PhnSettingsDeleteListForm.cpp
19 * @brief Settings Delete list form
22 #include "PhnAppUtility.h"
23 #include "PhnCustomItemBgElement.h"
24 #include "PhnSettingsConstants.h"
25 #include "PhnSettingsDeleteListForm.h"
26 #include "PhnSettingsPresentationModel.h"
27 #include "PhnSceneRegister.h"
30 using namespace Tizen::App;
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Graphics;
34 using namespace Tizen::Ui;
35 using namespace Tizen::Ui::Controls;
36 using namespace Tizen::Ui::Scenes;
39 const int IDI_SELECT_ALL_ITEM_ELEMENT_ID = 20010;
40 //by default, list has 1 item
41 const int IDI_DEFAULT_LIST_COUNT = 1;
42 //Element Id for main text used in List view item
43 const int IDI_LIST_MAIN_TXT_ITEMID = 1000;
44 static const wchar_t* IDL_SETTINGS_DELETE_LIST_FORM = L"IDL_SETTINGS_DELETE_LIST_FORM";
45 static const wchar_t* IDC_LABEL_DELETE_SELECTED = L"IDC_LABEL_DELETE_SELECTED";
47 static const unsigned int COLOR_DELETE_LABEL_SELECTED = Color32<215, 225, 232, 255>::Value;
49 SettingsDeleteListForm::SettingsDeleteListForm(ListOfType listOfType)
50 : __listOfType(listOfType)
51 , __pNumbersList(null)
53 , __pSettingsPresentor(null)
54 , __checkedItemCount(0)
55 , __pSelectedLabel(null)
59 SettingsDeleteListForm::~SettingsDeleteListForm(void)
64 SettingsDeleteListForm::Initialize(void)
66 Construct(IDL_SETTINGS_DELETE_LIST_FORM);
70 SettingsDeleteListForm::OnInitializing(void)
74 __pSettingsPresentor = SettingsPresentationModel::GetInstance();
81 title.Append(AppUtility::GetResourceString(IDS_DELETE_NUMBER_TITLE));
87 title.Append(AppUtility::GetResourceString(IDS_DELETE_MSGS_TITLE));
96 Header* pHeader = GetHeader();
99 pHeader->SetTitleText(title);
104 //initialize list view
105 r = InitializeListView();
110 SettingsDeleteListForm::InitializeSelectLabel()
112 __pSelectedLabel = static_cast<Label*>(GetControl(IDC_LABEL_DELETE_SELECTED));
113 if(__pSelectedLabel != null)
115 if(__listOfType == LISTOF_NUMBERS)
117 __pSelectedLabel->SetText(AppUtility::GetResourceString(IDS_SELECT_NUMBER));
119 else if(__listOfType == LISTOF_MESSAGES)
121 __pSelectedLabel->SetText(AppUtility::GetResourceString(IDS_SELECT_MESSAGE));
124 SetControlAlwaysOnTop(*__pSelectedLabel,true);
125 __pSelectedLabel->SetBackgroundColor(COLOR_DELETE_LABEL_SELECTED);
126 __pSelectedLabel->SetShowState(true);
130 SettingsDeleteListForm::InitializeFooter(void)
132 Footer* pFooter = GetFooter();
135 pFooter->SetStyle(FOOTER_STYLE_BUTTON_ICON_TEXT);
137 String footerItemName(L"");
139 footerItemName.Append(AppUtility::GetResourceString(IDS_DELETE_BTN_STRING));
140 FooterItem delFooterItem;
141 delFooterItem.Construct(IDA_DELETE_FOOTER_ITEMID);
142 delFooterItem.SetText(footerItemName);
143 pFooter->InsertItemAt(0, delFooterItem);
144 pFooter->SetItemEnabled(0, false);
147 Bitmap* pNormalBmp = AppUtility::GetBitmapFromResourcesN(IDB_CANCEL_FOOTER_ITEM, W_HDR_FTR_ICON, H_HDR_FTR_ICON);
148 ButtonItem cancelButtonItem;
149 cancelButtonItem.Construct(BUTTON_ITEM_STYLE_ICON, IDA_CANCEL_FOOTER_ITEMID);
150 cancelButtonItem.SetIcon(BUTTON_ITEM_STATUS_NORMAL, pNormalBmp);
151 cancelButtonItem.SetIcon(BUTTON_ITEM_STATUS_PRESSED, pNormalBmp);
152 pFooter->SetButton(BUTTON_POSITION_RIGHT, cancelButtonItem);
156 pFooter->AddActionEventListener(*this);
161 SettingsDeleteListForm::OnTerminating(void)
163 result r = E_SUCCESS;
167 delete __pNumbersList;
168 __pNumbersList = null;
176 __pSettingsPresentor = null;
181 SettingsDeleteListForm::OnActionPerformed(const Control& source, int actionId)
183 SceneManager* pSceneManager = SceneManager::GetInstance();
184 AppAssert(pSceneManager != null);
188 case IDA_CANCEL_FOOTER_ITEMID:
190 if (__listOfType == LISTOF_NUMBERS)
192 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTLIST_MENU), null);
196 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTMSGS_MENU), null);
200 case IDA_DELETE_FOOTER_ITEMID:
202 if (__listOfType == LISTOF_NUMBERS)
204 DeleteRejectNumbersList();
205 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTLIST_MENU), null);
209 DeleteRejectMsgsList();
210 pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SCENE_CALL_REJECTMSGS_MENU), null);
221 SettingsDeleteListForm::DeleteRejectNumbersList(void)
223 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
224 if (pDelListView != null)
226 for (int index = 1; index < pDelListView->GetItemCount(); index++)
228 if (pDelListView->IsItemChecked(index) == true)
230 CallRejectInfo rejectInfo;
231 __pNumbersList->GetAt(index-1, rejectInfo);
232 __pSettingsPresentor->RemoveCallRejectRow(rejectInfo.rowId);
239 SettingsDeleteListForm::DeleteRejectMsgsList(void)
241 IListT<int> *pMsgKeyList = __pMsgsMap->GetKeysN();
242 //list of deleted keys
243 ArrayListT<int> *pDelKeyList = new (std::nothrow) ArrayListT<int>();
244 pDelKeyList->Construct();
245 //fetch checked messages to be deleted
246 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
247 if (pDelListView != null)
249 for (int index = 1; index < pDelListView->GetItemCount(); index++)
251 if (pDelListView->IsItemChecked(index) == true)
254 if(pMsgKeyList->GetAt(index-1, key) == E_SUCCESS)
256 pDelKeyList->Add(key);
263 if(pDelKeyList->GetCount() > 0)
265 __pSettingsPresentor->RemoveRejectMessage(*pDelKeyList);
271 SettingsDeleteListForm::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
273 // Add your scene activate code here
274 switch (__listOfType)
278 //fetch "reject numbers" or "reject msg" list
279 FetchNumbersRejectList();
283 case LISTOF_MESSAGES:
285 //fetch "reject msgs" list
286 FetchRejectMsgsList();
294 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
295 if (pDelListView != null)
297 pDelListView->UpdateList();
298 int itemCount = pDelListView->GetItemCount();
299 for(int itemIndex = itemCount-1; itemIndex >=0 ; itemIndex--)
301 bool isSelected = pDelListView->IsItemChecked(itemIndex);
302 if(isSelected == true)
304 pDelListView->SetItemChecked(itemIndex,false);
308 __checkedItemCount = 0;
309 Footer* pFooter = GetFooter();
312 pFooter->SetItemEnabled(0, false);
313 pFooter->Invalidate(true);
315 //to show selected msg or numbers
316 InitializeSelectLabel();
320 SettingsDeleteListForm::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
325 SettingsDeleteListForm::FetchNumbersRejectList(void)
327 if (__pNumbersList != null)
329 delete __pNumbersList;
330 __pNumbersList = null;
332 __pNumbersList = static_cast<ArrayListT<CallRejectInfo>*>(__pSettingsPresentor->GetCallRejectList());
336 SettingsDeleteListForm::FetchRejectMsgsList(void)
338 if (__pMsgsMap != null)
343 //item to be fetched from Db
344 __pMsgsMap = __pSettingsPresentor->GetRejectMessageListN();
348 SettingsDeleteListForm::InitializeListView(void)
350 result r = E_FAILURE;
351 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
352 if (pDelListView != null)
354 pDelListView->SetBackgroundColor(this->GetBackgroundColor());
355 pDelListView->AddListViewItemEventListener(*this);
356 r = pDelListView->SetItemProvider(*this);
362 SettingsDeleteListForm::OnListViewItemStateChanged(ListView& listView, int index, int elementId, ListItemStatus status)
368 case 0://"Select All"
370 bool isSelect = (status == LIST_ITEM_STATUS_CHECKED);
371 SelectAllItems(isSelect);
377 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
378 bool isItemUnchecked = (status == LIST_ITEM_STATUS_UNCHECKED);
379 if(isItemUnchecked == true)
381 __checkedItemCount--;
382 //un-check "Select All", if it was checked earlier and any other item is unchecked.
383 if(pDelListView->IsItemChecked(0) == true)
385 pDelListView->SetItemChecked(0,false);
390 __checkedItemCount++;
391 if(pDelListView->GetItemCount() == (__checkedItemCount+1))
393 pDelListView->SetItemChecked(0,true);
396 if (__checkedItemCount == 0)
399 if(__listOfType == LISTOF_NUMBERS)
401 selStr = AppUtility::GetResourceString(IDS_SELECT_NUMBER);
403 else if(__listOfType == LISTOF_MESSAGES)
405 selStr = AppUtility::GetResourceString(IDS_SELECT_MESSAGE);
407 __pSelectedLabel->SetText(selStr);
411 if(__listOfType == LISTOF_NUMBERS)
413 //selStr = AppUtility::GetResourceString(IDS_NUMBER_SELECTED);
414 if(__checkedItemCount > 1)
416 selStr = AppUtility::GetResourceString(IDS_NUMBERS_SELECTED);
420 selStr = AppUtility::GetResourceString(IDS_NUMBER_SELECTED);
423 else if(__listOfType == LISTOF_MESSAGES)
425 if(__checkedItemCount > 1)
427 selStr = AppUtility::GetResourceString(IDS_MESSAGES_SELECTED);
431 selStr = AppUtility::GetResourceString(IDS_MESSAGE_SELECTED);
435 text.Format(100, selStr.GetPointer(), __checkedItemCount);
436 __pSelectedLabel->SetText(text);
438 pDelListView->Invalidate(true);
439 __pSelectedLabel->Invalidate(false);
444 Footer* pFooter = GetFooter();
447 if(__checkedItemCount > 0)
449 pFooter->SetItemEnabled(0, true);
453 pFooter->SetItemEnabled(0, false);
455 pFooter->Invalidate(true);
460 SettingsDeleteListForm::OnListViewItemSwept(ListView& listView, int index, SweepDirection direction)
464 SettingsDeleteListForm::OnListViewContextItemStateChanged(ListView& listView, int index, int elementId, ListContextItemStatus state)
469 SettingsDeleteListForm::OnListViewItemLongPressed(ListView& listView, int index, int elementId, bool& invokeListViewItemCallback)
474 SettingsDeleteListForm::SelectAllItems(bool isSelect)
478 ListView* pDelListView = static_cast<ListView*>(GetControl(IDC_LISTVIEW));
479 int itemCount = pDelListView->GetItemCount();
480 for (int index = 1; index < itemCount; index++)
482 pDelListView->SetItemChecked(index,isSelect);
484 pDelListView->RequestRedraw();
487 __checkedItemCount = pDelListView->GetItemCount()-1;
488 if(__listOfType == LISTOF_NUMBERS)
490 if(__checkedItemCount > 1)
492 selStr = AppUtility::GetResourceString(IDS_NUMBERS_SELECTED);
496 selStr = AppUtility::GetResourceString(IDS_NUMBER_SELECTED);
500 else if(__listOfType == LISTOF_MESSAGES)
502 if(__checkedItemCount > 1)
504 selStr = AppUtility::GetResourceString(IDS_MESSAGES_SELECTED);
508 selStr = AppUtility::GetResourceString(IDS_MESSAGE_SELECTED);
511 text.Format(100, selStr.GetPointer(), __checkedItemCount);
512 __pSelectedLabel->SetText(text);
516 __checkedItemCount = 0;
517 if(__listOfType == LISTOF_NUMBERS)
519 selStr = AppUtility::GetResourceString(IDS_SELECT_NUMBER);
521 else if(__listOfType == LISTOF_MESSAGES)
523 selStr = AppUtility::GetResourceString(IDS_SELECT_MESSAGE);
525 __pSelectedLabel->SetText(selStr);
529 __pSelectedLabel->Invalidate(false);
534 SettingsDeleteListForm::GetItemCount(void)
536 int itemCount = IDI_DEFAULT_LIST_COUNT;
538 switch (__listOfType)
542 if (__pNumbersList != null)
544 itemCount += __pNumbersList->GetCount();
549 case LISTOF_MESSAGES:
551 if (__pMsgsMap != null)
553 itemCount += __pMsgsMap->GetCount();
565 SettingsDeleteListForm::CreateItem(int index, int itemWidth)
567 CustomItem* pItem = null;
571 //Default Item - "SELECT ALL"
572 pItem = new (std::nothrow) CustomItem();
573 pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), LIST_ANNEX_STYLE_MARK);
575 String itemName = AppUtility::GetResourceString(IDS_SELECT_ALL_LIST_ITEM_STRING);
576 pItem->AddElement(Rectangle(X_DEL_LIST_ELEMENT, Y_DEL_LIST_ELEMENT, W_DELETE_LIST_ITEM, H_LIST_NORMAL_MENU_ITEM), IDI_SELECT_ALL_ITEM_ELEMENT_ID, itemName, false);
577 pItem->SetElementTextHorizontalAlignment(IDI_LIST_MAIN_TXT_ITEMID, ALIGNMENT_LEFT);
578 pItem->SetElementTextVerticalAlignment(IDI_LIST_MAIN_TXT_ITEMID, ALIGNMENT_MIDDLE);
579 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, COLOR_SELECTALL_ITEM_BG);
583 switch (__listOfType)
586 pItem = CreateListItemForNumbers(index, itemWidth);
589 case LISTOF_MESSAGES:
590 pItem = CreateListItemForMsgs(index, itemWidth);
603 SettingsDeleteListForm::CreateListItemForNumbers(int index, int itemWidth)
605 CustomItem* pItem = null;
606 int listIndex = index - 1;
608 if (__pNumbersList != null && listIndex < __pNumbersList->GetCount())
612 CallRejectInfo rejectInfo;
613 __pNumbersList->GetAt(listIndex, rejectInfo);
614 number.Append(rejectInfo.phoneNumber);
616 pItem = new (std::nothrow) CustomItem();
617 pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), LIST_ANNEX_STYLE_MARK);
619 pItem->AddElement(Rectangle(X_DEL_LIST_ELEMENT, Y_DEL_LIST_ELEMENT, W_DELETE_LIST_ITEM, H_LIST_NORMAL_MENU_ITEM), listIndex, number,
620 FONT_SIZE_MAIN_TXT, COLOR_NORMAL_SUB_TXT, COLOR_PRESS_MAIN_TXT, COLOR_PRESS_MAIN_TXT, false);
621 pItem->SetElementTextHorizontalAlignment(listIndex, ALIGNMENT_LEFT);
622 pItem->SetElementTextVerticalAlignment(listIndex, ALIGNMENT_MIDDLE);
623 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, COLOR_NORMAL_ITEM_BG);
624 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, COLOR_PRESS_ITEM_BG);
630 SettingsDeleteListForm::CreateListItemForMsgs(int index, int itemWidth)
632 CustomItem* pItem = null;
633 int listIndex = index - 1;
635 if (__pMsgsMap != null && listIndex < __pMsgsMap->GetCount())
637 IListT<String> *pMsgList = __pMsgsMap->GetValuesN();
642 pMsgList->GetAt(listIndex, message);
645 pItem = new (std::nothrow) CustomItem();
646 pItem->Construct(Dimension(itemWidth, H_LIST_NORMAL_MENU_ITEM), LIST_ANNEX_STYLE_MARK);
648 pItem->AddElement(Rectangle(X_DEL_LIST_ELEMENT, Y_DEL_LIST_ELEMENT, W_DELETE_LIST_ITEM, H_LIST_NORMAL_MENU_ITEM), listIndex, message,
649 FONT_SIZE_MAIN_TXT, COLOR_NORMAL_SUB_TXT, COLOR_PRESS_MAIN_TXT, COLOR_PRESS_MAIN_TXT, false);
650 pItem->SetElementTextHorizontalAlignment(listIndex, ALIGNMENT_LEFT);
651 pItem->SetElementTextVerticalAlignment(listIndex, ALIGNMENT_MIDDLE);
652 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_NORMAL, COLOR_NORMAL_ITEM_BG);
653 pItem->SetBackgroundColor(LIST_ITEM_DRAWING_STATUS_PRESSED, COLOR_PRESS_ITEM_BG);
661 SettingsDeleteListForm::DeleteItem(int index, ListItemBase* pItem, int itemWidth)