Search in sources :

Example 1 with DocumentStack

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

the class RecentsProvider method purgeByAuthority.

/**
 * Purge all internal data whose authority matches the given
 * {@link Predicate}.
 */
private void purgeByAuthority(Predicate<String> predicate) {
    final SQLiteDatabase db = mHelper.getWritableDatabase();
    final DocumentStack stack = new DocumentStack();
    Cursor cursor = db.query(TABLE_RECENT, null, null, null, null, null, null);
    try {
        while (cursor.moveToNext()) {
            try {
                final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(RecentColumns.STACK));
                DurableUtils.readFromArray(rawStack, stack);
                if (stack.root != null && predicate.apply(stack.root.authority)) {
                    final String key = getCursorString(cursor, RecentColumns.KEY);
                    db.delete(TABLE_RECENT, RecentColumns.KEY + "=?", new String[] { key });
                }
            } catch (IOException ignored) {
            }
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    cursor = db.query(TABLE_STATE, new String[] { StateColumns.AUTHORITY }, null, null, StateColumns.AUTHORITY, null, null);
    try {
        while (cursor.moveToNext()) {
            final String authority = getCursorString(cursor, StateColumns.AUTHORITY);
            if (predicate.apply(authority)) {
                db.delete(TABLE_STATE, StateColumns.AUTHORITY + "=?", new String[] { authority });
                Log.d(TAG, "Purged state for " + authority);
            }
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
    cursor = db.query(TABLE_RESUME, null, null, null, null, null, null);
    try {
        while (cursor.moveToNext()) {
            try {
                final byte[] rawStack = cursor.getBlob(cursor.getColumnIndex(ResumeColumns.STACK));
                DurableUtils.readFromArray(rawStack, stack);
                if (stack.root != null && predicate.apply(stack.root.authority)) {
                    final String packageName = getCursorString(cursor, ResumeColumns.PACKAGE_NAME);
                    db.delete(TABLE_RESUME, ResumeColumns.PACKAGE_NAME + "=?", new String[] { packageName });
                }
            } catch (IOException ignored) {
            }
        }
    } finally {
        IoUtils.closeQuietly(cursor);
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DocumentStack(dev.dworks.apps.anexplorer.model.DocumentStack) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) IOException(java.io.IOException) Cursor(android.database.Cursor)

Example 2 with DocumentStack

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

the class RecentsCreateFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    mAdapter = new DocumentStackAdapter();
    mListView.setAdapter(mAdapter);
    final RootsCache roots = DocumentsApplication.getRootsCache(context);
    final State state = ((BaseActivity) getActivity()).getDisplayState();
    mCallbacks = new LoaderCallbacks<List<DocumentStack>>() {

        @Override
        public Loader<List<DocumentStack>> onCreateLoader(int id, Bundle args) {
            return new RecentsCreateLoader(context, roots, state);
        }

        @Override
        public void onLoadFinished(Loader<List<DocumentStack>> loader, List<DocumentStack> data) {
            mAdapter.swapStacks(data);
            if (isResumed()) {
                setListShown(true);
            } else {
                setListShownNoAnimation(true);
            }
            // When launched into empty recents, show drawer
            if (mAdapter.isEmpty() && !state.stackTouched) {
                ((BaseActivity) context).setRootsDrawerOpen(true);
            }
        }

        @Override
        public void onLoaderReset(Loader<List<DocumentStack>> loader) {
            mAdapter.swapStacks(null);
        }
    };
    setListAdapter(mAdapter);
    setListShown(false);
    getLoaderManager().restartLoader(LOADER_RECENTS, getArguments(), mCallbacks);
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) UriDerivativeLoader(dev.dworks.apps.anexplorer.loader.UriDerivativeLoader) Loader(android.content.Loader) RootsCache(dev.dworks.apps.anexplorer.misc.RootsCache) State(dev.dworks.apps.anexplorer.BaseActivity.State) BaseActivity(dev.dworks.apps.anexplorer.BaseActivity) ArrayList(java.util.ArrayList) List(java.util.List) DocumentStack(dev.dworks.apps.anexplorer.model.DocumentStack)

Aggregations

DocumentStack (dev.dworks.apps.anexplorer.model.DocumentStack)2 Context (android.content.Context)1 Loader (android.content.Loader)1 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 Bundle (android.os.Bundle)1 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)1 State (dev.dworks.apps.anexplorer.BaseActivity.State)1 UriDerivativeLoader (dev.dworks.apps.anexplorer.loader.UriDerivativeLoader)1 RootsCache (dev.dworks.apps.anexplorer.misc.RootsCache)1 DocumentInfo.getCursorString (dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1