update page caching

This commit is contained in:
Luke Pulverenti 2015-06-30 01:45:20 -04:00
parent b038bc1785
commit a81a127cc6
15 changed files with 72 additions and 55 deletions

View File

@ -0,0 +1,6 @@
window.Logger = {
log: function (str) {
LoggingBridge.log(str);
}
};

View File

@ -96,6 +96,8 @@
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
@ -184,7 +186,7 @@
page.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
reload(page);
}
});

View File

@ -55,6 +55,7 @@
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
@ -62,7 +63,7 @@
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
loadUpcoming(page);
}
});

View File

@ -176,7 +176,7 @@
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
if (window.ApiClient) {
var userId = Dashboard.getCurrentUserId();
@ -192,6 +192,8 @@
showWelcomeIfNeeded(page, result);
}
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
});

View File

@ -3,7 +3,7 @@
var pageSizeKey = 'pagesize_v4';
return {
getDefaultPageSize: function (key, defaultValue) {
getDefaultPageSize: function(key, defaultValue) {
var saved = appStorage.getItem(key || pageSizeKey);
@ -21,13 +21,13 @@
return isChrome ? 200 : 100;
},
getDefaultItemsView: function (view, mobileView) {
getDefaultItemsView: function(view, mobileView) {
return $.browser.mobile ? mobileView : view;
},
loadSavedQueryValues: function (key, query) {
loadSavedQueryValues: function(key, query) {
var values = appStorage.getItem(key + '_' + Dashboard.getCurrentUserId());
@ -41,7 +41,7 @@
return query;
},
saveQueryValues: function (key, query) {
saveQueryValues: function(key, query) {
var values = {};
@ -59,7 +59,7 @@
}
},
saveViewSetting: function (key, value) {
saveViewSetting: function(key, value) {
try {
appStorage.setItem(key + '_' + Dashboard.getCurrentUserId() + '_view', value);
@ -68,7 +68,7 @@
}
},
getSavedViewSetting: function (key) {
getSavedViewSetting: function(key) {
var deferred = $.Deferred();
var val = appStorage.getItem(key + '_' + Dashboard.getCurrentUserId() + '_view');
@ -77,6 +77,27 @@
return deferred.promise();
},
needsRefresh: function(elem) {
var last = elem.getAttribute('data-lastrefresh') || '0';
if (NavHelper.isBack()) {
return false;
}
var now = new Date().getTime();
if ((now - parseInt(last)) < 90000) {
return false;
}
return true;
},
setLastRefreshed: function(elem) {
elem.setAttribute('data-lastrefresh', new Date().getTime());
},
getDateParamValue: function (date) {
function formatDigit(i) {

View File

@ -699,28 +699,13 @@
}
}
// The first time we create the view menu bar, wait until doc ready + login validated
// Otherwise we run into the jQM redirect back and forth problem
var updateViewMenuBarBeforePageShow = false;
$(document).on('pagebeforeshowready', ".page", function () {
var page = this;
requiresDashboardDrawerRefresh = true;
if (updateViewMenuBarBeforePageShow) {
onPageBeforeShowDocumentReady(page);
}
}).one('pageshowready', ".page", function () {
var page = this;
$(function () {
onPageBeforeShowDocumentReady(page);
updateViewMenuBarBeforePageShow = true;
});
onPageBeforeShowDocumentReady(page);
}).on('pageshowready', ".page", function () {
@ -757,10 +742,7 @@
if (AppInfo.enableBottomTabs) {
page.classList.add('noSecondaryNavPage');
$(function () {
document.querySelector('.footer').classList.add('footerOverBottomTabs');
});
document.querySelector('.footer').classList.add('footerOverBottomTabs');
} else {
@ -972,25 +954,7 @@ $.fn.createHoverTouch = function () {
return backUrl == getWindowUrl();
}
function needsRefresh(elem) {
var last = elem.getAttribute('data-lastrefresh') || '0';
if (isBack()) {
return false;
}
var now = new Date().getTime();
if ((now - parseInt(last)) < 60000) {
return false;
}
elem.setAttribute('data-lastrefresh', now);
return true;
}
window.NavHelper = {
needsRefresh: needsRefresh,
isBack: isBack
};

View File

@ -65,6 +65,8 @@
renderChannels(page, result);
hideLoadingMessage(page);
LibraryBrowser.setLastRefreshed(page);
});
}
@ -116,7 +118,7 @@
// Can't use pagebeforeshow here or the loading popup won't center correctly
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
query.UserId = Dashboard.getCurrentUserId();
LibraryBrowser.loadSavedQueryValues('movies', query);
reloadItems(page);

View File

@ -70,6 +70,8 @@
Dashboard.hideModalLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
var channelPagingHtml = LibraryBrowser.getQueryPagingHtml({
@ -484,7 +486,7 @@
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
reloadPage(page);
}
});

View File

@ -28,6 +28,8 @@
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
@ -116,7 +118,7 @@
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
reload(page);
}
});

View File

@ -249,7 +249,7 @@
$(containers).removeClass('hiddenScrollX');
}
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
loadResume(page, userId, parentId);
loadLatest(page, userId, parentId);

View File

@ -47,6 +47,8 @@
ImageLoader.lazyChildren(elem);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
@ -192,7 +194,7 @@
$(containers).removeClass('hiddenScrollX');
}
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
loadLatest(page, parentId);
loadPlaylists(page, parentId);
loadRecentlyPlayed(page, parentId);

View File

@ -2016,6 +2016,10 @@ var AppInfo = {};
if (Dashboard.isConnectMode()) {
if (AppInfo.isNativeApp && $.browser.android) {
require(['cordova/android/logging']);
}
require(['appstorage'], function () {
capabilities.DeviceProfile = MediaPlayer.getDeviceProfile(Math.max(screen.height, screen.width));

View File

@ -7,6 +7,8 @@
function loadLatest(page) {
Dashboard.showLoadingMsg();
var userId = Dashboard.getCurrentUserId();
var parentId = LibraryMenu.getTopParentId();
@ -68,13 +70,16 @@
var elem = page.querySelector('#latestEpisodes');
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
$(document).on('pagebeforeshowready', "#tvNextUpPage", function () {
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
loadLatest(page);
}
});

View File

@ -92,6 +92,8 @@
elem.innerHTML = html;
ImageLoader.lazyChildren(elem);
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
@ -180,7 +182,7 @@
page.querySelector('#resumableItems').classList.remove('hiddenScrollX');
}
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
reload(page);
}
});

View File

@ -56,13 +56,15 @@
Dashboard.hideLoadingMsg();
LibraryBrowser.setLastRefreshed(page);
});
}
$(document).on('pagebeforeshowready', "#tvUpcomingPage", function () {
var page = this;
if (NavHelper.needsRefresh(page)) {
if (LibraryBrowser.needsRefresh(page)) {
loadUpcoming(page);
}
});