Search in sources :

Example 21 with RootInfo

use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.

the class DocumentsActivity method onCurrentDirectoryChanged.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public void onCurrentDirectoryChanged(int anim) {
    // FIX for java.lang.IllegalStateException ("Activity has been destroyed")
    if (!Utils.isActivityAlive(DocumentsActivity.this)) {
        return;
    }
    final FragmentManager fm = getFragmentManager();
    final RootInfo root = getCurrentRoot();
    DocumentInfo cwd = getCurrentDirectory();
    // TODO : this has to be done nicely
    if (cwd == null && (null != root && !root.isServerStorage())) {
        final Uri uri = DocumentsContract.buildDocumentUri(root.authority, root.documentId);
        DocumentInfo result;
        try {
            result = DocumentInfo.fromUri(getContentResolver(), uri);
            if (result != null) {
                mState.stack.push(result);
                mState.stackTouched = true;
                cwd = result;
            }
        } catch (FileNotFoundException e) {
            CrashReportingManager.logException(e);
        }
    }
    if (!SettingsActivity.getFolderAnimation(this)) {
        anim = 0;
    }
    mDirectoryContainer.setDrawDisappearingFirst(anim == ANIM_DOWN);
    if (cwd == null) {
        // No directory means recents
        if (mState.action == ACTION_CREATE || mState.action == ACTION_OPEN_TREE) {
            RecentsCreateFragment.show(fm);
        } else {
            if (root.isHome()) {
                HomeFragment.show(fm);
            } else if (root.isConnections()) {
                ConnectionsFragment.show(fm);
            } else if (root.isServerStorage()) {
                ServerFragment.show(fm, root);
            } else {
                DirectoryFragment.showRecentsOpen(fm, anim);
                // Start recents in grid when requesting visual things
                // MimePredicate.mimeMatches(MimePredicate.VISUAL_MIMES, mState.acceptMimes);
                final boolean visualMimes = true;
                mState.userMode = visualMimes ? MODE_GRID : MODE_LIST;
                mState.derivedMode = mState.userMode;
            }
        }
    } else {
        if (mState.currentSearch != null && mSearchResultShown) {
            // Ongoing search
            DirectoryFragment.showSearch(fm, root, cwd, mState.currentSearch, anim);
            mSearchResultShown = false;
        } else {
            // Normal boring directory
            DirectoryFragment.showNormal(fm, root, cwd, anim);
        }
    }
    // Forget any replacement target
    if (mState.action == ACTION_CREATE) {
        final SaveFragment save = SaveFragment.get(fm);
        if (save != null) {
            save.setReplaceTarget(null);
        }
    }
    if (mState.action == ACTION_OPEN_TREE) {
        final PickFragment pick = PickFragment.get(fm);
        if (pick != null) {
            final CharSequence displayName = (mState.stack.size() <= 1) && null != root ? root.title : cwd.displayName;
            pick.setPickTarget(cwd, displayName);
        }
    }
    final MoveFragment move = MoveFragment.get(fm);
    if (move != null) {
        move.setReplaceTarget(cwd);
    }
    final RootsFragment roots = RootsFragment.get(fm);
    if (roots != null) {
        roots.onCurrentRootChanged();
    }
    updateActionBar();
    invalidateMenu();
    dumpStack();
    if (!Utils.isOtherBuild() && !isTelevision()) {
        AppRate.with(this, mRateContainer).listener(mOnShowListener).checkAndShow();
    }
}
Also used : FragmentManager(android.app.FragmentManager) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) FileNotFoundException(java.io.FileNotFoundException) SaveFragment(dev.dworks.apps.anexplorer.fragment.SaveFragment) RootsFragment(dev.dworks.apps.anexplorer.fragment.RootsFragment) Uri(android.net.Uri) PickFragment(dev.dworks.apps.anexplorer.fragment.PickFragment) MoveFragment(dev.dworks.apps.anexplorer.fragment.MoveFragment) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo) TargetApi(android.annotation.TargetApi)

Example 22 with RootInfo

use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.

the class DirectoryFragment method updateUserState.

