Fix b/241885070: Unexpected texts moving when going back to battery usage page

This bug is because two charts visibility were set to visible everytime
when entering the battery usage page. Only after loading the data and
refresh the UI, one of them could be hidden.

screen record after fix: https://drive.google.com/file/d/1zpynm8UX3XXunlD-WE1eyv6yenrVhAH5/view?usp=sharing&resourcekey=0-y79NYHcm8lgiNRbgy8SEfQ

Test: manual
Bug: 236101166
Bug: 241885070
Change-Id: I9c1dbf79a95dad2c3dece71af6d52f546d8a5808
This commit is contained in:
Zaiyue Xue
2022-08-09 14:38:45 +08:00
parent 248895db72
commit 5316bb71fe
2 changed files with 9 additions and 4 deletions

View File

@@ -273,7 +273,7 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
mDailyTimestampFullTexts = null; mDailyTimestampFullTexts = null;
mDailyViewModel = null; mDailyViewModel = null;
mHourlyViewModels = null; mHourlyViewModels = null;
addFooterPreferenceIfNeeded(false); refreshUi();
return; return;
} }
mDailyTimestampFullTexts = generateTimestampDayOfWeekTexts( mDailyTimestampFullTexts = generateTimestampDayOfWeekTexts(
@@ -338,14 +338,20 @@ public class BatteryChartPreferenceControllerV2 extends AbstractPreferenceContro
@VisibleForTesting @VisibleForTesting
boolean refreshUi() { boolean refreshUi() {
if (mBatteryUsageMap == null || mDailyChartView == null || mHourlyChartView == null) { if (mDailyChartView == null || mHourlyChartView == null) {
// Chart views are not initialized.
return false; return false;
} }
if (mDailyViewModel == null || mHourlyViewModels == null) { if (mDailyViewModel == null || mHourlyViewModels == null) {
// Fail to get battery level data, show an empty hourly chart view. // Fail to get battery level data, show an empty hourly chart view.
mDailyChartView.setVisibility(View.GONE); mDailyChartView.setVisibility(View.GONE);
mHourlyChartView.setVisibility(View.VISIBLE);
mHourlyChartView.setViewModel(null); mHourlyChartView.setViewModel(null);
addFooterPreferenceIfNeeded(false);
return false;
}
if (mBatteryUsageMap == null) {
// Battery usage data is not ready, wait for data ready to refresh UI.
return false; return false;
} }

View File

@@ -158,7 +158,6 @@ public class BatteryChartViewV2 extends AppCompatImageView implements View.OnCli
} else { } else {
mTextPaint = null; mTextPaint = null;
} }
setVisibility(View.VISIBLE);
requestLayout(); requestLayout();
} }