comparison cagou/core/platform_/android.py @ 403:b0af45a92055

android: do not restore previously selected widget if an intent contains a widget to create.
author Goffi <goffi@goffi.org>
date Wed, 12 Feb 2020 20:02:58 +0100
parents 788e05d1e2bf
children c466678c57b2
comparison
equal deleted inserted replaced
402:ab1e97b7e8a5 403:b0af45a92055
88 service.start(mActivity, argument) 88 service.start(mActivity, argument)
89 89
90 activity.bind(on_new_intent=self.on_new_intent) 90 activity.bind(on_new_intent=self.on_new_intent)
91 self.cache.append((self.on_new_intent, mActivity.getIntent())) 91 self.cache.append((self.on_new_intent, mActivity.getIntent()))
92 self.last_selected_wid = None 92 self.last_selected_wid = None
93 self.restore_selected_wid = True
93 host.addListener('profilePlugged', self.onProfilePlugged) 94 host.addListener('profilePlugged', self.onProfilePlugged)
94 host.addListener('selected', self.onSelectedWidget) 95 host.addListener('selected', self.onSelectedWidget)
95 local_dir = Path(host.getConfig('', 'local_dir')).resolve() 96 local_dir = Path(host.getConfig('', 'local_dir')).resolve()
96 self.tmp_dir = local_dir / 'tmp' 97 self.tmp_dir = local_dir / 'tmp'
97 # we assert to avoid disaster if `/ 'tmp'` is removed by mistake on the line 98 # we assert to avoid disaster if `/ 'tmp'` is removed by mistake on the line
172 request_permissions(PERMISSION_MANDATORY, callback=self.permission_cb) 173 request_permissions(PERMISSION_MANDATORY, callback=self.permission_cb)
173 return False 174 return False
174 175
175 def privateDataGetCb(self, data_s, profile): 176 def privateDataGetCb(self, data_s, profile):
176 data = data_format.deserialise(data_s, type_check=None) 177 data = data_format.deserialise(data_s, type_check=None)
177 if data is not None: 178 if data is not None and self.restore_selected_wid:
178 log.debug(f"restoring previous widget {data}") 179 log.debug(f"restoring previous widget {data}")
179 try: 180 try:
180 name = data['name'] 181 name = data['name']
181 target = data['target'] 182 target = data['target']
182 except KeyError as e: 183 except KeyError as e:
366 widget = action['widget'] 367 widget = action['widget']
367 target = action['target'] 368 target = action['target']
368 except KeyError as e: 369 except KeyError as e:
369 log.warning(f"incomplete action {action}: {e}") 370 log.warning(f"incomplete action {action}: {e}")
370 else: 371 else:
372 # we don't want stored selected widget to be displayed after this
373 # one
374 log.debug("cancelling restoration of previous widget")
375 self.restore_selected_wid = False
376 # and now we open the widget linked to the intent
371 current_profile = next(iter(G.host.profiles)) 377 current_profile = next(iter(G.host.profiles))
372 Clock.schedule_once( 378 Clock.schedule_once(
373 lambda *args: G.host.doAction( 379 lambda *args: G.host.doAction(
374 widget, jid.JID(target), [current_profile]), 380 widget, jid.JID(target), [current_profile]),
375 0) 381 0)