Search in sources :

Example 16 with LayoutElementParcelable

use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.

the class ItemPopupMenu method onMenuItemClick.

@Override
public boolean onMenuItemClick(MenuItem item) {
    switch(item.getItemId()) {
        case R.id.about:
            GeneralDialogCreation.showPropertiesDialogWithPermissions((rowItem).generateBaseFile(), rowItem.permissions, (ThemedActivity) mainFragment.getActivity(), mainActivity.isRootExplorer(), utilitiesProvider.getAppTheme());
            /*
                                PropertiesSheet propertiesSheet = new PropertiesSheet();
                                Bundle arguments = new Bundle();
                                arguments.putParcelable(PropertiesSheet.KEY_FILE, rowItem.generateBaseFile());
                                arguments.putString(PropertiesSheet.KEY_PERMISSION, rowItem.getPermissions());
                                arguments.putBoolean(PropertiesSheet.KEY_ROOT, ThemedActivity.rootMode);
                                propertiesSheet.setArguments(arguments);
                                propertiesSheet.show(main.getFragmentManager(), PropertiesSheet.TAG_FRAGMENT);
                                */
            return true;
        case R.id.share:
            switch(rowItem.getMode()) {
                case DROPBOX:
                case BOX:
                case GDRIVE:
                case ONEDRIVE:
                    FileUtils.shareCloudFile(rowItem.desc, rowItem.getMode(), context);
                    break;
                default:
                    ArrayList<File> arrayList = new ArrayList<>();
                    arrayList.add(new File(rowItem.desc));
                    FileUtils.shareFiles(arrayList, mainFragment.getMainActivity(), utilitiesProvider.getAppTheme(), accentColor);
                    break;
            }
            return true;
        case R.id.rename:
            mainFragment.rename(rowItem.generateBaseFile());
            return true;
        case R.id.cpy:
        case R.id.cut:
            {
                int op = item.getItemId() == R.id.cpy ? PasteHelper.OPERATION_COPY : PasteHelper.OPERATION_CUT;
                PasteHelper pasteHelper = new PasteHelper(op, new HybridFileParcelable[] { rowItem.generateBaseFile() });
                mainFragment.getMainActivity().setPaste(pasteHelper);
                return true;
            }
        case R.id.ex:
            mainFragment.getMainActivity().mainActivityHelper.extractFile(new File(rowItem.desc));
            return true;
        case R.id.book:
            DataUtils dataUtils = DataUtils.getInstance();
            dataUtils.addBook(new String[] { rowItem.title, rowItem.desc }, true);
            mainFragment.getMainActivity().getDrawer().refreshDrawer();
            Toast.makeText(mainFragment.getActivity(), mainFragment.getResources().getString(R.string.bookmarksadded), Toast.LENGTH_LONG).show();
            return true;
        case R.id.delete:
            ArrayList<LayoutElementParcelable> positions = new ArrayList<>();
            positions.add(rowItem);
            GeneralDialogCreation.deleteFilesDialog(context, mainFragment.getElementsList(), mainFragment.getMainActivity(), positions, utilitiesProvider.getAppTheme());
            return true;
        case R.id.open_with:
            boolean useNewStack = sharedPrefs.getBoolean(PreferencesConstants.PREFERENCE_TEXTEDITOR_NEWSTACK, false);
            FileUtils.openWith(new File(rowItem.desc), mainFragment.getActivity(), useNewStack);
            return true;
        case R.id.encrypt:
            final Intent encryptIntent = new Intent(context, EncryptService.class);
            encryptIntent.putExtra(EncryptService.TAG_OPEN_MODE, rowItem.getMode().ordinal());
            encryptIntent.putExtra(EncryptService.TAG_SOURCE, rowItem.generateBaseFile());
            final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
            final EncryptDecryptUtils.EncryptButtonCallbackInterface encryptButtonCallbackInterfaceAuthenticate = new EncryptDecryptUtils.EncryptButtonCallbackInterface() {

                @Override
                public void onButtonPressed(Intent intent) {
                }

                @Override
                public void onButtonPressed(Intent intent, String password) throws Exception {
                    EncryptDecryptUtils.startEncryption(context, rowItem.generateBaseFile().getPath(), password, intent);
                }
            };
            EncryptDecryptUtils.EncryptButtonCallbackInterface encryptButtonCallbackInterface = new EncryptDecryptUtils.EncryptButtonCallbackInterface() {

                @Override
                public void onButtonPressed(Intent intent) throws Exception {
                    // check if a master password or fingerprint is set
                    if (!preferences.getString(PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD, PreferencesConstants.PREFERENCE_CRYPT_MASTER_PASSWORD_DEFAULT).equals("")) {
                        EncryptDecryptUtils.startEncryption(context, rowItem.generateBaseFile().getPath(), PreferencesConstants.ENCRYPT_PASSWORD_MASTER, encryptIntent);
                    } else if (preferences.getBoolean(PreferencesConstants.PREFERENCE_CRYPT_FINGERPRINT, PreferencesConstants.PREFERENCE_CRYPT_FINGERPRINT_DEFAULT)) {
                        EncryptDecryptUtils.startEncryption(context, rowItem.generateBaseFile().getPath(), PreferencesConstants.ENCRYPT_PASSWORD_FINGERPRINT, encryptIntent);
                    } else {
                        // let's ask a password from user
                        GeneralDialogCreation.showEncryptAuthenticateDialog(context, encryptIntent, mainFragment.getMainActivity(), utilitiesProvider.getAppTheme(), encryptButtonCallbackInterfaceAuthenticate);
                    }
                }

                @Override
                public void onButtonPressed(Intent intent, String password) {
                }
            };
            if (preferences.getBoolean(PreferencesConstants.PREFERENCE_CRYPT_WARNING_REMEMBER, PreferencesConstants.PREFERENCE_CRYPT_WARNING_REMEMBER_DEFAULT)) {
                // let's skip warning dialog call
                try {
                    encryptButtonCallbackInterface.onButtonPressed(encryptIntent);
                } catch (Exception e) {
                    e.printStackTrace();
                    Toast.makeText(context, mainFragment.getResources().getString(R.string.crypt_encryption_fail), Toast.LENGTH_LONG).show();
                }
            } else {
                GeneralDialogCreation.showEncryptWarningDialog(encryptIntent, mainFragment, utilitiesProvider.getAppTheme(), encryptButtonCallbackInterface);
            }
            return true;
        case R.id.decrypt:
            EncryptDecryptUtils.decryptFile(context, mainActivity, mainFragment, mainFragment.openMode, rowItem.generateBaseFile(), rowItem.generateBaseFile().getParent(context), utilitiesProvider, false);
            return true;
        case R.id.return_select:
            mainFragment.returnIntentResults(rowItem.generateBaseFile());
            return true;
    }
    return false;
}
Also used : SharedPreferences(android.content.SharedPreferences) PasteHelper(com.amaze.filemanager.filesystem.PasteHelper) ArrayList(java.util.ArrayList) Intent(android.content.Intent) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) EncryptDecryptUtils(com.amaze.filemanager.utils.files.EncryptDecryptUtils) HybridFileParcelable(com.amaze.filemanager.filesystem.HybridFileParcelable) DataUtils(com.amaze.filemanager.utils.DataUtils) File(java.io.File)

