Search in sources :

Example 1 with LimitCursorWrapper

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

Aggregations

LoaderManager (android.app.LoaderManager)1 Loader (android.content.Loader)1 Bundle (android.os.Bundle)1 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)1 RecyclerView (android.support.v7.widget.RecyclerView)1 View (android.view.View)1 TextView (android.widget.TextView)1 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)1 RecentsAdapter (dev.dworks.apps.anexplorer.adapter.RecentsAdapter)1 LimitCursorWrapper (dev.dworks.apps.anexplorer.cursor.LimitCursorWrapper)1 RecentLoader (dev.dworks.apps.anexplorer.loader.RecentLoader)1 RootsCache (dev.dworks.apps.anexplorer.misc.RootsCache)1 DirectoryResult (dev.dworks.apps.anexplorer.model.DirectoryResult)1 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)1