Search in sources :

Example 1 with RootsCache

use of dev.dworks.apps.anexplorer.misc.RootsCache in project AnExplorer by 1hakr.

the class DirectoryFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final Context context = getActivity();
    final State state = getDisplayState(DirectoryFragment.this);
    root = getArguments().getParcelable(EXTRA_ROOT);
    doc = getArguments().getParcelable(EXTRA_DOC);
    if (null != root && root.isSecondaryStorage() && state.action == ACTION_BROWSE) {
        if (!doc.isWriteSupported()) {
            SAFManager.takeCardUriPermission(getActivity(), root, doc);
        }
    }
    isApp = root != null && root.isApp();
    isOperationSupported = root != null && (root.isRootedStorage() || root.isUsbStorage());
    mAdapter = new DocumentsAdapter();
    mType = getArguments().getInt(EXTRA_TYPE);
    mStateKey = buildStateKey(root, doc);
    if (mType == TYPE_RECENT_OPEN) {
        // Hide titles when showing recents for picking images/videos
        mHideGridTitles = MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, state.acceptMimes);
    } else {
        mHideGridTitles = (doc != null) && doc.isGridTitlesHidden();
    }
    mSvelteRecents = Utils.isLowRamDevice(context) && (mType == TYPE_RECENT_OPEN);
    mCallbacks = new LoaderCallbacks<DirectoryResult>() {

        @Override
        public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
            final String query = getArguments().getString(EXTRA_QUERY);
            Uri contentsUri;
            switch(mType) {
                case TYPE_NORMAL:
                    contentsUri = DocumentsContract.buildChildDocumentsUri(doc.authority, doc.documentId);
                    if (state.action == ACTION_MANAGE) {
                        contentsUri = DocumentsContract.setManageMode(contentsUri);
                    }
                    return new DirectoryLoader(context, mType, root, doc, contentsUri, state.userSortOrder);
                case TYPE_SEARCH:
                    contentsUri = DocumentsContract.buildSearchDocumentsUri(root.authority, root.rootId, query);
                    if (state.action == ACTION_MANAGE) {
                        contentsUri = DocumentsContract.setManageMode(contentsUri);
                    }
                    return new DirectoryLoader(context, mType, root, doc, contentsUri, state.userSortOrder);
                case TYPE_RECENT_OPEN:
                    final RootsCache roots = DocumentsApplication.getRootsCache(context);
                    return new RecentLoader(context, roots, state);
                default:
                    throw new IllegalStateException("Unknown type " + mType);
            }
        }

        @Override
        public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            if (!isAdded())
                return;
            mAdapter.swapResult(result);
            // TODO: if mode change was racing with us, don't overwrite it
            if (result.mode != MODE_UNKNOWN) {
                state.derivedMode = result.mode;
            }
            if (result.sortOrder != SORT_ORDER_UNKNOWN) {
                state.derivedSortOrder = result.sortOrder;
            }
            ((BaseActivity) context).onStateChanged();
            updateDisplayState();
            // When launched into empty recents, show drawer
            if (mType == TYPE_RECENT_OPEN && mAdapter.isEmpty() && !state.stackTouched) {
                ((BaseActivity) context).setRootsDrawerOpen(true);
            }
            if (isResumed()) {
                setListShown(true);
            } else {
                setListShownNoAnimation(true);
            }
            // Restore any previous instance state
            final SparseArray<Parcelable> container = state.dirState.remove(mStateKey);
            if (container != null && !getArguments().getBoolean(EXTRA_IGNORE_STATE, false)) {
                getView().restoreHierarchyState(container);
            } else if (mLastSortOrder != state.derivedSortOrder) {
                mListView.smoothScrollToPosition(0);
                mGridView.smoothScrollToPosition(0);
            }
            mLastSortOrder = state.derivedSortOrder;
            if (isTelevision()) {
                mCurrentView.requestFocus();
            }
        }

        @Override
        public void onLoaderReset(Loader<DirectoryResult> loader) {
            mAdapter.swapResult(null);
        }
    };
    setListAdapter(mAdapter);
    setListShown(false);
    // Kick off loader at least once
    getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
    updateDisplayState();
}
Also used : Context(android.content.Context) DirectoryLoader(dev.dworks.apps.anexplorer.loader.DirectoryLoader) Bundle(android.os.Bundle) DirectoryLoader(dev.dworks.apps.anexplorer.loader.DirectoryLoader) Loader(android.content.Loader) RecentLoader(dev.dworks.apps.anexplorer.loader.RecentLoader) DocumentInfo.getCursorString(dev.dworks.apps.anexplorer.model.DocumentInfo.getCursorString) Uri(android.net.Uri) Point(android.graphics.Point) SparseArray(android.util.SparseArray) RootsCache(dev.dworks.apps.anexplorer.misc.RootsCache) DirectoryResult(dev.dworks.apps.anexplorer.model.DirectoryResult) State(dev.dworks.apps.anexplorer.BaseActivity.State) RecentLoader(dev.dworks.apps.anexplorer.loader.RecentLoader)

