From 92e88e03e068b9b3b05f42ef26f376f2c7b65646 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Wed, 21 Apr 2021 22:59:16 -0400 Subject: [PATCH 1/4] Add a continue reading section --- src/components/homesections/homesections.js | 101 ++++---------------- src/strings/en-gb.json | 1 + src/strings/en-us.json | 1 + 3 files changed, 18 insertions(+), 85 deletions(-) diff --git a/src/components/homesections/homesections.js b/src/components/homesections/homesections.js index 794422ad1..b2edfc713 100644 --- a/src/components/homesections/homesections.js +++ b/src/components/homesections/homesections.js @@ -24,12 +24,14 @@ import ServerConnections from '../ServerConnections'; case 2: return 'resumeaudio'; case 3: - return 'livetv'; + return 'resumebook'; case 4: - return 'nextup'; + return 'livetv'; case 5: - return 'latestmedia'; + return 'nextup'; case 6: + return 'latestmedia'; + case 7: return 'none'; default: return ''; @@ -142,15 +144,17 @@ import ServerConnections from '../ServerConnections'; } else if (section === 'librarybuttons') { loadlibraryButtons(elem, apiClient, user, userSettings, userViews); } else if (section === 'resume') { - loadResumeVideo(elem, apiClient); + return loadResume(elem, apiClient, 'HeaderContinueWatching', 'Video'); } else if (section === 'resumeaudio') { - loadResumeAudio(elem, apiClient); + return loadResume(elem, apiClient, 'HeaderContinueListening', 'Audio'); } else if (section === 'activerecordings') { loadLatestLiveTvRecordings(elem, true, apiClient); } else if (section === 'nextup') { loadNextUp(elem, apiClient); } else if (section === 'onnow' || section === 'livetv') { return loadOnNow(elem, apiClient, user); + } else if (section == 'resumebook') { + return loadResume(elem, apiClient, 'HeaderContinueReading', 'Book'); } else { elem.innerHTML = ''; return Promise.resolve(); @@ -365,58 +369,10 @@ import ServerConnections from '../ServerConnections'; imageLoader.lazyChildren(elem); } - function getContinueWatchingFetchFn(serverId) { - return function () { - const apiClient = ServerConnections.getApiClient(serverId); - const screenWidth = dom.getWindowSize().innerWidth; - - let limit; - if (enableScrollX()) { - limit = 12; - } else { - limit = screenWidth >= 1920 ? 8 : (screenWidth >= 1600 ? 8 : (screenWidth >= 1200 ? 9 : 6)); - limit = Math.min(limit, 5); - } - - const options = { - Limit: limit, - Recursive: true, - Fields: 'PrimaryImageAspectRatio,BasicSyncInfo', - ImageTypeLimit: 1, - EnableImageTypes: 'Primary,Backdrop,Thumb', - EnableTotalRecordCount: false, - MediaTypes: 'Video' - }; - - return apiClient.getResumableItems(apiClient.getCurrentUserId(), options); - }; - } - - function getContinueWatchingItemsHtml(items) { - const cardLayout = false; - return cardBuilder.getCardsHtml({ - items: items, - preferThumb: true, - shape: getThumbShape(), - overlayText: false, - showTitle: true, - showParentTitle: true, - lazy: true, - showDetailsMenu: true, - overlayPlayButton: true, - context: 'home', - centerText: !cardLayout, - allowBottomPadding: false, - cardLayout: cardLayout, - showYear: true, - lines: 2 - }); - } - - function loadResumeVideo(elem, apiClient) { + function loadResume(elem, apiClient, headerText, mediaType) { let html = ''; - html += '

' + globalize.translate('HeaderContinueWatching') + '

'; + html += '

' + globalize.translate(headerText) + '

'; if (enableScrollX()) { html += '
'; html += '
'; @@ -433,12 +389,12 @@ import ServerConnections from '../ServerConnections'; elem.innerHTML = html; const itemsContainer = elem.querySelector('.itemsContainer'); - itemsContainer.fetchData = getContinueWatchingFetchFn(apiClient.serverId()); - itemsContainer.getItemsHtml = getContinueWatchingItemsHtml; + itemsContainer.fetchData = getItemsToResumeFn(mediaType, apiClient.serverId()); + itemsContainer.getItemsHtml = getItemsToResumeHtml; itemsContainer.parentContainer = elem; } - function getContinueListeningFetchFn(serverId) { + function getItemsToResumeFn(mediaType, serverId) { return function () { const apiClient = ServerConnections.getApiClient(serverId); const screenWidth = dom.getWindowSize().innerWidth; @@ -458,14 +414,14 @@ import ServerConnections from '../ServerConnections'; ImageTypeLimit: 1, EnableImageTypes: 'Primary,Backdrop,Thumb', EnableTotalRecordCount: false, - MediaTypes: 'Audio' + MediaTypes: mediaType }; return apiClient.getResumableItems(apiClient.getCurrentUserId(), options); }; } - function getContinueListeningItemsHtml(items) { + function getItemsToResumeHtml(items) { const cardLayout = false; return cardBuilder.getCardsHtml({ items: items, @@ -486,31 +442,6 @@ import ServerConnections from '../ServerConnections'; }); } - function loadResumeAudio(elem, apiClient) { - let html = ''; - - html += '

' + globalize.translate('HeaderContinueListening') + '

'; - if (enableScrollX()) { - html += '
'; - html += '
'; - } else { - html += '
'; - } - - if (enableScrollX()) { - html += '
'; - } - html += '
'; - - elem.classList.add('hide'); - elem.innerHTML = html; - - const itemsContainer = elem.querySelector('.itemsContainer'); - itemsContainer.fetchData = getContinueListeningFetchFn(apiClient.serverId()); - itemsContainer.getItemsHtml = getContinueListeningItemsHtml; - itemsContainer.parentContainer = elem; - } - function getOnNowFetchFn(serverId) { return function () { const apiClient = ServerConnections.getApiClient(serverId); diff --git a/src/strings/en-gb.json b/src/strings/en-gb.json index d1a563d91..15b379d00 100644 --- a/src/strings/en-gb.json +++ b/src/strings/en-gb.json @@ -37,6 +37,7 @@ "Folders": "Folders", "Genres": "Genres", "HeaderAlbumArtists": "Album Artists", + "HeaderContinueReading": "Continue Reading", "HeaderContinueWatching": "Continue Watching", "Movies": "Movies", "Photos": "Photos", diff --git a/src/strings/en-us.json b/src/strings/en-us.json index bf6d74a0b..54d4a8ca7 100644 --- a/src/strings/en-us.json +++ b/src/strings/en-us.json @@ -321,6 +321,7 @@ "HeaderContainerProfileHelp": "Container profiles indicate the limitations of a device when playing specific formats. If a limitation applies then the media will be transcoded, even if the format is configured for direct play.", "HeaderContinueListening": "Continue Listening", "HeaderContinueWatching": "Continue Watching", + "HeaderContinueReading": "Continue Reading", "HeaderCustomDlnaProfiles": "Custom Profiles", "HeaderDateIssued": "Date Issued", "HeaderDebugging": "Debugging and Tracing", From 064b85d0eeb25c3fb82b327095bdf82f97f8e9e9 Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Wed, 28 Apr 2021 20:37:37 -0400 Subject: [PATCH 2/4] Set correct data-monitor based on type --- src/components/homesections/homesections.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/components/homesections/homesections.js b/src/components/homesections/homesections.js index b2edfc713..bc31d6049 100644 --- a/src/components/homesections/homesections.js +++ b/src/components/homesections/homesections.js @@ -372,12 +372,20 @@ import ServerConnections from '../ServerConnections'; function loadResume(elem, apiClient, headerText, mediaType) { let html = ''; + let dataMonitor = 'data-monitor="'; + if (mediaType == 'Video') { + dataMonitor += 'videoplayback,' + } else if (mediaType == 'Audio') { + dataMonitor += 'audioplayback,' + } + dataMonitor += 'markplayed">'; + html += '

' + globalize.translate(headerText) + '

'; if (enableScrollX()) { html += '
'; - html += '
'; + html += '
Date: Thu, 29 Apr 2021 22:19:20 -0400 Subject: [PATCH 3/4] Apply suggestions from code review Co-authored-by: Dmitry Lyzo <56478732+dmitrylyzo@users.noreply.github.com> --- src/components/homesections/homesections.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/components/homesections/homesections.js b/src/components/homesections/homesections.js index bc31d6049..85b5583f7 100644 --- a/src/components/homesections/homesections.js +++ b/src/components/homesections/homesections.js @@ -153,7 +153,7 @@ import ServerConnections from '../ServerConnections'; loadNextUp(elem, apiClient); } else if (section === 'onnow' || section === 'livetv') { return loadOnNow(elem, apiClient, user); - } else if (section == 'resumebook') { + } else if (section === 'resumebook') { return loadResume(elem, apiClient, 'HeaderContinueReading', 'Book'); } else { elem.innerHTML = ''; @@ -369,23 +369,22 @@ import ServerConnections from '../ServerConnections'; imageLoader.lazyChildren(elem); } + const dataMonitorHints = { + 'Audio': 'audioplayback,markplayed', + 'Video': 'videoplayback,markplayed' + }; + function loadResume(elem, apiClient, headerText, mediaType) { let html = ''; - let dataMonitor = 'data-monitor="'; - if (mediaType == 'Video') { - dataMonitor += 'videoplayback,' - } else if (mediaType == 'Audio') { - dataMonitor += 'audioplayback,' - } - dataMonitor += 'markplayed">'; + const dataMonitor = dataMonitorHints[mediaType] || 'markplayed'; html += '

' + globalize.translate(headerText) + '

'; if (enableScrollX()) { html += '
'; - html += '
`; } else { - html += '
`; } if (enableScrollX()) { From 054e34d499b79b8d774350ba1cf3b8952f9b125f Mon Sep 17 00:00:00 2001 From: Nathan Mascitelli Date: Thu, 29 Apr 2021 22:26:18 -0400 Subject: [PATCH 4/4] Add continue reading to template --- .../homeScreenSettings/homeScreenSettings.template.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/homeScreenSettings/homeScreenSettings.template.html b/src/components/homeScreenSettings/homeScreenSettings.template.html index 615598a1a..d3a9206c3 100644 --- a/src/components/homeScreenSettings/homeScreenSettings.template.html +++ b/src/components/homeScreenSettings/homeScreenSettings.template.html @@ -24,6 +24,7 @@ + @@ -37,6 +38,7 @@ + @@ -50,6 +52,7 @@ + @@ -63,6 +66,7 @@ + @@ -76,6 +80,7 @@ + @@ -89,6 +94,7 @@ + @@ -102,6 +108,7 @@ +