Search in sources :

Example 11 with File_POJO

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);
    }
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) Uri(android.net.Uri)

Example 12 with File_POJO

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();
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) FileLoader(us.koller.cameraroll.data.provider.itemLoader.FileLoader) File(java.io.File)

Example 13 with File_POJO

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);
    }
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) Uri(android.net.Uri)

Example 14 with File_POJO

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();
                }
            });
        }
    }
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) Uri(android.net.Uri)

Example 15 with File_POJO

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();
                }
            });
        }
    }
}
Also used : File_POJO(us.koller.cameraroll.data.models.File_POJO) Uri(android.net.Uri)

Aggregations

File_POJO (us.koller.cameraroll.data.models.File_POJO)22 Intent (android.content.Intent)10 Uri (android.net.Uri)6 RecyclerView (android.support.v7.widget.RecyclerView)6 View (android.view.View)6 BroadcastReceiver (android.content.BroadcastReceiver)5 Context (android.content.Context)5 TextView (android.widget.TextView)5 SuppressLint (android.annotation.SuppressLint)3 AlertDialog (android.support.v7.app.AlertDialog)3 Album (us.koller.cameraroll.data.models.Album)3 Activity (android.app.Activity)2 DialogInterface (android.content.DialogInterface)2 Handler (android.os.Handler)2 RequiresApi (android.support.annotation.RequiresApi)2 Snackbar (android.support.design.widget.Snackbar)2 ActionBar (android.support.v7.app.ActionBar)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 Toolbar (android.support.v7.widget.Toolbar)2 SpannableString (android.text.SpannableString)2