Merge lp:~ahayzen/music-app/fix-1409186-queue-delete-refactor into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 774
Merged at revision: 774
Proposed branch: lp:~ahayzen/music-app/fix-1409186-queue-delete-refactor
Merge into: lp:music-app/remix
Diff against target: 128 lines (+85/-5)
2 files modified
MusicNowPlaying.qml (+59/-4)
meta-database.js (+26/-1)
To merge this branch: bzr merge lp:~ahayzen/music-app/fix-1409186-queue-delete-refactor
Reviewer Review Type Date Requested Status
Victor Thompson Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+246036@code.launchpad.net

Commit message

* Refactor multiselect deleting from the Queue (by adding removeQueueList)

Description of the change

* Refactor multiselect deleting from the Queue (by adding removeQueueList)

This adds an optimised version of removeQueue to both MusicNowPlaying and meta-database called removeQueueList for removing multiple items at once.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) wrote :

I only have 1 inline question. I think this looks and works very well though!

review: Needs Information
Revision history for this message
Victor Thompson (vthompson) wrote :

This looks good. There doesn't seem to be any speed benefits to using a different array copy method. LGTM!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'MusicNowPlaying.qml'
2--- MusicNowPlaying.qml 2015-01-08 00:47:52 +0000
3+++ MusicNowPlaying.qml 2015-01-10 17:39:12 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2013, 2014
7+ * Copyright (C) 2013, 2014, 2015
8 * Andrew Hayzen <ahayzen@gmail.com>
9 * Daniel Holm <d.holmen@gmail.com>
10 * Victor Thompson <victor.thompson@gmail.com>
11@@ -172,9 +172,10 @@
12 iconName: "delete"
13 text: i18n.tr("Delete")
14 onTriggered: {
15- for (var i=0; i < queueListLoader.item.selectedItems.length; i++) {
16- removeQueue(queueListLoader.item.selectedItems[i])
17- }
18+ // Remove the tracks from the queue
19+ // Use slice() to copy the list
20+ // so that the indexes don't change as they are removed
21+ removeQueueList(queueListLoader.item.selectedItems.slice())
22
23 queueListLoader.item.closeSelection()
24 }
25@@ -505,6 +506,60 @@
26 }
27 }
28
29+ // Optimised removeQueue for removing multiple tracks from the queue
30+ function removeQueueList(items)
31+ {
32+ var i;
33+
34+ // Remove from the saved queue database
35+ Library.removeQueueList(items)
36+
37+
38+ // Remove from the listmodel
39+ for (i=0; i < items.length; i++) {
40+ trackQueue.model.remove(items[i] - i);
41+ }
42+
43+ // Update the currentIndex and playing status
44+
45+ if (trackQueue.model.count === 0) {
46+ // Nothing in the queue so stop and pop the queue
47+ player.stop()
48+ musicToolbar.goBack()
49+ } else if (items.indexOf(player.currentIndex) > -1) {
50+ // Current track was removed
51+
52+ // Find the first index that still exists before the currentIndex
53+ for (i=player.currentIndex - 1; i > -1; i--) {
54+ if (items.indexOf(i) === -1) {
55+ break;
56+ }
57+ }
58+
59+ // Set this as the current track
60+ player.currentIndex = i
61+ queueIndex = i
62+
63+ // Play the next track
64+ player.nextSong(player.isPlaying);
65+ } else {
66+ // Current track not in removed list
67+ // Check if the index needs to be shuffled down due to removals
68+
69+ var before = 0
70+
71+ for (i in items) {
72+ if (i < player.currentIndex) {
73+ before++;
74+ }
75+ }
76+
77+ // Update the index
78+ player.currentIndex -= before;
79+ queueIndex -= before;
80+ }
81+ }
82+
83 Loader {
84 id: queueListLoader
85 anchors {
86
87=== modified file 'meta-database.js'
88--- meta-database.js 2014-11-15 22:48:52 +0000
89+++ meta-database.js 2015-01-10 17:39:12 +0000
90@@ -1,5 +1,5 @@
91 /*
92- * Copyright (C) 2013, 2014
93+ * Copyright (C) 2013, 2014, 2015
94 * Andrew Hayzen <ahayzen@gmail.com>
95 * Daniel Holm <d.holmen@gmail.com>
96 * Victor Thompson <victor.thompson@gmail.com>
97@@ -121,6 +121,31 @@
98 }
99
100
101+// Optimised removeQueue for removing multiple tracks from the queue
102+function removeQueueList(list)
103+{
104+ var db = getDatabase()
105+ var res = false
106+
107+ db.transaction(function (tx) {
108+ // Remove all the deleted indexes
109+ for (var ind in list) {
110+ tx.executeSql('DELETE FROM queue WHERE ind=?;', [ind])
111+ }
112+
113+ // Rebuild queue in order
114+ var rs = tx.executeSql('SELECT ind FROM queue')
115+
116+ for (var i=0; i < rs.rows.length; i++) {
117+ tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
118+ [i, rs.rows.item(i).ind])
119+ }
120+ })
121+
122+ return res
123+}
124+
125+
126 function getQueue() {
127 var res = [];
128 var db = getDatabase();

Subscribers

People subscribed via source and target branches