Skip to content

Commit

Permalink
Simplify progress dialog updates
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Dec 7, 2024
1 parent bf50321 commit dfcd335
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ class XbmcContext(AbstractContext):
'live.completed': 30647,
'live.upcoming': 30646,
'loading': 575,
'loading.directory': 1040,
'loading.directory.progress': 1042,
'maintenance.bookmarks': 30800,
'maintenance.data_cache': 30687,
'maintenance.feed_history': 30814,
Expand All @@ -153,7 +155,7 @@ class XbmcContext(AbstractContext):
'my_channel': 30507,
'my_location': 30654,
'my_subscriptions': 30510,
'my_subscriptions.loading': 575,
'my_subscriptions.loading': 30510,
'my_subscriptions.filter.add': 30587,
'my_subscriptions.filter.added': 30589,
'my_subscriptions.filter.remove': 30588,
Expand Down
20 changes: 15 additions & 5 deletions resources/lib/youtube_plugin/kodion/ui/abstract_progress_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ def __init__(self,

self._message = message
self._message_template = message_template
self._template_params = template_params or {}
self._template_params = {
'_progress': (0, self._total),
'_current': 0,
'_total': self._total,
}
if template_params:
self._template_params.update(template_params)

# simple reset because KODI won't do it :(
self.update(position=0)
Expand Down Expand Up @@ -97,10 +103,14 @@ def update(self, steps=1, position=None, message=None, **template_params):
elif self._message_template:
if template_params:
self._template_params.update(template_params)
else:
self._template_params['current'] = self._position
self._template_params['total'] = self._total
message = self._message_template.format(**self._template_params)
template_params = self._template_params
progress = (self._position, self._total)
template_params['_progress'] = progress
template_params['_current'], template_params['_total'] = progress
message = self._message_template.format(
*template_params['_progress'],
**template_params
)
self._message = message

self._dialog.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ def create_progress_dialog(self,
message_template=None,
template_params=None):
if not message_template:
message_template = ('{wait} {{current}}/{{total}}'.format(
wait=self._context.localize('please_wait')
message_template = ('{wait} {{_current}}/{{_total}}'.format(
wait=(message or self._context.localize('please_wait'))
))
template_params = {
'current': 0,
'total': 0,
'_progress': (0, 100),
'_current': 0,
'_total': 100,
}
return XbmcProgressDialog(
heading, message, background, message_template, template_params
Expand Down
14 changes: 5 additions & 9 deletions resources/lib/youtube_plugin/youtube/client/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,7 @@ def _parse_feeds(feeds,
_cache=cache):
if progress_dialog:
total = len(feeds)
progress_dialog.reset_total(new_total=total,
current=0,
total=total)
progress_dialog.reset_total(total)

all_items = {}
new_cache = {}
Expand Down Expand Up @@ -1812,7 +1810,7 @@ def _parse_feeds(feeds,
all_items[channel_id] = feed_items

if progress_dialog:
progress_dialog.update(current=len(all_items))
progress_dialog.update(position=len(all_items))

if new_cache:
_cache.set_items(new_cache)
Expand Down Expand Up @@ -1938,13 +1936,11 @@ def _threaded_fetch(kwargs,
completed = []
iterator = iter(payloads)
if progress_dialog:
total = progress_dialog.grow_total(
new_total=len(threaded_output['channel_ids']),
progress_dialog.grow_total(
len(threaded_output['channel_ids']),
)
progress_dialog.update(
steps=0,
current=len(threaded_output['feeds']),
total=total,
position=len(threaded_output['feeds']),
)
continue

Expand Down
10 changes: 5 additions & 5 deletions resources/lib/youtube_plugin/youtube/helper/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ def _fetch(resource):
threads['loop'].set()

if progress_dialog:
total = (len(video_id_dict)
delta = (len(video_id_dict)
+ len(channel_id_dict)
+ len(playlist_id_dict)
+ len(playlist_item_id_dict)
+ len(subscription_id_dict))
total = progress_dialog.grow_total(delta=total)
progress_dialog.update(steps=0, total=total)
progress_dialog.grow_total(delta=delta)
progress_dialog.update(steps=delta)

while threads['loop'].wait():
try:
Expand Down Expand Up @@ -539,8 +539,8 @@ def response_to_items(provider,
next_page = None

with context.get_ui().create_progress_dialog(
heading=context.localize('loading'),
message=context.localize('please_wait'),
heading=context.localize('loading.directory'),
message_template=context.localize('loading.directory.progress'),
background=True,
) as progress_dialog:
remaining = None
Expand Down
13 changes: 2 additions & 11 deletions resources/lib/youtube_plugin/youtube/helper/yt_play.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,7 @@ def _play_playlist(provider, context):
json_data = resource_manager.get_playlist_items(playlist_ids)

total = sum(len(chunk.get('items', [])) for chunk in json_data.values())
progress_dialog.set_total(total)
progress_dialog.update(
steps=0,
current=0,
total=total,
)
progress_dialog.reset_total(total)

# start the loop and fill the list with video items
for chunk in json_data.values():
Expand All @@ -216,11 +211,7 @@ def _play_playlist(provider, context):
process_next_page=False)
video_items.extend(result)

progress_dialog.update(
steps=len(result),
current=len(video_items),
total=total,
)
progress_dialog.update(steps=len(result))

if not video_items:
return False
Expand Down
2 changes: 1 addition & 1 deletion resources/lib/youtube_plugin/youtube/helper/yt_specials.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def _process_my_subscriptions(provider, context, client, filtered=False):

with context.get_ui().create_progress_dialog(
heading=context.localize('my_subscriptions.loading'),
message=context.localize('please_wait'),
message=context.localize('channels'),
background=True,
) as progress_dialog:
json_data = client.get_my_subscriptions(
Expand Down

0 comments on commit dfcd335

Please sign in to comment.