# HG changeset patch # User Goffi # Date 1527242507 -7200 # Node ID 9cefc9f8efc925ee599becf024d5d24fd5ebe5c4 # Parent 37638765c97b4314b9742f4244c0dd4fceaa2b4d plugin file sharing: use external storage directory instead of home (which is "/data") on Android when expanding "~" diff -r 37638765c97b -r 9cefc9f8efc9 cagou/plugins/plugin_wid_file_sharing.py --- a/cagou/plugins/plugin_wid_file_sharing.py Fri May 25 11:59:16 2018 +0200 +++ b/cagou/plugins/plugin_wid_file_sharing.py Fri May 25 12:01:47 2018 +0200 @@ -37,6 +37,7 @@ from kivy.garden import modernmenu from kivy.clock import Clock from kivy.metrics import dp +from kivy import utils as kivy_utils from functools import partial import os.path import json @@ -52,8 +53,16 @@ MODE_LOCAL = u"local" SELECT_INSTRUCTIONS = _(u"Please select entities to share with") - -dist = modernmenu.dist +if kivy_utils.platform == "android": + from jnius import autoclass + Environment = autoclass("android.os.Environment") + base_dir = Environment.getExternalStorageDirectory().getAbsolutePath() + def expanduser(path): + if path == u'~' or path.startswith(u'~/'): + return path.replace(u'~', base_dir, 1) + return path +else: + expanduser = os.path.expanduser class ModeBtn(Button): @@ -213,7 +222,7 @@ float_layout = properties.ObjectProperty() layout = properties.ObjectProperty() mode = properties.OptionProperty(MODE_LOCAL, options=[MODE_VIEW, MODE_LOCAL]) - local_dir = properties.StringProperty(os.path.expanduser(u'~')) + local_dir = properties.StringProperty(expanduser(u'~')) remote_dir = properties.StringProperty(u'') remote_entity = properties.StringProperty(u'') shared_paths = properties.ListProperty() @@ -264,12 +273,11 @@ self.mode = opt[new_idx] def on_mode(self, instance, new_mode): - print(instance) self.update_view(None, self.local_dir) def onHeaderInput(self): if u'/' in self.header_input.text or self.header_input.text == u'~': - self.current_dir = os.path.expanduser(self.header_input.text) + self.current_dir = expanduser(self.header_input.text) def onHeaderInputComplete(self, wid, text, **kwargs): """we filter items when text is entered in input box"""