use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class Move method execute.
@Override
public void execute(Intent workIntent) {
File_POJO[] files = getFiles(workIntent);
File_POJO target = workIntent.getParcelableExtra(TARGET);
movedFilePaths = new ArrayList<>();
if (target == null) {
return;
}
int success_count = 0;
onProgress(success_count, files.length);
// check if file is on removable storage
boolean movingOntoRemovableStorage = Util.isOnRemovableStorage(target.getPath());
/*if (movingOntoRemovableStorage) {
//failed = true;
Uri treeUri = getTreeUri(workIntent, target.getPath());
if (treeUri == null) {
return;
}
} else {*/
for (int i = files.length - 1; i >= 0; i--) {
boolean movingFromRemovableStorage = Util.isOnRemovableStorage(files[i].getPath());
boolean result;
if (movingFromRemovableStorage || movingOntoRemovableStorage) {
// failed = true;
Uri treeUri;
if (movingFromRemovableStorage) {
treeUri = getTreeUri(workIntent, files[i].getPath());
} else {
treeUri = getTreeUri(workIntent, target.getPath());
}
if (treeUri == null) {
return;
}
result = copyAndDeleteFiles(getApplicationContext(), treeUri, files[i].getPath(), target.getPath());
// break;
} else {
result = moveFile(files[i].getPath(), target.getPath());
}
// boolean result = moveFile(files[i].getPath(), target.getPath());
if (result) {
movedFilePaths.add(files[i].getPath());
}
success_count += result ? 1 : 0;
onProgress(success_count, files.length);
}
/*if (failed) {
showRemovableStorageToast();
} else */
if (success_count == 0) {
onProgress(success_count, files.length);
}
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class StorageRetriever method loadFilesForDir.
public void loadFilesForDir(final Activity context, String dirPath, final FilesProvider.Callback callback) {
if (new File(dirPath).isFile()) {
callback.onDirLoaded(null);
return;
}
threads = new ArrayList<>();
Thread.Callback threadCallback = new Thread.Callback() {
@Override
public void done(Thread thread, ItemLoader.Result result) {
File_POJO files = result.files;
boolean filesContainMedia = false;
for (int i = 0; i < files.getChildren().size(); i++) {
if (files.getChildren().get(i) != null && MediaType.isMedia(files.getChildren().get(i).getPath())) {
filesContainMedia = true;
break;
}
}
if (filesContainMedia) {
SortUtil.sortByDate(files.getChildren());
} else {
SortUtil.sortByName(files.getChildren());
}
callback.onDirLoaded(files);
thread.cancel();
threads = null;
}
};
final File[] files = new File[] { new File(dirPath) };
Thread thread = new Thread(context, files, new FileLoader()).notSearchSubDirs().setCallback(threadCallback);
threads.add(thread);
thread.start();
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class Delete method execute.
@Override
public void execute(Intent workIntent) {
final File_POJO[] files = getFiles(workIntent);
int success_count = 0;
onProgress(success_count, files.length);
for (int i = 0; i < files.length; i++) {
boolean result;
// check if file is on removable storage
if (Util.isOnRemovableStorage(files[i].getPath())) {
// file is on removable storage
Uri treeUri = getTreeUri(workIntent, files[i].getPath());
if (treeUri == null) {
return;
}
result = deleteFileOnRemovableStorage(getApplicationContext(), treeUri, files[i].getPath());
} else {
result = deleteFile(files[i].getPath());
// Delete Album, when empty
/*String parentPath = Util.getParentPath(files[i].getPath());
if (result && Util.isDirectoryEmpty(parentPath)) {
deleteFile(parentPath);
}*/
}
if (result) {
success_count++;
onProgress(success_count, files.length);
} else {
sendFailedBroadcast(workIntent, files[i].getPath());
}
}
if (success_count == 0) {
onProgress(success_count, files.length);
}
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class NewDirectory method execute.
@Override
public void execute(Intent workIntent) {
final File_POJO[] files = getFiles(workIntent);
if (files.length > 0) {
final File_POJO file = files[0];
// check if file is on removable storage
boolean writingOntoRemovableStorage = Util.isOnRemovableStorage(file.getPath());
Uri treeUri = null;
if (writingOntoRemovableStorage) {
treeUri = getTreeUri(workIntent, null);
if (treeUri == null) {
return;
}
}
boolean result;
if (!writingOntoRemovableStorage) {
result = createNewFolder(file.getPath());
} else {
result = StorageUtil.createDocumentDir(getApplicationContext(), treeUri, file.getPath()) != null;
}
if (!result) {
sendFailedBroadcast(workIntent, file.getPath());
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), getString(R.string.successfully_created_new_folder), Toast.LENGTH_SHORT).show();
}
});
}
}
}
use of us.koller.cameraroll.data.models.File_POJO in project Camera-Roll-Android-App by kollerlukas.
the class Rename method execute.
@Override
public void execute(Intent workIntent) {
final File_POJO[] files = getFiles(workIntent);
final String newFileName = workIntent.getStringExtra(FileOperation.NEW_FILE_NAME);
if (files.length > 0 && newFileName != null) {
final File_POJO file = files[0];
boolean result;
if (FileOperation.Util.isOnRemovableStorage(file.getPath())) {
// file is on removable storage
Uri treeUri = getTreeUri(workIntent, file.getPath());
if (treeUri == null) {
return;
}
result = renameFileRemovableStorage(getApplicationContext(), treeUri, file.getPath(), newFileName);
} else {
result = renameFile(file.getPath(), newFileName);
}
if (!result) {
sendFailedBroadcast(workIntent, file.getPath());
} else {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(getApplicationContext(), getString(R.string.successfully_renamed_file), Toast.LENGTH_SHORT).show();
}
});
}
}
}
Aggregations