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)); } }