Merge lp:~ahayzen/music-app/remix-recent-db-changes into lp:music-app/remix

Proposed by Andrew Hayzen
Status: Merged
Approved by: Victor Thompson
Approved revision: 705
Merged at revision: 709
Proposed branch: lp:~ahayzen/music-app/remix-recent-db-changes
Merge into: lp:music-app/remix
Diff against target: 330 lines (+90/-89)
4 files modified
MusicStart.qml (+14/-7)
common/SongsPage.qml (+18/-12)
meta-database.js (+53/-65)
music-app.qml (+5/-5)
To merge this branch: bzr merge lp:~ahayzen/music-app/remix-recent-db-changes
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Victor Thompson Approve
Review via email: mp+239665@code.launchpad.net

Commit message

* Change recent schemas so that it stores less and loads more from ms2 (eg art)

Description of the change

* Change recent schemas so that it stores less and loads more from ms2 (eg art)

NOTE if you use this branch you will have to delete the database in order to go back to older branches as this has db changes.

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
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
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 :

LGTM!

review: Approve
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Victor Thompson (vthompson) :
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 'MusicStart.qml'
2--- MusicStart.qml 2014-10-26 16:18:12 +0000
3+++ MusicStart.qml 2014-10-28 02:09:23 +0000
4@@ -51,24 +51,31 @@
5 model: recentModel.model
6 delegate: Card {
7 id: albumCard
8- coverSources: model.type === "playlist" ? Playlists.getPlaylistCovers(title) : (model.art !== undefined ? [{art: model.art}] : [{author: model.title2, album: model.title}])
9+
10+ SongsModel {
11+ id: recentAlbumSongs
12+ album: model.type === "album" ? model.data : undefined
13+ store: musicStore
14+ }
15+
16+ coverSources: model.type === "playlist" ? Playlists.getPlaylistCovers(model.data) : (recentAlbumSongs.status === SongsModel.Ready ? [makeDict(recentAlbumSongs.get(0, SongsModel.RoleModelData))] : [])
17 objectName: "albumsPageGridItem" + index
18- primaryText: model.title
19- secondaryText: model.title2 !== "Playlist" ? model.title2 : i18n.tr("Playlist")
20+ primaryText: model.type === "playlist" ? model.data : (recentAlbumSongs.status === SongsModel.Ready ? recentAlbumSongs.get(0, SongsModel.RoleModelData).album : "")
21+ secondaryText: model.type === "playlist" ? i18n.tr("Playlist") : (recentAlbumSongs.status === SongsModel.Ready ? recentAlbumSongs.get(0, SongsModel.RoleModelData).author : "")
22
23 onClicked: {
24 if (type === "playlist") {
25- albumTracksModel.filterPlaylistTracks(model.key)
26+ albumTracksModel.filterPlaylistTracks(model.data)
27 }
28
29 var comp = Qt.createComponent("common/SongsPage.qml")
30 var songsPage = comp.createObject(mainPageStack,
31 {
32- "album": type !== "playlist" ? title : undefined,
33+ "album": model.type !== "playlist" ? title : undefined,
34 "covers": coverSources,
35- "isAlbum": (type === "album"),
36+ "isAlbum": (model.type === "album"),
37 "genre": undefined,
38- "title": (type === "album") ? i18n.tr("Album") : i18n.tr("Playlist"),
39+ "title": (model.type === "album") ? i18n.tr("Album") : i18n.tr("Playlist"),
40 "line1": secondaryText,
41 "line2": primaryText,
42 });
43
44=== modified file 'common/SongsPage.qml'
45--- common/SongsPage.qml 2014-10-28 00:00:26 +0000
46+++ common/SongsPage.qml 2014-10-28 02:09:23 +0000
47@@ -233,12 +233,14 @@
48 shuffleModel(albumtrackslist.model) // play track
49
50 if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
51- Library.addRecent(songStackPage.line2, songStackPage.line1, songStackPage.covers[0], songStackPage.line2, "album")
52- recentModel.filterRecent()
53+ Library.addRecent(albumtrackslist.model.get(0, albumtrackslist.model.RoleModelData).album, "album")
54 } else if (songStackPage.line1 === i18n.tr("Playlist")) {
55- Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
56- recentModel.filterRecent()
57+ Library.addRecent(songStackPage.line2, "playlist")
58+ } else {
59+ console.debug("Unknown type to add to recent")
60 }
61+
62+ recentModel.filterRecent()
63 }
64 }
65 Button {
66@@ -265,12 +267,14 @@
67 trackClicked(albumtrackslist.model, 0) // play track
68
69 if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
70- Library.addRecent(songStackPage.line2, songStackPage.line1, songStackPage.covers[0], songStackPage.line2, "album")
71- recentModel.filterRecent()
72+ Library.addRecent(albumtrackslist.model.get(0, albumtrackslist.model.RoleModelData).album, "album")
73 } else if (songStackPage.line1 === i18n.tr("Playlist")) {
74- Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
75- recentModel.filterRecent()
76+ Library.addRecent(songStackPage.line2, "playlist")
77+ } else {
78+ console.debug("Unknown type to add to recent")
79 }
80+
81+ recentModel.filterRecent()
82 }
83 }
84 }
85@@ -364,12 +368,14 @@
86 trackClicked(albumtrackslist.model, index) // play track
87
88 if (isAlbum && songStackPage.line1 !== i18n.tr("Genre")) {
89- Library.addRecent(songStackPage.line2, songStackPage.line1, model.art, songStackPage.line2, "album")
90- recentModel.filterRecent()
91+ Library.addRecent(albumtrackslist.model.get(0, albumtrackslist.model.RoleModelData).album, "album")
92 } else if (songStackPage.line1 === i18n.tr("Playlist")) {
93- Library.addRecent(songStackPage.line2, "Playlist", songStackPage.covers[0], songStackPage.line2, "playlist")
94- recentModel.filterRecent()
95+ Library.addRecent(songStackPage.line2, "playlist")
96+ } else {
97+ console.debug("Unknown type to add to recent")
98 }
99+
100+ recentModel.filterRecent()
101 }
102 onReorder: {
103 console.debug("Move: ", from, to);
104
105=== modified file 'meta-database.js'
106--- meta-database.js 2014-10-27 18:34:26 +0000
107+++ meta-database.js 2014-10-28 02:09:23 +0000
108@@ -22,20 +22,6 @@
109 return LocalStorage.openDatabaseSync("music-app-metadata", "1.0", "StorageDatabase", 1000000);
110 }
111
112-// At the start of the application, we can initialize the tables we need if they haven't been created yet
113-function initialize() {
114- var db = getDatabase();
115- db.transaction(
116- function(tx) {
117- // Create the table if it doesn't already exist
118- // If the table exists, this is skipped
119- tx.executeSql('DROP TABLE IF EXISTS metadata'); // TODO: drop recent as well to reset data
120-
121- createRecent();
122- createQueue();
123- });
124-}
125-
126 function createQueue() {
127 var db = getDatabase();
128 db.transaction(
129@@ -170,10 +156,15 @@
130 var db = getDatabase();
131 db.transaction(
132 function(tx) {
133- // "key" is the search criteria for the type.
134- // album title for album, and playlist title for playlist
135- //tx.executeSql('DROP TABLE recent');
136- tx.executeSql("CREATE TABLE IF NOT EXISTS recent(time DATETIME, title TEXT, title2 TEXT, cover TEXT, key TEXT UNIQUE, type TEXT)");
137+ // Data is either the playlist name or album name
138+ tx.executeSql("CREATE TABLE IF NOT EXISTS recent(time DATETIME UNIQUE, data TEXT, type TEXT)");
139+
140+ // Check of old version of db and then clear if needed
141+ try {
142+ tx.executeSql("SELECT data FROM recent");
143+ } catch (e) {
144+ clearRecentHistory();
145+ }
146 });
147 }
148
149@@ -182,53 +173,46 @@
150 db.transaction(
151 function(tx) {
152 tx.executeSql('DROP TABLE IF EXISTS recent');
153- tx.executeSql("CREATE TABLE IF NOT EXISTS recent(time DATETIME, title TEXT, title2 TEXT, cover TEXT, key TEXT UNIQUE, type TEXT)");
154+ tx.executeSql("CREATE TABLE IF NOT EXISTS recent(time DATETIME UNIQUE, data TEXT, type TEXT)");
155 });
156 }
157
158+
159 // This function is used to insert a recent item into the database
160-function addRecent(title, title2, cover, key, type) {
161+function addRecent(data, type) {
162 var db = getDatabase();
163- var res="";
164-
165- console.log("RECENT " + key + title + title2 + cover)
166-
167- db.transaction(function(tx) {
168- var rs = tx.executeSql('INSERT OR REPLACE INTO recent (time, title, title2, cover, key, type) VALUES (?,?,?,?,?,?);', [new Date(), title, title2, cover, key, type]);
169- if (rs.rowsAffected > 0) {
170- console.log("RECENT add OK")
171- res = "OK";
172- } else {
173- console.log("RECENT add Fail")
174- res = "Error";
175- }
176- }
177- );
178+
179+ console.debug("RECENT", data, type);
180+
181+
182+ db.transaction(function (tx) {
183+ // Remove old albums/playlists with same name as they have a new time
184+ if (type === "album") {
185+ tx.executeSql("DELETE FROM recent WHERE type=? AND data=?", ["album", data])
186+ } else if (type === "playlist") {
187+ tx.executeSql("DELETE FROM recent WHERE type=? AND data=?", ["playlist", data])
188+ }
189+
190+ var rs = tx.executeSql('INSERT OR REPLACE INTO recent (time, data, type) VALUES (?, ?, ?)', [new Date(), data, type]);
191+
192+ if (rs.rowsAffected <= 0) {
193+ console.debug("RECENT add Fail")
194+ }
195+ });
196 }
197
198 function getRecent() {
199 var res = [];
200 var db = getDatabase();
201+
202 db.transaction( function(tx) {
203 var rs = tx.executeSql("SELECT * FROM recent ORDER BY time DESC LIMIT 15");
204 for(var i = 0; i < rs.rows.length; i++) {
205 var dbItem = rs.rows.item(i);
206- console.log("Time:"+ dbItem.time + ", Key:"+dbItem.key + ", Title:"+dbItem.title + ", Title2:"+dbItem.title2 + ", Type:"+dbItem.type + ", Art:"+dbItem.cover);
207-
208- if (dbItem.type === "album")
209- {
210- res.push({time:dbItem.time,
211- title:dbItem.title || i18n.tr("Unknown Album"),
212- title2:dbItem.title2 || i18n.tr("Unknown Artist"),
213- key:dbItem.key || i18n.tr("Unknown Album"),
214- art:dbItem.cover || undefined,
215- type:dbItem.type
216- });
217- }
218- else
219- {
220- res.push({time:dbItem.time, title:dbItem.title, title2:dbItem.title2, key:dbItem.key, type:dbItem.type});
221- }
222+
223+ console.log("Time:", dbItem.time, ", Data:", dbItem.data, ", Type:", dbItem.type);
224+
225+ res.push({"time": dbItem.time, "data": dbItem.data, "type": dbItem.type});
226 }
227 });
228 return res;
229@@ -237,48 +221,52 @@
230 function recentContainsPlaylist(key) {
231 var db = getDatabase();
232 var rs;
233- db.transaction( function(tx) {
234- rs = tx.executeSql("SELECT count(*) as value FROM recent WHERE type=? AND key=?",
235- ["playlist", key]);
236- }
237- );
238+
239+ db.transaction(function(tx) {
240+ rs = tx.executeSql("SELECT count(*) as value FROM recent WHERE type=? AND data=?",
241+ ["playlist", key]);
242+ });
243+
244 return rs.rows.item(0).value > 0;
245 }
246
247 function recentRemovePlaylist(key) {
248 var res = false
249 var db = getDatabase();
250+
251 db.transaction( function(tx) {
252- res = tx.executeSql("DELETE FROM recent WHERE type=? AND key=?",
253+ res = tx.executeSql("DELETE FROM recent WHERE type=? AND data=?",
254 ["playlist", key]).rowsAffected > 0;
255
256 })
257- return res
258+
259+ return res;
260 }
261
262 function recentRenamePlaylist(oldKey, newKey) {
263 var db = getDatabase();
264+
265 db.transaction( function(tx) {
266- tx.executeSql("UPDATE recent SET title=?,key=? WHERE type=? AND key=?",
267- [newKey, newKey, "playlist", oldKey]);
268+ tx.executeSql("UPDATE recent SET data=?, WHERE type=? AND data=?",
269+ [newKey, "playlist", oldKey]);
270
271- })
272+ });
273 }
274
275 function isRecentEmpty() {
276 var db = getDatabase();
277 var res = 0;
278
279- db.transaction( function(tx) {
280- createRecent();
281+ db.transaction(function(tx) {
282 var rs = tx.executeSql("SELECT count(*) as value FROM recent")
283+
284 if (rs.rows.item(0).value > 0) {
285 res = rs.rows.item(0).value;
286 } else {
287 console.log("RECENT does not exist")
288 res = 0;
289 }
290- }
291- );
292+ });
293+
294 return res === 0;
295 }
296
297=== modified file 'music-app.qml'
298--- music-app.qml 2014-10-28 00:15:37 +0000
299+++ music-app.qml 2014-10-28 02:09:23 +0000
300@@ -203,10 +203,6 @@
301 // Filter by artist and album
302 songsAlbumArtistModel.artist = decodeURIComponent(split[0]);
303 songsAlbumArtistModel.album = decodeURIComponent(split[1]);
304-
305- // Add album to recent list
306- Library.addRecent(songsAlbumArtistModel.album, songsAlbumArtistModel.artist, songsAlbumArtistModel.art, songsAlbumArtistModel.album, "album")
307- recentModel.filterRecent()
308 }
309
310 function processFile(uri, play) {
311@@ -557,7 +553,7 @@
312
313 customdebug("Arguments on startup: Debug: "+args.values.debug+ " and file: ")
314
315- Library.initialize();
316+ Library.createRecent() // initialize recent
317
318 // initialize playlists
319 Playlists.initializePlaylist()
320@@ -738,6 +734,10 @@
321 // Play album it tracks exist
322 if (rowCount > 0 && selectedAlbum) {
323 trackClicked(songsAlbumArtistModel, 0, true, true);
324+
325+ // Add album to recent list
326+ Library.addRecent(songsAlbumArtistModel.model.get(0, model.RoleModelData).album, "album")
327+ recentModel.filterRecent()
328 } else if (selectedAlbum) {
329 console.debug("Unknown artist-album " + artist + "/" + album + ", skipping")
330 }

Subscribers

People subscribed via source and target branches