Cross fade escalation card when content changes.
Fixes: 30079520
Whenever escalation card needs to change content:
- Instead of rebuilding entire data set, rebuild just escalation data.
- Instead of notify entire data set change, only notify the position
change for escalation card.
This triggers the cross-fade animation in RecyclerView's
DefaultItemAnimator.
Change-Id: Ia19593d852fa6a1c366aecf9330d8274d7295e85
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
index 1d4e99a..a0ba57b 100644
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ b/src/com/android/settings/dashboard/SupportItemAdapter.java
@@ -148,7 +148,7 @@
public void setHasInternet(boolean hasInternet) {
if (mHasInternet != hasInternet) {
mHasInternet = hasInternet;
- refreshData();
+ refreshEscalationCards();
}
}
@@ -156,7 +156,7 @@
if (!Objects.equals(mAccount, account)) {
mAccount = account;
mSupportFeatureProvider.refreshOperationRules();
- refreshData();
+ refreshEscalationCards();
}
}
@@ -170,18 +170,42 @@
*/
private void refreshData() {
mSupportData.clear();
- if (mAccount == null) {
- addSignInPromo();
- } else if (mHasInternet) {
- addEscalationCards();
- } else {
- addOfflineEscalationCards();
- }
+ addEscalationCards();
addMoreHelpItems();
notifyDataSetChanged();
}
+ /**
+ * Adds 1 escalation card. Based on current phone state, the escalation card can display
+ * different content.
+ */
private void addEscalationCards() {
+ if (mAccount == null) {
+ addSignInPromo();
+ } else if (mHasInternet) {
+ addOnlineEscalationCards();
+ } else {
+ addOfflineEscalationCards();
+ }
+ }
+
+ /**
+ * Finds and refreshes escalation card data.
+ */
+ private void refreshEscalationCards() {
+ if (getItemCount() > 0) {
+ final int itemType = getItemViewType(0 /* position */);
+ if (itemType == TYPE_SIGN_IN_BUTTON
+ || itemType == TYPE_ESCALATION_OPTIONS
+ || itemType == TYPE_ESCALATION_OPTIONS_OFFLINE) {
+ mSupportData.remove(0 /* position */);
+ addEscalationCards();
+ notifyItemChanged(0 /* position */);
+ }
+ }
+ }
+
+ private void addOnlineEscalationCards() {
final boolean hasPhoneOperation =
mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE);
final boolean hasChatOperation =
@@ -218,7 +242,7 @@
.setSummary2(mSupportFeatureProvider.getEstimatedWaitTime(mActivity, CHAT))
.setEnabled2(mSupportFeatureProvider.isOperatingNow(CHAT));
}
- mSupportData.add(builder.build());
+ mSupportData.add(0 /* index */, builder.build());
}
private void addOfflineEscalationCards() {
@@ -231,7 +255,7 @@
operatingHours = mSupportFeatureProvider.getOperationHours(mActivity,
PHONE, mSelectedCountry, false /* hasInternet */);
}
- mSupportData.add(new OfflineEscalationData.Builder(mActivity)
+ mSupportData.add(0 /* index */, new OfflineEscalationData.Builder(mActivity)
.setCountries(mSupportFeatureProvider.getPhoneSupportCountries())
.setTollFreePhone(mSupportFeatureProvider.getSupportPhones(
mSelectedCountry, true /* isTollFree */))
@@ -245,7 +269,7 @@
}
private void addSignInPromo() {
- mSupportData.add(new EscalationData.Builder(mActivity, TYPE_SIGN_IN_BUTTON)
+ mSupportData.add(0 /* index */, new EscalationData.Builder(mActivity, TYPE_SIGN_IN_BUTTON)
.setText1(R.string.support_sign_in_button_text)
.setText2(R.string.support_sign_in_required_help)
.setTileTitle(R.string.support_sign_in_required_title)
@@ -437,7 +461,7 @@
final String selectedCountry = countryCodes.get(position);
if (!TextUtils.equals(selectedCountry, mSelectedCountry)) {
mSelectedCountry = selectedCountry;
- refreshData();
+ refreshEscalationCards();
}
}