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

Commit 6f991c29 authored by tturney's avatar tturney
Browse files

QS BluetoothTile proiritizes connected device

When there is a connected device and the
Bluetooth Cacheded Device list is too large
it doesn't guarantee a connected device
will show up at all in the Bluetooth
Quick Settings Tile. This code modifies
the tile to match Wifi witch guarantees
connected devices be at the top of the
Bluetooth Tile list.

Bug: 37438599
Test: Manually pair multiple deivces to create
a large list and change connected states.

Change-Id: I93caa43743e1d63f4eab6b8bc636e8e8b2b40ec4
parent a86e3d70
Loading
Loading
Loading
Loading
+7 −2
Original line number Original line Diff line number Diff line
@@ -259,24 +259,29 @@ public class BluetoothTile extends QSTileImpl<BooleanState> {
            ArrayList<Item> items = new ArrayList<Item>();
            ArrayList<Item> items = new ArrayList<Item>();
            final Collection<CachedBluetoothDevice> devices = mController.getDevices();
            final Collection<CachedBluetoothDevice> devices = mController.getDevices();
            if (devices != null) {
            if (devices != null) {
                int connectedDevices = 0;
                for (CachedBluetoothDevice device : devices) {
                for (CachedBluetoothDevice device : devices) {
                    if (device.getBondState() == BluetoothDevice.BOND_NONE) continue;
                    if (device.getBondState() == BluetoothDevice.BOND_NONE) continue;
                    final Item item = new Item();
                    final Item item = new Item();
                    item.icon = R.drawable.ic_qs_bluetooth_on;
                    item.icon = R.drawable.ic_qs_bluetooth_on;
                    item.line1 = device.getName();
                    item.line1 = device.getName();
                    item.tag = device;
                    int state = device.getMaxConnectionState();
                    int state = device.getMaxConnectionState();
                    if (state == BluetoothProfile.STATE_CONNECTED) {
                    if (state == BluetoothProfile.STATE_CONNECTED) {
                        item.icon = R.drawable.ic_qs_bluetooth_connected;
                        item.icon = R.drawable.ic_qs_bluetooth_connected;
                        item.line2 = mContext.getString(R.string.quick_settings_connected);
                        item.line2 = mContext.getString(R.string.quick_settings_connected);
                        item.canDisconnect = true;
                        item.canDisconnect = true;
                        items.add(connectedDevices, item);
                        connectedDevices++;
                    } else if (state == BluetoothProfile.STATE_CONNECTING) {
                    } else if (state == BluetoothProfile.STATE_CONNECTING) {
                        item.icon = R.drawable.ic_qs_bluetooth_connecting;
                        item.icon = R.drawable.ic_qs_bluetooth_connecting;
                        item.line2 = mContext.getString(R.string.quick_settings_connecting);
                        item.line2 = mContext.getString(R.string.quick_settings_connecting);
                    }
                        items.add(connectedDevices, item);
                    item.tag = device;
                    } else {
                        items.add(item);
                        items.add(item);
                    }
                    }
                }
                }
            }
            mItems.setItems(items.toArray(new Item[items.size()]));
            mItems.setItems(items.toArray(new Item[items.size()]));
        }
        }