Search in sources :

Example 21 with HybridFile

use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.

the class MainActivityHelper method rename.

public void rename(OpenMode mode, final String oldPath, final String newPath, final Activity context, boolean rootmode) {
    final Toast toast = Toast.makeText(context, context.getString(R.string.renaming), Toast.LENGTH_SHORT);
    toast.show();
    Operations.rename(new HybridFile(mode, oldPath), new HybridFile(mode, newPath), rootmode, context, new Operations.ErrorCallBack() {

        @Override
        public void exists(HybridFile file) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                Toast.makeText(mainActivity, context.getString(R.string.fileexist), Toast.LENGTH_SHORT).show();
            });
        }

        @Override
        public void launchSAF(HybridFile file) {
        }

        @Override
        public void launchSAF(final HybridFile file, final HybridFile file1) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                mainActivity.oppathe = file.getPath();
                mainActivity.oppathe1 = file1.getPath();
                mainActivity.operation = DataUtils.RENAME;
                guideDialogForLEXA(mainActivity.oppathe1);
            });
        }

        @Override
        public void done(final HybridFile hFile, final boolean b) {
            context.runOnUiThread(() -> {
                if (b) {
                    Intent intent = new Intent(MainActivity.KEY_INTENT_LOAD_LIST);
                    intent.putExtra(MainActivity.KEY_INTENT_LOAD_LIST_FILE, hFile.getParent(context));
                    mainActivity.sendBroadcast(intent);
                    // update the database entry to reflect rename for encrypted file
                    if (oldPath.endsWith(CryptUtil.CRYPT_EXTENSION)) {
                        try {
                            CryptHandler cryptHandler = new CryptHandler(context);
                            EncryptedEntry oldEntry = cryptHandler.findEntry(oldPath);
                            EncryptedEntry newEntry = new EncryptedEntry();
                            newEntry.setId(oldEntry.getId());
                            newEntry.setPassword(oldEntry.getPassword());
                            newEntry.setPath(newPath);
                            cryptHandler.updateEntry(oldEntry, newEntry);
                        } catch (Exception e) {
                            e.printStackTrace();
                        // couldn't change the entry, leave it alone
                        }
                    }
                } else
                    Toast.makeText(context, context.getString(R.string.operationunsuccesful), Toast.LENGTH_SHORT).show();
            });
        }

        @Override
        public void invalidName(final HybridFile file) {
            context.runOnUiThread(() -> {
                if (toast != null)
                    toast.cancel();
                Toast.makeText(context, context.getString(R.string.invalid_name) + ": " + file.getName(), Toast.LENGTH_LONG).show();
            });
        }
    });
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile) Toast(android.widget.Toast) CryptHandler(com.amaze.filemanager.database.CryptHandler) EncryptedEntry(com.amaze.filemanager.database.models.EncryptedEntry) Intent(android.content.Intent) Operations(com.amaze.filemanager.filesystem.Operations)

Example 22 with HybridFile

use of com.amaze.filemanager.filesystem.HybridFile in project AmazeFileManager by TeamAmaze.

the class MainActivityHelper method mkdir.

/**
 * Prompt a dialog to user to input directory name
 *
 * @param openMode
 * @param path     current path at which directory to create
 * @param ma       {@link MainFragment} current fragment
 */
void mkdir(final OpenMode openMode, final String path, final MainFragment ma) {
    mk(R.string.newfolder, materialDialog -> {
        String a = materialDialog.getInputEditText().getText().toString();
        mkDir(new HybridFile(openMode, path + "/" + a), ma);
        materialDialog.dismiss();
    });
}
Also used : HybridFile(com.amaze.filemanager.filesystem.HybridFile)

Aggregations

HybridFile (com.amaze.filemanager.filesystem.HybridFile)22 File (java.io.File)7 ArrayList (java.util.ArrayList)5 Toast (android.widget.Toast)4 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)4 MainFragment (com.amaze.filemanager.fragments.MainFragment)4 SmbFile (jcifs.smb.SmbFile)4 Intent (android.content.Intent)3 DeleteTask (com.amaze.filemanager.asynchronous.asynctasks.DeleteTask)3 Uri (android.net.Uri)2 MoveFiles (com.amaze.filemanager.asynchronous.asynctasks.MoveFiles)2 CopyService (com.amaze.filemanager.asynchronous.services.CopyService)2 CryptHandler (com.amaze.filemanager.database.CryptHandler)2 CloudPluginException (com.amaze.filemanager.exceptions.CloudPluginException)2 Operations (com.amaze.filemanager.filesystem.Operations)2 RootHelper (com.amaze.filemanager.filesystem.RootHelper)2 OpenMode (com.amaze.filemanager.utils.OpenMode)2 CloudStorage (com.cloudrail.si.interfaces.CloudStorage)2 MalformedURLException (java.net.MalformedURLException)2 Pattern (java.util.regex.Pattern)2