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);
}
}
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);
}
Aggregations