Refresh support screen more often
Support screen is now refreshed in the onResume. This will prevent the situation where you open the support tab and then you cross a hours of operation boundary and the button is not updated. Test: make RunSettingsRoboTests Bug: 33272736 Change-Id: I9312b3b6f711eda91d5d60b3ff30e5ac12bf89c1
This commit is contained in:
@@ -119,6 +119,7 @@ public final class SupportFragment extends InstrumentedFragment implements View.
|
|||||||
.build(),
|
.build(),
|
||||||
mNetworkCallback);
|
mNetworkCallback);
|
||||||
mSupportItemAdapter.setHasInternet(hasInternet());
|
mSupportItemAdapter.setHasInternet(hasInternet());
|
||||||
|
mSupportItemAdapter.refreshData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -192,7 +192,7 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
* Create data for the adapter. If there is already data in the adapter, they will be
|
* Create data for the adapter. If there is already data in the adapter, they will be
|
||||||
* destroyed and recreated.
|
* destroyed and recreated.
|
||||||
*/
|
*/
|
||||||
private void refreshData() {
|
void refreshData() {
|
||||||
mSupportData.clear();
|
mSupportData.clear();
|
||||||
addEscalationCards();
|
addEscalationCards();
|
||||||
addMoreHelpItems();
|
addMoreHelpItems();
|
||||||
@@ -601,7 +601,8 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
/**
|
/**
|
||||||
* Data for a single support item.
|
* Data for a single support item.
|
||||||
*/
|
*/
|
||||||
private static class SupportData {
|
@VisibleForTesting
|
||||||
|
static class SupportData {
|
||||||
|
|
||||||
final Intent intent;
|
final Intent intent;
|
||||||
final int metricsEvent;
|
final int metricsEvent;
|
||||||
@@ -688,7 +689,8 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
/**
|
/**
|
||||||
* Data model for escalation cards.
|
* Data model for escalation cards.
|
||||||
*/
|
*/
|
||||||
private static class EscalationData extends SupportData {
|
@VisibleForTesting
|
||||||
|
static class EscalationData extends SupportData {
|
||||||
|
|
||||||
@StringRes
|
@StringRes
|
||||||
final int text1;
|
final int text1;
|
||||||
@@ -813,4 +815,9 @@ public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAd
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
List<SupportData> getSupportData() {
|
||||||
|
return mSupportData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -18,6 +18,7 @@ package com.android.settings.dashboard;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
@@ -26,7 +27,9 @@ import android.widget.Spinner;
|
|||||||
import android.widget.SpinnerAdapter;
|
import android.widget.SpinnerAdapter;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
|
import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
|
||||||
import com.android.settings.overlay.SupportFeatureProvider;
|
import com.android.settings.overlay.SupportFeatureProvider;
|
||||||
|
import java.util.List;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -38,6 +41,8 @@ import org.robolectric.annotation.Config;
|
|||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import org.robolectric.shadows.ShadowActivity;
|
import org.robolectric.shadows.ShadowActivity;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.robolectric.Shadows.shadowOf;
|
import static org.robolectric.Shadows.shadowOf;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -111,6 +116,37 @@ public class SupportItemAdapterTest {
|
|||||||
verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
|
verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
|
||||||
|
// pretend we have support right now
|
||||||
|
when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
|
||||||
|
.thenReturn(true);
|
||||||
|
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
|
||||||
|
when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
|
||||||
|
mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
|
||||||
|
mMetricsFeatureProvider, null);
|
||||||
|
|
||||||
|
// If this doesn't return escalation data something has gone wrong
|
||||||
|
EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
|
||||||
|
|
||||||
|
// precondition, support is enabled
|
||||||
|
assertThat(data.enabled1).isTrue();
|
||||||
|
|
||||||
|
// pretend we support hours are over
|
||||||
|
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
|
||||||
|
mSupportItemAdapter.refreshData();
|
||||||
|
data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
|
||||||
|
|
||||||
|
assertThat(data.enabled1).isFalse();
|
||||||
|
|
||||||
|
// pretend support hours have started again
|
||||||
|
when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
|
||||||
|
mSupportItemAdapter.refreshData();
|
||||||
|
data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
|
||||||
|
|
||||||
|
assertThat(data.enabled1).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
|
* Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
|
||||||
* invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
|
* invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
|
||||||
|
Reference in New Issue
Block a user