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

Commit c6ad9426 authored by Wenbo Jie's avatar Wenbo Jie
Browse files

[DocsUI M3] Fix video root layout in navigation rail

Video root supports cross profile but it doesn't have a counterpart
root for work profile user, so a stub root item will be created in
this case, for Navigation rail layout, the stub item needs to be
created with the NavRailRootItem instead of the RootItem.

Check the attached bug for the before/after comparison.

Bug: 409929088
Test: m DocumentsUIGoogle && manual inspection
Test: atest DocumentsUIUnitTests:com.android.documentsui.sidebar.RootItemListBuilderTest
Flag: com.android.documentsui.flags.use_material3
Change-Id: Ia5b5cf0f3c0bedb362edbc7d9657f137520d054f
parent cc59aa16
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -47,4 +47,13 @@ public class NavRailAppItem extends AppItem {

        bindIcon(icon);
    }

    @Override
    public String toString() {
        return "NavRailAppItem{"
                + "id=" + stringId
                + ", userId=" + userId
                + ", resolveInfo=" + info
                + "}";
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -45,4 +45,13 @@ public class NavRailProfileItem extends ProfileItem {

        bindIcon(icon);
    }

    @Override
    public String toString() {
        return "NavRailProfileItem{"
                + "id=" + stringId
                + ", userId=" + userId
                + ", resolveInfo=" + info
                + "}";
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -39,4 +39,15 @@ public class NavRailRootAndAppItem extends RootAndAppItem {
    public void bindView(View convertView) {
        bindIconAndTitle(convertView);
    }

    @Override
    public String toString() {
        return "NavRailRootAndAppItem{"
                + "id=" + stringId
                + ", userId=" + userId
                + ", root=" + root
                + ", resolveInfo=" + resolveInfo
                + ", docInfo=" + docInfo
                + "}";
    }
}
+21 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.view.View;
import com.android.documentsui.ActionHandler;
import com.android.documentsui.R;
import com.android.documentsui.base.RootInfo;
import com.android.documentsui.base.UserId;

/**
 * Similar to {@link RootItem} but only used in the navigation rail.
@@ -55,4 +56,24 @@ public class NavRailRootItem extends RootItem {
    public void bindView(View convertView) {
        bindIconAndTitle(convertView);
    }

    @Override
    public String toString() {
        return "NavRailRootItem{"
                + "id=" + stringId
                + ", userId=" + userId
                + ", root=" + root
                + ", docInfo=" + docInfo
                + "}";
    }

    /**
     * Creates a stub root item for a user. A stub root item is used as a place holder when
     * there is no such root available. We can therefore show the item on the UI.
     */
    public static NavRailRootItem createStubItem(NavRailRootItem item, UserId targetUser) {
        RootInfo stubRootInfo = RootInfo.copyRootInfo(item.root);
        stubRootInfo.userId = targetUser;
        return new NavRailRootItem(stubRootInfo, item.mActionHandler, item.mMaybeShowBadge);
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.documentsui.sidebar;

import static androidx.core.util.Preconditions.checkNotNull;

import static com.android.documentsui.util.FlagUtils.isUseMaterial3FlagEnabled;

import com.android.documentsui.base.UserId;

import com.google.common.collect.ArrayListMultimap;
@@ -96,6 +98,16 @@ class RootItemListBuilder {
            }
        }

        return Collections.singletonList(RootItem.createStubItem(testRootItem, mSelectedUser));
        final RootItem stubItem;
        // When use_material3 flag is ON, a sub class of RootItem is introduced: NavRailRootItem,
        // which has different underlying layout, so for NavRailRootItem we need to call its own
        // static method to create stub item.
        if (isUseMaterial3FlagEnabled() && testRootItem instanceof NavRailRootItem) {
            stubItem =
                    NavRailRootItem.createStubItem((NavRailRootItem) testRootItem, mSelectedUser);
        } else {
            stubItem = RootItem.createStubItem(testRootItem, mSelectedUser);
        }
        return Collections.singletonList(stubItem);
    }
}
Loading