private void updateUserState(String column) {
    final ContentResolver resolver = getActivity().getContentResolver();
    final State state = getDisplayState(this);
    final RootInfo root = getArguments().getParcelable(EXTRA_ROOT);
    final DocumentInfo doc = getArguments().getParcelable(EXTRA_DOC);
    if (root != null && doc != null) {
        final Uri stateUri = RecentsProvider.buildState(root.authority, root.rootId, doc.documentId);
        final ContentValues values = new ContentValues();
        if (column.startsWith(StateColumns.MODE)) {
            values.put(StateColumns.MODE, state.userMode);
        } else {
            values.put(StateColumns.SORT_ORDER, state.userSortOrder);
        }
        new AsyncTask<Void, Void, Void>() {

            @Override
            protected Void doInBackground(Void... params) {
                resolver.insert(stateUri, values);
                return null;
            }
        }.execute();
    }
    if (column.startsWith(StateColumns.MODE)) {
        state.derivedMode = state.userMode;
    } else {
        state.derivedSortOrder = state.userSortOrder;
    }
}
Also used : ContentValues(android.content.ContentValues) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) State(dev.dworks.apps.anexplorer.BaseActivity.State) Uri(android.net.Uri) ContentResolver(android.content.ContentResolver) DocumentInfo(dev.dworks.apps.anexplorer.model.DocumentInfo)

Example 23 with RootInfo

use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.

the class RootsFragment method onCurrentRootChanged.

public void onCurrentRootChanged() {
    if (mAdapter == null || mList == null)
        return;
    final RootInfo root = ((BaseActivity) getActivity()).getCurrentRoot();
    for (int i = 0; i < mAdapter.getGroupCount(); i++) {
        for (int j = 0; j < mAdapter.getChildrenCount(i); j++) {
            final Object item = mAdapter.getChild(i, j);
            if (item instanceof RootItem) {
                final RootInfo testRoot = ((RootItem) item).root;
                if (Objects.equal(testRoot, root)) {
                    try {
                        long id = ExpandableListView.getPackedPositionForChild(i, j);
                        int index = mList.getFlatListPosition(id);
                        // mList.setSelection(index);
                        mList.setItemChecked(index, true);
                    } catch (Exception e) {
                        CrashReportingManager.logException(e);
                    }
                    return;
                }
            }
        }
    }
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) BaseActivity(dev.dworks.apps.anexplorer.BaseActivity)

Example 24 with RootInfo

use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.

the class StandaloneActivity method updateActionBar.

public void updateActionBar() {
    final RootInfo root = getCurrentRoot();
    mToolbar.setNavigationIcon(root != null ? root.loadToolbarIcon(mToolbar.getContext()) : null);
    mToolbar.setNavigationContentDescription(R.string.drawer_open);
    mToolbar.setNavigationOnClickListener(null);
    if (mSearchExpanded) {
        mToolbar.setTitle(null);
        mToolbarStack.setVisibility(View.GONE);
        mToolbarStack.setAdapter(null);
    } else {
        if (mState.stack.size() <= 1) {
            mToolbar.setTitle(root.title);
            mToolbarStack.setVisibility(View.GONE);
            mToolbarStack.setAdapter(null);
        } else {
            mToolbar.setTitle(null);
            mToolbarStack.setVisibility(View.VISIBLE);
            mToolbarStack.setAdapter(mStackAdapter);
            mIgnoreNextNavigation = true;
            mToolbarStack.setSelection(mStackAdapter.getCount() - 1);
        }
    }
}
Also used : RootInfo(dev.dworks.apps.anexplorer.model.RootInfo)

Example 25 with RootInfo

use of dev.dworks.apps.anexplorer.model.RootInfo in project AnExplorer by 1hakr.

the class RootsExpandableAdapter method processRoots.

