Files
app_Settings/src/com/android/settings/homepage/contextualcards/ContextualCardsDiffCallback.java
Jason Chiu e0327ee583 Reload homepage cards when necessary
Many users leave Settings app by pressing Home key, but Settings remains
in the same card status and doesn't update when users come back, which
may lead to a bad UX.

This change reloads cards and resets the UI session for some events,
including home key, recent app key, and screen off.

Fixes: 151789260
Test: robotest
Change-Id: Idb575cef4a58894984cb42238d7b3b43c49389a3
2020-05-05 10:03:49 +00:00

68 lines
2.4 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.homepage.contextualcards;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.IMPORTANT_VALUE;
import static com.android.settings.intelligence.ContextualCardProto.ContextualCard.Category.STICKY_VALUE;
import androidx.recyclerview.widget.DiffUtil;
import java.util.List;
/**
* A DiffCallback to calculate the difference between old and new {@link ContextualCard} List.
*/
public class ContextualCardsDiffCallback extends DiffUtil.Callback {
private final List<ContextualCard> mOldCards;
private final List<ContextualCard> mNewCards;
public ContextualCardsDiffCallback(List<ContextualCard> oldCards,
List<ContextualCard> newCards) {
mOldCards = oldCards;
mNewCards = newCards;
}
@Override
public int getOldListSize() {
return mOldCards.size();
}
@Override
public int getNewListSize() {
return mNewCards.size();
}
@Override
public boolean areItemsTheSame(int oldCardPosition, int newCardPosition) {
return mOldCards.get(oldCardPosition).getName().equals(
mNewCards.get(newCardPosition).getName());
}
@Override
public boolean areContentsTheSame(int oldCardPosition, int newCardPosition) {
final ContextualCard newCard = mNewCards.get(newCardPosition);
// Sticky, important, or toggleable slices need to be updated continuously, which means
// their contents may change. So here we assume the content will always be different to
// force view rebinding.
if (newCard.getCategory() == STICKY_VALUE || newCard.getCategory() == IMPORTANT_VALUE
|| newCard.hasInlineAction()) {
return false;
}
return mOldCards.get(oldCardPosition).equals(newCard);
}
}