Skip to content

Commit d1120a4

Browse files
committed
Major speed optimizations for exploring very large folders on Android 11+ (Storage Access Framework) (closes #67)
1 parent 99fc7ba commit d1120a4

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

.github/AAR Source (Android)/java/com/yasirkula/unity/FileBrowser.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,16 +301,9 @@ public static void CopyDirectory( Context context, String sourceRawUri, String d
301301
public static String OpenSAFFolder( Context context, String rawUri )
302302
{
303303
FileBrowserSAFEntry directory = new FileBrowserSAFEntry( context, Uri.parse( rawUri ) );
304-
ArrayList<FileBrowserSAFEntry> entries = directory.listFiles();
305304

306305
stringBuilder.setLength( 0 );
307-
stringBuilder.append( entries.size() ).append( "<>" );
308-
309-
for( int i = 0; i < entries.size(); i++ )
310-
{
311-
FileBrowserSAFEntry entry = entries.get( i );
312-
stringBuilder.append( entry.isDirectory() ? "d" : "f" ).append( entry.getName() ).append( "<>" ).append( entry.getUri().toString() ).append( "<>" );
313-
}
306+
directory.appendFilesToStringBuilder( stringBuilder );
314307

315308
return stringBuilder.toString();
316309
}

.github/AAR Source (Android)/java/com/yasirkula/unity/FileBrowserSAFEntry.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,49 @@ public ArrayList<FileBrowserSAFEntry> listFiles()
271271
return results;
272272
}
273273

274+
public void appendFilesToStringBuilder( StringBuilder stringBuilder )
275+
{
276+
final ContentResolver resolver = mContext.getContentResolver();
277+
final Uri childrenUri = DocumentsContract.buildChildDocumentsUriUsingTree( mUri, DocumentsContract.getDocumentId( mUri ) );
278+
Cursor c = null;
279+
try
280+
{
281+
c = resolver.query( childrenUri, new String[] { DocumentsContract.Document.COLUMN_DOCUMENT_ID, DocumentsContract.Document.COLUMN_MIME_TYPE, DocumentsContract.Document.COLUMN_DISPLAY_NAME }, null, null, null );
282+
stringBuilder.append( c.getCount() ).append( "<>" );
283+
if( c.moveToNext() )
284+
{
285+
int documentIdIndex = c.getColumnIndex( DocumentsContract.Document.COLUMN_DOCUMENT_ID );
286+
int mimeTypeIndex = c.getColumnIndex( DocumentsContract.Document.COLUMN_MIME_TYPE );
287+
int nameIndex = c.getColumnIndex( DocumentsContract.Document.COLUMN_DISPLAY_NAME );
288+
289+
do
290+
{
291+
final boolean isDirectory = DocumentsContract.Document.MIME_TYPE_DIR.equals( c.getString( mimeTypeIndex ) );
292+
final String name = c.getString( nameIndex );
293+
final String uri = DocumentsContract.buildDocumentUriUsingTree( mUri, c.getString( documentIdIndex ) ).toString();
294+
295+
stringBuilder.append( isDirectory ? "d" : "f" ).append( name ).append( "<>" ).append( uri ).append( "<>" );
296+
} while( c.moveToNext() );
297+
}
298+
}
299+
catch( Exception e )
300+
{
301+
Log.w( "Unity", "Failed query: " + e );
302+
}
303+
finally
304+
{
305+
try
306+
{
307+
if( c != null )
308+
c.close();
309+
}
310+
catch( Exception e )
311+
{
312+
Log.e( TAG, "Exception:", e );
313+
}
314+
}
315+
}
316+
274317
public String renameTo( String displayName )
275318
{
276319
try
Binary file not shown.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.yasirkula.simplefilebrowser",
33
"displayName": "Simple File Browser",
4-
"version": "1.5.5",
4+
"version": "1.5.6",
55
"documentationUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser",
66
"changelogUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/releases",
77
"licensesUrl": "https://github.com/yasirkula/UnitySimpleFileBrowser/blob/master/LICENSE.txt",

0 commit comments

Comments
 (0)