Fix for N_SE-49387
[apps/osp/Calendar.git] / src / ClListPanel.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        ClListPanel.cpp
19  * @brief       This is the implementation file for the ListPanel class.
20  */
21
22 #include <FApp.h>
23 #include <FSocial.h>
24 #include "ClEventItem.h"
25 #include "ClEventListPresentationModel.h"
26 #include "ClGoToDatePopup.h"
27 #include "ClListPanel.h"
28 #include "ClMainForm.h"
29 #include "ClResourceManager.h"
30 #include "ClSharePopup.h"
31 #include "ClThreeButtonPopup.h"
32 #include "ClTwoButtonPopup.h"
33 #include "ClTypes.h"
34
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Base::Collection;
38 using namespace Tizen::Graphics;
39 using namespace Tizen::Social;
40 using namespace Tizen::System;
41 using namespace Tizen::Ui;
42 using namespace Tizen::Ui::Controls;
43 using namespace Tizen::Ui::Scenes;
44 using namespace Tizen::Locales;
45
46 static const RecordId ID_DEFAULT_BIRTHDAY_CALENDAR = 3;
47
48 static const int IDA_LIST_PANEL_CONTEXT_MENU_EDIT = 11511;
49 static const int IDA_LIST_PANEL_CONTEXT_MENU_SHARE = 11512;
50 static const int IDA_LIST_PANEL_CONTEXT_MENU_DELETE = 11513;
51
52 static const int ID_LIST_ITEM_BEFORE_AFTER = 100;
53
54 static const int ITEM_HEIGHT = 128;
55 static const int GROUP_ITEM_HEIGHT = 76;
56 static const int LEFT_MARGIN = 16;
57 static const int TOTAL_MARGIN = 32;
58 static const int EVENT_SUB_LIST_TEXT_SIZE = 32;
59 static const int TOP_BOTTOM_GROUP_ITEM_COUNT = 2;
60 static const int TOP_BOTTOM_ITEM_COUNT = 1;
61 static const int GROUP_ITEM_MINIMUM_HEIGHT = 0;
62 static const int PREVIOUS_DATE = -1;
63 static const int NEXT_DATE = 1;
64
65 static const unsigned int COLOR_GROUP_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
66 static const unsigned int COLOR_GROUP_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
67 static const unsigned int COLOR_GROUP_ITEM_TEXT = Color32<128, 128, 128>::Value;
68 static const unsigned int COLOR_GROUP_ITEM_TODAY_TEXT = Color32<59, 115, 182>::Value;
69 static const unsigned int COLOR_TOP_BOTTOM_ITEM_TEXT = Color32<42, 137, 194>::Value;
70 static const unsigned int COLOR_ITEM_BACKGROUND = Color32<248, 246, 239>::Value;
71 static const unsigned int COLOR_ITEM_TODAY_BACKGROUND = Color32<239, 236, 224>::Value;
72 static const unsigned int COLOR_ITEM_TEXT_PRESSED = Color32<255, 255, 255>::Value;
73 static const unsigned int COLOR_ITEM_DELETE_BACKGROUND = Color32<208, 82, 82>::Value;
74 static const unsigned int COLOR_ITEM_DELETE_PRESSED_BACKGROUND = Color32<194, 71, 71>::Value;
75
76 ListPanel::ListPanel(void)
77         : __pPm(null)
78         , __pGroupedListViewEventsList(null)
79         , __pContextItem(null)
80         , __pContextItemNoEdit(null)
81         , __pDateFormatter(null)
82         , __pSharePopup(null)
83         , __pThreeButtonPopup(null)
84         , __pTwoButtonPopup(null)
85         , __pGoToDatePopup(null)
86         , __fontSize(44.f)
87         , __itemHeight(112.f)
88 {
89 }
90
91 ListPanel::~ListPanel(void)
92 {
93
94 }
95
96 result
97 ListPanel::Initialize(void)
98 {
99         static const int _MIN_SIZE = 1;
100         return Construct(Rectangle(0, 0, _MIN_SIZE, _MIN_SIZE));
101 }
102
103 result
104 ListPanel::OnInitializing(void)
105 {
106         String fontSizeString;
107         SettingInfo::GetValue(L"http://tizen.org/setting/font.size", fontSizeString);
108
109         AppLogDebug("fontSize: %ls", fontSizeString.GetPointer());
110         if (fontSizeString == L"small")
111         {
112                 __fontSize = 36.f;
113                 __itemHeight = 120.f;
114         }
115         else if (fontSizeString == L"medium")
116         {
117                 __fontSize = 44.f;
118                 __itemHeight = 140.f;
119         }
120         else if (fontSizeString == L"large")
121         {
122                 __fontSize = 64.f;
123                 __itemHeight = 157.f;
124         }
125         else if (fontSizeString == L"huge")
126         {
127                 __fontSize = 81.f;
128                 __itemHeight = 176.f;
129         }
130         else if (fontSizeString == L"giant")
131         {
132                 __fontSize = 106.f;
133                 __itemHeight = 205.f;
134         }
135
136         __pPm = EventListPresentationModel::GetInstance();
137
138         Form* pForm = dynamic_cast<Form*>(GetParent());
139         AppAssertf(pForm != null, "[E_FAILURE] Unable to get Form.");
140
141         Rectangle clientAreaBounds = pForm->GetClientAreaBounds();
142         clientAreaBounds.x = 0;
143         clientAreaBounds.y = 0;
144         SetBounds(clientAreaBounds);
145
146         Rectangle bounds = GetBounds();
147         __pGroupedListViewEventsList = new (std::nothrow) GroupedListView();
148         __pGroupedListViewEventsList->Construct(Rectangle(0, 0, bounds.width, bounds.height),
149                                                                                         GROUPED_LIST_VIEW_STYLE_INDEXED, true, SCROLL_STYLE_FADE_OUT);
150         __pGroupedListViewEventsList->SetItemProvider(*this);
151
152         AddControl(__pGroupedListViewEventsList);
153
154         __pGroupedListViewEventsList->SetTextOfEmptyList(ResourceManager::GetString(IDS_CLD_BODY_NO_EVENTS));
155         __pGroupedListViewEventsList->SetBitmapOfEmptyList(ResourceManager::GetBitmapN(IDB_LIST_VIEW_NO_CONTENTS_TEXT));
156         __pGroupedListViewEventsList->AddGroupedListViewItemEventListener(*this);
157         Tizen::System::SettingInfo::AddSettingEventListener(*this);
158
159         __pDateFormatter = ResourceManager::CreateDateFormatterN(DATE_TIME_STYLE_SHORT);
160
161         __pSharePopup = new (std::nothrow) SharePopup();
162         __pSharePopup->Initialize();
163
164         __pThreeButtonPopup = new (std::nothrow) ThreeButtonPopup();
165         __pThreeButtonPopup->Initialize();
166
167         __pTwoButtonPopup = new (std::nothrow) TwoButtonPopup();
168         __pTwoButtonPopup->Initialize();
169
170         __pGoToDatePopup = new (std::nothrow) GoToDatePopup();
171         __pGoToDatePopup->Initialize();
172
173         return E_SUCCESS;
174 }
175
176 result
177 ListPanel::OnTerminating(void)
178 {
179         __pPm->RemoveCalendarEventChangedEventListener(*this);
180         __pPm->RemoveCurrentDateChangedEventListener(*this);
181
182         delete __pContextItem;
183         delete __pContextItemNoEdit;
184         delete __pDateFormatter;
185
186         if (__pSharePopup)
187         {
188                 __pSharePopup->Destroy();
189         }
190         if (__pThreeButtonPopup)
191         {
192                 __pThreeButtonPopup->Destroy();
193         }
194         if (__pTwoButtonPopup)
195         {
196                 __pTwoButtonPopup->Destroy();
197         }
198         if (__pGoToDatePopup)
199         {
200                 __pGoToDatePopup->Destroy();
201         }
202
203         Tizen::System::SettingInfo::RemoveSettingEventListener(*this);
204         return E_SUCCESS;
205 }
206
207 void
208 ListPanel::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
209 {
210         DateTime minRange;
211         DateTime maxRange;
212
213         switch (requestId)
214         {
215         case IDA_MAIN_FORM_HEADER_TODAY:
216                 __pPm->SetTodayToCurrentDate();
217
218                 minRange = __pPm->GetCurrentDate();
219                 minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), minRange.GetDay());
220
221                 maxRange = minRange;
222                 maxRange.AddMonths(NEXT_DATE);
223                 maxRange.AddSeconds(PREVIOUS_DATE);
224
225                 __pPm->SetViewType(VIEW_TYPE_LIST);
226                 __pPm->SetViewRange(minRange, maxRange);
227
228                 Update();
229                 __pGroupedListViewEventsList->ScrollToItem(0,0);
230                 break;
231         case IDA_MAIN_FORM_FOOTER_CREATE:
232         {
233                 LinkedList* pArgs = new (std::nothrow) LinkedList();
234                 pArgs->Add(new (std::nothrow) DateTime(__pPm->GetCurrentDate()));
235                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
236                                                                                                                                           SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
237                 break;
238         }
239                 break;
240         case IDA_SUB_MENU_GO_TO_DATE:
241                 __pGoToDatePopup->RequestPopup(__pPm->GetCurrentDate(), this);
242                 break;
243         case IDA_SUB_MENU_DELETE:
244                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_DELETER,
245                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
246                 break;
247         case IDA_SUB_MENU_SEARCH:
248                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_SEARCHER,
249                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
250                 break;
251         case IDA_SUB_MENU_CALENDARS:
252                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_CALENDAR_LIST,
253                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
254                 break;
255         case IDA_SUB_MENU_SETTING:
256                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_SETTING,
257                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT));
258                 break;
259         case IDA_VIEW_MENU_YEAR:
260                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_YEAR,
261                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
262                                                                                                                                                                         SCENE_HISTORY_OPTION_NO_HISTORY));
263                 break;
264         case IDA_VIEW_MENU_MONTH:
265                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_MONTH,
266                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
267                                                                                                                                                                         SCENE_HISTORY_OPTION_NO_HISTORY));
268                 break;
269         case IDA_VIEW_MENU_DAY:
270                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_DAY,
271                                                                                                                                                                         SCENE_TRANSITION_ANIMATION_TYPE_LEFT,
272                                                                                                                                                                         SCENE_HISTORY_OPTION_NO_HISTORY));
273                 break;
274         case IDA_GO_TO_DATE_POPUP_DONE:
275         {
276                 DateTime selectedDate = *static_cast<DateTime*>(pArgs->GetAt(0));
277                 DateTime currentDate = __pPm->GetCurrentDate();
278                 currentDate.SetValue(selectedDate.GetYear(), selectedDate.GetMonth(), selectedDate.GetDay(), currentDate.GetHour(), currentDate.GetMinute());
279                 __pPm->SetCurrentDate(currentDate);
280
281                 minRange = __pPm->GetCurrentDate();
282                 minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), minRange.GetDay());
283
284                 maxRange = minRange;
285                 maxRange.AddMonths(NEXT_DATE);
286                 maxRange.AddSeconds(PREVIOUS_DATE);
287
288                 __pPm->SetViewType(VIEW_TYPE_LIST);
289                 __pPm->SetViewRange(minRange, maxRange);
290
291                 Update();
292                 break;
293         }
294         case IDA_EVENT_POPUP_DELETE:
295                 __pPm->RemoveEvent(*static_cast<const CalEventInstance*>(pArgs->GetAt(0)), true);
296                 break;
297         case IDA_EVENT_POPUP_ONLY_THIS_EVENT_DELETE:
298                 __pPm->RemoveEvent(*static_cast<const CalEventInstance*>(pArgs->GetAt(0)), false);
299                 break;
300         case IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_DELETE:
301                 __pPm->RemoveEvent(*static_cast<const CalEventInstance*>(pArgs->GetAt(0)), true);
302                 break;
303         case IDA_EVENT_POPUP_ONLY_THIS_EVENT_EDIT:
304                 pArgs->Add(new (std::nothrow) Boolean(false));
305                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
306                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
307                 pArgs = null;
308                 break;
309         case IDA_EVENT_POPUP_ALL_REPETITIVE_EVENT_EDIT:
310                 pArgs->Add(new (std::nothrow) Boolean(true));
311                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
312                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pArgs);
313                 pArgs = null;
314                 break;
315         }
316
317         if (pArgs != null)
318         {
319                 pArgs->RemoveAll(true);
320                 delete pArgs;
321         }
322 }
323
324 int
325 ListPanel::GetGroupCount(void)
326 {
327         int groupCount = __pPm->GetWholeDayCount();
328         if (groupCount == 0 && __pPm->GetAllOriginalEventCount() == 0)
329         {
330                 return 0;
331         }
332         return groupCount + TOP_BOTTOM_GROUP_ITEM_COUNT;
333 }
334
335 int
336 ListPanel::GetItemCount(int groupIndex)
337 {
338         if (groupIndex == 0 || groupIndex == GetGroupCount() - 1)
339         {
340                 return TOP_BOTTOM_ITEM_COUNT;
341         }
342         else
343         {
344                 return __pPm->GetWholeEventCount(groupIndex - TOP_BOTTOM_ITEM_COUNT);
345         }
346 }
347
348 GroupItem*
349 ListPanel::CreateGroupItem(int groupIndex, int itemWidth)
350 {
351         GroupItem* pItem = new (std::nothrow) GroupItem();
352
353         DateTime date;
354
355         if (groupIndex == 0 || groupIndex == GetGroupCount() - 1)
356         {
357                 pItem->Construct(Dimension(itemWidth, GROUP_ITEM_MINIMUM_HEIGHT));
358                 __pGroupedListViewEventsList->SetItemEnabled(groupIndex, -1, false);
359                 return pItem;
360         }
361
362         pItem->Construct(Dimension(itemWidth, GROUP_ITEM_HEIGHT));
363
364         date = __pPm->GetDateTimeFromGroupIndex(groupIndex - TOP_BOTTOM_ITEM_COUNT);
365         pItem->SetElement(__pPm->GetDateString(date));
366
367         if (EventListPresentationModel::IsToday(date) == true)
368         {
369                 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TODAY_TEXT));
370         }
371         else
372         {
373                 pItem->SetTextColor(Color(COLOR_GROUP_ITEM_TEXT));
374         }
375         __pGroupedListViewEventsList->SetItemEnabled(groupIndex, -1, true);
376         return pItem;
377 }
378
379 bool
380 ListPanel::DeleteGroupItem(int groupIndex, GroupItem* pItem, int itemWidth)
381 {
382         delete pItem;
383         return true;
384 }
385
386 ListItemBase*
387 ListPanel::CreateItem(int groupIndex, int itemIndex, int itemWidth)
388 {
389         if (groupIndex == 0 || groupIndex == GetGroupCount() - 1)
390         {
391                 CustomItem* pItem = new (std::nothrow) CustomItem();
392
393                 String string;
394                 String dateString;
395                 if (groupIndex == 0)
396                 {
397                         __pDateFormatter->Format(__pPm->GetViewMinRange(), dateString);
398                         string = ResourceManager::GetString(IDS_LIST_VIEW_TAP_VIEW_BEFORE);
399                 }
400                 else
401                 {
402                         __pDateFormatter->Format(__pPm->GetViewMaxRange(), dateString);
403                         string = ResourceManager::GetString(IDS_LIST_VIEW_TAP_VIEW_AFTER);
404                 }
405                 string.Format(string.GetLength() + dateString.GetLength(), string.GetPointer(), dateString.GetPointer());
406
407                 pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), LIST_ANNEX_STYLE_NORMAL);
408                 pItem->AddElement(Rectangle(LEFT_MARGIN, 0, itemWidth - TOTAL_MARGIN, ITEM_HEIGHT)
409                                                                                 , ID_LIST_ITEM_BEFORE_AFTER, string, EVENT_SUB_LIST_TEXT_SIZE
410                                                                                 , Color(COLOR_TOP_BOTTOM_ITEM_TEXT), Color(COLOR_ITEM_TEXT_PRESSED), Color(COLOR_ITEM_TEXT_PRESSED));
411
412                 if (groupIndex == 0)
413                 {
414                         DateTime minDateTime = Calendarbook::GetMinDateTime();
415                         minDateTime.AddYears(1);
416                         __pGroupedListViewEventsList->SetItemEnabled(groupIndex, itemIndex, __pPm->GetViewMinRange() > minDateTime);
417                 }
418                 else
419                 {
420                         DateTime maxDateTime = Calendarbook::GetMaxDateTime();
421                         maxDateTime.AddYears(-1);
422                         __pGroupedListViewEventsList->SetItemEnabled(groupIndex, itemIndex, __pPm->GetViewMaxRange() < maxDateTime);
423                 }
424                 return pItem;
425         }
426         __pGroupedListViewEventsList->SetItemEnabled(groupIndex, itemIndex, true);
427
428         const CalEventInstance* pEvent = __pPm->GetEventWithWholeIndex(groupIndex - TOP_BOTTOM_ITEM_COUNT, itemIndex);
429         if (pEvent == null)
430         {
431                 return null;
432         }
433
434         EventItem* pItem = new (std::nothrow) EventItem();
435         pItem->Initialize(EVENT_ITEM_STYLE_NORMAL, itemWidth, __itemHeight);
436         pItem->SetTitle(pEvent->GetSubject());
437         pItem->SetFontSize(__fontSize);
438         pItem->SetCalendarColor(__pPm->GetCalendarColor(pEvent->GetCalendarId()));
439         if (pEvent->IsAllDayEvent() == true)
440         {
441                 pItem->SetAllDayEvent();
442         }
443         else
444         {
445                 DateTime startTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetStartTime());
446                 DateTime endTime = ResourceManager::ConvertUtcTimeToWallTime(pEvent->GetEndTime());
447                 pItem->SetDateRange(startTime, endTime, __pPm->GetDateTimeFromGroupIndex(groupIndex - TOP_BOTTOM_ITEM_COUNT), __pPm->GetTimeFormatter());
448         }
449
450         pItem->SetLocation(pEvent->GetLocation());
451         pItem->SetReminder(pEvent->HasReminder());
452         pItem->SetRepeat(pEvent->IsRecurring());
453         pItem->SetPriority(pEvent->GetPriority());
454
455         if (__pContextItem == null)
456         {
457                 ListContextItem* pContextItem = new (std::nothrow) ListContextItem();
458                 pContextItem->Construct();
459                 pContextItem->AddElement(IDA_LIST_PANEL_CONTEXT_MENU_EDIT,
460                                                                  ResourceManager::GetString(IDS_CLD_SK3_EDIT), true);
461                 pContextItem->AddElement(IDA_LIST_PANEL_CONTEXT_MENU_SHARE,
462                                                                  ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
463                 pContextItem->AddElement(IDA_LIST_PANEL_CONTEXT_MENU_DELETE,
464                                                                  ResourceManager::GetString(IDS_CLD_SK3_DELETE), true);
465                 pContextItem->SetElementBackgroundColor(IDA_LIST_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_DELETE_BACKGROUND));
466                 pContextItem->SetElementBackgroundColor(IDA_LIST_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_PRESSED, Color(COLOR_ITEM_DELETE_PRESSED_BACKGROUND));
467                 pContextItem->SetElementTextColor(IDA_LIST_PANEL_CONTEXT_MENU_DELETE, LIST_CONTEXT_ITEM_ELEMENT_STATUS_NORMAL, Color(COLOR_ITEM_TEXT_PRESSED));
468
469                 __pContextItem = pContextItem;
470         }
471         if (__pContextItemNoEdit == null)
472         {
473                 ListContextItem* pContextItem = new (std::nothrow) ListContextItem();
474                 pContextItem->Construct();
475                 pContextItem->AddElement(IDA_LIST_PANEL_CONTEXT_MENU_SHARE,
476                                                                  ResourceManager::GetString(IDS_COM_SK4_SHARE), true);
477
478                 __pContextItemNoEdit = pContextItem;
479         }
480         pItem->SetContextItem((pEvent->GetCalendarId() == ID_DEFAULT_BIRTHDAY_CALENDAR) ? __pContextItemNoEdit : __pContextItem);
481
482         pItem->UpdateElements();
483         return pItem;
484 }
485
486 bool
487 ListPanel::DeleteItem(int groupIndex, int itemIndex, ListItemBase* pItem, int itemWidth)
488 {
489         delete pItem;
490         return true;
491 }
492
493 void
494 ListPanel::OnGroupedListViewItemStateChanged(GroupedListView& listView,
495                                                                                          int groupIndex, int itemIndex, int elementId, ListItemStatus status)
496 {
497         int lastGroupIndex = listView.GetGroupCount() - 1;
498
499         if (groupIndex == 0)
500         {
501                 DateTime minRange = __pPm->GetViewMinRange();
502                 minRange.AddMonths(PREVIOUS_DATE);
503                 DateTime minDateTime = Calendarbook::GetMinDateTime();
504                 minDateTime.AddYears(1);
505                 if (minRange < minDateTime)
506                 {
507                         minRange = minDateTime;
508                 }
509
510                 __pPm->SetViewType(VIEW_TYPE_LIST);
511                 __pPm->SetViewRange(minRange, __pPm->GetViewMaxRange());
512
513                 Update();
514                 return;
515         }
516         else if (groupIndex == lastGroupIndex)
517         {
518                 DateTime maxRange = __pPm->GetViewMaxRange();
519                 maxRange.AddMonths(NEXT_DATE);
520                 DateTime maxDateTime = Calendarbook::GetMaxDateTime();
521                 maxDateTime.AddYears(-1);
522                 if (maxRange > maxDateTime)
523                 {
524                         maxRange = maxDateTime;
525                 }
526
527                 __pPm->SetViewType(VIEW_TYPE_LIST);
528                 __pPm->SetViewRange(__pPm->GetViewMinRange(), maxRange);
529
530                 Update();
531
532                 listView.ScrollToItem(listView.GetGroupCount() - 1, 0);
533                 listView.Invalidate(false);
534                 return;
535         }
536
537         if (status == LIST_ITEM_STATUS_SELECTED)
538         {
539                 LinkedList* pList = new (std::nothrow) LinkedList;
540                 CalEventInstance* pEventInstance = new (std::nothrow) CalEventInstance(*__pPm->GetEventWithWholeIndex(groupIndex - (TOP_BOTTOM_GROUP_ITEM_COUNT / 2), itemIndex));
541                 pList->Add(pEventInstance);
542                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_DETAILS,
543                                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
544         }
545 }
546
547 void
548 ListPanel::OnGroupedListViewItemSwept(GroupedListView& listView, int groupIndex, int itemIndex, SweepDirection direction)
549 {
550
551 }
552
553 void
554 ListPanel::OnGroupedListViewContextItemStateChanged(GroupedListView& listView,
555                                                                                                         int groupIndex, int itemIndex, int elementId, ListContextItemStatus status)
556 {
557         if (status == LIST_CONTEXT_ITEM_STATUS_SELECTED)
558         {
559                 int actualGroupIndex = groupIndex - (TOP_BOTTOM_GROUP_ITEM_COUNT / 2);
560                 const CalEventInstance* pEventInstance = __pPm->GetEventWithWholeIndex(actualGroupIndex, itemIndex);
561                 switch (elementId)
562                 {
563                 case IDA_LIST_PANEL_CONTEXT_MENU_EDIT:
564                         if (__pPm->IsEditableAllEvent(*pEventInstance))
565                         {
566                                 __pThreeButtonPopup->RequestPopup(THREE_BUTTON_POPUP_STYLE_EDIT, this, pEventInstance);
567                         }
568                         else
569                         {
570                                 LinkedList* pList = new (std::nothrow) LinkedList(SingleObjectDeleter);
571                                 CalEventInstance* pEventInstance = new (std::nothrow) CalEventInstance(*__pPm->GetEventWithWholeIndex(groupIndex - (TOP_BOTTOM_GROUP_ITEM_COUNT / 2), itemIndex));
572                                 pList->Add(pEventInstance);
573                                 pList->Add(new (std::nothrow) Boolean(true));
574                                 SceneManager::GetInstance()->GoForward(ForwardSceneTransition(IDSCN_EVENT_EDITOR,
575                                                                                                                                                   SCENE_TRANSITION_ANIMATION_TYPE_LEFT), pList);
576                         }
577                         break;
578                 case IDA_LIST_PANEL_CONTEXT_MENU_SHARE:
579                         __pSharePopup->RequestShare(__pPm->GetEventWithWholeIndex(groupIndex - (TOP_BOTTOM_GROUP_ITEM_COUNT / 2), itemIndex)->GetOriginalEventId());
580                         break;
581                 case IDA_LIST_PANEL_CONTEXT_MENU_DELETE:
582                         if (pEventInstance->IsRecurring())
583                         {
584                                 __pThreeButtonPopup->RequestPopup(THREE_BUTTON_POPUP_STYLE_DELETE, this, pEventInstance);
585                         }
586                         else
587                         {
588                                 __pTwoButtonPopup->RequestPopup(TWO_BUTTON_POPUP_STYLE_SINGLE_EVENT, this, pEventInstance);
589                         }
590                         break;
591                 }
592         }
593 }
594
595 void
596 ListPanel::OnGroupedListViewItemLongPressed(GroupedListView& listView,
597                                                                                         int groupIndex, int itemIndex, int elementId, bool& invokeListViewItemCallback)
598 {
599
600 }
601
602 void
603 ListPanel::OnGroupedListViewGroupItemSelected(GroupedListView& listView, int groupIndex)
604 {
605         if (listView.IsGroupExpanded(groupIndex) == true)
606         {
607                 listView.CollapseGroup(groupIndex);
608         }
609         else
610         {
611                 listView.ExpandGroup(groupIndex);
612         }
613 }
614
615 void
616 ListPanel::OnSceneActivatedN(const SceneId& previousSceneId, const SceneId& currentSceneId, IList* pArgs)
617 {
618         AppLogDebug("Enter.");
619         if (pArgs != null)
620         {
621                 pArgs->RemoveAll(true);
622                 delete pArgs;
623         }
624
625         if (__pPm->GetViewType() != VIEW_TYPE_LIST)
626         {
627                 DateTime minRange = __pPm->GetCurrentDate();
628                 minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), minRange.GetDay());
629                 DateTime maxRange = minRange;
630                 maxRange.AddMonths(NEXT_DATE);
631                 maxRange.AddSeconds(PREVIOUS_DATE);
632
633                 __pPm->SetViewType(VIEW_TYPE_LIST);
634                 __pPm->SetViewRange(minRange, maxRange);
635         }
636         __pPm->AddCalendarEventChangedEventListener(*this);
637         __pPm->AddCurrentDateChangedEventListener(*this);
638
639         Form* pForm = dynamic_cast<Form*>(GetParent());
640         if (pForm)
641         {
642                 Header* pHeader = pForm->GetHeader();
643                 if (pHeader)
644                 {
645                         pHeader->SetTitleText(__pPm->GetTitleString());
646                 }
647         }
648
649         Update();
650         AppLogDebug("Exit.");
651 }
652
653 void
654 ListPanel::OnSceneDeactivated(const SceneId& currentSceneId, const SceneId& nextSceneId)
655 {
656         AppLogDebug("Enter.");
657         __pPm->RemoveCalendarEventChangedEventListener(*this);
658         __pPm->RemoveCurrentDateChangedEventListener(*this);
659         AppLogDebug("Exit.");
660 }
661
662 void
663 ListPanel::OnSettingChanged(Tizen::Base::String& key)
664 {
665         if (key.Equals(KEY_SYSTEM_DATE,false))
666         {
667                 __pGroupedListViewEventsList->UpdateList();
668         }
669 }
670
671 void
672 ListPanel::OnActionPerformed(const Control& source, int actionId)
673 {
674 }
675
676 void
677 ListPanel::OnCalendarEventChanged(void)
678 {
679         AppLogDebug("Enter.");
680         if (__pPm->GetViewType() != VIEW_TYPE_LIST)
681         {
682                 DateTime minRange = __pPm->GetCurrentDate();
683                 minRange.SetValue(minRange.GetYear(), minRange.GetMonth(), minRange.GetDay());
684                 DateTime maxRange = minRange;
685
686                 maxRange.AddMonths(NEXT_DATE);
687                 maxRange.AddSeconds(PREVIOUS_DATE);
688                 __pPm->SetViewType(VIEW_TYPE_LIST);
689                 __pPm->SetViewRange(minRange, maxRange);
690         }
691         
692         Update();
693         AppLogDebug("Exit.");
694 }
695
696 void
697 ListPanel::OnCurrentDateChanged(const DateTime& currentDate, const DateTime& prevDate)
698 {
699         AppLogDebug("Enter.");
700         if (EventListPresentationModel::IsSameDay(currentDate, prevDate) == false)
701         {
702                 Update();
703         }
704         AppLogDebug("Exit.");
705 }
706
707 result
708 ListPanel::Update(void)
709 {
710         result r = __pGroupedListViewEventsList->UpdateList();
711
712         if (r == E_SUCCESS)
713         {
714                 if (__pGroupedListViewEventsList->IsGroupExpanded(GetGroupCount() - 1) == false)
715                 {
716                         __pGroupedListViewEventsList->ExpandGroup(GetGroupCount() - 1);
717                 }
718         }
719
720         return r;
721 }