From 53f963a36783806b1fc8901e9b55b0ca8aa44754 Mon Sep 17 00:00:00 2001 From: VishnuSanal Date: Tue, 26 Sep 2023 23:21:16 +0530 Subject: [PATCH] refactor HybridFile#isDirectory --- .../filemanager/filesystem/HybridFile.java | 57 +++++++------------ 1 file changed, 21 insertions(+), 36 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java index 1a39909b00..23ca40e89f 100644 --- a/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java +++ b/app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java @@ -612,7 +612,6 @@ public boolean isDirectory() { } public boolean isDirectory(Context context) { - boolean isDirectory; switch (mode) { case SFTP: final Boolean returnValue = @@ -634,60 +633,46 @@ public Boolean execute(@NonNull SFTPClient client) { if (returnValue == null) { LOG.error("Error obtaining if path is directory over SFTP"); + return false; } - //noinspection SimplifiableConditionalExpression - return returnValue == null ? false : returnValue; + return returnValue; case SMB: try { - isDirectory = - Single.fromCallable(() -> getSmbFile().isDirectory()) - .subscribeOn(Schedulers.io()) - .blockingGet(); + return Single.fromCallable(() -> getSmbFile().isDirectory()) + .subscribeOn(Schedulers.io()) + .blockingGet(); } catch (Exception e) { - isDirectory = false; LOG.warn("failed to get isDirectory with context for smb file", e); + return false; } - break; case FTP: FTPFile ftpFile = getFtpFile(); - isDirectory = ftpFile != null && ftpFile.isDirectory(); - break; - case FILE: - File file = getFile(); - isDirectory = file != null && file.isDirectory(); - break; + return ftpFile != null && ftpFile.isDirectory(); case ROOT: - isDirectory = NativeOperations.isDirectory(path); - break; + return NativeOperations.isDirectory(path); case DOCUMENT_FILE: DocumentFile documentFile = getDocumentFile(false); - isDirectory = documentFile != null && documentFile.isDirectory(); - break; + return documentFile != null && documentFile.isDirectory(); case OTG: DocumentFile otgFile = OTGUtil.getDocumentFile(path, context, false); - isDirectory = otgFile != null && otgFile.isDirectory(); - break; + return otgFile != null && otgFile.isDirectory(); case DROPBOX: case BOX: case GDRIVE: case ONEDRIVE: - isDirectory = - Single.fromCallable( - () -> - dataUtils - .getAccount(mode) - .getMetadata(CloudUtil.stripPath(mode, path)) - .getFolder()) - .subscribeOn(Schedulers.io()) - .blockingGet(); - break; - default: - File f = getFile(); - isDirectory = f != null && f.isDirectory(); - break; + return Single.fromCallable( + () -> + dataUtils + .getAccount(mode) + .getMetadata(CloudUtil.stripPath(mode, path)) + .getFolder()) + .subscribeOn(Schedulers.io()) + .blockingGet(); + default: // also handles the case `FILE` + File file = getFile(); + return file != null && file.isDirectory(); } - return isDirectory; } /**