Show an empty view when there is no widget available
Test: Remove all widgets from work profile using TestDpc. Observe empty view is shown in the full widget tray. Add back some widgets to work profile and observe widgets showing up in the full widgets tray Bug: 179797520 Change-Id: I2e1fcb5a0014568a4674e2bcc0a3ed3c6ec5a44a
This commit is contained in:
parent
3c08f580c3
commit
d73d6e56a9
|
@ -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"
|
||||
|
|
|
@ -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] -->
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in New Issue