Example 2 with RootsCache

use of dev.dworks.apps.anexplorer.misc.RootsCache in project AnExplorer by 1hakr.

the class RootsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (null != savedInstanceState) {
        group_size = savedInstanceState.getInt(GROUP_SIZE, 0);
        expandedIds = (ArrayList<Long>) savedInstanceState.getSerializable(GROUP_IDS);
    }
    final Context context = getActivity();
    final RootsCache roots = DocumentsApplication.getRootsCache(context);
    final State state = ((BaseActivity) context).getDisplayState();
    mCallbacks = new LoaderCallbacks<Collection<RootInfo>>() {

        @Override
        public Loader<Collection<RootInfo>> onCreateLoader(int id, Bundle args) {
            return new RootsLoader(context, roots, state);
        }

        @Override
        public void onLoadFinished(Loader<Collection<RootInfo>> loader, Collection<RootInfo> result) {
            if (!isAdded())
                return;
            final Intent includeApps = getArguments().getParcelable(EXTRA_INCLUDE_APPS);
            if (mAdapter == null) {
                mAdapter = new RootsExpandableAdapter(context, result, includeApps);
                Parcelable state = mList.onSaveInstanceState();
                mList.setAdapter(mAdapter);
                mList.onRestoreInstanceState(state);
            } else {
                mAdapter.setData(result);
            }
            int groupCount = mAdapter.getGroupCount();
            if (group_size != 0 && group_size == groupCount) {
                if (expandedIds != null) {
                    restoreExpandedState(expandedIds);
                }
            } else {
                group_size = groupCount;
                for (int i = 0; i < group_size; i++) {
                    mList.expandGroup(i);
                }
                expandedIds = getExpandedIds();
                mList.setOnGroupExpandListener(mOnGroupExpandListener);
                mList.setOnGroupCollapseListener(mOnGroupCollapseListener);
            }
        }

        @Override
        public void onLoaderReset(Loader<Collection<RootInfo>> loader) {
            mAdapter = null;
            mList.setAdapter((RootsExpandableAdapter) null);
        }
    };
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) Loader(android.content.Loader) RootsLoader(dev.dworks.apps.anexplorer.loader.RootsLoader) Intent(android.content.Intent) Parcelable(android.os.Parcelable) RootsLoader(dev.dworks.apps.anexplorer.loader.RootsLoader) RootsCache(dev.dworks.apps.anexplorer.misc.RootsCache) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) State(dev.dworks.apps.anexplorer.BaseActivity.State) BaseActivity(dev.dworks.apps.anexplorer.BaseActivity) RootsExpandableAdapter(dev.dworks.apps.anexplorer.adapter.RootsExpandableAdapter) Collection(java.util.Collection)

Example 3 with RootsCache

use of dev.dworks.apps.anexplorer.misc.RootsCache in project AnExplorer by 1hakr.

the class HomeFragment method showRecents.

