Skip to content

Commit

Permalink
Retain list position when refreshing listings
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Sep 1, 2024
1 parent 0ce873f commit 23235f0
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 12 deletions.
29 changes: 26 additions & 3 deletions resources/lib/youtube_plugin/kodion/abstract_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@

import re

from .constants import CHECK_SETTINGS, CONTENT, PATHS, REROUTE_PATH
from .constants import (
CHECK_SETTINGS,
CONTAINER_ID,
CONTAINER_POSITION,
CONTENT,
PATHS,
REROUTE_PATH,
)
from .exceptions import KodionException
from .items import (
DirectoryItem,
Expand Down Expand Up @@ -234,11 +241,21 @@ def reroute(self, context, path=None, params=None, uri=None):

if not path:
return False

do_refresh = 'refresh' in params

if path == current_path and params == current_params:
if 'refresh' not in params:
if not do_refresh:
return False
params['refresh'] += 1

if do_refresh:
container = context.get_infolabel('System.CurrentControlId')
position = context.get_infolabel('Container.CurrentItem')
else:
container = None
position = None

result = None
function_cache = context.get_function_cache()
window_return = params.pop('window_return', True)
Expand All @@ -258,7 +275,13 @@ def reroute(self, context, path=None, params=None, uri=None):
status='' if result else ' failed'))
if not result:
return False
context.get_ui().set_property(REROUTE_PATH, path)

ui = context.get_ui()
ui.set_property(REROUTE_PATH, path)
if container and position:
ui.set_property(CONTAINER_ID, container)
ui.set_property(CONTAINER_POSITION, position)

context.execute(''.join((
'ActivateWindow(Videos, ',
context.create_uri(path, params),
Expand Down
6 changes: 6 additions & 0 deletions resources/lib/youtube_plugin/kodion/constants/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
PLAY_WITH = 'play_with'

# Stored data
CONTAINER_ID = 'container_id'
CONTAINER_FOCUS = 'container_focus'
CONTAINER_POSITION = 'container_position'
CONTENT_TYPE = 'content_type'
DEVELOPER_CONFIGS = 'configs'
LICENSE_TOKEN = 'license_token'
Expand Down Expand Up @@ -127,6 +130,9 @@
'PLAY_WITH',

# Stored data
'CONTAINER_ID',
'CONTAINER_FOCUS',
'CONTAINER_POSITION',
'CONTENT_TYPE',
'DEVELOPER_CONFIGS',
'LICENSE_TOKEN',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from ..constants import (
ADDON_ID,
CHECK_SETTINGS,
CONTAINER_FOCUS,
PLUGIN_WAKEUP,
REFRESH_CONTAINER,
RELOAD_ACCESS_MANAGER,
Expand Down Expand Up @@ -88,7 +89,7 @@ def onNotification(self, sender, method, data):
return
group, separator, event = method.partition('.')
if event == CHECK_SETTINGS:
if not isinstance(data, dict):
if data:
data = json.loads(data)
if data == 'defer':
self._settings_state = data
Expand All @@ -113,6 +114,12 @@ def onNotification(self, sender, method, data):
self.set_property(WAKEUP, target)
elif event == REFRESH_CONTAINER:
self.refresh_container()
elif event == CONTAINER_FOCUS:
if data:
data = json.loads(data)
if not data or not self.is_plugin_container(check_all=True):
return
xbmc.executebuiltin('SetFocus({0},{1},absolute)'.format(*data))
elif event == RELOAD_ACCESS_MANAGER:
self._context.reload_access_manager()
self.refresh_container()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
from ...constants import (
BUSY_FLAG,
CHECK_SETTINGS,
CONTAINER_FOCUS,
CONTAINER_ID,
CONTAINER_POSITION,
PLAYLIST_PATH,
PLAYLIST_POSITION,
PLUGIN_SLEEPING,
Expand Down Expand Up @@ -246,4 +249,8 @@ def run(self, provider, context, focused=None):
updateListing=update_listing,
cacheToDisc=cache_to_disc,
)
container = ui.pop_property(CONTAINER_ID)
position = ui.pop_property(CONTAINER_POSITION)
if container and position:
context.send_notification(CONTAINER_FOCUS, [container, position])
return succeeded
20 changes: 12 additions & 8 deletions resources/lib/youtube_plugin/kodion/ui/xbmc/xbmc_context_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,20 @@ def new_line(value=1, cr_before=0, cr_after=0):
'[CR]' * cr_after,
))

def set_focus_next_item(self):
list_id = xbmcgui.Window(xbmcgui.getCurrentWindowId()).getFocusId()
@staticmethod
def set_focus_next_item():
container = xbmc.getInfoLabel('System.CurrentControlId')
position = xbmc.getInfoLabel('Container.CurrentItem')
try:
position = xbmc.getInfoLabel('Container.Position')
next_position = int(position) + 1
self._context.execute('SetFocus({list_id},{position})'.format(
list_id=list_id, position=next_position
))
position = int(position) + 1
except ValueError:
pass
return
xbmc.executebuiltin(
'SetFocus({container},{position},absolute)'.format(
container=container,
position=position
)
)

@staticmethod
def busy_dialog_active():
Expand Down

0 comments on commit 23235f0

Please sign in to comment.