Example 17 with LayoutElementParcelable

use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.

the class MainFragment method addSearchResult.

// adds search results based on result boolean. If false, the adapter is initialised with initial
// values, if true, new values are added to the adapter.
public void addSearchResult(HybridFileParcelable a, String query) {
    if (listView != null) {
        // initially clearing the array for new result set
        if (!results) {
            LIST_ELEMENTS.clear();
            file_count = 0;
            folder_count = 0;
        }
        // adding new value to LIST_ELEMENTS
        LayoutElementParcelable layoutElementAdded = addTo(a);
        if (!results) {
            reloadListElements(false, false, !IS_LIST);
            getMainActivity().getAppbar().getBottomBar().setPathText("");
            getMainActivity().getAppbar().getBottomBar().setFullPathText(getString(R.string.searching, query));
            results = true;
        } else {
            adapter.addItem(layoutElementAdded);
        }
        stopAnimation();
    }
}
Also used : LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable)

Example 18 with LayoutElementParcelable

use of com.amaze.filemanager.adapters.data.LayoutElementParcelable in project AmazeFileManager by TeamAmaze.

the class MainFragment method addToSmb.

public ArrayList<LayoutElementParcelable> addToSmb(SmbFile[] mFile, String path) throws SmbException {
    ArrayList<LayoutElementParcelable> a = new ArrayList<>();
    if (searchHelper.size() > 500)
        searchHelper.clear();
    for (SmbFile aMFile : mFile) {
        if (dataUtils.isFileHidden(aMFile.getPath()))
            continue;
        String name = aMFile.getName();
        name = (aMFile.isDirectory() && name.endsWith("/")) ? name.substring(0, name.length() - 1) : name;
        if (path.equals(smbPath)) {
            if (name.endsWith("$"))
                continue;
        }
        if (aMFile.isDirectory()) {
            folder_count++;
            LayoutElementParcelable layoutElement = new LayoutElementParcelable(name, aMFile.getPath(), "", "", "", 0, false, aMFile.lastModified() + "", true, getBoolean(PREFERENCE_SHOW_THUMB));
            layoutElement.setMode(OpenMode.SMB);
            searchHelper.add(layoutElement.generateBaseFile());
            a.add(layoutElement);
        } else {
            file_count++;
            try {
                LayoutElementParcelable layoutElement = new LayoutElementParcelable(name, aMFile.getPath(), "", "", Formatter.formatFileSize(getContext(), aMFile.length()), aMFile.length(), false, aMFile.lastModified() + "", false, getBoolean(PREFERENCE_SHOW_THUMB));
                layoutElement.setMode(OpenMode.SMB);
                searchHelper.add(layoutElement.generateBaseFile());
                a.add(layoutElement);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return a;
}
Also used : ArrayList(java.util.ArrayList) LayoutElementParcelable(com.amaze.filemanager.adapters.data.LayoutElementParcelable) SmbException(jcifs.smb.SmbException) ActivityNotFoundException(android.content.ActivityNotFoundException) MalformedURLException(java.net.MalformedURLException) SmbFile(jcifs.smb.SmbFile)

Aggregations

LayoutElementParcelable (com.amaze.filemanager.adapters.data.LayoutElementParcelable)18 File (java.io.File)11 ArrayList (java.util.ArrayList)11 SmbFile (jcifs.smb.SmbFile)11 HybridFile (com.amaze.filemanager.filesystem.HybridFile)10 HybridFileParcelable (com.amaze.filemanager.filesystem.HybridFileParcelable)10 Cursor (android.database.Cursor)6 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 View (android.view.View)2 SmbException (jcifs.smb.SmbException)2 Context (android.content.Context)1 Color (android.graphics.Color)1 Typeface (android.graphics.Typeface)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 FingerprintManager (android.hardware.fingerprint.FingerprintManager)1 Uri (android.net.Uri)1 AsyncTask (android.os.AsyncTask)1 Build (android.os.Build)1