Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
TranceLove committed Sep 15, 2024
1 parent ba93d8f commit dc5482b
Show file tree
Hide file tree
Showing 31 changed files with 1,162 additions and 1,080 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ android {
properties.load(project.rootProject.file('local.properties').newDataInputStream())

buildConfigField "String", "GOOGLE_CLIENT_ID", "\"${properties.getProperty('GOOGLE_CLIENT_ID')}\""
buildConfigField "String", "DROPBOX_APP_KEY", "\"${properties.getProperty('DROPBOX_APP_KEY')}\""
}

signingConfigs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class HiddenAdapter(
val task = DeleteTask(context, false)
task.execute(filesToDelete)
}
DataUtils.getInstance().removeHiddenFile(hiddenFiles[position].path)
DataUtils.removeHiddenFile(hiddenFiles[position].path)
hiddenFiles.remove(hiddenFiles[position])
notifyItemRemoved(position)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class DeleteTask
private CompressedExplorerFragment compressedExplorerFragment;

private boolean doDeletePermanently;
private final DataUtils dataUtils = DataUtils.getInstance();
private final DataUtils dataUtils = DataUtils.INSTANCE;

public DeleteTask(@NonNull Context applicationContext, @NonNull boolean doDeletePermanently) {
this.applicationContext = applicationContext.getApplicationContext();
Expand Down Expand Up @@ -174,14 +174,15 @@ private boolean doDeleteFile(@NonNull HybridFileParcelable file) throws Exceptio
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorage = dataUtils.getAccount(file.getMode());
try {
cloudStorage.delete(CloudUtil.stripPath(file.getMode(), file.getPath()));
return true;
} catch (Exception e) {
LOG.warn("failed to delete cloud files", e);
return false;
}
return false;
// CloudStorage cloudStorage = dataUtils.getAccount(file.getMode());
// try {
// cloudStorage.delete(CloudUtil.stripPath(file.getMode(), file.getPath()));
// return true;
// } catch (Exception e) {
// LOG.warn("failed to delete cloud files", e);
// return false;
// }
default:
try {
/* SMB and SFTP (or any remote files that may support in the future) should not be
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public class LoadFilesListTask
private WeakReference<Context> context;
private OpenMode openmode;
private boolean showHiddenFiles, showThumbs;
private DataUtils dataUtils = DataUtils.getInstance();
private DataUtils dataUtils = DataUtils.INSTANCE;
private OnAsyncTaskFinished<Pair<OpenMode, List<LayoutElementParcelable>>> listener;
private boolean forceReload;

Expand Down Expand Up @@ -761,16 +761,16 @@ private List<LayoutElementParcelable> listCloud(
if (cloudCache != null && !forceReload) {
list = cloudCache;
} else {
CloudStorage cloudStorage = dataUtils.getAccount(openmode);
// CloudStorage cloudStorage = dataUtils.getAccount(openmode);
list = new ArrayList<>();
listCloudInternal(
path,
cloudStorage,
openmode,
file -> {
LayoutElementParcelable elem = createListParcelables(file);
if (elem != null) list.add(elem);
});
// listCloudInternal(
// path,
// cloudStorage,
// openmode,
// file -> {
// LayoutElementParcelable elem = createListParcelables(file);
// if (elem != null) list.add(elem);
// });
mainActivityViewModel.putInCache(path, list);
}
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,24 +133,24 @@ private MoveFilesReturn processFile(
case BOX:
case ONEDRIVE:
case GDRIVE:
DataUtils dataUtils = DataUtils.getInstance();

CloudStorage cloudStorage = dataUtils.getAccount(mode);
if (baseFile.getMode() == mode) {
// source and target both in same filesystem, use API method
try {
cloudStorage.move(
CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, destPath));
} catch (RuntimeException e) {
LOG.warn("failed to move file in cloud filesystem", e);
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}
} else {
// not in same filesystem, execute service
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}
default:
return new MoveFilesReturn(false, false, destinationSize, totalBytes);
// DataUtils dataUtils = DataUtils.INSTANCE;
//
// CloudStorage cloudStorage = dataUtils.getAccount(mode);
// if (baseFile.getMode() == mode) {
// // source and target both in same filesystem, use API method
// try {
// cloudStorage.move(
// CloudUtil.stripPath(mode, baseFile.getPath()), CloudUtil.stripPath(mode, destPath));
// } catch (RuntimeException e) {
// LOG.warn("failed to move file in cloud filesystem", e);
// return new MoveFilesReturn(false, false, destinationSize, totalBytes);
// }
// } else {
// // not in same filesystem, execute service
// return new MoveFilesReturn(false, false, destinationSize, totalBytes);
// }
// default:
// return new MoveFilesReturn(false, false, destinationSize, totalBytes);
}

return null;
Expand Down
14 changes: 7 additions & 7 deletions app/src/main/java/com/amaze/filemanager/filesystem/FileUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ public static final void writeUriToStorage(
}

String finalFilePath = currentPath + "/" + filename;
DataUtils dataUtils = DataUtils.getInstance();
DataUtils dataUtils = DataUtils.INSTANCE;

HybridFile hFile = new HybridFile(OpenMode.UNKNOWN, currentPath);
hFile.generateMode(mainActivity);
Expand Down Expand Up @@ -199,12 +199,12 @@ public static final void writeUriToStorage(
case BOX:
case ONEDRIVE:
case GDRIVE:
OpenMode mode = hFile.getMode();

CloudStorage cloudStorage = dataUtils.getAccount(mode);
String path = CloudUtil.stripPath(mode, finalFilePath);
cloudStorage.upload(path, bufferedInputStream, documentFile.length(), true);
retval.add(path);
// OpenMode mode = hFile.getMode();
//
// CloudStorage cloudStorage = dataUtils.getAccount(mode);
// String path = CloudUtil.stripPath(mode, finalFilePath);
// cloudStorage.upload(path, bufferedInputStream, documentFile.length(), true);
// retval.add(path);
break;
case OTG:
DocumentFile documentTargetFile =
Expand Down
153 changes: 78 additions & 75 deletions app/src/main/java/com/amaze/filemanager/filesystem/HybridFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static com.amaze.filemanager.filesystem.ssh.SFTPClientExtKt.READ_AHEAD_MAX_UNCONFIRMED_READS;
import static com.amaze.filemanager.filesystem.ssh.SshClientUtils.sftpGetSize;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
Expand Down Expand Up @@ -147,7 +148,7 @@ public class HybridFile {
protected OpenMode mode;
protected String name;

private final DataUtils dataUtils = DataUtils.getInstance();
private final DataUtils dataUtils = DataUtils.INSTANCE;

public HybridFile(OpenMode mode, String path) {
this.path = path;
Expand Down Expand Up @@ -416,24 +417,24 @@ public long length(Context context) {
case BOX:
case ONEDRIVE:
case GDRIVE:
s =
Single.fromCallable(
() -> {
OmhStorageMetadata metadata =
(OmhStorageMetadata)
OMHClientHelper.getGoogleStorageClient(context)
.getFileMetadata(
dataUtils.getAccount(mode).getOmhStorageEntity().getId(),
CoroutineCallback.Companion.call((result, error) -> {}));

OmhStorageEntity entity = metadata.getEntity();

if (entity instanceof OmhStorageEntity.OmhFile)
return ((OmhStorageEntity.OmhFile) entity).getSize().longValue();
else return 0L;
})
.subscribeOn(Schedulers.io())
.blockingGet();
// s =
// Single.fromCallable(
// () -> {
// OmhStorageMetadata metadata =
// (OmhStorageMetadata)
// OMHClientHelper.getGoogleStorageClient(context)
// .getFileMetadata(
// dataUtils.getAccount(mode).getOmhStorageEntity().getId(),
// CoroutineCallback.Companion.call((result, error) -> {}));
//
// OmhStorageEntity entity = metadata.getEntity();
//
// if (entity instanceof OmhStorageEntity.OmhFile)
// return ((OmhStorageEntity.OmhFile) entity).getSize().longValue();
// else return 0L;
// })
// .subscribeOn(Schedulers.io())
// .blockingGet();
return s;
default:
break;
Expand Down Expand Up @@ -699,21 +700,22 @@ public Boolean execute(@NonNull SFTPClient client) {
case BOX:
case GDRIVE:
case ONEDRIVE:
return Single.fromCallable(
() -> {
OmhStorageMetadata metadata =
(OmhStorageMetadata)
OMHClientHelper.getGoogleStorageClient(context)
.getFileMetadata(
dataUtils.getAccount(mode).getOmhStorageEntity().getId(),
CoroutineCallback.Companion.call((result, error) -> {}));

OmhStorageEntity entity = metadata.getEntity();

return entity instanceof OmhStorageEntity.OmhFolder;
})
.subscribeOn(Schedulers.io())
.blockingGet();
// return Single.fromCallable(
// () -> {
// OmhStorageMetadata metadata =
// (OmhStorageMetadata)
// OMHClientHelper.getGoogleStorageClient(context)
// .getFileMetadata(
// dataUtils.getAccount(mode).getOmhStorageEntity().getId(),
// CoroutineCallback.Companion.call((result, error) -> {}));
//
// OmhStorageEntity entity = metadata.getEntity();
//
// return entity instanceof OmhStorageEntity.OmhFolder;
// })
// .subscribeOn(Schedulers.io())
// .blockingGet();
return false;
case TRASH_BIN:
default: // also handles the case `FILE`
File file = getFile();
Expand Down Expand Up @@ -803,18 +805,18 @@ public long folderSize(Context context) {
case BOX:
case GDRIVE:
case ONEDRIVE:
size =
FileUtils.folderSizeCloud(
mode,
(OmhStorageMetadata)
OMHClientHelper.getGoogleStorageClient(context)
.getFileMetadata(
dataUtils.getAccount(mode).getOmhStorageEntity().getId(),
CoroutineCallback.Companion.call((resultValue, error) -> {})));
// size = 0L;
// FileUtils.folderSizeCloud(
// mode,
// (OmhStorageMetadata)
// OMHClientHelper.getGoogleStorageClient(context)
// .getFileMetadata(
// dataUtils.getAccount(mode).getCredentials().getId(),
// CoroutineCallback.Companion.call((resultValue, error) -> {})));
break;
case FTP:
default:
return 0l;
return 0L;
}
return size;
}
Expand Down Expand Up @@ -848,10 +850,10 @@ public long getUsableSpace() {
case BOX:
case GDRIVE:
case ONEDRIVE:
SpaceAllocation spaceAllocation =
((OmhStorageEntity.OmhFolder) dataUtils.getAccount(mode).getOmhStorageEntity())
.get.getAllocation();
size = spaceAllocation.getTotal() - spaceAllocation.getUsed();
// SpaceAllocation spaceAllocation =
// ((OmhStorageEntity.OmhFolder) dataUtils.getAccount(mode).getOmhStorageEntity())
// .get.getAllocation();
// size = spaceAllocation.getTotal() - spaceAllocation.getUsed();
break;
case SFTP:
final Long returnValue =
Expand Down Expand Up @@ -916,7 +918,7 @@ public Long execute(@NonNull SFTPClient client) throws IOException {

/** Gets total size of the disk */
public long getTotal(Context context) {
long size = 0l;
long size = 0L;
switch (mode) {
case SMB:
// TODO: Find total storage space of SMB when JCIFS adds support
Expand All @@ -936,8 +938,8 @@ public long getTotal(Context context) {
case BOX:
case ONEDRIVE:
case GDRIVE:
SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
size = spaceAllocation.getTotal();
// SpaceAllocation spaceAllocation = dataUtils.getAccount(mode).getAllocation();
// size = spaceAllocation.getTotal();
break;
case SFTP:
final Long returnValue =
Expand Down Expand Up @@ -1066,11 +1068,11 @@ public FTPFile[] executeWithFtpClient(@NonNull FTPClient ftpClient)
case BOX:
case GDRIVE:
case ONEDRIVE:
try {
CloudUtil.getCloudFiles(path, dataUtils.getAccount(mode), mode, onFileFound);
} catch (CloudPluginException e) {
LOG.warn("failed to get children file for cloud file", e);
}
// try {
// CloudUtil.getCloudFiles(path, dataUtils.getAccount(mode), mode, onFileFound);
// } catch (CloudPluginException e) {
// LOG.warn("failed to get children file for cloud file", e);
// }
break;
case TRASH_BIN:
default:
Expand Down Expand Up @@ -1220,9 +1222,10 @@ public InputStream executeWithFtpClient(@NonNull FTPClient ftpClient)
case BOX:
case GDRIVE:
case ONEDRIVE:
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(mode);
// CloudStorage cloudStorageOneDrive = dataUtils.getAccount(mode);
LOG.debug(CloudUtil.stripPath(mode, path));
inputStream = cloudStorageOneDrive.download(CloudUtil.stripPath(mode, path));
// inputStream = cloudStorageOneDrive.download(CloudUtil.stripPath(mode, path));
inputStream = new ByteArrayInputStream(new byte[0]);
break;
case TRASH_BIN:
default:
Expand Down Expand Up @@ -1360,18 +1363,18 @@ public Boolean execute(SFTPClient client) throws IOException {
else {
exists = getFtpFile() != null;
}
} else if (isDropBoxFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
exists = cloudStorageDropbox.exists(CloudUtil.stripPath(OpenMode.DROPBOX, path));
} else if (isBoxFile()) {
CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
exists = cloudStorageBox.exists(CloudUtil.stripPath(OpenMode.BOX, path));
} else if (isGoogleDriveFile()) {
CloudStorage cloudStorageGoogleDrive = dataUtils.getAccount(OpenMode.GDRIVE);
exists = cloudStorageGoogleDrive.exists(CloudUtil.stripPath(OpenMode.GDRIVE, path));
} else if (isOneDriveFile()) {
CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
exists = cloudStorageOneDrive.exists(CloudUtil.stripPath(OpenMode.ONEDRIVE, path));
// } else if (isDropBoxFile()) {
// CloudStorage cloudStorageDropbox = dataUtils.getAccount(OpenMode.DROPBOX);
// exists = cloudStorageDropbox.exists(CloudUtil.stripPath(OpenMode.DROPBOX, path));
// } else if (isBoxFile()) {
// CloudStorage cloudStorageBox = dataUtils.getAccount(OpenMode.BOX);
// exists = cloudStorageBox.exists(CloudUtil.stripPath(OpenMode.BOX, path));
// } else if (isGoogleDriveFile()) {
// CloudStorage cloudStorageGoogleDrive = dataUtils.getAccount(OpenMode.GDRIVE);
// exists = cloudStorageGoogleDrive.exists(CloudUtil.stripPath(OpenMode.GDRIVE, path));
// } else if (isOneDriveFile()) {
// CloudStorage cloudStorageOneDrive = dataUtils.getAccount(OpenMode.ONEDRIVE);
// exists = cloudStorageOneDrive.exists(CloudUtil.stripPath(OpenMode.ONEDRIVE, path));
} else if (isLocal()) {
exists = getFile().exists();
} else if (isRoot()) {
Expand Down Expand Up @@ -1536,12 +1539,12 @@ public Boolean executeWithFtpClient(@NonNull FTPClient ftpClient) throws IOExcep
}
}
} else if (isCloudDriveFile()) {
CloudStorage cloudStorageDropbox = dataUtils.getAccount(mode);
try {
cloudStorageDropbox.createFolder(CloudUtil.stripPath(mode, path));
} catch (Exception e) {
LOG.warn("failed to create folder for cloud file", e);
}
// CloudStorage cloudStorageDropbox = dataUtils.getAccount(mode);
// try {
// cloudStorageDropbox.createFolder(CloudUtil.stripPath(mode, path));
// } catch (Exception e) {
// LOG.warn("failed to create folder for cloud file", e);
// }
} else if (isTrashBin()) { // do nothing
} else MakeDirectoryOperation.mkdirs(context, this);
}
Expand Down
Loading

0 comments on commit dc5482b

Please sign in to comment.