Search in sources :

Example 1 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method onSaveDocuments.

public boolean onSaveDocuments(ArrayList<DocumentInfo> docs) {
    final Context context = getActivity();
    final ContentResolver resolver = context.getContentResolver();
    boolean hadTrouble = false;
    for (DocumentInfo doc : docs) {
        if (!doc.isCopySupported()) {
            Log.w(TAG, "Skipping " + doc);
            hadTrouble = true;
            continue;
        }
        try {
            Uri appBackupUri = DocumentsContract.buildDocumentUri(ExternalStorageProvider.AUTHORITY, DIRECTORY_APPBACKUP);
            hadTrouble = DocumentsContract.copyDocument(resolver, doc.derivedUri, appBackupUri) == null;
        } catch (Exception e) {
            Log.w(TAG, "Failed to save " + doc);
            CrashReportingManager.logException(e);
            hadTrouble = true;
        }
    }
    return hadTrouble;
}
Also used : Context(android.content.Context) Uri(android.net.Uri) OperationCanceledException(android.os.OperationCanceledException) ContentResolver(android.content.ContentResolver) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 2 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method onCompressDocuments.

public boolean onCompressDocuments(DocumentInfo parent, ArrayList<DocumentInfo> docs) {
    final Context context = getActivity();
    final ContentResolver resolver = context.getContentResolver();
    boolean hadTrouble = false;
    if (!parent.isArchiveSupported()) {
        Log.w(TAG, "Skipping " + doc);
        hadTrouble = true;
    }
    try {
        ArrayList<String> documentIds = new ArrayList<>();
        for (DocumentInfo doc : docs) {
            documentIds.add(DocumentsContract.getDocumentId(doc.derivedUri));
        }
        hadTrouble = !DocumentsContract.compressDocument(resolver, doc.derivedUri, documentIds);
    } catch (Exception e) {
        Log.w(TAG, "Failed to Compress " + doc);
        CrashReportingManager.logException(e);
        hadTrouble = true;
    }
    return hadTrouble;
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) OperationCanceledException(android.os.OperationCanceledException) ContentResolver(android.content.ContentResolver) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 3 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method onDeleteDocuments.

private boolean onDeleteDocuments(ArrayList<DocumentInfo> docs) {
    final Context context = getActivity();
    final ContentResolver resolver = context.getContentResolver();
    boolean hadTrouble = false;
    for (DocumentInfo doc : docs) {
        if (!doc.isDeleteSupported()) {
            Log.w(TAG, "Skipping " + doc);
            hadTrouble = true;
            continue;
        }
        try {
            hadTrouble = !DocumentsContract.deleteDocument(resolver, doc.derivedUri);
        } catch (Exception e) {
            Log.w(TAG, "Failed to delete " + doc);
            CrashReportingManager.logException(e);
            hadTrouble = true;
        }
    }
    return hadTrouble;
}
Also used : Context(android.content.Context) OperationCanceledException(android.os.OperationCanceledException) ContentResolver(android.content.ContentResolver) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 4 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method showPopupMenu.

private void showPopupMenu(View view, final int position) {
    PopupMenu popup = new PopupMenu(getActivity(), view);
    int menuId = R.menu.popup_simple_directory;
    if (isApp) {
        menuId = R.menu.popup_apps;
    } else {
        menuId = R.menu.popup_directory;
    }
    popup.getMenuInflater().inflate(menuId, popup.getMenu());
    popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {

        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            return onPopupMenuItemClick(menuItem, position);
        }
    });
    if (isApp) {
        final MenuItem open = popup.getMenu().findItem(R.id.menu_open);
        final MenuItem delete = popup.getMenu().findItem(R.id.menu_delete);
        final MenuItem save = popup.getMenu().findItem(R.id.menu_save);
        open.setVisible(root.isAppPackage());
        save.setVisible(root.isAppPackage());
        delete.setVisible(root.isUserApp());
    } else {
        final State state = getDisplayState(DirectoryFragment.this);
        final MenuItem share = popup.getMenu().findItem(R.id.menu_share);
        final MenuItem delete = popup.getMenu().findItem(R.id.menu_delete);
        final MenuItem rename = popup.getMenu().findItem(R.id.menu_rename);
        final MenuItem copy = popup.getMenu().findItem(R.id.menu_copy);
        final MenuItem cut = popup.getMenu().findItem(R.id.menu_cut);
        final MenuItem compress = popup.getMenu().findItem(R.id.menu_compress);
        final MenuItem uncompress = popup.getMenu().findItem(R.id.menu_uncompress);
        final MenuItem bookmark = popup.getMenu().findItem(R.id.menu_bookmark);
        final Cursor cursor = mAdapter.getItem(position);
        final DocumentInfo doc = DocumentInfo.fromDirectoryCursor(cursor);
        final boolean manageMode = state.action == ACTION_BROWSE;
        if (null != doc) {
            final boolean isCompressed = doc != null && MimePredicate.mimeMatches(MimePredicate.COMPRESSED_MIMES, doc.mimeType);
            if (null != compress)
                compress.setVisible(manageMode && doc.isArchiveSupported() && !isCompressed && !isOperationSupported);
            if (null != uncompress)
                uncompress.setVisible(manageMode && doc.isArchiveSupported() && isCompressed && !isOperationSupported);
            if (null != bookmark) {
                bookmark.setVisible(manageMode && doc.isBookmarkSupported() && Utils.isDir(doc.mimeType) && !isOperationSupported);
            }
            share.setVisible(manageMode);
            delete.setVisible(manageMode && doc.isDeleteSupported());
            rename.setVisible(manageMode && doc.isRenameSupported());
            copy.setVisible(manageMode && doc.isCopySupported());
            cut.setVisible(manageMode && doc.isMoveSupported());
        }
    }
    popup.show();
}
Also used : State(dev.dworks.apps.anexplorer.BaseActivity.State) MenuItem(android.view.MenuItem) Cursor(android.database.Cursor) Point(android.graphics.Point) PopupMenu(android.widget.PopupMenu) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 5 with DocumentInfo

use of dev.dworks.apps.anexplorer.model.DocumentInfo in project AnExplorer by 1hakr.

the class StandaloneActivity method dumpStack.

private void dumpStack() {
    Log.d(TAG, "Current stack: ");
    Log.d(TAG, " * " + mState.stack.root);
    for (DocumentInfo doc : mState.stack) {
        Log.d(TAG, " +-- " + doc);
    }
}
Also used : DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Aggregations

DocumentInfo (dev.dworks.apps.anexplorer.model.DocumentInfo)20 Context (android.content.Context)6 ContentResolver (android.content.ContentResolver)5 Uri (android.net.Uri)5 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)5 ArrayList (java.util.ArrayList)5 FragmentManager (android.app.FragmentManager)4 Intent (android.content.Intent)4 OperationCanceledException (android.os.OperationCanceledException)4 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)4 Bundle (android.os.Bundle)3 MenuItem (android.view.MenuItem)3 ContentValues (android.content.ContentValues)2 DialogInterface (android.content.DialogInterface)2 OnClickListener (android.content.DialogInterface.OnClickListener)2 Cursor (android.database.Cursor)2 Point (android.graphics.Point)2 AlertDialog (android.support.v7.app.AlertDialog)2 LayoutInflater (android.view.LayoutInflater)2 View (android.view.View)2