mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-27 07:58:49 +01:00
inval new file from main thread after async task finished. Seems to
prevent attempts to read file while it's still being written (but only on external storage.)
This commit is contained in:
parent
e1e181949e
commit
0171d0ccb2
1 changed files with 11 additions and 3 deletions
|
@ -44,9 +44,12 @@ public class DictImportActivity extends XWActivity {
|
|||
}
|
||||
|
||||
private class DownloadFilesTask extends AsyncTask<Uri, Integer, Long> {
|
||||
private String m_saved = null;
|
||||
@Override
|
||||
protected Long doInBackground( Uri... uris )
|
||||
{
|
||||
m_saved = null;
|
||||
|
||||
int count = uris.length;
|
||||
Assert.assertTrue( 1 == count );
|
||||
long totalSize = 0;
|
||||
|
@ -59,7 +62,7 @@ public class DictImportActivity extends XWActivity {
|
|||
uri.getSchemeSpecificPart(),
|
||||
uri.getFragment() );
|
||||
InputStream is = jUri.toURL().openStream();
|
||||
saveDict( is, uri.getPath() );
|
||||
m_saved = saveDict( is, uri.getPath() );
|
||||
is.close();
|
||||
} catch ( java.net.URISyntaxException use ) {
|
||||
Utils.logf( "URISyntaxException: %s" + use.toString() );
|
||||
|
@ -76,6 +79,9 @@ public class DictImportActivity extends XWActivity {
|
|||
protected void onPostExecute( Long result )
|
||||
{
|
||||
Utils.logf( "onPostExecute passed %d", result );
|
||||
if ( null != m_saved ) {
|
||||
DictLangCache.inval( DictImportActivity.this, m_saved, true );
|
||||
}
|
||||
finish();
|
||||
}
|
||||
} // class DownloadFilesTask
|
||||
|
@ -112,11 +118,13 @@ public class DictImportActivity extends XWActivity {
|
|||
}
|
||||
}
|
||||
|
||||
private void saveDict( InputStream inputStream, String path )
|
||||
private String saveDict( InputStream inputStream, String path )
|
||||
{
|
||||
String name = basename( path );
|
||||
if ( GameUtils.saveDict( this, inputStream, name, s_useSD ) ) {
|
||||
DictLangCache.inval( this, name, true );
|
||||
return name;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue