Fix flicker for Mobile data & Wi-Fi page

Both "Mobile data usage" & "Non-carrier data usage".

By,
1. Add header in onCreate() instead of onViewCreated()
2. Keep the space for Spinner, and preload initial cycles
3. Keep the space for 3 usage summaries

Bug: 191730864
Test: manual
Change-Id: I8c309c5f51ce6290383a2d10f75e41d0f207d61a
This commit is contained in:
Chaohui Wang
2022-04-28 19:09:02 +08:00
parent 3663986909
commit ddedb31f6e
5 changed files with 53 additions and 160 deletions

View File

@@ -43,7 +43,6 @@ import android.os.Process;
import android.telephony.SubscriptionManager;
import android.text.format.DateUtils;
import android.util.ArraySet;
import android.view.View;
import androidx.fragment.app.FragmentActivity;
import androidx.preference.Preference;
@@ -96,6 +95,10 @@ public class AppDataUsageTest {
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
when(mHeaderController.setUid(anyInt())).thenReturn(mHeaderController);
}
@After
@@ -163,10 +166,6 @@ public class AppDataUsageTest {
@Test
public void bindAppHeader_allWorkApps_shouldNotShowAppInfoLink() {
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
when(mHeaderController.setUid(anyInt())).thenReturn(mHeaderController);
mFragment = spy(new AppDataUsage());
when(mFragment.getPreferenceManager())
@@ -174,7 +173,7 @@ public class AppDataUsageTest {
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
ReflectionHelpers.setField(mFragment, "mAppItem", mock(AppItem.class));
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
mFragment.addEntityHeader();
verify(mHeaderController).setHasAppInfoLink(false);
}
@@ -196,16 +195,13 @@ public class AppDataUsageTest {
when(mPackageManager.getPackageUidAsUser(anyString(), anyInt()))
.thenReturn(fakeUserId);
ShadowEntityHeaderController.setUseMock(mHeaderController);
when(mHeaderController.setRecyclerView(any(), any())).thenReturn(mHeaderController);
when(mHeaderController.setUid(fakeUserId)).thenReturn(mHeaderController);
when(mHeaderController.setHasAppInfoLink(anyBoolean())).thenReturn(mHeaderController);
when(mFragment.getPreferenceManager())
.thenReturn(mock(PreferenceManager.class, RETURNS_DEEP_STUBS));
doReturn(mock(PreferenceScreen.class)).when(mFragment).getPreferenceScreen();
mFragment.onViewCreated(new View(RuntimeEnvironment.application), new Bundle());
mFragment.addEntityHeader();
verify(mHeaderController).setHasAppInfoLink(true);
verify(mHeaderController).setUid(fakeUserId);
@@ -268,7 +264,7 @@ public class AppDataUsageTest {
mFragment.bindData(0 /* position */);
verify(cycle).setVisible(false);
verify(cycle).setHasCycles(false);
}
@Test
@@ -293,7 +289,7 @@ public class AppDataUsageTest {
mFragment.bindData(0 /* position */);
verify(cycle).setVisible(true);
verify(cycle).setHasCycles(true);
verify(totalPref).setSummary(
DataUsageUtils.formatDataUsage(context, backgroundBytes + foregroundBytes));
verify(backgroundPref).setSummary(DataUsageUtils.formatDataUsage(context, backgroundBytes));