Restrict the number of contextual cards shown in suggestion area.
In order to make static IA visible in the homepage, we have to limit the number of cards. Bug: 118691898 Test: robotest Change-Id: Iefb8b7e874ec1334e93be2d196b7cb72624b17b0
This commit is contained in:
@@ -33,6 +33,8 @@ import androidx.annotation.VisibleForTesting;
|
||||
import androidx.slice.Slice;
|
||||
|
||||
import com.android.settings.homepage.contextualcards.deviceinfo.BatterySlice;
|
||||
import com.android.settings.homepage.contextualcards.slices.ConnectedDeviceSlice;
|
||||
import com.android.settings.wifi.WifiSlice;
|
||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -40,9 +42,13 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>> {
|
||||
private static final String TAG = "ContextualCardLoader";
|
||||
|
||||
@VisibleForTesting
|
||||
static final int DEFAULT_CARD_COUNT = 4;
|
||||
static final int CARD_CONTENT_LOADER_ID = 1;
|
||||
|
||||
private static final String TAG = "ContextualCardLoader";
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public interface CardContentLoaderListener {
|
||||
@@ -77,7 +83,30 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>
|
||||
}
|
||||
}
|
||||
}
|
||||
return filterEligibleCards(result);
|
||||
return getFinalDisplayableCards(result);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
List<ContextualCard> getFinalDisplayableCards(List<ContextualCard> candidates) {
|
||||
List<ContextualCard> eligibleCards = filterEligibleCards(candidates);
|
||||
eligibleCards = eligibleCards.stream().limit(DEFAULT_CARD_COUNT).collect(
|
||||
Collectors.toList());
|
||||
|
||||
if (eligibleCards.size() <= 2 || getNumberOfLargeCard(eligibleCards) == 0) {
|
||||
return eligibleCards;
|
||||
}
|
||||
|
||||
if (eligibleCards.size() == DEFAULT_CARD_COUNT) {
|
||||
eligibleCards.remove(eligibleCards.size() - 1);
|
||||
}
|
||||
|
||||
if (getNumberOfLargeCard(eligibleCards) == 1) {
|
||||
return eligibleCards;
|
||||
}
|
||||
|
||||
eligibleCards.remove(eligibleCards.size() - 1);
|
||||
|
||||
return eligibleCards;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
@@ -139,6 +168,13 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getNumberOfLargeCard(List<ContextualCard> cards) {
|
||||
return (int) cards.stream()
|
||||
.filter(card -> card.getSliceUri().equals(WifiSlice.WIFI_URI)
|
||||
|| card.getSliceUri().equals(ConnectedDeviceSlice.CONNECTED_DEVICE_URI))
|
||||
.count();
|
||||
}
|
||||
|
||||
private long getAppVersionCode() {
|
||||
try {
|
||||
return mContext.getPackageManager().getPackageInfo(mContext.getPackageName(),
|
||||
|
Reference in New Issue
Block a user