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
=== modified file 'MusicNowPlaying.qml'
--- MusicNowPlaying.qml 2015-01-08 00:47:52 +0000
+++ MusicNowPlaying.qml 2015-01-10 17:39:12 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013, 20142 * Copyright (C) 2013, 2014, 2015
3 * Andrew Hayzen <ahayzen@gmail.com>3 * Andrew Hayzen <ahayzen@gmail.com>
4 * Daniel Holm <d.holmen@gmail.com>4 * Daniel Holm <d.holmen@gmail.com>
5 * Victor Thompson <victor.thompson@gmail.com>5 * Victor Thompson <victor.thompson@gmail.com>
@@ -172,9 +172,10 @@
172 iconName: "delete"172 iconName: "delete"
173 text: i18n.tr("Delete")173 text: i18n.tr("Delete")
174 onTriggered: {174 onTriggered: {
175 for (var i=0; i < queueListLoader.item.selectedItems.length; i++) {175 // Remove the tracks from the queue
176 removeQueue(queueListLoader.item.selectedItems[i])176 // Use slice() to copy the list
177 }177 // so that the indexes don't change as they are removed
178 removeQueueList(queueListLoader.item.selectedItems.slice())
178179
179 queueListLoader.item.closeSelection()180 queueListLoader.item.closeSelection()
180 }181 }
@@ -505,6 +506,60 @@
505 }506 }
506 }507 }
507508
509 // Optimised removeQueue for removing multiple tracks from the queue
510 function removeQueueList(items)
511 {
512 var i;
513
514 // Remove from the saved queue database
515 Library.removeQueueList(items)
516
517
518 // Remove from the listmodel
519 for (i=0; i < items.length; i++) {
520 trackQueue.model.remove(items[i] - i);
521 }
522
523 // Update the currentIndex and playing status
524
525 if (trackQueue.model.count === 0) {
526 // Nothing in the queue so stop and pop the queue
527 player.stop()
528 musicToolbar.goBack()
529 } else if (items.indexOf(player.currentIndex) > -1) {
530 // Current track was removed
531
532 // Find the first index that still exists before the currentIndex
533 for (i=player.currentIndex - 1; i > -1; i--) {
534 if (items.indexOf(i) === -1) {
535 break;
536 }
537 }
538
539 // Set this as the current track
540 player.currentIndex = i
541 queueIndex = i
542
543 // Play the next track
544 player.nextSong(player.isPlaying);
545 } else {
546 // Current track not in removed list
547 // Check if the index needs to be shuffled down due to removals
548
549 var before = 0
550
551 for (i in items) {
552 if (i < player.currentIndex) {
553 before++;
554 }
555 }
556
557 // Update the index
558 player.currentIndex -= before;
559 queueIndex -= before;
560 }
561 }
562
508 Loader {563 Loader {
509 id: queueListLoader564 id: queueListLoader
510 anchors {565 anchors {
511566
=== modified file 'meta-database.js'
--- meta-database.js 2014-11-15 22:48:52 +0000
+++ meta-database.js 2015-01-10 17:39:12 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013, 20142 * Copyright (C) 2013, 2014, 2015
3 * Andrew Hayzen <ahayzen@gmail.com>3 * Andrew Hayzen <ahayzen@gmail.com>
4 * Daniel Holm <d.holmen@gmail.com>4 * Daniel Holm <d.holmen@gmail.com>
5 * Victor Thompson <victor.thompson@gmail.com>5 * Victor Thompson <victor.thompson@gmail.com>
@@ -121,6 +121,31 @@
121}121}
122122
123123
124// Optimised removeQueue for removing multiple tracks from the queue
125function removeQueueList(list)
126{
127 var db = getDatabase()
128 var res = false
129
130 db.transaction(function (tx) {
131 // Remove all the deleted indexes
132 for (var ind in list) {
133 tx.executeSql('DELETE FROM queue WHERE ind=?;', [ind])
134 }
135
136 // Rebuild queue in order
137 var rs = tx.executeSql('SELECT ind FROM queue')
138
139 for (var i=0; i < rs.rows.length; i++) {
140 tx.executeSql('UPDATE queue SET ind=? WHERE ind=?;',
141 [i, rs.rows.item(i).ind])
142 }
143 })
144
145 return res
146}
147
148
124function getQueue() {149function getQueue() {
125 var res = [];150 var res = [];
126 var db = getDatabase();151 var db = getDatabase();

Subscribers

People subscribed via source and target branches