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

Commit be849c55 authored by Adnan Begovic's avatar Adnan Begovic
Browse files

systemui: Provide empty view for empty lists published in QSTile.

  Also subvert possible NPE when publishing tiles with empty content.

Ticket: BAMBOO-160

Change-Id: I5bb8b82f1eb479e14d28fd755da2f687c33c1f6c
parent 571d5f64
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2015 The CyanogenMod Project

   Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

         http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24"
        android:viewportHeight="24">

    <path
            android:pathData="M0 0h24v24H0z" />
    <path
            android:fillColor="@color/qs_detail_empty"
            android:pathData="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1
15h-2v-2h2v2zm0-4h-2V7h2v6z" />
</vector>
 No newline at end of file
+3 −0
Original line number Diff line number Diff line
@@ -306,4 +306,7 @@

    <!-- Content description of the dock battery level icon for accessibility (not shown on the screen). [CHAR LIMIT=NONE] -->
    <string name="accessibility_dock_battery_level">Dock battery <xliff:g id="number">%d</xliff:g> percent.</string>

    <!-- Empty view text for CustomQSTile -->
    <string name="quick_settings_custom_qs_detail_empty_text">No items found</string>
</resources>
+47 −30
Original line number Diff line number Diff line
@@ -190,34 +190,16 @@ public class CustomQSTile extends QSTile<QSTile.State> {
        @Override
        public View createDetailView(Context context, View convertView, ViewGroup parent) {
            View rootView = null;
            if (mExpandedStyle == null) {
                rootView = (LinearLayout) LayoutInflater.from(context)
                        .inflate(R.layout.qs_custom_detail, parent, false);
                ImageView imageView = (ImageView)
                        rootView.findViewById(R.id.custom_qs_tile_icon);
                TextView customTileTitle = (TextView)
                        rootView.findViewById(R.id.custom_qs_tile_title);
                TextView customTilePkg = (TextView) rootView
                        .findViewById(R.id.custom_qs_tile_package);
                TextView customTileContentDesc = (TextView) rootView
                        .findViewById(R.id.custom_qs_tile_content_description);
                // icon is cached in state, fetch it
                imageView.setImageDrawable(getState().icon.getDrawable(mContext));
                customTileTitle.setText(mTile.getCustomTile().label);
                if (isDynamicTile()) {
                    customTilePkg.setText(R.string.quick_settings_dynamic_tile_detail_title);
                } else {
                    customTilePkg.setText(mTile.getPackage());
                    customTileContentDesc.setText(mTile.getCustomTile().contentDescription);
                }
            } else {
            if (mExpandedStyle != null) {
                switch (mExpandedStyle.getStyle()) {
                    case CustomTile.ExpandedStyle.GRID_STYLE:
                        rootView = QSDetailItemsGrid.inflate(context, parent, false);
                        if (mExpandedStyle.getExpandedItems() != null) {
                            mGridAdapter = ((QSDetailItemsGrid) rootView)
                                    .createAndSetAdapter(mTile.getPackage(),
                                            mExpandedStyle.getExpandedItems());
                            mGridAdapter.setOnPseudoGridItemClickListener(this);
                        }
                        break;
                    case CustomTile.ExpandedStyle.REMOTE_STYLE:
                        rootView = (LinearLayout) LayoutInflater.from(context)
@@ -233,20 +215,55 @@ public class CustomQSTile extends QSTile<QSTile.State> {
                        }
                        break;
                    case CustomTile.ExpandedStyle.LIST_STYLE:
                    default:
                        rootView = QSDetailItemsList.convertOrInflate(context, convertView, parent);
                        ((QSDetailItemsList) rootView)
                                .setEmptyState(R.drawable.ic_qs_custom_detail_empty,
                                        R.string.quick_settings_custom_qs_detail_empty_text);
                        ListView listView = ((QSDetailItemsList) rootView).getListView();
                        listView.setDivider(null);
                        listView.setOnItemClickListener(this);
                        if (mExpandedStyle.getExpandedItems() != null) {
                            listView.setAdapter(mListAdapter =
                                new QSDetailItemsList.QSCustomDetailListAdapter(mTile.getPackage(),
                                        context, Arrays.asList(mExpandedStyle.getExpandedItems())));
                                    new QSDetailItemsList.QSCustomDetailListAdapter(
                                            mTile.getPackage(), context,
                                            Arrays.asList(mExpandedStyle.getExpandedItems())));
                            listView.setOnItemClickListener(this);
                        }
                        break;
                    default:
                        // Shouldn't ever happen, but handle it anyway.
                        rootView = (LinearLayout) LayoutInflater.from(context)
                                .inflate(R.layout.qs_custom_detail, parent, false);
                        populateDefaultLayout(rootView);
                        break;
                }
            } else {
                rootView = (LinearLayout) LayoutInflater.from(context)
                        .inflate(R.layout.qs_custom_detail, parent, false);
                populateDefaultLayout(rootView);
            }
            return rootView;
        }

        private void populateDefaultLayout(View rootView) {
            ImageView imageView = (ImageView)
                    rootView.findViewById(R.id.custom_qs_tile_icon);
            TextView customTileTitle = (TextView)
                    rootView.findViewById(R.id.custom_qs_tile_title);
            TextView customTilePkg = (TextView) rootView
                    .findViewById(R.id.custom_qs_tile_package);
            TextView customTileContentDesc = (TextView) rootView
                    .findViewById(R.id.custom_qs_tile_content_description);
            // icon is cached in state, fetch it
            imageView.setImageDrawable(getState().icon.getDrawable(mContext));
            customTileTitle.setText(mTile.getCustomTile().label);
            if (isDynamicTile()) {
                customTilePkg.setText(R.string.quick_settings_dynamic_tile_detail_title);
            } else {
                customTilePkg.setText(mTile.getPackage());
                customTileContentDesc.setText(mTile.getCustomTile().contentDescription);
            }
        }

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            CustomTile.ExpandedItem item = mListAdapter.getItem(position);