Skip to content

Commit c9af9fa

Browse files
committed
Factored out the Intent name expansion
1 parent 5c8b109 commit c9af9fa

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

recipes/android/src/android/broadcast.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,26 @@ def __init__(self, callback, actions=None, categories=None):
2424
if not actions and not categories:
2525
raise Exception('You need to define at least actions or categories')
2626

27+
def _expand_partial_name(partial_name):
28+
if '.' in partial_name:
29+
return partial_name # Its actually a full dotted name
30+
else:
31+
name = 'ACTION_{}'.format(partial_name.upper())
32+
if not hasattr(Intent, name):
33+
raise Exception('The intent {} doesnt exist'.format(name))
34+
return getattr(Intent, name)
35+
2736
# resolve actions/categories first
2837
Intent = autoclass('android.content.Intent')
2938
resolved_actions = []
3039
if actions:
3140
for x in actions:
32-
if '.' in x:
33-
full_name = x
34-
else:
35-
name = 'ACTION_{}'.format(x.upper())
36-
if not hasattr(Intent, name):
37-
raise Exception('The intent {} doesnt exist'.format(name))
38-
full_name = getattr(Intent, name)
39-
resolved_actions += [full_name]
41+
resolved_actions += [_expand_partial_name(x)]
4042

4143
resolved_categories = []
4244
if categories:
4345
for x in categories:
44-
if '.' in x:
45-
full_name = x
46-
else:
47-
name = 'CATEGORY_{}'.format(x.upper())
48-
if not hasattr(Intent, name):
49-
raise Exception('The intent {} doesnt exist'.format(name))
50-
full_name = getattr(Intent, name)
51-
resolved_categories += [full_name]
46+
resolved_categories += [_expand_partial_name(x)]
5247

5348
# resolve android API
5449
PythonActivity = autoclass('org.renpy.android.PythonActivity')

0 commit comments

Comments
 (0)