From a9de196cc7ec623d5641fbe0f768c082736ac84c Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sun, 5 May 2024 10:34:58 +0800 Subject: [PATCH] Improve performance when using SAF (#4) --- .../main/java/com/hippo/unifile/TreeDocumentFile.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/library/src/main/java/com/hippo/unifile/TreeDocumentFile.java b/library/src/main/java/com/hippo/unifile/TreeDocumentFile.java index 615ef62..d0d0598 100644 --- a/library/src/main/java/com/hippo/unifile/TreeDocumentFile.java +++ b/library/src/main/java/com/hippo/unifile/TreeDocumentFile.java @@ -116,10 +116,10 @@ public Uri getUri() { @Override public String getName() { - if (mName != null) { - return mName; + if (mName == null) { + mName = DocumentsContractApi19.getName(mContext, mUri); } - return DocumentsContractApi19.getName(mContext, mUri); + return mName; } @Override @@ -211,8 +211,7 @@ public UniFile[] listFiles(FilenameFilter filter) { final NamedUri[] uris = DocumentsContractApi21.listFilesNamed(mContext, mUri); final ArrayList results = new ArrayList<>(); for (NamedUri uri : uris) { - String name = DocumentsContractApi19.getName(mContext, uri.uri); - if (name != null && filter.accept(this, name)) { + if (uri.name != null && filter.accept(this, uri.name)) { results.add(new TreeDocumentFile(this, mContext, uri.uri, uri.name)); } }