Merge lp:~ahayzen/music-app/remix-fix-playlists-1392022 into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 737
Merged at revision: 737
Proposed branch: lp:~ahayzen/music-app/remix-fix-playlists-1392022
Merge into: lp:music-app/remix
Diff against target: 83 lines (+37/-16)
1 file modified
playlists.js (+37/-16)
To merge this branch: bzr merge lp:~ahayzen/music-app/remix-fix-playlists-1392022
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Victor Thompson Approve
Review via email: mp+241626@code.launchpad.net

Commit message

* Remove erroneous tracks from the playlist

Description of the change

* Remove erroneous tracks from the playlist

This removes any tracks that are no longer in the playlist.

TESTING:
1) Make a playlist with multiple tracks eg 1, 2, 3, 2, 3
2) Optionally close the app
3) Delete track 2 from the device
4) Start the app if you closed it
5) Open the playlist and only tracks 1, 3, 3 should be shown.
Note the covers should be correct on the playlists tab but the count will be incorrect until a restart.

To post a comment you must log in.
Revision history for this message
Victor Thompson (vthompson) wrote :

LGTM! Good work with the quick turnaround!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'playlists.js'
2--- playlists.js 2014-11-10 02:55:32 +0000
3+++ playlists.js 2014-11-12 21:21:22 +0000
4@@ -202,6 +202,8 @@
5 var db = getPlaylistDatabase()
6 var res = []
7
8+ var erroneousTracks = [];
9+
10 try {
11 db.transaction(function (tx) {
12 var rs = tx.executeSql('SELECT * FROM track WHERE playlist=?;',
13@@ -209,20 +211,37 @@
14 for (var j = 0; j < rs.rows.length; j++) {
15 var dbItem = rs.rows.item(j)
16
17- res.push({
18- i: dbItem.i,
19- filename: dbItem.filename,
20- title: dbItem.title,
21- author: dbItem.author,
22- album: dbItem.album,
23- art: musicStore.lookup(dbItem.filename).art
24- })
25- }
26+ if (musicStore.lookup(dbItem.filename) === null) {
27+ erroneousTracks.push(dbItem.i);
28+ } else {
29+ res.push({
30+ i: dbItem.i,
31+ filename: dbItem.filename,
32+ title: dbItem.title,
33+ author: dbItem.author,
34+ album: dbItem.album,
35+ art: musicStore.lookup(dbItem.filename).art
36+ })
37+ }
38+ }
39+
40+ // remove bad tracks
41+ for (var j=0; j < erroneousTracks.length; j++) {
42+ console.debug("Remove", erroneousTracks[j], "from playlist", playlist);
43+ res = tx.executeSql('DELETE FROM track WHERE playlist=? AND i=?;',
44+ [playlist, erroneousTracks[j]]).rowsAffected > 0
45+ }
46+
47+ reorder(playlist, "remove", tx)
48 })
49 } catch (e) {
50 return []
51 }
52
53+ if (erroneousTracks.length > 0) { // reget data as indexes are out of sync
54+ res = getPlaylistTracks(playlist)
55+ }
56+
57 return res
58 }
59
60@@ -260,14 +279,16 @@
61
62 for (var i = 0; i < rs.rows.length
63 && i < (max || rs.rows.length); i++) {
64- var row = {
65- author: rs.rows.item(i).author,
66- album: rs.rows.item(i).album,
67- art: musicStore.lookup(rs.rows.item(i).filename).art
68- }
69+ if (musicStore.lookup(rs.rows.item(i).filename) !== null) {
70+ var row = {
71+ author: rs.rows.item(i).author,
72+ album: rs.rows.item(i).album,
73+ art: musicStore.lookup(rs.rows.item(i).filename).art
74+ }
75
76- if (find(res, row) === null) {
77- res.push(row)
78+ if (find(res, row) === null) {
79+ res.push(row)
80+ }
81 }
82 }
83 })

Subscribers

People subscribed via source and target branches