From 4a6deb3b44441a2eee7f8a0f34ed1b0d68c965b6 Mon Sep 17 00:00:00 2001 From: Nick Bisby Date: Sat, 24 Oct 2020 17:50:07 -0500 Subject: [PATCH 1/3] Add a favorites filter to movies --- components/ItemGrid2/ItemGrid2.brs | 18 +++++++++++- components/ItemGrid2/ItemGridOptions.brs | 35 +++++++++++++++++++++++- components/ItemGrid2/ItemGridOptions.xml | 8 ++---- components/ItemGrid2/LoadItemsTask2.brs | 9 +++++- components/ItemGrid2/LoadItemsTask2.xml | 3 +- source/ShowScenes.brs | 2 +- 6 files changed, 65 insertions(+), 10 deletions(-) diff --git a/components/ItemGrid2/ItemGrid2.brs b/components/ItemGrid2/ItemGrid2.brs index 0a8a3f9c..e32eb54d 100644 --- a/components/ItemGrid2/ItemGrid2.brs +++ b/components/ItemGrid2/ItemGrid2.brs @@ -29,6 +29,8 @@ sub init() m.sortField = "SortName" m.sortAscending = true + m.filter = "All" + m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2") m.loadItemsTask.observeField("content", "ItemDataLoaded") @@ -45,6 +47,7 @@ sub loadInitialItems() m.loadItemsTask.itemId = m.top.parentItem.Id m.loadItemsTask.sortField = m.sortField m.loadItemsTask.sortAscending = m.sortAscending + m.loadItemsTask.filter = m.filter m.loadItemsTask.startIndex = 0 if m.top.parentItem.collectionType = "movies" then @@ -70,7 +73,9 @@ sub SetUpOptions() 'Movies if m.top.parentItem.collectionType = "movies" then - options.views = [{ "Title": tr("Movies"), "Name": "movies" }] + options.views = [ + { "Title": tr("Movies"), "Name": "movies" }, + ] options.sort = [ { "Title": tr("TITLE"), "Name": "SortName" }, { "Title": tr("IMDB_RATING"), "Name": "CommunityRating" }, @@ -82,6 +87,10 @@ sub SetUpOptions() { "Title": tr("RELEASE_DATE"), "Name": "PremiereDate" }, { "Title": tr("RUNTIME"), "Name": "Runtime" } ] + options.filter = [ + { "Title": tr("All"), "Name": "All", "selected": true }, + { "Title": tr("Favorites"), "Name": "Favorites" } + ] 'TV Shows else if m.top.parentItem.collectionType = "tvshows" then options.views = [{ "Title": tr("Shows"), "Name": "shows" }] @@ -237,6 +246,13 @@ sub optionsClosed() m.data = CreateObject("roSGNode", "ContentNode") m.itemGrid.content = m.data loadInitialItems() + else if m.options.filter <> m.filter then + m.filter = m.options.filter + m.loadedRows = 0 + m.loadedItems = 0 + m.data = CreateObject("roSGNode", "ContentNode") + m.itemGrid.content = m.data + loadInitialItems() end if m.itemGrid.setFocus(true) end sub diff --git a/components/ItemGrid2/ItemGridOptions.brs b/components/ItemGrid2/ItemGridOptions.brs index cc54a1ff..edffb75a 100644 --- a/components/ItemGrid2/ItemGridOptions.brs +++ b/components/ItemGrid2/ItemGridOptions.brs @@ -14,6 +14,7 @@ sub init() m.viewNames = [] m.sortNames = [] + m.filterNames = [] ' Animation m.fadeAnim = m.top.findNode("fadeAnim") @@ -78,6 +79,33 @@ sub optionsSet() end if end if + ' Filter Tab + if m.top.options.filter <> invalid then + filterContent = CreateObject("roSGNode", "ContentNode") + index = 0 + m.selectedFilterIndex = 0 + + for each filterItem in m.top.options.filter + entry = filterContent.CreateChild("ContentNode") + entry.title = filterItem.Title + m.filterNames.push(filterItem.Name) + if filterItem.selected <> invalid and filterItem.selected = true then + m.selectedFilterIndex = index + end if + index = index + 1 + end for + m.menus[2].content = filterContent + m.menus[2].checkedItem = m.selectedFilterIndex + else + filterContent = CreateObject("roSGNode", "ContentNode") + entry = filterContent.CreateChild("ContentNode") + entry.title = "All" + m.filterNames.push("All") + m.menus[2].content = filterContent + m.menus[2].checkedItem = 0 + end if + + end sub ' Switch menu shown when button focus changes @@ -106,8 +134,8 @@ function onKeyEvent(key as string, press as boolean) as boolean return true else if key = "OK" - ' Handle Sort screen if(m.menus[m.selectedItem].isInFocusChain()) then + ' Handle Sort screen if(m.selectedItem = 1) then if m.menus[1].itemSelected <> m.selectedSortIndex then m.menus[1].focusedCheckedIconUri = m.global.constants.icons.ascending_black @@ -129,6 +157,11 @@ function onKeyEvent(key as string, press as boolean) as boolean end if end if end if + ' Handle Filter screen + if(m.selectedItem = 2) then + m.selectedFilterIndex = m.menus[2].itemSelected + m.top.filter = m.filterNames[m.selectedFilterIndex] + end if end if return true else if key = "back" or key = "up" diff --git a/components/ItemGrid2/ItemGridOptions.xml b/components/ItemGrid2/ItemGridOptions.xml index 8fbbab9e..28907179 100644 --- a/components/ItemGrid2/ItemGridOptions.xml +++ b/components/ItemGrid2/ItemGridOptions.xml @@ -11,11 +11,8 @@ - - - - - + + @@ -33,6 +30,7 @@ +