Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit decb8320 authored by Daichi Hirono's avatar Daichi Hirono Committed by Android (Google) Code Review
Browse files

Merge "Show MTP roots at the bottom of root list."

parents 0f6cb2d7 abf39745
Loading
Loading
Loading
Loading
+10 −19
Original line number Diff line number Diff line
@@ -287,33 +287,24 @@ public class RootsFragment extends Fragment {
            super(context, 0);

            final List<RootItem> libraries = new ArrayList<>();
            final List<RootItem> clouds = new ArrayList<>();
            final List<RootItem> locals = new ArrayList<>();

            for (RootInfo root : roots) {
                RootItem item = new RootItem(root);
                switch (root.derivedType) {
                    case RootInfo.TYPE_LOCAL:
                        locals.add(item);
                        break;
                    case RootInfo.TYPE_CLOUD:
                        clouds.add(item);
                        break;
                    default:
            final List<RootItem> others = new ArrayList<>();

            for (final RootInfo root : roots) {
                final RootItem item = new RootItem(root);
                if (root.isLibrary()) {
                    libraries.add(item);
                        break;
                } else {
                    others.add(item);
                }
            }

            final RootComparator comp = new RootComparator();
            Collections.sort(libraries, comp);
            Collections.sort(locals, comp);
            Collections.sort(clouds, comp);
            Collections.sort(others, comp);

            addAll(libraries);
            add(new SpacerItem());
            addAll(locals);
            addAll(clouds);
            addAll(others);

            if (includeApps != null) {
                final PackageManager pm = context.getPackageManager();
+13 −1
Original line number Diff line number Diff line
@@ -51,7 +51,8 @@ public class RootInfo implements Durable, Parcelable {
    public static final int TYPE_RECENTS = 4;
    public static final int TYPE_DOWNLOADS = 5;
    public static final int TYPE_LOCAL = 6;
    public static final int TYPE_CLOUD = 7;
    public static final int TYPE_MTP = 7;
    public static final int TYPE_CLOUD = 8;

    public String authority;
    public String rootId;
@@ -184,6 +185,8 @@ public class RootInfo implements Durable, Parcelable {
            derivedType = TYPE_AUDIO;
        } else if (isRecents()) {
            derivedType = TYPE_RECENTS;
        } else if (isMtp()) {
            derivedType = TYPE_MTP;
        } else {
            derivedType = TYPE_CLOUD;
        }
@@ -216,6 +219,15 @@ public class RootInfo implements Durable, Parcelable {
                && "audio_root".equals(rootId);
    }

    public boolean isMtp() {
        return "com.android.mtp.documents".equals(authority);
    }

    public boolean isLibrary() {
        return derivedType == TYPE_IMAGES || derivedType == TYPE_VIDEO || derivedType == TYPE_AUDIO
                || derivedType == TYPE_RECENTS || derivedType == TYPE_DOWNLOADS;
    }

    @Override
    public String toString() {
        return "Root{authority=" + authority + ", rootId=" + rootId + ", title=" + title + "}";