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

Commit bfda3a93 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add an empty text when there is no app view."

parents dcc2b928 7a91a0d0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -33,7 +33,7 @@
        android:textAppearance="@style/AppEntitiesHeader.Text.HeaderTitle"/>

    <LinearLayout
        android:id="@+id/all_apps_view"
        android:id="@+id/app_views_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dp"
@@ -61,4 +61,12 @@
        android:layout_height="48dp"
        android:gravity="center"/>

    <TextView
        android:id="@+id/empty_view"
        android:layout_width="match_parent"
        android:layout_height="106dp"
        android:gravity="center"
        android:visibility="gone"
        android:textAppearance="@style/AppEntitiesHeader.Text.Summary"/>

</LinearLayout>
+37 −0
Original line number Diff line number Diff line
@@ -77,9 +77,11 @@ public class AppEntitiesHeaderController {

    private final Context mContext;
    private final TextView mHeaderTitleView;
    private final TextView mHeaderEmptyView;
    private final Button mHeaderDetailsView;

    private final AppEntityInfo[] mAppEntityInfos;
    private final View mAppViewsContainer;
    private final View[] mAppEntityViews;
    private final ImageView[] mAppIconViews;
    private final TextView[] mAppTitleViews;
@@ -87,6 +89,7 @@ public class AppEntitiesHeaderController {

    private int mHeaderTitleRes;
    private int mHeaderDetailsRes;
    private int mHeaderEmptyRes;
    private View.OnClickListener mDetailsOnClickListener;

    /**
@@ -104,6 +107,8 @@ public class AppEntitiesHeaderController {
        mContext = context;
        mHeaderTitleView = appEntitiesHeaderView.findViewById(R.id.header_title);
        mHeaderDetailsView = appEntitiesHeaderView.findViewById(R.id.header_details);
        mHeaderEmptyView = appEntitiesHeaderView.findViewById(R.id.empty_view);
        mAppViewsContainer = appEntitiesHeaderView.findViewById(R.id.app_views_container);

        mAppEntityInfos = new AppEntityInfo[MAXIMUM_APPS];
        mAppIconViews = new ImageView[MAXIMUM_APPS];
@@ -151,6 +156,14 @@ public class AppEntitiesHeaderController {
        return this;
    }

    /**
     * Sets the string resource id for the empty text.
     */
    public AppEntitiesHeaderController setHeaderEmptyRes(@StringRes int emptyRes) {
        mHeaderEmptyRes = emptyRes;
        return this;
    }

    /**
     * Set an app entity at a specified position view.
     *
@@ -192,6 +205,12 @@ public class AppEntitiesHeaderController {
     */
    public void apply() {
        bindHeaderTitleView();

        if (isAppEntityInfosEmpty()) {
            setEmptyViewVisible(true);
            return;
        }
        setEmptyViewVisible(false);
        bindHeaderDetailsView();

        // Rebind all apps view
@@ -245,4 +264,22 @@ public class AppEntitiesHeaderController {
            mAppSummaryViews[index].setText(summary);
        }
    }

    private void setEmptyViewVisible(boolean visible) {
        if (mHeaderEmptyRes != 0) {
            mHeaderEmptyView.setText(mHeaderEmptyRes);
        }
        mHeaderEmptyView.setVisibility(visible ? View.VISIBLE : View.GONE);
        mHeaderDetailsView.setVisibility(visible ? View.GONE : View.VISIBLE);
        mAppViewsContainer.setVisibility(visible ? View.GONE : View.VISIBLE);
    }

    private boolean isAppEntityInfosEmpty() {
        for (AppEntityInfo info : mAppEntityInfos) {
            if (info != null) {
                return false;
            }
        }
        return true;
    }
}
+26 −3
Original line number Diff line number Diff line
@@ -60,6 +60,7 @@ public class AppEntitiesHeaderControllerTest {
                .setOnClickListener(v -> {
                })
                .build();
        mController.setAppEntity(0, mAppEntityInfo);
    }

    @Test
@@ -172,6 +173,8 @@ public class AppEntitiesHeaderControllerTest {
        mController.setAppEntity(0, mAppEntityInfo)
                .setAppEntity(1, mAppEntityInfo)
                .setAppEntity(2, mAppEntityInfo).apply();
        final View appViewsContainer = mAppEntitiesHeaderView.findViewById(
                R.id.app_views_container);
        final View app1View = mAppEntitiesHeaderView.findViewById(R.id.app1_view);
        final View app2View = mAppEntitiesHeaderView.findViewById(R.id.app2_view);
        final View app3View = mAppEntitiesHeaderView.findViewById(R.id.app3_view);
@@ -181,8 +184,28 @@ public class AppEntitiesHeaderControllerTest {
        assertThat(app3View.getVisibility()).isEqualTo(View.VISIBLE);

        mController.clearAllAppEntities().apply();
        assertThat(app1View.getVisibility()).isEqualTo(View.GONE);
        assertThat(app2View.getVisibility()).isEqualTo(View.GONE);
        assertThat(app3View.getVisibility()).isEqualTo(View.GONE);

        assertThat(appViewsContainer.getVisibility()).isEqualTo(View.GONE);
    }

    @Test
    public void apply_noAppEntitySet_shouldOnlyShowTitleAndEmptyView() {
        mController.setHeaderTitleRes(R.string.expand_button_title)
                .setAppEntity(0, mAppEntityInfo)
                .setAppEntity(1, mAppEntityInfo)
                .setAppEntity(2, mAppEntityInfo).apply();
        final View titleView = mAppEntitiesHeaderView.findViewById(R.id.header_title);
        final View detailsView = mAppEntitiesHeaderView.findViewById(R.id.header_details);
        final View emptyView = mAppEntitiesHeaderView.findViewById(R.id.empty_view);
        final View appViewsContainer = mAppEntitiesHeaderView.findViewById(
                R.id.app_views_container);

        mController.clearAllAppEntities().apply();

        assertThat(titleView.getVisibility()).isEqualTo(View.VISIBLE);
        assertThat(emptyView.getVisibility()).isEqualTo(View.VISIBLE);

        assertThat(detailsView.getVisibility()).isEqualTo(View.GONE);
        assertThat(appViewsContainer.getVisibility()).isEqualTo(View.GONE);
    }
}