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

Commit a061cf33 authored by Steven Ng's avatar Steven Ng Committed by Android (Google) Code Review
Browse files

Merge "Show an empty view when there is no widget available" into sc-dev

parents 43b93101 d73d6e56
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
-->
<com.android.launcher3.widget.picker.WidgetsFullSheet
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
@@ -27,6 +28,14 @@
        android:background="?android:attr/colorPrimary"
        android:elevation="4dp">

        <TextView
            android:id="@+id/no_widgets_text"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:visibility="gone"
            tools:text="No widgets available" />

        <!-- Fast scroller popup -->
        <TextView
            android:id="@+id/fast_scroller_popup"
+3 −0
Original line number Diff line number Diff line
@@ -74,6 +74,9 @@
    <!-- Search bar text shown in the popup view showing all available widgets installed on the
         device. [CHAR_LIMIT=50] -->
    <string name="widgets_full_sheet_search_bar_hint">Search</string>
    <!-- Text shown when there is no widgets shown in the popup view showing all available widgets
         installed on the device. [CHAR_LIMIT=none] -->
    <string name="no_widgets_available">No widgets available</string>

    <!-- All Apps -->
    <!-- Search bar text in the apps view. [CHAR_LIMIT=50] -->
+18 −2
Original line number Diff line number Diff line
@@ -82,6 +82,7 @@ public class WidgetsFullSheet extends BaseWidgetSheet
    @Nullable private PersonalWorkPagedView mViewPager;
    private int mInitialTabsHeight = 0;
    private View mTabsView;
    private TextView mNoWidgetsView;
    private SearchAndRecommendationViewHolder mSearchAndRecommendationViewHolder;
    private SearchAndRecommendationsScrollController mSearchAndRecommendationsScrollController;

@@ -141,19 +142,32 @@ public class WidgetsFullSheet extends BaseWidgetSheet
                mViewPager);
        fastScroller.setOnFastScrollChangeListener(mSearchAndRecommendationsScrollController);

        mNoWidgetsView = findViewById(R.id.no_widgets_text);

        onWidgetsBound();
    }

    @Override
    public void onActivePageChanged(int currentActivePage) {
        WidgetsRecyclerView currentRecyclerView =
                mAdapters.get(currentActivePage).mWidgetsRecyclerView;
        AdapterHolder currentAdapterHolder = mAdapters.get(currentActivePage);
        WidgetsRecyclerView currentRecyclerView = currentAdapterHolder.mWidgetsRecyclerView;
        currentRecyclerView.bindFastScrollbar();
        mSearchAndRecommendationsScrollController.setCurrentRecyclerView(currentRecyclerView);

        updateNoWidgetsView(currentAdapterHolder);

        reset();
    }

    private void updateNoWidgetsView(AdapterHolder adapterHolder) {
        boolean isWidgetAvailable = adapterHolder.mWidgetsListAdapter.getItemCount() > 0;
        adapterHolder.mWidgetsRecyclerView.setVisibility(isWidgetAvailable ? VISIBLE : GONE);

        // Always resets the text in case this is updated by search.
        mNoWidgetsView.setText(R.string.no_widgets_available);
        mNoWidgetsView.setVisibility(isWidgetAvailable ? GONE : VISIBLE);
    }

    private void reset() {
        mAdapters.get(AdapterHolder.PRIMARY).mWidgetsRecyclerView.scrollToTop();
        if (mHasWorkProfile) {
@@ -276,6 +290,8 @@ public class WidgetsFullSheet extends BaseWidgetSheet
        AdapterHolder primaryUserAdapterHolder = mAdapters.get(AdapterHolder.PRIMARY);
        primaryUserAdapterHolder.setup(findViewById(R.id.primary_widgets_list_view));
        primaryUserAdapterHolder.mWidgetsListAdapter.setWidgets(allWidgets);
        updateNoWidgetsView(primaryUserAdapterHolder);

        if (mHasWorkProfile) {
            AdapterHolder workUserAdapterHolder = mAdapters.get(AdapterHolder.WORK);
            workUserAdapterHolder.setup(findViewById(R.id.work_widgets_list_view));