From f5c8d10f656a8a30a2fe02ff286a80d645e96ca2 Mon Sep 17 00:00:00 2001 From: Webpage-gh <70434775+Webpage-gh@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:06:05 +0800 Subject: [PATCH 1/2] Implement rename and move operations in `TermuxDocumentsProvider` --- .../filepicker/TermuxDocumentsProvider.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java index 7974d6dbc1..38819a0087 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java +++ b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java @@ -265,4 +265,31 @@ private void includeFile(MatrixCursor result, String docId, File file) row.add(Document.COLUMN_ICON, R.mipmap.ic_launcher); } + // 当前缺失的方法 + @Override + public String renameDocument(String documentId, String displayName) throws FileNotFoundException { + File file = getFileForDocId(documentId); + if (file != null) { + File target = new File(file.getParentFile(), displayName); + if (file.renameTo(target)) { + int i = documentId.lastIndexOf('/', documentId.length() - 2); + return documentId.substring(0, i) + "/" + displayName; + } + } + throw new FileNotFoundException("Failed to rename document " + documentId + " to " + displayName); + } + + @Override + public String moveDocument(String sourceDocumentId, String sourceParentDocumentId, String targetParentDocumentId) throws FileNotFoundException { + File sourceFile = getFileForDocId(sourceDocumentId); + File targetDir = getFileForDocId(targetParentDocumentId); + if (sourceFile != null && targetDir != null) { + File targetFile = new File(targetDir, sourceFile.getName()); + if (!targetFile.exists() && sourceFile.renameTo(targetFile)) { + return targetParentDocumentId.endsWith("/") ? targetParentDocumentId + targetFile.getName() : targetParentDocumentId + "/" + targetFile.getName(); + } + } + throw new FileNotFoundException("Filed to move document " + sourceDocumentId + " to " + targetParentDocumentId); + } + } From 6fbe57ac56bc5301cdd02885419c876b07f714db Mon Sep 17 00:00:00 2001 From: Webpage <70434775+Webpage-gh@users.noreply.github.com> Date: Sat, 14 Mar 2026 20:14:12 +0800 Subject: [PATCH 2/2] Remove unnecessary comments --- .../main/java/com/termux/filepicker/TermuxDocumentsProvider.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java index 38819a0087..198652794f 100644 --- a/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java +++ b/app/src/main/java/com/termux/filepicker/TermuxDocumentsProvider.java @@ -265,7 +265,6 @@ private void includeFile(MatrixCursor result, String docId, File file) row.add(Document.COLUMN_ICON, R.mipmap.ic_launcher); } - // 当前缺失的方法 @Override public String renameDocument(String documentId, String displayName) throws FileNotFoundException { File file = getFileForDocId(documentId);