Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Alpha menu - refactor, bugfix, and QOL updates #1539

Merged
merged 10 commits into from
Jul 12, 2024
45 changes: 24 additions & 21 deletions components/ItemGrid/Alpha.bs
Original file line number Diff line number Diff line change
@@ -1,40 +1,43 @@
sub init()
m.top.visible = true
m.Alphamenu = m.top.findNode("Alphamenu")
m.Alphamenu.focusable = true
m.Alphatext = m.top.findNode("alphatext")
m.focusedChild = m.top.findNode("focusedChild")
m.Alphamenu.focusedFont.size = 25
m.Alphamenu.font.size = 25
m.top.setFocus(false)

m.alphaText = m.top.findNode("alphaText")
m.alphaMenu = m.top.findNode("alphaMenu")

m.alphaMenu.setFocus(false)
m.alphaMenu.focusedFont.size = 25
m.alphaMenu.font.size = 25

' show mic icon above alpha menu if remote supports voice commands
if m.global.device.hasVoiceRemote
alphaMic = m.top.findNode("alphaMic")
alphaMic.visible = true

micText = m.top.findNode("alphaMicText")
micText.font.size = 22
end if
end sub

function onKeyEvent(key as string, press as boolean) as boolean

if not press then return false
if not m.alphaMenu.isInFocusChain() then return false

if key = "OK"
child = m.Alphatext.getChild(m.Alphamenu.itemFocused)

if child.title = m.top.itemAlphaSelected
m.top.itemAlphaSelected = ""
m.Alphamenu.focusFootprintBitmapUri = ""
else
m.Alphamenu.focusFootprintBitmapUri = "pkg:/images/white.png"
m.top.itemAlphaSelected = child.title
end if
child = m.alphaText.getChild(m.alphaMenu.itemFocused)
m.top.letterSelected = child.title
return true
end if

if key = "up"
if m.Alphamenu.itemFocused = 0
m.Alphamenu.jumpToItem = m.Alphamenu.numRows - 1
if m.alphaMenu.itemFocused = 0
m.alphaMenu.jumpToItem = m.alphaMenu.numRows - 1
return true
end if
end if

if key = "down"
if m.Alphamenu.itemFocused = m.Alphamenu.numRows - 1
m.Alphamenu.jumpToItem = 0
if m.alphaMenu.itemFocused = m.alphaMenu.numRows - 1
m.alphaMenu.jumpToItem = 0
return true
end if
end if
Expand Down
14 changes: 8 additions & 6 deletions components/ItemGrid/Alpha.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<component name="Alpha" extends="Group">
<children>
<Label id="alphaMicText" font="font:SmallSystemFont" translation="[1600,130]" text="Search" />
<Poster id="alphaMic" height="22" width="15" uri="pkg:/images/icons/mic_icon.png" translation="[1578, 130]" visible="false" />
<LabelList
translation="[50, 185]"
id="alphaMenu"
translation="[52, 206]"
vertFocusAnimationStyle="floatingFocus"
drawFocusFeedback="true"
id="Alphamenu"
font="font:SmallestSystemFont"
focusedFont="font:SmallestSystemFont"
itemSpacing="[0,2]"
itemSize="[28,28]"
numRows="27"
textHorizAlign="center"
drawFocusFeedback="true"
focusBitmapUri="pkg:/images/white.png"
focusBitmapBlendColor="#FFFFFF"
focusFootprintBlendColor="#666666"
>
<ContentNode id="alphatext" role="content">
<ContentNode id="alphaText" role="content">
<ContentNode title="#" />
<ContentNode title="A" />
<ContentNode title="B" />
Expand Down Expand Up @@ -47,7 +50,6 @@
</LabelList>
</children>
<interface>
<field id="selectedItem" type="node" alwaysNotify="true" />
<field id="itemAlphaSelected" type="string" />
<field id="letterSelected" type="string" alwaysNotify="true" />
</interface>
</component>
85 changes: 46 additions & 39 deletions components/ItemGrid/ItemGrid.bs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ sub init()

m.itemGrid.observeField("itemFocused", "onItemFocused")
m.itemGrid.observeField("itemSelected", "onItemSelected")
m.itemGrid.observeField("alphaSelected", "onItemalphaSelected")

'Voice filter setup
m.voiceBox = m.top.findNode("voiceBox")
Expand Down Expand Up @@ -64,19 +63,11 @@ sub init()
'set inital counts for overhang before content is loaded.
m.loadItemsTask.totalRecordCount = 0

