Search in sources :

Example 1 with RootsLoader

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

Aggregations

Context (android.content.Context)1 Intent (android.content.Intent)1 Loader (android.content.Loader)1 Bundle (android.os.Bundle)1 Parcelable (android.os.Parcelable)1 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)1 State (dev.dworks.apps.anexplorer.BaseActivity.State)1 RootsExpandableAdapter (dev.dworks.apps.anexplorer.adapter.RootsExpandableAdapter)1 RootsLoader (dev.dworks.apps.anexplorer.loader.RootsLoader)1 RootsCache (dev.dworks.apps.anexplorer.misc.RootsCache)1 RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)1 Collection (java.util.Collection)1