Applied latest source code
[apps/native/preloaded/MusicPlayer.git] / src / MpArtistAllSongListForm.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                MpArtistAllSongListForm.cpp
19  * @brief               This is the implementation file for ArtistAllSongListForm class.
20  */
21
22 #include "MpArtistAllSongListForm.h"
23 #include "MpArtistListPresentationModel.h"
24 #include "MpNowPlayContentPanel.h"
25 #include "MpPlaylistPickerPopup.h"
26 #include "MpThumbnailInfo.h"
27
28 using namespace Tizen::Base;
29 using namespace Tizen::Base::Collection;
30 using namespace Tizen::Content;
31 using namespace Tizen::Graphics;
32 using namespace Tizen::Social;
33 using namespace Tizen::Ui::Controls;
34 using namespace Tizen::Ui::Scenes;
35
36 static const int W_SONG_TIME = 120;
37 static const int Y_GAP_LABEL = 10;
38
39 ArtistAllSongListForm::ArtistAllSongListForm(void)
40         : ThumbnailBase::ThumbnailBase()
41         , __pContentTableView(null)
42         , __pThumbnail(null)
43         , __pPlayListPickerPopup(null)
44         , __fontSize(FONT_MAIN_TEXT_SIZE_NORMAL)
45         , __itemHeight(ITEM_HEIGHT_MAIN_TEXT_NORMAL)
46 {
47         AppLogDebug("ENTER");
48         AppLogDebug("EXIT");
49 }
50
51 ArtistAllSongListForm::~ArtistAllSongListForm(void)
52 {
53         AppLogDebug("ENTER");
54         AppLogDebug("EXIT");
55 }
56
57 bool
58 ArtistAllSongListForm::Initialize(void)
59 {
60         AppLogDebug("ENTER");
61
62         result r = Form::Construct(FORM_STYLE_NORMAL | FORM_STYLE_PORTRAIT_INDICATOR | FORM_STYLE_LANDSCAPE_INDICATOR_AUTO_HIDE | FORM_STYLE_HEADER | FORM_STYLE_FOOTER);
63         if (IsFailed(r))
64         {
65                 return false;
66         }
67
68         AppLogDebug("EXIT");
69         return true;
70 }
71
72 result
73 ArtistAllSongListForm::OnInitializing(void)
74 {
75         AppLogDebug("ENTER");
76
77 //      Header* pHeader = GetHeader();
78 //      pHeader->SetStyle(HEADER_STYLE_TITLE);
79 //      pHeader->SetTitleText(ResourceManager::GetString("IDS_MUSIC_BODY_ALL_SONGS"));
80
81         __pContentTableView = new (std::nothrow) TableView();
82         __pContentTableView->Construct(Rectangle(0, 0, GetClientAreaBounds().width, GetClientAreaBounds().height),
83                                         true,
84                                         TABLE_VIEW_SCROLL_BAR_STYLE_FADE_OUT);
85         __pContentTableView->AddTableViewItemEventListener(*this);
86         __pContentTableView->SetItemProvider(this);
87         AddControl(__pContentTableView);
88
89         __pPresentationModel = ArtistListPresentationModel::GetInstance();
90         __fontSizeValue = CommonUtil::GetFontSizeValue();
91         __itemHeight = CommonUtil::GetItemHeight(__fontSizeValue);
92         __fontSize = CommonUtil::GetFontSize(__fontSizeValue);
93
94         AppLogDebug("EXIT");
95         return ThumbnailBase::Construct();
96 }
97
98 result
99 ArtistAllSongListForm::OnTerminating(void)
100 {
101         AppLogDebug("ENTER");
102         ThumbnailBase::Stop();
103         delete __pPlayListPickerPopup;
104         __pPlayListPickerPopup = null;
105         AppLogDebug("EXIT");
106         return E_SUCCESS;
107 }
108
109 void
110 ArtistAllSongListForm::OnActionPerformed(const Tizen::Ui::Control& source, int actionId)
111 {
112         AppLogDebug("ENTER");
113         SceneManager* pSceneManager = SceneManager::GetInstance();
114         AppAssert(pSceneManager);
115
116         switch (actionId)
117         {
118         case IDA_FOOTER_BUTTON_ADD_TO_PLAYLIST:
119                 {
120                         Tizen::Base::Collection::IList* pDataList = null;
121                         pDataList = __pPresentationModel->GetAllContentPathListN();
122
123                         if (pDataList == null)
124                         {
125                                 break;
126                         }
127
128                         __pPlayListPickerPopup = new (std::nothrow) PlayListPickerPopup();
129                         __pPlayListPickerPopup->Initialize(this, pDataList);
130
131                         __pPlayListPickerPopup->SetShowState(true);
132                         __pPlayListPickerPopup->Show();
133                         //__pPlayListPickerPopup->SetCollectedContent(pDataList);
134                 }
135                 break;
136
137         /*case IDA_FOOTER_BUTTON_SEARCH:
138                 {
139                         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_SEARCH));
140                 }
141                 break;*/
142
143         default:
144                 break;
145         }
146         AppLogDebug("EXIT");
147 }
148
149 void
150 ArtistAllSongListForm::OnFormBackRequested(Tizen::Ui::Controls::Form& source)
151 {
152         AppLogDebug("ENTER");
153         SceneManager* pSceneManager = SceneManager::GetInstance();
154         AppAssert(pSceneManager);
155
156         pSceneManager->GoBackward(BackwardSceneTransition());
157         AppLogDebug("EXIT");
158 }
159
160 void
161 ArtistAllSongListForm::OnSceneActivatedN(const Tizen::Ui::Scenes::SceneId& previousSceneId,
162                                                 const Tizen::Ui::Scenes::SceneId& currentSceneId,
163                                                 Tizen::Base::Collection::IList* pArgs)
164 {
165         AppLogDebug("ENTER");
166         Footer* pFooter = CommonUtil::CreateAddtoPlaylistFooter(*this);
167         pFooter->AddActionEventListener(*this);
168         pFooter->SetBackButton();
169
170         SetFormBackEventListener(this);
171
172         Header* pHeader = GetHeader();
173         pHeader->SetStyle(HEADER_STYLE_TITLE);
174         pHeader->SetTitleText(ResourceManager::GetString("IDS_MUSIC_BODY_ALL_SONGS"));
175         AppLogDebug("EXIT");
176 }
177
178 void
179 ArtistAllSongListForm::OnSceneDeactivated(const Tizen::Ui::Scenes::SceneId& currentSceneId,
180                                                 const Tizen::Ui::Scenes::SceneId& nextSceneId)
181 {
182         AppLogDebug("ENTER");
183         Header* pHeader = GetHeader();
184         pHeader->RemoveAllButtons();
185         pHeader->RemoveAllItems();
186
187         Footer* pFooter = GetFooter();
188         if (pFooter != null)
189         {
190                 pFooter->RemoveAllButtons();
191                 pFooter->RemoveAllItems();
192                 pFooter->RemoveActionEventListener(*this);
193         }
194
195         CancelAllThumbnailRequest();
196         AppLogDebug("EXIT");
197 }
198
199 int
200 ArtistAllSongListForm::GetItemCount(void)
201 {
202         AppLogDebug("ENTER");
203         if (__pPresentationModel == null)
204         {
205                 return INIT_VALUE;
206         }
207
208         AppLogDebug("EXIT");
209         return __pPresentationModel->GetArtistContentListCount();
210 }
211
212 Tizen::Ui::Controls::TableViewItem*
213 ArtistAllSongListForm::CreateItem(const int itemIndex, int itemWidth)
214 {
215         AppLogDebug("ENTER");
216         ContentInformation* pContentInfo = __pPresentationModel->GetArtistContentInfoN(itemIndex);
217         if (pContentInfo == null)
218         {
219                 AppLogDebug("EXIT");
220                 return null;
221         }
222
223         TableViewItem* pItem = new (std::nothrow) TableViewItem();
224         pItem->Construct(Dimension(itemWidth, __itemHeight), TABLE_VIEW_ANNEX_STYLE_NORMAL);
225         CreateTableViewItem(*pItem, *pContentInfo);
226
227         RequestThumbnail(pContentInfo->contentId, (new (std::nothrow) Integer(itemIndex)));
228         delete pContentInfo;
229
230         AppLogDebug("EXIT");
231         return pItem;
232 }
233
234 bool
235 ArtistAllSongListForm::DeleteItem(const int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
236 {
237         AppLogDebug("ENTER");
238         AppLogDebug("EXIT");
239         return false;
240 }
241
242 int
243 ArtistAllSongListForm::GetDefaultItemHeight(void)
244 {
245         AppLogDebug("ENTER");
246         AppLogDebug("EXIT");
247         return ITEM_HEIGHT;
248 }
249
250 void
251 ArtistAllSongListForm::OnTableViewItemStateChanged(Tizen::Ui::Controls::TableView& tableView,
252                                                                 int itemIndex,
253                                                                 Tizen::Ui::Controls::TableViewItem* pItem,
254                                                                 Tizen::Ui::Controls::TableViewItemStatus status)
255 {
256         AppLogDebug("ENTER");
257         SceneManager* pSceneManager = SceneManager::GetInstance();
258         AppAssert(pSceneManager);
259
260         ArrayList* pTempList = new (std::nothrow) ArrayList();
261         pTempList->Construct();
262
263         pTempList->Add(*(new (std::nothrow) String(MUSIC)));
264         pTempList->Add(*(new (std::nothrow) Integer(itemIndex)));
265         pTempList->Add(*(__pPresentationModel->GetAllContentPathListN()));
266
267         pSceneManager->GoForward(ForwardSceneTransition(IDSCN_PLAYER),pTempList);
268         AppLogDebug("EXIT");
269 }
270
271 void
272 ArtistAllSongListForm::OnTableViewContextItemActivationStateChanged(Tizen::Ui::Controls::TableView& tableView,
273                                                                                 int itemIndex,
274                                                                                 Tizen::Ui::Controls::TableViewContextItem* pContextItem,
275                                                                                 bool activated)
276 {
277         AppLogDebug("ENTER");
278         AppLogDebug("EXIT");
279 }
280
281 void
282 ArtistAllSongListForm::OnTableViewItemReordered(Tizen::Ui::Controls::TableView& tableView,
283                                                         int itemIndexFrom,
284                                                         int itemIndexTo)
285 {
286         AppLogDebug("ENTER");
287         AppLogDebug("EXIT");
288 }
289
290 result
291 ArtistAllSongListForm::CreateTableViewItem(Tizen::Ui::Container& parent,
292                                                                            const ContentInformation& contentInfoStruct)
293 {
294         AppLogDebug("ENTER");
295         result r = E_SUCCESS;
296
297         Label* pSongThumbnailBGLabel = new (std::nothrow) Label();
298         pSongThumbnailBGLabel->Construct(Rectangle(X_GAP_THUMBNAIL - 1, Y_GAP_THUMBNAIL - 1, W_THUMBNAIL + 1, W_THUMBNAIL + 1), L"");
299
300         Label* pSongThumbnailLabel = new (std::nothrow) Label();
301         pSongThumbnailLabel->Construct(Rectangle(X_GAP_THUMBNAIL, Y_GAP_THUMBNAIL, W_THUMBNAIL, H_THUMBNAIL), L"");
302         pSongThumbnailLabel->SetBackgroundBitmap(*GetDefaultThumbnail());
303         pSongThumbnailLabel->SetName(L"pSongThumbnailLabel");
304
305         int X_Gap = W_THUMBNAIL + (X_GAP_THUMBNAIL * 2);
306         int W_Label = W_CLIENT_AREA - X_Gap;
307
308         Label* pSongTitleLabel = new (std::nothrow) Label();
309         pSongTitleLabel->Construct(Rectangle(X_Gap,Y_GAP_LABEL, W_Label - W_SONG_TIME, (ITEM_HEIGHT - (Y_GAP_LABEL * 2)) / 2), L"");
310         pSongTitleLabel->SetTextColor(COLOR_MAIN_TEXT);
311         pSongTitleLabel->SetTextConfig(MAIN_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
312         pSongTitleLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
313         pSongTitleLabel->SetText(contentInfoStruct.TitleName);
314
315         Label* pSongTimeLabel = new (std::nothrow) Label();
316         pSongTimeLabel->Construct(Rectangle(pSongTitleLabel->GetWidth() + X_Gap, pSongTitleLabel->GetY(), W_SONG_TIME, pSongTitleLabel->GetHeight()) , L"");
317         pSongTimeLabel->SetTextColor(COLOR_SUB_TEXT);
318         pSongTimeLabel->SetTextConfig(SUB_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
319         pSongTimeLabel->SetTextHorizontalAlignment(ALIGNMENT_CENTER);
320         pSongTimeLabel->SetText(CommonUtil::GetFormatDate(contentInfoStruct.Duration));
321
322         Label* pSongArtistLabel = new (std::nothrow) Label();
323         pSongArtistLabel->Construct(Rectangle(X_Gap, pSongTimeLabel->GetHeight() + Y_GAP_LABEL, W_Label, pSongTitleLabel->GetHeight()), L"");
324         pSongArtistLabel->SetTextColor(COLOR_SUB_TEXT);
325         pSongArtistLabel->SetTextConfig(SUB_TEXT_SIZE, LABEL_TEXT_STYLE_NORMAL);
326         pSongArtistLabel->SetTextHorizontalAlignment(ALIGNMENT_LEFT);
327         pSongArtistLabel->SetText(contentInfoStruct.ArtistName);
328
329         parent.AddControl(pSongThumbnailBGLabel);
330         parent.AddControl(pSongThumbnailLabel);
331         parent.AddControl(pSongTitleLabel);
332         parent.AddControl(pSongTimeLabel);
333         parent.AddControl(pSongArtistLabel);
334
335         AppLogDebug("EXIT");
336         return r;
337 }
338
339 void
340 ArtistAllSongListForm::OnThumbnailInfoReveivedN(ThumbnailInfo* pThumbnailInfo)
341 {
342         AppLogDebug("ENTER");
343         __pThumbnail = pThumbnailInfo->GetBitmapN();
344         Object* pParam = pThumbnailInfo->GetUserParamN();
345         if (pParam != null)
346         {
347                 __pContentTableView->RefreshItem((static_cast<Integer*>(pParam))->ToInt(), TABLE_VIEW_REFRESH_TYPE_ITEM_MODIFY);
348                 delete pParam;
349         }
350
351         delete pThumbnailInfo;
352         AppLogDebug("EXIT");
353 }
354
355 void
356 ArtistAllSongListForm::OnUserEventReceivedN(RequestId requestId, Tizen::Base::Collection::IList* pArgs)
357 {
358         AppLogDebug("ENTER");
359         AppLogDebug("OnUserEventReceivedN %d", requestId);
360         if (requestId == ID_DESTORY_PLAY_LIST_PICKER_POPUP)
361         {
362                 if (__pPlayListPickerPopup != null)
363                 {
364                         delete __pPlayListPickerPopup;
365                         __pPlayListPickerPopup = null;
366                 }
367         }
368         AppLogDebug("EXIT");
369 }
370
371 void
372 ArtistAllSongListForm::UpdateItem(int itemIndex, Tizen::Ui::Controls::TableViewItem* pItem)
373 {
374         AppLogDebug("ENTER");
375         Label* pThumbnailLabel = static_cast<Label*>(pItem->GetControl(L"pSongThumbnailLabel"));
376         if (__pThumbnail == null || pThumbnailLabel == null)
377         {
378                 AppLogDebug("__pThumbnail or pThumbnailLabel is null");
379                 delete __pThumbnail;
380                 __pThumbnail = null;
381                 return;
382         }
383         pThumbnailLabel->SetBackgroundBitmap(*__pThumbnail);
384         delete __pThumbnail;
385         __pThumbnail = null;
386         pThumbnailLabel->Invalidate(true);
387         AppLogDebug("EXIT");
388 }