Skip to content

Commit

Permalink
refactor HybridFile#isDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
VishnuSanal committed Sep 26, 2023
1 parent 0200fa8 commit 53f963a
Showing 1 changed file with 21 additions and 36 deletions.
57 changes: 21 additions & 36 deletions app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ public boolean isDirectory() {
}

public boolean isDirectory(Context context) {
boolean isDirectory;
switch (mode) {
case SFTP:
final Boolean returnValue =
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 53f963a

Please sign in to comment.