Applied latest source code
[apps/native/preloaded/MusicPlayer.git] / src / MpArtistContentPickerPanel.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                MpArtistContentPickerPanel.cpp
19  * @brief               This is the implementation file for ArtistContentPickerPanel class.
20  */
21
22 #include "MpArtistContentPickerPanel.h"
23
24 using namespace Tizen::Base;
25 using namespace Tizen::Base::Collection;
26 using namespace Tizen::Content;
27 using namespace Tizen::Graphics;
28 using namespace Tizen::Social;
29 using namespace Tizen::Ui;
30 using namespace Tizen::Ui::Controls;
31 using namespace Tizen::Ui::Scenes;
32
33 ArtistContentPickerPanel::ArtistContentPickerPanel(void)
34         : __checkedItemCount(0)
35         , __pContentTableView(null)
36         , __pSelectAllCheckedButton(null)
37         , __pCheckedCountLabel(null)
38 {
39         AppLogDebug("ENTER");
40         AppLogDebug("EXIT");
41 }
42
43 ArtistContentPickerPanel::~ArtistContentPickerPanel(void)
44 {
45         AppLogDebug("ENTER");
46         AppLogDebug("EXIT");
47 }
48
49 bool
50 ArtistContentPickerPanel::Initialize(void)
51 {
52         AppLogDebug("ENTER");
53         result r = Construct(Rectangle(INIT_VALUE, INIT_VALUE, INIT_VALUE, INIT_VALUE));
54         if (IsFailed(r))
55         {
56                 return false;
57         }
58         AppLogDebug("EXIT");
59         return true;
60 }
61
62 result
63 ArtistContentPickerPanel::OnInitializing(void)
64 {
65         AppLogDebug("ENTER");
66         Form* pForm = dynamic_cast<Form*>(GetParent());
67         AppAssert(pForm);
68
69         int width = pForm->GetClientAreaBounds().width;
70         int height = pForm->GetClientAreaBounds().height;
71
72         SetBounds(INIT_VALUE, INIT_VALUE, width, height);
73
74         __pContentTableView = CommonUtil::CreateEditorTableView(width, height);
75         __pContentTableView->AddTableViewItemEventListener(*this);
76         __pContentTableView->SetItemProvider(this);
77
78         __pSelectAllCheckedButton = CommonUtil::CreateSelectAllCheckedButton(width);
79         __pSelectAllCheckedButton->AddActionEventListener(*this);
80
81         __pCheckedCountLabel = CommonUtil::CreateCheckedCountLabel(width, height);
82         __pCheckedCountLabel->SetShowState(false);
83
84         AddControl(__pContentTableView);
85         AddControl(__pSelectAllCheckedButton);
86         AddControl(__pCheckedCountLabel);
87
88         __pPresentationModel = ArtistListPresentationModel::GetInstance();
89
90         AppLogDebug("EXIT");
91         return E_SUCCESS;
92 }
93
94 result
95 ArtistContentPickerPanel::OnTerminating(void)
96 {
97         AppLogDebug("ENTER");
98         AppLogDebug("EXIT");
99         return E_SUCCESS;
100 }
101
102 void
103 ArtistContentPickerPanel::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
104 {
105         AppLogDebug("ENTER");
106         SceneManager* pSceneManager = SceneManager::GetInstance();
107         AppAssert(pSceneManager);
108
109         int totalCount = __pPresentationModel->GetArtistContentListCount();
110
111         switch (actionId)
112         {
113         case IDA_CHECK_BUTTON:
114                 {
115                         __checkedItemCount = totalCount;
116                         CommonUtil::SetAllCheckState(true, *__pContentTableView, totalCount);
117                         Form* pForm = dynamic_cast<Form*>(GetParent());
118                         AppAssert(pForm);
119                         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
120                         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount, actionId);
121                 }
122                 break;
123
124         case IDA_UNCHECK_BUTTON:
125                 {
126                         __checkedItemCount = INIT_VALUE;
127                         CommonUtil::SetAllCheckState(false, *__pContentTableView, totalCount);
128                         Form* pForm = dynamic_cast<Form*>(GetParent());
129                         AppAssert(pForm);
130                         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
131                         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount, actionId);
132                 }
133                 break;
134
135         case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
136                 {
137                         if (__checkedItemCount <= 0)
138                         {
139                                 return;
140                         }
141
142                         int totalCount = __pPresentationModel->GetArtistContentListCount();
143                         for (int iCount = 0; iCount < totalCount; iCount++)
144                         {
145                                 if (__pContentTableView->IsItemChecked(iCount) == true)
146                                 {
147                                         __pPresentationModel->AddContent(CommonUtil::GetAddtoPlaylistName(), iCount);
148                                         __pContentTableView->SetItemChecked(iCount, false);
149                                 }
150                         }
151
152                         Form* pForm = dynamic_cast<Form*>(GetParent());
153                         AppAssert(pForm);
154                         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount, actionId);
155
156                         __checkedItemCount = 0;
157                         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
158                         CommonUtil::ShowSelectAllCheckButton(*__pSelectAllCheckedButton);
159                         CommonUtil::SetAddtoPlaylistState(false);
160
161                         Invalidate(true);
162
163                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYLIST_LIST,
164                                                                                                                 SCENE_TRANSITION_ANIMATION_TYPE_NONE,
165                                                                                                                 SCENE_HISTORY_OPTION_NO_HISTORY,
166                                                                                                                 SCENE_DESTROY_OPTION_DESTROY));
167                 }
168                 break;
169
170         case IDA_FOOTER_BUTTON_CANCEL:
171                 {
172                         Form* pForm = dynamic_cast<Form*>(GetParent());
173                         AppAssert(pForm);
174                         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount, actionId);
175                         pSceneManager->GoBackward(BackwardSceneTransition());
176                 }
177                 break;
178
179         default:
180                 break;
181         }
182         AppLogDebug("EXIT");
183 }
184
185 void
186 ArtistContentPickerPanel::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
187                                                         const Tizen::Ui::Scenes::SceneId& currentSceneId,
188                                                         Tizen::Base::Collection::IList* pArgs)
189 {
190         AppLogDebug("ENTER");
191         Form* pForm = dynamic_cast<Form*>(GetParent());
192         AppAssert(pForm);
193
194         Footer* pFooter = CommonUtil::CreateAddtoPlaylistPickerFooter(*pForm);
195         pFooter->AddActionEventListener(*this);
196         if (pArgs != null && (previousSceneId.Equals(IDSCN_ARTIST_PICKER, true)))
197         {
198                 String* pTemp = static_cast<String*>(pArgs->GetAt(0));
199                 __pPresentationModel->InitializeArtistAlbumList(*pTemp);
200         }
201
202         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount);
203
204         if (pArgs != null)
205         {
206                 pArgs->RemoveAll(true);
207                 delete pArgs;
208         }
209         AppLogDebug("EXIT");
210 }
211
212 void
213 ArtistContentPickerPanel::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
214                                                                                         const Tizen::Ui::Scenes::SceneId& nextSceneId)
215 {
216         AppLogDebug("ENTER");
217         Form* pForm = dynamic_cast<Form*>(GetParent());
218         AppAssert(pForm);
219
220         Footer* pFooter = pForm->GetFooter();
221         if (pFooter != null)
222         {
223                 pFooter->RemoveAllButtons();
224                 pFooter->RemoveAllItems();
225                 pFooter->RemoveActionEventListener(*this);
226         }
227         AppLogDebug("EXIT");
228 }
229
230 int
231 ArtistContentPickerPanel::GetItemCount(void)
232 {
233         AppLogDebug("ENTER");
234         if (__pPresentationModel == null)
235         {
236                 return INIT_VALUE;
237         }
238         AppLogDebug("EXIT");
239         return __pPresentationModel->GetArtistContentListCount();
240 }
241
242 Tizen::Ui::Controls::TableViewItem*
243 ArtistContentPickerPanel::CreateItem(const int itemIndex, int itemWidth)
244 {
245         AppLogDebug("ENTER");
246         ContentInformation* pContentInfoStruct = __pPresentationModel->GetArtistContentInfoN(itemIndex);
247         if (pContentInfoStruct == null)
248         {
249                 return null;
250         }
251
252         TableViewItem* pItem = new (std::nothrow) TableViewItem();
253         pItem->Construct(Dimension(itemWidth, ITEM_HEIGHT), TABLE_VIEW_ANNEX_STYLE_MARK);
254 //      pItem->SetBackgroundColor(COLOR_ITEM);
255
256         CommonUtil::CreateContentPikerTableViewItem(*pItem, pContentInfoStruct->TitleName, CommonUtil::GetFormatDate(pContentInfoStruct->Duration));
257
258         delete pContentInfoStruct;
259         pContentInfoStruct = null;
260
261         AppLogDebug("EXIT");
262         return pItem;
263 }
264
265 bool
266 ArtistContentPickerPanel::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
267 {
268         AppLogDebug("ENTER");
269         AppLogDebug("EXIT");
270         return false;
271 }
272
273 void
274 ArtistContentPickerPanel::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
275 {
276         AppLogDebug("ENTER");
277         AppLogDebug("EXIT");
278 }
279
280 int
281 ArtistContentPickerPanel::GetDefaultItemHeight(void)
282 {
283         AppLogDebug("ENTER");
284         AppLogDebug("EXIT");
285         return ITEM_HEIGHT;
286 }
287
288 void
289 ArtistContentPickerPanel::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
290                                                                 int itemIndex,
291                                                                 Tizen::Ui::Controls::TableViewItem* pItem,
292                                                                 Tizen::Ui::Controls::TableViewItemStatus status)
293 {
294         AppLogDebug("ENTER");
295         switch (status)
296         {
297         case TABLE_VIEW_ITEM_STATUS_CHECKED:
298                 {
299                         __checkedItemCount++;
300                         tableView.SetItemChecked(itemIndex, true);
301                 }
302                 break;
303
304         case TABLE_VIEW_ITEM_STATUS_UNCHECKED:
305                 {
306                         __checkedItemCount--;
307                         tableView.SetItemChecked(itemIndex, false);
308                 }
309                 break;
310
311         default:
312                 break;
313         }
314
315         CommonUtil::ShowSelectAllCheckButton(*__pSelectAllCheckedButton);
316
317         if (__checkedItemCount == __pPresentationModel->GetArtistContentListCount())
318         {
319                 __pSelectAllCheckedButton->SetSelected(true);
320         }
321
322         Invalidate(true);
323
324         Form* pForm = dynamic_cast<Form*>(GetParent());
325         AppAssert(pForm);
326         CommonUtil::ShowCheckedCountLabel(*__pCheckedCountLabel, __checkedItemCount, *__pContentTableView, *pForm);
327         CommonUtil::SetButtonEnabled(*pForm, __checkedItemCount);
328         AppLogDebug("EXIT");
329 }
330
331 void
332 ArtistContentPickerPanel::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
333                                                                                 int itemIndex,
334                                                                                 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
335                                                                                 bool activated)
336 {
337         AppLogDebug("ENTER");
338         AppLogDebug("EXIT");
339 }
340 void
341 ArtistContentPickerPanel::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
342                                                                 int itemIndexFrom,
343                                                                 int itemIndexTo)
344 {
345         AppLogDebug("ENTER");
346         AppLogDebug("EXIT");
347 }