~vthompson/music-app/remix-empty-states-001

« back to all changes in this revision

Viewing changes to MusicStart.qml

  • Committer: Victor Thompson
  • Date: 2014-10-20 22:02:55 UTC
  • mfrom: (677.1.2 remix)
  • Revision ID: victor.thompson@gmail.com-20141020220255-hiaalbts18zeczfy
merge of remix and fix issues

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
 
33
33
MusicPage {
34
34
    id: mainpage
35
 
    title: i18n.tr("Music")
 
35
    title: i18n.tr("Recent")
36
36
 
37
 
    /* Dev button for search.
38
 
    Button {
39
 
        id: searchButton
40
 
        text: i18n.tr("Search")
41
 
        anchors.top: parent.top
42
 
        anchors.topMargin: units.gu(2)
43
 
        anchors.bottom: recentlyPlayed.top
44
 
        anchors.bottomMargin: units.gu(1)
45
 
        height: units.gu(4)
46
 
        onClicked: {
47
 
            PopupUtils.open(Qt.resolvedUrl("MusicSearch.qml"), mainView,
48
 
            {
49
 
                                title: i18n.tr("Search")
50
 
            } )
51
 
        }
 
37
    head {
 
38
        actions: [
 
39
            Action {
 
40
                iconName: "delete"
 
41
                onTriggered: {
 
42
                    Library.clearRecentHistory()
 
43
                    recentModel.filterRecent()
 
44
                }
 
45
            }
 
46
        ]
52
47
    }
53
 
    */
54
 
    Flickable{
55
 
        id: musicFlickable
56
 
        anchors.fill: parent
57
 
 
58
 
        width:  mainpage.width
59
 
        height: mainpage.height
60
 
 
61
 
        contentHeight:  mainView.hasRecent ? recentlyPlayed.height + recentlist.height + genres.height + genrelist.height + albums.height + albumlist.height + units.gu(4)
62
 
                                           :  genres.height + genrelist.height + albums.height + albumlist.height + units.gu(3)
63
 
        contentWidth: width
64
 
 
65
 
        focus: true
66
 
 
67
 
        ListItem.Standard {
68
 
            id: recentlyPlayed
69
 
            Label {
70
 
                anchors {
71
 
                    verticalCenter: parent.verticalCenter
72
 
                    left: parent.left
73
 
                    leftMargin: units.gu(2)
74
 
                }
75
 
                text: i18n.tr("Recent")
76
 
                color: styleMusic.common.music
77
 
            }
78
 
            visible: mainView.hasRecent
79
 
        }
80
 
 
81
 
        ListView {
82
 
            id: recentlist
83
 
            anchors.top: recentlyPlayed.bottom
84
 
            anchors.topMargin: units.gu(1)
85
 
            width: parent.width
86
 
            spacing: units.gu(1)
87
 
            height: units.gu(18)
88
 
            // TODO: Update when view counts are collected
89
 
            model: recentModel.model
90
 
            delegate: recentDelegate
91
 
            header: Item {
92
 
                id: recentSpacer
93
 
                width: units.gu(1)
94
 
            }
95
 
            footer: Item {
96
 
                id: clearRecent
97
 
                width: recentlist.height - units.gu(2)
98
 
                height: width
99
 
                visible: mainView.hasRecent && !loading.visible
100
 
                Button {
101
 
                    id: clearRecentButton
102
 
                    anchors.centerIn: parent
103
 
                    text: i18n.tr("Clear History")
104
 
                    onClicked: {
105
 
                        Library.clearRecentHistory()
106
 
                        mainView.hasRecent = false
107
 
                        recentModel.filterRecent()
108
 
                    }
109
 
                }
110
 
            }
111
 
            orientation: ListView.Horizontal
112
 
            visible: mainView.hasRecent
113
 
 
114
 
            Component {
115
 
                id: recentDelegate
116
 
                Item {
117
 
                    property string title: model.title
118
 
                    property string title2: model.title2  !== "Playlist" ? model.title2 : i18n.tr("Playlist")
119
 
                    property var covers: type === "playlist" ? Playlists.getPlaylistCovers(title) : (model.art !== undefined ? [{art: model.art}] : [{author: model.title2, album: model.title}])
120
 
                    property string type: model.type
121
 
                    property string time: model.time
122
 
                    property string key: model.key
123
 
                    id: recentItem
124
 
                    height: recentlist.height - units.gu(1)
125
 
                    width: height
126
 
                    CoverRow {
127
 
                        id: recentShape
128
 
                        anchors {
129
 
                            top: parent.top
130
 
                            left: parent.left
131
 
                            verticalCenter: parent.verticalCenter
132
 
                        }
133
 
                        count: recentItem.covers.length
134
 
                        size: recentItem.width
135
 
                        covers: recentItem.covers
136
 
                        spacing: units.gu(2)
137
 
                    }
138
 
                    Item {  // Background so can see text in current state
139
 
                        id: albumBg
140
 
                        anchors {
141
 
                            bottom: parent.bottom
142
 
                            left: parent.left
143
 
                            right: parent.right
144
 
                        }
145
 
                        height: units.gu(6)
146
 
                        clip: true
147
 
                        UbuntuShape{
148
 
                            anchors {
149
 
                                bottom: parent.bottom
150
 
                                left: parent.left
151
 
                                right: parent.right
152
 
                            }
153
 
                            height: recentShape.height
154
 
                            radius: "medium"
155
 
                            color: styleMusic.common.black
156
 
                            opacity: 0.6
157
 
                        }
158
 
                    }
159
 
                    Label {
160
 
                        id: albumArtist
161
 
                        anchors.bottom: parent.bottom
162
 
                        anchors.bottomMargin: units.gu(3)
163
 
                        anchors.left: parent.left
164
 
                        anchors.leftMargin: units.gu(1)
165
 
                        anchors.right: parent.right
166
 
                        anchors.rightMargin: units.gu(1)
167
 
                        color: styleMusic.common.white
168
 
                        elide: Text.ElideRight
169
 
                        text: title
170
 
                        fontSize: "small"
171
 
                        font.weight: Font.DemiBold
172
 
                    }
173
 
                    Label {
174
 
                        id: albumLabel
175
 
                        anchors.left: parent.left
176
 
                        anchors.leftMargin: units.gu(1)
177
 
                        anchors.bottom: parent.bottom
178
 
                        anchors.bottomMargin: units.gu(1)
179
 
                        anchors.right: parent.right
180
 
                        anchors.rightMargin: units.gu(1)
181
 
                        color: styleMusic.common.white
182
 
                        elide: Text.ElideRight
183
 
                        text: title2
184
 
                        fontSize: "x-small"
185
 
                    }
186
 
                    MouseArea {
187
 
                        anchors.fill: parent
188
 
                        onClicked: {
189
 
                            if (type === "playlist") {
190
 
                                albumTracksModel.filterPlaylistTracks(key)
191
 
                            } else {
192
 
                                songsPage.album = title;
193
 
                            }
194
 
                            songsPage.genre = undefined;
195
 
 
196
 
                            songsPage.line1 = title2
197
 
                            songsPage.line2 = title
198
 
                            songsPage.covers = recentItem.covers
199
 
                            songsPage.isAlbum = (type === "album")
200
 
                            songsPage.title = songsPage.isAlbum ? i18n.tr("Album") : i18n.tr("Playlist")
201
 
 
202
 
                            mainPageStack.push(songsPage)
203
 
                        }
204
 
 
205
 
                        // TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
206
 
                        onPressedChanged: recentShape.pressed = pressed
207
 
                    }
208
 
                }
209
 
            }
210
 
        }
211
 
 
212
 
        ListItem.ThinDivider {
213
 
            id: genreDivider
214
 
            anchors.top: mainView.hasRecent ? recentlist.bottom : parent.top
215
 
            visible: genrelist.count > 1
216
 
        }
217
 
        ListItem.Standard {
218
 
            id: genres
219
 
            anchors.top: genreDivider.bottom
220
 
            visible: genrelist.count > 1
221
 
            Label {
222
 
                anchors {
223
 
                    verticalCenter: parent.verticalCenter
224
 
                    left: parent.left
225
 
                    leftMargin: units.gu(2)
226
 
                }
227
 
                text: i18n.tr("Genres")
228
 
                color: styleMusic.common.music
229
 
            }
230
 
        }
231
 
        // TODO: add music genres. frequency of play? most tracks?
232
 
        ListView {
233
 
            id: genrelist
234
 
            width: parent.width
235
 
            anchors.top: genres.bottom
236
 
            anchors.topMargin: units.gu(1)
237
 
            spacing: units.gu(1)
238
 
            height: units.gu(18)
239
 
            visible: genrelist.count > 1
240
 
            model: SortFilterModel {
241
 
                id: genresModelFilter
242
 
                model: GenresModel {
243
 
                    id: genresModel
244
 
                    store: musicStore
245
 
                }
246
 
                filter.property: "genre"
247
 
                filter.pattern: /\S+/
248
 
            }
249
 
 
250
 
            delegate: genreDelegate
251
 
            header: Item {
252
 
                id: genreSpacer
253
 
                width: units.gu(1)
254
 
            }
255
 
            orientation: ListView.Horizontal
256
 
 
257
 
            Component {
258
 
                id: genreDelegate
259
 
                Item {
260
 
                    id: genreItem
261
 
                    objectName: "genreItemObject"
262
 
                    height: genrelist.height - units.gu(1)
263
 
                    width: height
264
 
 
265
 
                    Repeater {
266
 
                        id: albumGenreModelRepeater
267
 
                        model: AlbumsModel {
268
 
                            genre: model.genre
269
 
                            store: musicStore
270
 
                        }
271
 
 
272
 
                        delegate: Item {
273
 
                            property string art: model.art
274
 
                        }
275
 
                        property var covers: []
276
 
                        signal finished()
277
 
 
278
 
                        onFinished: {
279
 
                            genreShape.count = count
280
 
                            genreShape.covers = covers
281
 
                        }
282
 
                        onItemAdded: {
283
 
                            covers.push({art: item.art});
284
 
 
285
 
                            if (index === count - 1) {
286
 
                                finished();
287
 
                            }
288
 
                        }
289
 
                    }
290
 
 
291
 
                    SongsModel {
292
 
                        id: songGenreModel
293
 
                        genre: model.genre
294
 
                        store: musicStore
295
 
                    }
296
 
 
297
 
                    CoverRow {
298
 
                        id: genreShape
299
 
                        anchors {
300
 
                            top: parent.top
301
 
                            left: parent.left
302
 
                            verticalCenter: parent.verticalCenter
303
 
                        }
304
 
                        count: 0
305
 
                        size: genreItem.width
306
 
                        covers: []
307
 
                        spacing: units.gu(2)
308
 
                    }
309
 
                    MouseArea {
310
 
                        anchors.fill: parent
311
 
                        onClicked: {
312
 
                            songsPage.album = undefined
313
 
                            songsPage.covers = genreShape.covers
314
 
                            songsPage.genre = model.genre
315
 
                            songsPage.isAlbum = true
316
 
                            songsPage.line1 = i18n.tr("Genre")
317
 
                            songsPage.line2 = model.genre
318
 
                            songsPage.title = i18n.tr("Genre")
319
 
 
320
 
                            mainPageStack.push(songsPage)
321
 
                        }
322
 
 
323
 
                        // TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
324
 
                        onPressedChanged: genreShape.pressed = pressed
325
 
                    }
326
 
                    Item {  // Background so can see text in current state
327
 
                        id: genreBg
328
 
                        anchors {
329
 
                            bottom: parent.bottom
330
 
                            left: parent.left
331
 
                            right: parent.right
332
 
                        }
333
 
                        height: units.gu(5.5)
334
 
                        clip: true
335
 
                        UbuntuShape{
336
 
                            anchors {
337
 
                                bottom: parent.bottom
338
 
                                left: parent.left
339
 
                                right: parent.right
340
 
                            }
341
 
                            height: genreShape.height
342
 
                            radius: "medium"
343
 
                            color: styleMusic.common.black
344
 
                            opacity: 0.6
345
 
                        }
346
 
                    }
347
 
                    Label {
348
 
                        id: genreLabel
349
 
                        anchors.bottom: parent.bottom
350
 
                        anchors.bottomMargin: units.gu(1)
351
 
                        anchors.left: parent.left
352
 
                        anchors.leftMargin: units.gu(1)
353
 
                        anchors.right: parent.right
354
 
                        anchors.rightMargin: units.gu(1)
355
 
                        color: styleMusic.common.white
356
 
                        elide: Text.ElideRight
357
 
                        text: model.genre
358
 
                        fontSize: "small"
359
 
                        font.weight: Font.DemiBold
360
 
                    }
361
 
                    Label {
362
 
                        id: genreTotal
363
 
                        anchors.bottom: parent.bottom
364
 
                        anchors.bottomMargin: units.gu(3)
365
 
                        anchors.left: parent.left
366
 
                        anchors.leftMargin: units.gu(1)
367
 
                        anchors.right: parent.right
368
 
                        anchors.rightMargin: units.gu(1)
369
 
                        color: styleMusic.common.white
370
 
                        elide: Text.ElideRight
371
 
                        text: i18n.tr("%1 song", "%1 songs", songGenreModel.rowCount).arg(songGenreModel.rowCount)
372
 
                        fontSize: "x-small"
373
 
                    }
374
 
                }
375
 
            }
376
 
        }
377
 
 
378
 
        ListItem.ThinDivider {
379
 
            id: albumsDivider
380
 
            anchors.top: genrelist.visible
381
 
                         ? genrelist.bottom
382
 
                         : (mainView.hasRecent ? recentlist.bottom : parent.top)
383
 
        }
384
 
        ListItem.Standard {
385
 
            id: albums
386
 
            Label {
387
 
                anchors {
388
 
                    verticalCenter: parent.verticalCenter
389
 
                    left: parent.left
390
 
                    leftMargin: units.gu(2)
391
 
                }
392
 
                text: i18n.tr("Albums")
393
 
                color: styleMusic.common.music
394
 
            }
395
 
            anchors.top: albumsDivider.bottom
396
 
        }
397
 
 
398
 
        ListView {
399
 
            id: albumlist
400
 
            width: parent.width
401
 
            anchors.top: albums.bottom
402
 
            anchors.topMargin: units.gu(1)
403
 
            spacing: units.gu(1)
404
 
            height: units.gu(18)
405
 
            model: SortFilterModel {
406
 
                id: albumsModelFilter
407
 
                property alias rowCount: albumsModel.rowCount
408
 
                model: AlbumsModel {
409
 
                    id: albumsModel
410
 
                    store: musicStore
411
 
                }
412
 
                sort.property: "title"
413
 
                sort.order: Qt.AscendingOrder
414
 
            }
415
 
            delegate: albumDelegate
416
 
            header: Item {
417
 
                id: albumSpacer
418
 
                width: units.gu(1)
419
 
            }
420
 
            orientation: ListView.Horizontal
421
 
 
422
 
            Component {
423
 
                id: albumDelegate
424
 
                Item {
425
 
                    property string artist: model.artist
426
 
                    property string album: model.title
427
 
                    property var covers: [{art: model.art}]
428
 
 
429
 
                    id: albumItem
430
 
                    objectName: "albumItemObject"
431
 
                    height: albumlist.height - units.gu(1)
432
 
                    width: height
433
 
                    CoverRow {
434
 
                        id: albumShape
435
 
                        anchors {
436
 
                            top: parent.top
437
 
                            left: parent.left
438
 
                            verticalCenter: parent.verticalCenter
439
 
                        }
440
 
                        count: albumItem.covers.length
441
 
                        size: albumItem.width
442
 
                        covers: albumItem.covers
443
 
                        spacing: units.gu(2)
444
 
                    }
445
 
                    MouseArea {
446
 
                        anchors.fill: parent
447
 
                        onClicked: {
448
 
                            songsPage.album = album
449
 
                            songsPage.covers = covers
450
 
                            songsPage.genre = undefined
451
 
                            songsPage.isAlbum = true
452
 
                            songsPage.line1 = artist
453
 
                            songsPage.line2 = album
454
 
                            songsPage.title = i18n.tr("Album")
455
 
 
456
 
                            mainPageStack.push(songsPage)
457
 
                        }
458
 
 
459
 
                        // TODO: If http://pad.lv/1354753 is fixed to expose whether the Shape should appear pressed, update this as well.
460
 
                        onPressedChanged: albumShape.pressed = pressed
461
 
                    }
462
 
                    Item {  // Background so can see text in current state
463
 
                        id: albumBg
464
 
                        anchors {
465
 
                            bottom: parent.bottom
466
 
                            left: parent.left
467
 
                            right: parent.right
468
 
                        }
469
 
                        height: units.gu(6)
470
 
                        clip: true
471
 
                        UbuntuShape{
472
 
                            anchors {
473
 
                                bottom: parent.bottom
474
 
                                left: parent.left
475
 
                                right: parent.right
476
 
                            }
477
 
                            height: albumShape.height
478
 
                            radius: "medium"
479
 
                            color: styleMusic.common.black
480
 
                            opacity: 0.6
481
 
                        }
482
 
                    }
483
 
                    Label {
484
 
                        id: albumLabel
485
 
                        anchors.bottom: parent.bottom
486
 
                        anchors.bottomMargin: units.gu(1)
487
 
                        anchors.left: parent.left
488
 
                        anchors.leftMargin: units.gu(1)
489
 
                        anchors.right: parent.right
490
 
                        anchors.rightMargin: units.gu(1)
491
 
                        color: styleMusic.common.white
492
 
                        elide: Text.ElideRight
493
 
                        text: artist
494
 
                        fontSize: "x-small"
495
 
                    }
496
 
                    Label {
497
 
                        id: albumLabel2
498
 
                        anchors.bottom: parent.bottom
499
 
                        anchors.bottomMargin: units.gu(3)
500
 
                        anchors.left: parent.left
501
 
                        anchors.leftMargin: units.gu(1)
502
 
                        anchors.right: parent.right
503
 
                        anchors.rightMargin: units.gu(1)
504
 
                        color: styleMusic.common.white
505
 
                        elide: Text.ElideRight
506
 
                        text: album
507
 
                        fontSize: "small"
508
 
                        font.weight: Font.DemiBold
509
 
                    }
510
 
                }
 
48
 
 
49
    CardView {
 
50
        id: recentCardView
 
51
        model: recentModel.model
 
52
        delegate: Card {
 
53
            id: albumCard
 
54
            coverSources: model.type === "playlist" ? Playlists.getPlaylistCovers(title) : (model.art !== undefined ? [{art: model.art}] : [{author: model.title2, album: model.title}])
 
55
            objectName: "albumsPageGridItem" + index
 
56
            primaryText: model.title
 
57
            secondaryText: model.title2  !== "Playlist" ? model.title2 : i18n.tr("Playlist")
 
58
 
 
59
            onClicked: {
 
60
                if (type === "playlist") {
 
61
                    albumTracksModel.filterPlaylistTracks(model.key)
 
62
                } else {
 
63
                    songsPage.album = title;
 
64
                }
 
65
                songsPage.genre = undefined;
 
66
 
 
67
                songsPage.line1 = secondaryText
 
68
                songsPage.line2 = primaryText
 
69
                songsPage.covers = coverSources
 
70
                songsPage.isAlbum = (type === "album")
 
71
                songsPage.title = songsPage.isAlbum ? i18n.tr("Album") : i18n.tr("Playlist")
 
72
 
 
73
                mainPageStack.push(songsPage)
511
74
            }
512
75
        }
513
76
    }