Skip to content

Commit

Permalink
When querying DocumentProvider, the name returned included the file e…
Browse files Browse the repository at this point in the history
…xtension, which always caused no matches to be found.

Added utility to strip the file extension.

Resolves #1
  • Loading branch information
estasney committed Nov 30, 2022
1 parent 2ed58ec commit c997287
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ public MindRefFileData getOrMakeChild(ContentResolver contentResolver, String ch
)) {
if (cursor != null) {
while (cursor.moveToNext() && matchedFile == null) {
// childName may have an extension
String childName1 = cursor.getString(1);
childName1 = MindRefFileUtils.stripFileExt(childName1);
if (!Objects.equals(childName1, childName)) {
continue;
}
Expand All @@ -335,13 +337,15 @@ public MindRefFileData getOrMakeChild(ContentResolver contentResolver, String ch
}
}
} catch (Exception e) {
Log.w(TAG, "Failed getChildren: " + e);
Log.w(TAG, "Failed getOrMakeChild: " + e);
}
if (matchedFile != null) {
Log.d(TAG, "getOrMakeChild: found match");
return matchedFile;
}
Uri childTargetUri = DocumentsContract.createDocument(contentResolver, this.uri, childMime, childName);
matchedFile = new MindRefFileData(this.uri, DocumentsContract.getDocumentId(childTargetUri), childName, childMime, 0);
Log.d(TAG, "getOrMakeChild: Match Not Found, Created New Document : " + childTargetUri);
return matchedFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,16 @@ public static Path stringToPath(String path) {
return FileSystems.getDefault().getPath(path);
}

/**
* Returns the name (without extension) of a file
* @param fileName string filename
* @return String, fileName without extension
*/
public static String stripFileExt(String fileName) {
if (!fileName.contains(".")) {
return fileName;
}
return fileName.split("\\.")[0];
}

}

0 comments on commit c997287

Please sign in to comment.