Better decoupling of Index updates in Bluetooth Settings

- use a Handler
- force rebuilding

Change-Id: I474fa98ea0e0758abcc46d4812f744dff24fd455
This commit is contained in:
Fabrice Di Meglio
2014-04-21 11:32:39 -07:00
parent da0e6ff8c2
commit 131f49feea

View File

@@ -21,6 +21,8 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.widget.CompoundButton;
import android.widget.Switch;
@@ -42,6 +44,22 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
private final LocalBluetoothAdapter mLocalAdapter;
private final IntentFilter mIntentFilter;
private static final String EVENT_DATA_IS_BT_ON = "is_bluetooth_on";
private static final int EVENT_UPDATE_INDEX = 0;
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case EVENT_UPDATE_INDEX:
final boolean isBluetoothOn = msg.getData().getBoolean(EVENT_DATA_IS_BT_ON);
Index.getInstance(mContext).updateFromClassNameResource(
BluetoothSettings.class.getName(), true, isBluetoothOn);
break;
}
}
};
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
@@ -165,7 +183,11 @@ public final class BluetoothEnabler implements CompoundButton.OnCheckedChangeLis
}
private void updateSearchIndex(boolean isBluetoothOn) {
Index.getInstance(mContext).updateFromClassNameResource(
BluetoothSettings.class.getName(), false, isBluetoothOn);
mHandler.removeMessages(EVENT_UPDATE_INDEX);
Message msg = new Message();
msg.what = EVENT_UPDATE_INDEX;
msg.getData().putBoolean(EVENT_DATA_IS_BT_ON, isBluetoothOn);
mHandler.sendMessage(msg);
}
}