private void showRecents() {
    final RootInfo root = roots.getRecentsRoot();
    recents.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            openRoot(root);
        }
    });
    mRecentsAdapter = new RecentsAdapter(getActivity(), null);
    mRecentsAdapter.setOnItemClickListener(new RecentsAdapter.OnItemClickListener() {

        @Override
        public void onItemClick(RecentsAdapter.ViewHolder item, int position) {
            openDocument(item.mDocumentInfo);
        }
    });
    mRecentsRecycler.setAdapter(mRecentsAdapter);
    LinearSnapHelper helper = new LinearSnapHelper();
    helper.attachToRecyclerView(mRecentsRecycler);
    final BaseActivity.State state = getDisplayState(this);
    mCallbacks = new LoaderManager.LoaderCallbacks<DirectoryResult>() {

        @Override
        public Loader<DirectoryResult> onCreateLoader(int id, Bundle args) {
            final RootsCache roots = DocumentsApplication.getRootsCache(getActivity());
            return new RecentLoader(getActivity(), roots, state);
        }

        @Override
        public void onLoadFinished(Loader<DirectoryResult> loader, DirectoryResult result) {
            if (!isAdded())
                return;
            if (null == result.cursor || (null != result.cursor && result.cursor.getCount() == 0)) {
                recents_container.setVisibility(View.GONE);
            } else {
                // recents_container.setVisibility(View.VISIBLE);
                mRecentsAdapter.swapCursor(new LimitCursorWrapper(result.cursor, MAX_RECENT_COUNT));
            }
        }

        @Override
        public void onLoaderReset(Loader<DirectoryResult> loader) {
            mRecentsAdapter.swapCursor(null);
        }
    };
    getLoaderManager().restartLoader(mLoaderId, null, mCallbacks);
}
Also used : Bundle(android.os.Bundle) LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) RecentLoader(dev.dworks.apps.anexplorer.loader.RecentLoader) Loader(android.content.Loader) LimitCursorWrapper(dev.dworks.apps.anexplorer.cursor.LimitCursorWrapper) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RecentsAdapter(dev.dworks.apps.anexplorer.adapter.RecentsAdapter) LoaderManager(android.app.LoaderManager) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) RootsCache(dev.dworks.apps.anexplorer.misc.RootsCache) DirectoryResult(dev.dworks.apps.anexplorer.model.DirectoryResult) BaseActivity(dev.dworks.apps.anexplorer.BaseActivity) RecentLoader(dev.dworks.apps.anexplorer.loader.RecentLoader)

Example 4 with RootsCache

use of dev.dworks.apps.anexplorer.misc.RootsCache 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)

Example 5 with RootsCache

use of dev.dworks.apps.anexplorer.misc.RootsCache in project AnExplorer by 1hakr.

the class DocumentsApplication method onCreate.

@Override
public void onCreate() {
    super.onCreate();
    if (!BuildConfig.DEBUG) {
        AnalyticsManager.intialize(getApplicationContext());
    }
    sInstance = this;
    final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final int memoryClassBytes = am.getMemoryClass() * 1024 * 1024;
    mRoots = new RootsCache(this);
    mRoots.updateAsync();
    mSAFManager = new SAFManager(this);
    mThumbnails = new ThumbnailCache(memoryClassBytes / 4);
    final IntentFilter packageFilter = new IntentFilter();
    packageFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_CHANGED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    packageFilter.addAction(Intent.ACTION_PACKAGE_DATA_CLEARED);
    packageFilter.addDataScheme("package");
    registerReceiver(mCacheReceiver, packageFilter);
    final IntentFilter localeFilter = new IntentFilter();
    localeFilter.addAction(Intent.ACTION_LOCALE_CHANGED);
    registerReceiver(mCacheReceiver, localeFilter);
    isTelevision = Utils.isTelevision(this);
}
Also used : IntentFilter(android.content.IntentFilter) RootsCache(dev.dworks.apps.anexplorer.misc.RootsCache) SAFManager(dev.dworks.apps.anexplorer.misc.SAFManager) ThumbnailCache(dev.dworks.apps.anexplorer.misc.ThumbnailCache) ActivityManager(android.app.ActivityManager) Point(android.graphics.Point)

Aggregations

RootsCache (dev.dworks.apps.anexplorer.misc.RootsCache)5 Loader (android.content.Loader)4 Bundle (android.os.Bundle)4 Context (android.content.Context)3 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)3 State (dev.dworks.apps.anexplorer.BaseActivity.State)3 Point (android.graphics.Point)2 RecentLoader (dev.dworks.apps.anexplorer.loader.RecentLoader)2 DirectoryResult (dev.dworks.apps.anexplorer.model.DirectoryResult)2 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)2 ActivityManager (android.app.ActivityManager)1 LoaderManager (android.app.LoaderManager)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Uri (android.net.Uri)1 Parcelable (android.os.Parcelable)1 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)1 RecyclerView (android.support.v7.widget.RecyclerView)1 SparseArray (android.util.SparseArray)1 View (android.view.View)1