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

Commit 0c643082 authored by Ben Kwa's avatar Ben Kwa
Browse files

Reorganize DocumentsUI roots fragment to match mocks.

BUG=24329078

Change-Id: I80fe7b939772d929236aa9e0e6fa44cdb606a038
parent 01334b64
Loading
Loading
Loading
Loading
+31 −45
Original line number Diff line number Diff line
@@ -286,51 +286,34 @@ public class RootsFragment extends Fragment {
        public RootsAdapter(Context context, Collection<RootInfo> roots, Intent includeApps) {
            super(context, 0);

            RootItem recents = null;
            RootItem images = null;
            RootItem videos = null;
            RootItem audio = null;
            RootItem downloads = null;

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

            for (RootInfo root : roots) {
                if (root.isRecents()) {
                    recents = new RootItem(root);
                } else if (root.isExternalStorage()) {
                    locals.add(root);
                } else if (root.isDownloads()) {
                    downloads = new RootItem(root);
                } else if (root.isImages()) {
                    images = new RootItem(root);
                } else if (root.isVideos()) {
                    videos = new RootItem(root);
                } else if (root.isAudio()) {
                    audio = new RootItem(root);
                } else {
                    clouds.add(root);
                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:
                        libraries.add(item);
                        break;
                }
            }

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

            if (recents != null) add(recents);

            for (RootInfo cloud : clouds) {
                add(new RootItem(cloud));
            }

            if (images != null) add(images);
            if (videos != null) add(videos);
            if (audio != null) add(audio);
            if (downloads != null) add(downloads);

            for (RootInfo local : locals) {
                add(new RootItem(local));
            }
            addAll(libraries);
            add(new SpacerItem());
            addAll(locals);
            addAll(clouds);

            if (includeApps != null) {
                final PackageManager pm = context.getPackageManager();
@@ -348,9 +331,7 @@ public class RootsFragment extends Fragment {

                if (apps.size() > 0) {
                    add(new SpacerItem());
                    for (Item item : apps) {
                        add(item);
                    }
                    addAll(apps);
                }
            }
        }
@@ -387,15 +368,20 @@ public class RootsFragment extends Fragment {
        }
    }

    public static class RootComparator implements Comparator<RootInfo> {
    public static class RootComparator implements Comparator<RootItem> {
        @Override
        public int compare(RootInfo lhs, RootInfo rhs) {
            final int score = DocumentInfo.compareToIgnoreCaseNullable(lhs.title, rhs.title);
        public int compare(RootItem lhs, RootItem rhs) {
            // Sort by root type, then title, then summary.
            int score = lhs.root.derivedType - rhs.root.derivedType;
            if (score != 0) {
                return score;
            } else {
                return DocumentInfo.compareToIgnoreCaseNullable(lhs.summary, rhs.summary);
            }
            score = DocumentInfo.compareToIgnoreCaseNullable(lhs.root.title, rhs.root.title);
            if (score != 0) {
                return score;
            }

            return DocumentInfo.compareToIgnoreCaseNullable(lhs.root.summary, rhs.root.summary);
        }
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -44,6 +44,15 @@ public class RootInfo implements Durable, Parcelable {
    private static final int VERSION_INIT = 1;
    private static final int VERSION_DROP_TYPE = 2;

    // The values of these constants determine the sort order of various roots in the RootsFragment.
    public static final int TYPE_IMAGES = 1;
    public static final int TYPE_VIDEO = 2;
    public static final int TYPE_AUDIO = 3;
    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 String authority;
    public String rootId;
    public int flags;
@@ -57,6 +66,7 @@ public class RootInfo implements Durable, Parcelable {
    /** Derived fields that aren't persisted */
    public String[] derivedMimeTypes;
    public int derivedIcon;
    public int derivedType;

    public RootInfo() {
        reset();
@@ -76,6 +86,7 @@ public class RootInfo implements Durable, Parcelable {

        derivedMimeTypes = null;
        derivedIcon = 0;
        derivedType = 0;
    }

    @Override
@@ -158,14 +169,23 @@ public class RootInfo implements Durable, Parcelable {
        // TODO: remove these special case icons
        if (isExternalStorage()) {
            derivedIcon = R.drawable.ic_root_sdcard;
            derivedType = TYPE_LOCAL;
        } else if (isDownloads()) {
            derivedIcon = R.drawable.ic_root_download;
            derivedType = TYPE_DOWNLOADS;
        } else if (isImages()) {
            derivedIcon = R.drawable.ic_doc_image;
            derivedType = TYPE_IMAGES;
        } else if (isVideos()) {
            derivedIcon = R.drawable.ic_doc_video;
            derivedType = TYPE_VIDEO;
        } else if (isAudio()) {
            derivedIcon = R.drawable.ic_doc_audio;
            derivedType = TYPE_AUDIO;
        } else if (isRecents()) {
            derivedType = TYPE_RECENTS;
        } else {
            derivedType = TYPE_CLOUD;
        }
    }