Skip to content

Commit

Permalink
Fix video selection bug (#419)
Browse files Browse the repository at this point in the history
* Fix video selection bug

* Refactor key handling

* comment
  • Loading branch information
iBicha authored Jul 4, 2024
1 parent 896d0b9 commit ebc5d81
Show file tree
Hide file tree
Showing 28 changed files with 216 additions and 160 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Fixed

- A bug where a the right video will not play if selected too quickly

## [0.24.5] - 2024-07-03

- Additional Spanish (Mexico) translations (Thanks to Jean Carton)
Expand Down
15 changes: 8 additions & 7 deletions playlet-lib/src/components/AppController/AppController.bs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "pkg:/components/VideoQueue/VideoQueueViewUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

Expand Down Expand Up @@ -86,18 +87,18 @@ function GetRootScreen(screenName as string) as object
return m.screens[screenName]
end function

function onKeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if LongPressHandler(key, press)
return true
end if

if key = OPTIONS_LONG_PRESS_KEY and press
if key = RemoteKeys.OptionsLongPress and press
LogInfo("Opening VideoQueueView")
VideoQueueViewUtils.Open(m.top.videoQueue, m.top)
return true
end if

if key = "options" and not press
if key = RemoteKeys.Options and not press
if VideoQueueUtils.ToggleVideoPictureInPicture(m.top.videoQueue)
return true
end if
Expand All @@ -107,25 +108,25 @@ function onKeyEvent(key as string, press as boolean) as boolean
return false
end if

if key = "play"
if key = RemoteKeys.Play
if VideoQueueUtils.TogglePause(m.top.videoQueue)
return true
end if
end if

if key = "pause"
if key = RemoteKeys.Pause
if VideoQueueUtils.Pause(m.top.videoQueue)
return true
end if
end if

if key = "playonly"
if key = RemoteKeys.PlayOnly
if VideoQueueUtils.Play(m.top.videoQueue)
return true
end if
end if

if key = "back"
if key = RemoteKeys.Back
if VideoQueueUtils.IsVideoPlayerOpen(m.top.videoQueue) and not VideoQueueUtils.IsVideoPlayerFullScreen(m.top.videoQueue)
if VideoQueueUtils.ToggleVideoPictureInPicture(m.top.videoQueue)
return true
Expand Down
5 changes: 3 additions & 2 deletions playlet-lib/src/components/ButtonEx/ButtonEx.bs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "pkg:/source/utils/MathUtils.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

function Init()
Expand Down Expand Up @@ -129,12 +130,12 @@ function OnButtonFocused()
end if
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if not press
return false
end if

if key = "OK"
if key = RemoteKeys.Ok
disabled = m.top.disabled
if not disabled
m.top.buttonSelected = true
Expand Down
9 changes: 5 additions & 4 deletions playlet-lib/src/components/ChannelView/ChannelView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "pkg:/source/utils/DisposableObserve.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

Expand Down Expand Up @@ -36,8 +37,8 @@ end function
function OnNodeready()
m.rowList@.BindNode()

SetNavigation(m.rowList, "up", m.subscribeButton)
SetNavigation(m.subscribeButton, "down", m.rowList)
SetNavigation(m.rowList, RemoteKeys.Up, m.subscribeButton)
SetNavigation(m.subscribeButton, RemoteKeys.Down, m.rowList)

m.subscribeButton.text = Tr(Locale.Buttons.Subscribe)
DisposableObserveFieldScoped(m.subscribeButton, "buttonSelected", FuncName(OnSubscribeButtonSelected))
Expand Down Expand Up @@ -104,7 +105,7 @@ function CreateChannelFeeds(authorId as string, author as string, tabs as object
return feeds
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if NavigationKeyHandler(key, press).handled
return true
end if
Expand All @@ -113,7 +114,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
return false
end if

if key = "back"
if key = RemoteKeys.Back
Close()
return true
end if
Expand Down
9 changes: 5 additions & 4 deletions playlet-lib/src/components/ContextMenu/ContextMenu.bs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

Expand Down Expand Up @@ -152,22 +153,22 @@ function OnItemSelected(event as object) as void
end if
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if press = false
return false
end if

if key = "back"
if key = RemoteKeys.Back
Close()
return true
end if

if key = "up"
if key = RemoteKeys.Up
m.optionsList.jumpToItem = m.optionsList.content.getChildCount() - 1
return true
end if

if key = "down"
if key = RemoteKeys.Down
m.optionsList.jumpToItem = 0
return true
end if
Expand Down
2 changes: 1 addition & 1 deletion playlet-lib/src/components/Dialog/TimedDialog.bs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function OnDialogClosed()
CancelTimer()
end function

function onKeyEvent(_key as string, _press as boolean) as boolean
function OnKeyEvent(_key as string, _press as boolean) as boolean
if m.timer = invalid
return false
end if
Expand Down
5 changes: 3 additions & 2 deletions playlet-lib/src/components/NavBar/NavBar.bs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

function Init()
Expand Down Expand Up @@ -116,8 +117,8 @@ function UnfocusItem(index as integer) as void
m.appController@.HideRootScreen(item.screen)
end function

function onKeyEvent(key as string, press as boolean) as boolean
if key <> "right" or not press
function OnKeyEvent(key as string, press as boolean) as boolean
if key <> RemoteKeys.Right or not press
return false
end if

Expand Down
22 changes: 10 additions & 12 deletions playlet-lib/src/components/Navigation/LongPress.bs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
const OK_LONG_PRESS_KEY = "OK_LONG_PRESS"
const OPTIONS_LONG_PRESS_KEY = "OPTIONS_LONG_PRESS"
import "pkg:/source/utils/RemoteKeys.bs"

function InitializeLongPress(keys as object, duration = 1.0 as float)
longPressKeyMap = {
"OK": OK_LONG_PRESS_KEY
"options": OPTIONS_LONG_PRESS_KEY
}
longPressKeyMap = {}
longPressKeyMap[RemoteKeys.Ok] = RemoteKeys.OkLongPress
longPressKeyMap[RemoteKeys.Options] = RemoteKeys.OptionsLongPress

m._longPressKeyMap = {}
for each key in keys
m._longPressKeyMap[key] = longPressKeyMap[key]
Expand All @@ -16,10 +15,9 @@ function InitializeLongPress(keys as object, duration = 1.0 as float)
' Using the keyboard:
' - press K to simulate an "OK" long press on the remote.
' - press O to simulate an "options" long press on the remote.
simulatedLongPressKeyMap = {
"OK": "Lit_k"
"options": "Lit_o"
}
simulatedLongPressKeyMap = {}
simulatedLongPressKeyMap[RemoteKeys.Ok] = "Lit_k"
simulatedLongPressKeyMap[RemoteKeys.Options] = "Lit_o"

m._simulatedLongPressKeyMap = {}
for each key in keys
Expand All @@ -43,7 +41,7 @@ function LongPressHandler(key as string, press as boolean) as boolean
LogInfo(`[${subtype}] Simulating`, simulatedKey, "long press using key:", key, "press:", press)
longPressKey = m._longPressKeyMap[simulatedKey]
m._longPressFired = true
return OnkeyEvent(longPressKey, press)
return OnKeyEvent(longPressKey, press)
end if
#end if

Expand Down Expand Up @@ -87,5 +85,5 @@ function LongPressTimerFired() as void
return
end if

OnkeyEvent(m._longPressKeyMap[m._longPressKey], true)
OnKeyEvent(m._longPressKeyMap[m._longPressKey], true)
end function
9 changes: 5 additions & 4 deletions playlet-lib/src/components/PlaylistView/PlaylistView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "pkg:/source/AsyncTask/Tasks.bs"
import "pkg:/source/utils/ErrorUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Logging.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

Expand Down Expand Up @@ -61,17 +62,17 @@ function OnContentSet() as void
LoadPlaylistIfNeeded()
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if LongPressHandler(key, press)
return true
end if

if key = OK_LONG_PRESS_KEY and press
if key = RemoteKeys.OkLongPress and press
OnItemLongPressed(m.list.itemFocused)
return true
end if

if key = "OK" and not press
if key = RemoteKeys.Ok and not press
OnItemSelected(m.list.itemFocused)
return true
end if
Expand All @@ -80,7 +81,7 @@ function OnkeyEvent(key as string, press as boolean) as boolean
return false
end if

if key = "back"
if key = RemoteKeys.Back
Close()
return true
end if
Expand Down
15 changes: 8 additions & 7 deletions playlet-lib/src/components/ProfileView/ProfileView.bs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/utils/DisposableObserve.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/StringUtils.bs"
import "pkg:/source/utils/Types.bs"

Expand All @@ -16,10 +17,10 @@ function Init()
end function

function OnNodeReady()
SetNavigation(m.activateButton, "down", m.logoutButton)
SetNavigation(m.logoutButton, "down", m.closeButton)
SetNavigation(m.closeButton, "up", m.logoutButton)
SetNavigation(m.logoutButton, "up", m.activateButton)
SetNavigation(m.activateButton, RemoteKeys.Down, m.logoutButton)
SetNavigation(m.logoutButton, RemoteKeys.Down, m.closeButton)
SetNavigation(m.closeButton, RemoteKeys.Up, m.logoutButton)
SetNavigation(m.logoutButton, RemoteKeys.Up, m.activateButton)

DisposableObserveFieldScoped(m.profilesService, "currentProfile", FuncName(OnCunrrentProfileChanged))
DisposableObserveFieldScoped(m.profilesService, "onProfileLogout", FuncName(OnProfileLogout))
Expand Down Expand Up @@ -57,17 +58,17 @@ function OnFocusChange() as void
end if
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if NavigationKeyHandler(key, press).handled
return true
end if

if key = "options" or key = "play" or key = "pause" or key = "playonly"
if key = RemoteKeys.Options or key = RemoteKeys.Play or key = RemoteKeys.Pause or key = RemoteKeys.PlayOnly
' A pass-through to the app controller, so it can toggle picture-in-picture and pause/play
return false
end if

if key = "back" and press
if key = RemoteKeys.Back and press
Close()
return true
end if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/components/Services/BookmarksService/BookmarksServiceUtils.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/RemoteKeys.bs"
import "pkg:/source/utils/Types.bs"

function Init()
Expand All @@ -16,8 +17,8 @@ function Init()
end function

function OnNodeReady()
SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar)
SetNavigation(invalid, RemoteKeys.Back, m.navBar)
SetNavigation(invalid, RemoteKeys.Left, m.navBar)

m.rowList@.BindNode()

Expand Down Expand Up @@ -73,7 +74,7 @@ function SetRowListContent(bookmarksContent as object)
m.rowList.feeds = BookmarksServiceUtils.BookmarksContentToFeed(bookmarksContent)
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if NavigationKeyHandler(key, press).handled
return true
end if
Expand Down
7 changes: 4 additions & 3 deletions playlet-lib/src/components/Screens/HomeScreen/HomeScreen.bs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import "pkg:/components/ContextMenu/ContextMenuUtils.bs"
import "pkg:/components/Navigation/Navigation.bs"
import "pkg:/source/utils/FocusManagement.bs"
import "pkg:/source/utils/Locale.bs"
import "pkg:/source/utils/RemoteKeys.bs"

function Init()
m.top.focusable = true
Expand All @@ -12,8 +13,8 @@ function Init()
end function

function OnNodeReady()
SetNavigation(invalid, "back", m.navBar)
SetNavigation(invalid, "left", m.navBar)
SetNavigation(invalid, RemoteKeys.Back, m.navBar)
SetNavigation(invalid, RemoteKeys.Left, m.navBar)

m.rowList@.BindNode()

Expand All @@ -34,7 +35,7 @@ function OnFocusChange() as void
NodeSetFocus(m.rowList, true)
end function

function OnkeyEvent(key as string, press as boolean) as boolean
function OnKeyEvent(key as string, press as boolean) as boolean
if NavigationKeyHandler(key, press).handled
return true
end if
Expand Down
Loading

0 comments on commit ebc5d81

Please sign in to comment.