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