From 5d3dc87d629385a0a93b0edd97b4af44cd9e9607 Mon Sep 17 00:00:00 2001 From: Neil Burrows Date: Sun, 16 Aug 2020 15:44:03 +0100 Subject: [PATCH] Constants to own file and tighten up UI UX --- components/Buttons/JFButtons.brs | 3 + components/Buttons/JFButtons.xml | 2 +- components/ItemGrid2/GridItem.brs | 2 +- components/ItemGrid2/ItemGrid2.brs | 132 +++++++++++++++++------ components/ItemGrid2/LoadItemsTask2.brs | 10 +- components/ItemGrid2/LoadItemsTask2.xml | 2 + components/ListPoster.brs | 2 +- components/home/HomeItem.brs | 2 +- components/options/OptionsScreen.brs | 135 +++++++++++++++--------- components/options/OptionsScreen.xml | 56 ++-------- source/Main.brs | 5 +- source/api/constants.brs | 29 +++++ 12 files changed, 246 insertions(+), 134 deletions(-) create mode 100644 source/api/constants.brs diff --git a/components/Buttons/JFButtons.brs b/components/Buttons/JFButtons.brs index 83ff3c1f..3c31c71b 100644 --- a/components/Buttons/JFButtons.brs +++ b/components/Buttons/JFButtons.brs @@ -13,6 +13,9 @@ sub init() m.focusAnimWidth = m.top.findNode("focusWidth") m.focusAnimHeight = m.top.findNode("focusHeight") + ' Set button color to global + m.focusRing.color = m.global.constants.colors.button + m.buttonCount = 0 m.selectedFocusedIndex = 1 diff --git a/components/Buttons/JFButtons.xml b/components/Buttons/JFButtons.xml index 30b0f36a..dcbe6dcf 100644 --- a/components/Buttons/JFButtons.xml +++ b/components/Buttons/JFButtons.xml @@ -6,7 +6,7 @@ - + diff --git a/components/ItemGrid2/GridItem.brs b/components/ItemGrid2/GridItem.brs index 34b9ace2..e04eb9e5 100644 --- a/components/ItemGrid2/GridItem.brs +++ b/components/ItemGrid2/GridItem.brs @@ -13,7 +13,7 @@ end sub sub itemContentChanged() ' Set Randmom background colors from pallet - posterBackgrounds = m.global.poster_bg_pallet + posterBackgrounds = m.global.constants.poster_bg_pallet m.backdrop.color = posterBackgrounds[rnd(posterBackgrounds.count()) - 1] itemData = m.top.itemContent diff --git a/components/ItemGrid2/ItemGrid2.brs b/components/ItemGrid2/ItemGrid2.brs index 040419f1..662a9b73 100644 --- a/components/ItemGrid2/ItemGrid2.brs +++ b/components/ItemGrid2/ItemGrid2.brs @@ -2,7 +2,6 @@ sub init() m.options = m.top.findNode("options") - m.itemGrid = m.top.findNode("itemGrid") m.backdrop = m.top.findNode("backdrop") m.newBackdrop = m.top.findNode("backdropTransition") @@ -10,7 +9,7 @@ sub init() m.swapAnimation = m.top.findNode("backroundSwapAnimation") m.swapAnimation.observeField("state", "swapDone") - + m.loadedRows = 0 m.loadedItems = 0 @@ -26,20 +25,27 @@ sub init() 'Background Image Queued for loading m.queuedBGUri = "" + 'Item sort - maybe load defaults from user prefs? + m.sortField = "SortName" + m.sortAscending = true + m.loadItemsTask = createObject("roSGNode", "LoadItemsTask2") - + m.loadItemsTask.observeField("content", "ItemDataLoaded") + end sub ' 'Load initial set of Data -sub loadInitialItems() +sub loadInitialItems() if m.top.parentItem.backdropUrl <> invalid then SetBackground(m.top.parentItem.backdropUrl) end if m.loadItemsTask.itemId = m.top.parentItem.Id - m.loadItemsTask.observeField("content", "ItemDataLoaded") + m.loadItemsTask.sortField = m.sortField + m.loadItemsTask.sortAscending = m.sortAscending + m.loadItemsTask.startIndex = 0 if m.top.parentItem.collectionType = "movies" then m.loadItemsTask.itemType = "Movie" @@ -48,18 +54,63 @@ sub loadInitialItems() end if m.loadItemsTask.control = "RUN" + + SetUpOptions() + end sub +sub SetUpOptions() + + options = {} + + if m.top.parentItem.collectionType = "movies" then + options.views = [{ "Title": tr("Movies"), "Name": "movies" }] + options.sort = [ + { "Title": tr("Name"), "Name": "SortName" }, + { "Title": tr("IMDb Rating"), "Name": "CommunityRating" }, + { "Title": tr("Critic Rating"), "Name": "CriticRating" }, + { "Title": tr("Date Added"), "Name": "DateCreated" }, + { "Title": tr("Date Played"), "Name": "DatePlayed" }, + { "Title": tr("Parental Rating"), "Name": "OfficialRating" }, + { "Title": tr("Play Count"), "Name": "PlayCount" }, + { "Title": tr("Release Date"), "Name": "PremiereDate" }, + { "Title": tr("Run Time"), "Name": "Runtime" } + ] + else if m.top.parentItem.collectionType = "tvshows" then + options.views = [{ "Title": tr("Shows"), "Name": "shows" }] + options.sort = [ + { "Title": tr("Name"), "Name": "SortName" }, + { "Title": tr("IMDb Rating"), "Name": "CommunityRating" }, + { "Title": tr("Date Added"), "Name": "DateCreated" }, + { "Title": tr("Date Played"), "Name": "DatePlayed" }, + { "Title": tr("Parental Rating"), "Name": "OfficialRating" }, + { "Title": tr("Release Date"), "Name": "PremiereDate" }, + ] + + end if + + for each o in options.sort + if o.Name = m.sortField then + o.Selected = true + o.Ascending = m.sortAscending + end if + end for + + m.options.options = options + +end sub + + ' 'Handle loaded data, and add to Grid sub ItemDataLoaded(msg) - + itemData = msg.GetData() data = msg.getField() - if itemData = invalid then + if itemData = invalid then m.Loading = false - return + return end if for each item in itemData @@ -67,7 +118,7 @@ sub ItemDataLoaded(msg) end for 'Update the stored counts - m.loadedItems = m.itemGrid.content.getChildCount() + m.loadedItems = m.itemGrid.content.getChildCount() m.loadedRows = m.loadedItems / m.itemGrid.numColumns m.Loading = false @@ -114,7 +165,7 @@ sub onItemFocused() if focusedRow >= m.loadedRows - 3 and m.loadeditems < m.loadItemsTask.totalRecordCount then loadMoreData() end if -end sub +end sub ' 'When Image Loading Status changes @@ -130,16 +181,16 @@ end sub sub swapDone() if m.swapAnimation.state = "stopped" then - + 'Set main BG node image and hide transitioning node m.backdrop.uri = m.newBackdrop.uri m.backdrop.opacity = 0.25 m.newBackdrop.opacity = 0 - + 'If there is another one to load - if m.newBackdrop.uri <> m.queuedBGUri and m.queuedBGUri <> "" then - SetBackground(m.queuedBGUri) - m.queuedBGUri = "" + if m.newBackdrop.uri <> m.queuedBGUri and m.queuedBGUri <> "" then + SetBackground(m.queuedBGUri) + m.queuedBGUri = "" end if end if end sub @@ -162,22 +213,41 @@ sub onItemSelected() end sub -function onKeyEvent(key as string, press as boolean) as boolean - -' print "IG KeyPress " key - - if not press then return false +' +'Check if options updated and any reloading required +sub optionsClosed() + if m.options.sortField <> m.sortField or m.options.sortAscending <> m.sortAscending then + m.sortField = m.options.sortField + m.sortAscending = m.options.sortAscending + 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 - if key = "options" - print "OPTIONS!!!!!!!!!" - if m.options.visible = true then - m.options.visible = false - m.itemGrid.setFocus(true) - else - m.options.visible = true - m.options.setFocus(true) - end if - return true - end if + +function onKeyEvent(key as string, press as boolean) as boolean + + if not press then return false + + if key = "options" + if m.options.visible = true then + m.options.visible = false + optionsClosed() + else + m.options.visible = true + m.options.setFocus(true) + end if + return true + else if key = "back" then + if m.options.visible = true then + m.options.visible = false + optionsClosed() + return true + end if + end if return false end function diff --git a/components/ItemGrid2/LoadItemsTask2.brs b/components/ItemGrid2/LoadItemsTask2.brs index 4576a9e7..b0c774f8 100644 --- a/components/ItemGrid2/LoadItemsTask2.brs +++ b/components/ItemGrid2/LoadItemsTask2.brs @@ -6,9 +6,13 @@ sub loadItems() results = [] - sort_order = get_user_setting("movie_sort_order", "Ascending") - sort_field = get_user_setting("movie_sort_field", "SortName") - + sort_field = m.top.sortField + + if m.top.sortAscending = true then + sort_order = "Ascending" + else + sort_order = "Descending" + end if params = { limit: m.top.limit, diff --git a/components/ItemGrid2/LoadItemsTask2.xml b/components/ItemGrid2/LoadItemsTask2.xml index a4e13cf5..7dc630b0 100644 --- a/components/ItemGrid2/LoadItemsTask2.xml +++ b/components/ItemGrid2/LoadItemsTask2.xml @@ -7,6 +7,8 @@ + + diff --git a/components/ListPoster.brs b/components/ListPoster.brs index b7fb35ad..9020d17f 100644 --- a/components/ListPoster.brs +++ b/components/ListPoster.brs @@ -6,7 +6,7 @@ sub init() m.backdrop = m.top.findNode("backdrop") ' Randmomise the background colors - posterBackgrounds = m.global.poster_bg_pallet + posterBackgrounds = m.global.constants.poster_bg_pallet m.backdrop.color = posterBackgrounds[rnd(posterBackgrounds.count()) - 1] updateSize() diff --git a/components/home/HomeItem.brs b/components/home/HomeItem.brs index d0e68d9b..5a6cfc63 100644 --- a/components/home/HomeItem.brs +++ b/components/home/HomeItem.brs @@ -19,7 +19,7 @@ sub itemContentChanged() ' Randmomise the background colors m.backdrop = m.top.findNode("backdrop") - posterBackgrounds = m.global.poster_bg_pallet + posterBackgrounds = m.global.constants.poster_bg_pallet m.backdrop.color = posterBackgrounds[rnd(posterBackgrounds.count()) - 1] m.backdrop.width = imageWidth diff --git a/components/options/OptionsScreen.brs b/components/options/OptionsScreen.brs index fc569186..042beb2b 100644 --- a/components/options/OptionsScreen.brs +++ b/components/options/OptionsScreen.brs @@ -1,12 +1,10 @@ -sub init() +sub init() - m.buttons = m.top.findNode("buttons") - m.buttons.buttons = ["View", "Sort", "Filter"] + m.buttons = m.top.findNode("buttons") + m.buttons.buttons = [tr("View"), tr("Sort"), tr("Filter")] m.buttons.setFocus(true) - m.ascending = true m.selectedSortIndex = 0 - m.selectedItem = 1 m.menus = [] @@ -14,79 +12,122 @@ sub init() m.menus.push(m.top.findNode("sortMenu")) m.menus.push(m.top.findNode("filterMenu")) + m.viewNames = [] + m.sortNames = [] m.buttons.observeField("focusedIndex", "buttonFocusChanged") end sub +sub optionsSet() -sub buttonFocusChanged() + ' Views Tab + if m.top.options.views <> invalid then + viewContent = CreateObject("roSGNode", "ContentNode") + index = 0 + selectedViewIndex = 0 - print "Button focus changed to index ", m.buttons.focusedIndex + for each view in m.top.options.views + entry = viewContent.CreateChild("ContentNode") + entry.title = view.Title + m.viewNames.push(view.Name) + if view.selected <> invalid and view.selected = true then + selectedViewIndex = index + end if + index = index + 1 + end for + m.menus[0].content = viewContent + m.menus[0].checkedItem = selectedViewIndex + end if - if m.buttons.focusedIndex = m.selectedItem then return + ' Sort Tab + if m.top.options.sort <> invalid then + sortContent = CreateObject("roSGNode", "ContentNode") + index = 0 + m.selectedSortIndex = 0 - print "Hiding " m.selectedItem - m.menus[m.selectedItem].visible = false + for each sortItem in m.top.options.sort + entry = sortContent.CreateChild("ContentNode") + entry.title = sortItem.Title + m.sortNames.push(sortItem.Name) + if sortItem.Selected <> invalid and sortItem.Selected = true then + m.selectedSortIndex = index + if sortItem.Ascending <> invalid and sortItem.Ascending = false then + m.top.sortAscending = 0 + else + m.top.sortAscending = 1 + end if + end if + index = index + 1 + end for + m.menus[1].content = sortContent + m.menus[1].checkedItem = m.selectedSortIndex - print "Showing " m.buttons.focusedIndex - m.menus[m.buttons.focusedIndex].visible = true - - m.selectedItem = m.buttons.focusedIndex + if m.top.sortAscending = 1 then + m.menus[1].focusedCheckedIconUri = m.global.constants.icons.ascending_black + m.menus[1].checkedIconUri = m.global.constants.icons.ascending_white + else + m.menus[1].focusedCheckedIconUri = m.global.constants.icons.descending_black + m.menus[1].checkedIconUri = m.global.constants.icons.descending_white + end if + end if end sub +sub buttonFocusChanged() + if m.buttons.focusedIndex = m.selectedItem then return + m.menus[m.selectedItem].visible = false + m.menus[m.buttons.focusedIndex].visible = true + m.selectedItem = m.buttons.focusedIndex +end sub + + function onKeyEvent(key as string, press as boolean) as boolean - -' print "OS KeyPress " key - - if not press then -' print "OS Not Press!!" -' return false - end if - - if key = "down" + if key = "down" OR (key = "OK" AND m.top.findNode("buttons").hasFocus()) then m.top.findNode("buttons").setFocus(false) m.menus[m.selectedItem].setFocus(true) + m.menus[m.selectedItem].drawFocusFeedback = true return true - else if key = "OK" - print "OS Key OK" - + else if key = "OK" ' Handle Sort screen - if(m.selectedItem = 1) then - if m.menus[1].itemSelected <> m.selectedSortIndex then - print "OS - Resetting to ASC" - m.menus[1].focusedCheckedIconUri = "pkg:/images/icons/up_black.png" - m.menus[1].checkedIconUri="pkg:/images/icons/up_white.png" - m.selectedSortIndex = m.menus[1].itemSelected - m.ascending = true - else - if m.ascending = true then - print "Setting ascending to false" - m.ascending = false - m.menus[1].focusedCheckedIconUri = "pkg:/images/icons/down_black.png" - m.menus[1].checkedIconUri="pkg:/images/icons/down_white.png" + if(m.menus[m.selectedItem].isInFocusChain()) then + if(m.selectedItem = 1) then + if m.menus[1].itemSelected <> m.selectedSortIndex then + m.menus[1].focusedCheckedIconUri = m.global.constants.icons.ascending_black + m.menus[1].checkedIconUri = m.global.constants.icons.ascending_white + + m.selectedSortIndex = m.menus[1].itemSelected + m.top.sortAscending = true + m.top.sortField = m.sortNames[m.selectedSortIndex] else - print "Setting ascending to true" - m.ascending = true - m.menus[1].focusedCheckedIconUri = "pkg:/images/icons/up_black.png" - m.menus[1].checkedIconUri="pkg:/images/icons/up_white.png" + + if m.top.sortAscending = true then + m.top.sortAscending = false + m.menus[1].focusedCheckedIconUri = m.global.constants.icons.descending_black + m.menus[1].checkedIconUri = m.global.constants.icons.descending_white + else + m.top.sortAscending = true + m.menus[1].focusedCheckedIconUri = m.global.constants.icons.ascending_black + m.menus[1].checkedIconUri = m.global.constants.icons.ascending_white + end if end if end if end if return true - else if key = "back" OR key = "up" + else if key = "back" or key = "up" if m.menus[m.selectedItem].isInFocusChain() then m.buttons.setFocus(true) + m.menus[m.selectedItem].drawFocusFeedback = false return true end if - else -' print "Key Unhandled" + else if key = "options" + m.menus[m.selectedItem].drawFocusFeedback = false return false end if - print "Moo?????" + return false + end function \ No newline at end of file diff --git a/components/options/OptionsScreen.xml b/components/options/OptionsScreen.xml index c2b1f715..4cd8259f 100644 --- a/components/options/OptionsScreen.xml +++ b/components/options/OptionsScreen.xml @@ -2,68 +2,32 @@ - - - - - - - - - - - + - - - - - - - - - - - - - + - - + - - - - - - - + - - - - - - - - + + + + + +