use of dev.dworks.apps.anexplorer.model.RootInfo 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);
}
};
}
use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.
the class RootsCache method getMatchingRoots.
static List<RootInfo> getMatchingRoots(Collection<RootInfo> roots, State state) {
final List<RootInfo> matching = new ArrayList<>();
for (RootInfo root : roots) {
final boolean supportsCreate = (root.flags & Root.FLAG_SUPPORTS_CREATE) != 0;
final boolean supportsIsChild = (root.flags & Root.FLAG_SUPPORTS_IS_CHILD) != 0;
final boolean advanced = (root.flags & DocumentsContract.Root.FLAG_ADVANCED) != 0;
final boolean superAdvanced = (root.flags & Root.FLAG_SUPER_ADVANCED) != 0;
final boolean localOnly = (root.flags & Root.FLAG_LOCAL_ONLY) != 0;
final boolean empty = (root.flags & DocumentsContract.Root.FLAG_EMPTY) != 0;
if (null != root.authority && root.authority.equals(RootedStorageProvider.AUTHORITY)) {
if (state.action != State.ACTION_BROWSE || !state.rootMode) {
continue;
}
}
// Exclude read-only devices when creating
if (state.action == State.ACTION_CREATE && !supportsCreate)
continue;
// Exclude roots that don't support directory picking
if (state.action == State.ACTION_OPEN_TREE && !supportsIsChild)
continue;
// Exclude advanced devices when not requested
if (!state.showAdvanced && advanced)
continue;
// Exclude non-local devices when local only
if (state.localOnly && !localOnly)
continue;
// Only show empty roots when creating
if (state.action != State.ACTION_CREATE && empty)
continue;
if ((state.action == State.ACTION_GET_CONTENT || state.action == State.ACTION_GET_CONTENT || state.action == State.ACTION_OPEN || state.action == State.ACTION_OPEN_TREE) && superAdvanced) {
continue;
}
// Only include roots that serve requested content
final boolean overlap = MimePredicate.mimeMatches(root.derivedMimeTypes, state.acceptMimes) || MimePredicate.mimeMatches(state.acceptMimes, root.derivedMimeTypes);
if (!overlap) {
continue;
}
matching.add(root);
}
return matching;
}
use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.
the class RootsCache method isIconUniqueBlocking.
public boolean isIconUniqueBlocking(RootInfo root) {
waitForFirstLoad();
loadStoppedAuthorities();
synchronized (mLock) {
final int rootIcon = root.derivedIcon != 0 ? root.derivedIcon : root.icon;
for (RootInfo test : mRoots.get(root.authority)) {
if (Objects.equal(test.rootId, root.rootId)) {
continue;
}
final int testIcon = test.derivedIcon != 0 ? test.derivedIcon : test.icon;
if (testIcon == rootIcon) {
return false;
}
}
return true;
}
}
use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.
the class RootsCache method getRootOneshot.
/**
* Return the requested {@link RootInfo}, but only loading the roots for the
* requested authority. This is useful when we want to load fast without
* waiting for all the other roots to come back.
*/
public RootInfo getRootOneshot(String authority, String rootId) {
synchronized (mLock) {
RootInfo root = getRootLocked(authority, rootId);
if (root == null) {
mRoots.putAll(authority, loadRootsForAuthority(mContext.getContentResolver(), authority));
root = getRootLocked(authority, rootId);
}
return root;
}
}
use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.
the class RootsCache method getShortcutsInfo.
public ArrayList<RootInfo> getShortcutsInfo() {
ArrayList<RootInfo> list = new ArrayList<>();
if (Utils.hasWiFi(mContext)) {
list.add(getServerRoot());
}
list.add(getAppRoot());
for (RootInfo root : mRoots.get(MediaDocumentsProvider.AUTHORITY)) {
if (RootInfo.isLibraryMedia(root)) {
list.add(root);
}
}
return list;
}
Aggregations