m.Alpha = m.top.findNode("AlphaMenu")
m.AlphaSelected = m.top.findNode("AlphaSelected")
m.alpha = m.top.findNode("alpha")
m.alphaMenu = m.alpha.findNode("alphaMenu")

'Get reset folder setting
m.resetGrid = m.global.session.user.settings["itemgrid.reset"]

m.micButton = m.top.findNode("micButton")
m.micButtonText = m.top.findNode("micButtonText")
'Hide voice search if device does not have voice remote
if m.global.device.hasVoiceRemote = false
m.micButton.visible = false
m.micButtonText.visible = false
end if
end sub

'
Expand All @@ -103,14 +94,6 @@ sub loadInitialItems()
if m.top.parentItem.collectionType = "livetv"
' Translate between app and server nomenclature
viewSetting = m.global.session.user.settings["display.livetv.landing"]
'Move mic to be visiable on TV Guide screen
if m.global.device.hasVoiceRemote = true
m.micButton.translation = "[1540, 92]"
m.micButtonText.visible = true
m.micButtonText.translation = "[1600,130]"
m.micButtonText.font.size = 22
m.micButtonText.text = tr("Search")
end if
if viewSetting = "guide"
m.view = "tvGuide"
else
Expand Down Expand Up @@ -163,9 +146,15 @@ sub loadInitialItems()
else
m.loadItemsTask.itemId = m.top.parentItem.Id
end if

' if we already searched for this alpha text than reset filter
if m.loadItemsTask.nameStartsWith = m.top.alphaSelected
m.loadItemsTask.nameStartsWith = ""
else
m.loadItemsTask.nameStartsWith = m.alpha.letterSelected
end if
updateTitle()

m.loadItemsTask.nameStartsWith = m.top.alphaSelected
m.loadItemsTask.searchTerm = m.voiceBox.text
m.emptyText.visible = false
m.loadItemsTask.sortField = m.sortField
Expand Down Expand Up @@ -447,18 +436,16 @@ sub SetUpOptions()
m.options.options = options
end sub


'
'Handle loaded data, and add to Grid
sub ItemDataLoaded(msg)
stopLoadingSpinner()
m.top.alphaActive = false
itemData = msg.GetData()
m.loadItemsTask.unobserveField("content")
m.loadItemsTask.content = []

if itemData = invalid
m.Loading = false
stopLoadingSpinner()
return
end if

Expand All @@ -485,8 +472,17 @@ sub ItemDataLoaded(msg)
m.data.appendChild(item)
end for

m.itemGrid.opacity = "1"
m.genreList.opacity = "0"
' keep focus on alpha menu when loading new data
if m.top.alphaActive
m.alphaMenu.setFocus(true)
else
m.itemGrid.opacity = "1"
m.genreList.opacity = "0"

m.alphaMenu.setFocus(false)
m.itemGrid.setFocus(true)
m.genreList.setFocus(false)
end if

'Update the stored counts
m.loadedItems = m.itemGrid.content.getChildCount()
Expand All @@ -498,8 +494,6 @@ sub ItemDataLoaded(msg)
m.emptyText.visible = true
end if

m.itemGrid.setFocus(true)
m.genreList.setFocus(false)
stopLoadingSpinner()
end sub

Expand Down Expand Up @@ -588,16 +582,15 @@ sub onItemSelected()
m.top.selectedItem = m.itemGrid.content.getChild(m.itemGrid.itemSelected)
end sub

sub onItemalphaSelected()
sub alphaSelectedChanged()
if m.top.alphaSelected <> ""
m.loadedRows = 0
m.loadedItems = 0
m.data = CreateObject("roSGNode", "ContentNode")
m.itemGrid.content = m.data
m.loadItemsTask.searchTerm = ""
m.VoiceBox.text = ""
m.loadItemsTask.nameStartsWith = m.alpha.itemAlphaSelected
startLoadingSpinner(false)

loadInitialItems()
end if
end sub
Expand All @@ -612,7 +605,24 @@ sub onvoiceFilter()
m.loadItemsTask.NameStartsWith = " "
m.loadItemsTask.searchTerm = m.voiceBox.text
m.loadItemsTask.recursive = true
startLoadingSpinner(false)
if m.voiceBox.text.len() = 1
' move focus to the letter spoken
alphaMenu = m.top.findNode("alphaMenu")
intConversion = m.voiceBox.text.ToInt() ' non numeric input returns as 0

