Search in sources :

Example 1 with RootInfo

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);
        }
    };
}
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 2 with RootInfo

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;
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) ArrayList(java.util.ArrayList)

Example 3 with RootInfo

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;
    }
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo)

Example 4 with RootInfo

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;
    }
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo)

Example 5 with RootInfo

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;
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) ArrayList(java.util.ArrayList)

Aggregations

RootInfo (dev.dworks.apps.anexplorer.model.RootInfo)26 Bundle (android.os.Bundle)5 View (android.view.View)5 TextView (android.widget.TextView)5 DocumentInfo (dev.dworks.apps.anexplorer.model.DocumentInfo)5 ArrayList (java.util.ArrayList)5 FragmentManager (android.app.FragmentManager)4 Uri (android.net.Uri)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Intent (android.content.Intent)3 BaseActivity (dev.dworks.apps.anexplorer.BaseActivity)3 Timer (java.util.Timer)3 TargetApi (android.annotation.TargetApi)2 Context (android.content.Context)2 Loader (android.content.Loader)2 Cursor (android.database.Cursor)2 MenuItem (android.view.MenuItem)2 State (dev.dworks.apps.anexplorer.BaseActivity.State)2 RootsFragment (dev.dworks.apps.anexplorer.fragment.RootsFragment)2 SaveFragment (dev.dworks.apps.anexplorer.fragment.SaveFragment)2