private void processRoots(Collection<RootInfo> roots) {
    List<GroupInfo> groupRoots = new ArrayList<>();
    final List<Item> home = new ArrayList<>();
    final List<Item> phone = new ArrayList<>();
    final List<Item> recent = new ArrayList<>();
    final List<Item> connection = new ArrayList<>();
    final List<Item> rooted = new ArrayList<>();
    final List<Item> appbackup = new ArrayList<>();
    final List<Item> usb = new ArrayList<>();
    final List<Item> storage = new ArrayList<>();
    final List<Item> secondaryStorage = new ArrayList<>();
    final List<Item> network = new ArrayList<>();
    final List<Item> apps = new ArrayList<>();
    final List<Item> libraryMedia = new ArrayList<>();
    final List<Item> libraryNonMedia = new ArrayList<>();
    final List<Item> folders = new ArrayList<>();
    final List<Item> bookmarks = new ArrayList<>();
    for (RootInfo root : roots) {
        if (root.isHome()) {
            home.add(new RootItem(root));
        } else if (root.isRecents()) {
            if (recent.size() == 0) {
                recent.add(new RootItem(root));
            }
        } else if (root.isConnections()) {
            connection.add(new RootItem(root));
        } else if (root.isRootedStorage()) {
            rooted.add(new RootItem(root));
        } else if (root.isPhoneStorage()) {
            phone.add(new RootItem(root));
        } else if (root.isAppBackupFolder()) {
            appbackup.add(new RootItem(root));
        } else if (root.isUsbStorage()) {
            usb.add(new RootItem(root));
        } else if (RootInfo.isLibraryMedia(root)) {
            libraryMedia.add(new RootItem(root));
        } else if (RootInfo.isLibraryNonMedia(root)) {
            libraryNonMedia.add(new RootItem(root));
        } else if (RootInfo.isFolder(root)) {
            folders.add(new RootItem(root));
        } else if (RootInfo.isBookmark(root)) {
            bookmarks.add(new BookmarkItem(root));
        } else if (RootInfo.isStorage(root)) {
            if (root.isSecondaryStorage()) {
                secondaryStorage.add(new RootItem(root));
            } else {
                storage.add(new RootItem(root));
            }
        } else if (RootInfo.isApps(root)) {
            apps.add(new RootItem(root));
        } else if (RootInfo.isNetwork(root)) {
            network.add(new RootItem(root));
        }
    }
    if (!home.isEmpty() || !storage.isEmpty() || !phone.isEmpty() || !rooted.isEmpty()) {
        home.addAll(storage);
        home.addAll(secondaryStorage);
        home.addAll(usb);
        home.addAll(phone);
        home.addAll(rooted);
        groupRoots.add(new GroupInfo("Storage", home));
    }
    if (!network.isEmpty()) {
        network.addAll(connection);
        groupRoots.add(new GroupInfo("Network", network));
    } else if (!connection.isEmpty()) {
        groupRoots.add(new GroupInfo("Network", connection));
    }
    if (!apps.isEmpty()) {
        if (!appbackup.isEmpty()) {
            apps.addAll(appbackup);
        }
        groupRoots.add(new GroupInfo("Apps", apps));
    }
    if (!libraryMedia.isEmpty() || !libraryNonMedia.isEmpty()) {
        recent.addAll(libraryMedia);
        recent.addAll(libraryNonMedia);
        groupRoots.add(new GroupInfo("Library", recent));
    } else if (!recent.isEmpty()) {
        groupRoots.add(new GroupInfo("Library", recent));
    }
    if (!folders.isEmpty()) {
        folders.addAll(bookmarks);
        groupRoots.add(new GroupInfo("Folders", folders));
    }
    group.clear();
    group.addAll(groupRoots);
}
Also used : Item(dev.dworks.apps.anexplorer.fragment.RootsFragment.Item) RootItem(dev.dworks.apps.anexplorer.fragment.RootsFragment.RootItem) BookmarkItem(dev.dworks.apps.anexplorer.fragment.RootsFragment.BookmarkItem) GroupItem(dev.dworks.apps.anexplorer.fragment.RootsFragment.GroupItem) RootInfo(dev.dworks.apps.anexplorer.model.RootInfo) GroupInfo(dev.dworks.apps.anexplorer.model.GroupInfo) RootItem(dev.dworks.apps.anexplorer.fragment.RootsFragment.RootItem) ArrayList(java.util.ArrayList) BookmarkItem(dev.dworks.apps.anexplorer.fragment.RootsFragment.BookmarkItem)

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