if m.voiceBox.text = "0" or (isValid(intConversion) and intConversion <> 0)
alphaMenu.jumpToItem = 0
else
' loop through each option until we find a match
for i = 1 to alphaMenu.numRows - 1
alphaMenuOption = alphaMenu.content.getChild(i)
if Lcase(alphaMenuOption.TITLE) = Lcase(m.voiceBox.text)
alphaMenu.jumpToItem = i
exit for
end if
end for
end if
end if
loadInitialItems()
end if
end sub
Expand Down Expand Up @@ -755,7 +765,7 @@ function getItemFocused()
return m.itemGrid.content.getChild(m.itemGrid.itemFocused)
else if m.genreList.isinFocusChain() and isValid(m.genreList.rowItemFocused)
return m.genreList.content.getChild(m.genreList.rowItemFocused[0]).getChild(m.genreList.rowItemFocused[1])
else if m.scheduleGrid.isinFocusChain() and isValid(m.scheduleGrid.itemFocused)
else if isValid(m.scheduleGrid) and m.scheduleGrid.isinFocusChain() and isValid(m.scheduleGrid.itemFocused)
return m.scheduleGrid.content.getChild(m.scheduleGrid.itemFocused)
end if
return invalid
Expand Down Expand Up @@ -829,14 +839,11 @@ function onKeyEvent(key as string, press as boolean) as boolean
else if key = "left" and topGrp.isinFocusChain()
m.top.alphaActive = true
topGrp.setFocus(false)
alpha = m.alpha.getChild(0).findNode("Alphamenu")
alpha.setFocus(true)
m.alphaMenu.setFocus(true)
return true

else if key = "right" and m.Alpha.isinFocusChain()
else if key = "right" and m.alpha.isinFocusChain()
m.top.alphaActive = false
m.Alpha.setFocus(false)
m.Alpha.visible = true
m.alphaMenu.setFocus(false)
topGrp.setFocus(true)
return true
else if key = "replay" and topGrp.isinFocusChain()
Expand Down Expand Up @@ -874,7 +881,7 @@ sub updateTitle()
m.top.overhangTitle = m.top.parentItem.title + tr(" (Filtered by ") + m.loadItemsTask.searchTerm + ")"
end if

if m.top.alphaSelected <> ""
if m.loadItemsTask.nameStartsWith <> ""
m.top.overhangTitle = m.top.parentItem.title + tr(" (Filtered by ") + m.loadItemsTask.nameStartsWith + ")"
end if

Expand Down
8 changes: 3 additions & 5 deletions components/ItemGrid/ItemGrid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,22 @@
drawFocusFeedback="false" />

<RowList opacity="0" id="genrelist" translation="[120, 160]" showRowLabel="true" itemComponentName="GridItemSmall" numColumns="1" numRows="3" vertFocusAnimationStyle="fixed" itemSize="[1900, 360]" rowItemSize="[ [230, 320] ]" rowItemSpacing="[ [20, 0] ]" itemSpacing="[0, 60]" />

<Label id="micButtonText" font="font:SmallSystemFont" visible="false" />
<Button id="micButton" maxWidth="20" translation="[20, 120]" iconUri="pkg:/images/icons/mic_icon.png" />

<Label translation="[0,540]" id="emptyText" font="font:LargeSystemFont" width="1910" horizAlign="center" vertAlign="center" height="64" visible="false" />
<ItemGridOptions id="options" visible="false" />
<Animation id="backroundSwapAnimation" duration="1" repeat="false" easeFunction="linear">
<FloatFieldInterpolator id="fadeinLoading" key="[0.0, 1.0]" keyValue="[ 0.00, 0.25 ]" fieldToInterp="backdropTransition.opacity" />
<FloatFieldInterpolator id="fadeoutLoaded" key="[0.0, 1.0]" keyValue="[ 0.25, 0.00 ]" fieldToInterp="backdrop.opacity" />
</Animation>
<Alpha id="AlphaMenu" />
<Alpha id="alpha" />
</children>
<interface>
<field id="HomeLibraryItem" type="string" />
<field id="parentItem" type="node" onChange="loadInitialItems" />
<field id="selectedItem" type="node" alwaysNotify="true" />
<field id="quickPlayNode" type="node" alwaysNotify="true" />
<field id="imageDisplayMode" type="string" value="scaleToZoom" />
<field id="AlphaSelected" type="string" alias="AlphaMenu.itemAlphaSelected" alwaysNotify="true" onChange="onItemAlphaSelected" />
<field id="alphaSelected" type="string" alias="alpha.letterSelected" alwaysNotify="true" onChange="alphaSelectedChanged" />
<field id="alphaActive" type="boolean" value="false" />
<field id="jumpToItem" type="integer" value="" />
</interface>
Expand Down
Loading
Loading