diff --git a/js/controllers.js b/js/controllers.js index 45dd660..55b484b 100644 --- a/js/controllers.js +++ b/js/controllers.js @@ -52,10 +52,8 @@ function FeedCtrl($scope, $routeParams, $location, feeds, pageSwitcher) { pageSwitcher.setBack('feeds'); } -function QueueListCtrl($scope, $rootScope, pageSwitcher, feedItems, feeds, queueList) { - $scope.queue = []; - queueList.init($scope); - feedItems.listQueue(queueList); +function QueueListCtrl($scope, $rootScope, pageSwitcher, feedItems, feeds, downloader, newQueueList) { + $scope.queue = newQueueList.getQueueList(); $scope.playItem = function(id) { feedItems.get(id, function(feedItem) { diff --git a/js/services.js b/js/services.js index b613625..16ecad4 100644 --- a/js/services.js +++ b/js/services.js @@ -1,7 +1,7 @@ 'use strict'; /* Services */ -angular.module('podcasts.services', ['podcasts.utilities']) +angular.module('podcasts.services', ['podcasts.utilities', 'podcasts.queueList']) .value('queueList', { queue: [], scope: null, @@ -828,6 +828,46 @@ angular.module('podcasts.settings', ['podcasts.database']) }]) ; +angular.module('podcasts.queueList', ['podcasts.database']) + .run(['newQueueList', function(queueList) { + queueList.rebuildList(); + }]) + .service('newQueueList', ['db', '$rootScope', function(oldDb, $rootScope) { + var queueList = []; + + function getQueueList() { + return queueList; + } + + function rebuildList() { + oldDb.getCursor("feedItem", function(ixDbCursorReq) + { + if(typeof ixDbCursorReq !== "undefined") { + ixDbCursorReq.onsuccess = function (e) { + var cursor = ixDbCursorReq.result || e.result; + if (cursor) { + // This additional check is necessary, since the index doesn't seem to always catch correctly + if (cursor.value.queued) { + queueList.push(cursor.value); + } + + cursor.continue(); + } else { + $rootScope.$apply(); + } + } + } + }, undefined, IDBKeyRange.only(1), false, 'ixQueued'); + } + + return { + rebuildList: rebuildList, + getQueueList: getQueueList + }; + }]) +; + + angular.module('podcasts.importer', ['podcasts.utilities', 'podcasts.services']) .service('opml', ['xmlParser', 'feeds', function(xmlParser, feeds) { return {