Only show one tip at a time

1. Update the order for each tip.
2. Change BatteryTipPreferenceController and only show one precedent
tip.
3. Update the SummaryDetector since now it doesn't need visibleTips

Bug: 70570352
Test: RunSettingsRoboTests
Change-Id: I9e2b8e72aad263f8a210c9320e0ea1eaaf8d5042
This commit is contained in:
jackqdyulei
2018-01-10 18:21:11 -08:00
parent 62d6a9dca7
commit 2e0bdc34f2
6 changed files with 48 additions and 65 deletions

View File

@@ -22,7 +22,6 @@ import android.support.annotation.VisibleForTesting;
import com.android.internal.os.BatteryStatsHelper;
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
import com.android.settings.fuelgauge.batterytip.detectors.EarlyWarningDetector;
import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
@@ -47,9 +46,8 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
private static final boolean USE_FAKE_DATA = false;
private BatteryStatsHelper mBatteryStatsHelper;
private BatteryUtils mBatteryUtils;
@VisibleForTesting
int mVisibleTips;
BatteryUtils mBatteryUtils;
public BatteryTipLoader(Context context, BatteryStatsHelper batteryStatsHelper) {
super(context);
@@ -66,16 +64,12 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
final BatteryTipPolicy policy = new BatteryTipPolicy(getContext());
final BatteryInfo batteryInfo = mBatteryUtils.getBatteryInfo(mBatteryStatsHelper, TAG);
final Context context = getContext();
mVisibleTips = 0;
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
addBatteryTipFromDetector(tips,
new HighUsageDetector(context, policy, mBatteryStatsHelper));
addBatteryTipFromDetector(tips,
new SmartBatteryDetector(policy, context.getContentResolver()));
addBatteryTipFromDetector(tips, new EarlyWarningDetector(policy, context));
// Add summary detector at last since it need other detectors to update the mVisibleTips
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
tips.add(new LowBatteryDetector(policy, batteryInfo).detect());
tips.add(new HighUsageDetector(context, policy, mBatteryStatsHelper).detect());
tips.add(new SmartBatteryDetector(policy, context.getContentResolver()).detect());
tips.add(new EarlyWarningDetector(policy, context).detect());
tips.add(new SummaryDetector(policy).detect());
Collections.sort(tips);
return tips;
@@ -93,12 +87,4 @@ public class BatteryTipLoader extends AsyncLoader<List<BatteryTip>> {
return tips;
}
@VisibleForTesting
void addBatteryTipFromDetector(final List<BatteryTip> tips,
final BatteryTipDetector detector) {
final BatteryTip batteryTip = detector.detect();
mVisibleTips += batteryTip.isVisible() ? 1 : 0;
tips.add(batteryTip);
}
}