Loading src/com/android/settings/homepage/ContextualCardController.java +0 −8 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.settings.homepage; import java.util.List; /** * Data controller for {@link ContextualCard}. */ Loading @@ -26,12 +24,6 @@ public interface ContextualCardController { @ContextualCard.CardType int getCardType(); /** * When data is updated or changed, the new data should be passed to ContextualCardManager for * list updating. */ void onDataUpdated(List<ContextualCard> cardList); void onPrimaryClick(ContextualCard card); void onActionClick(ContextualCard card); Loading src/com/android/settings/homepage/ContextualCardManager.java +13 −10 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ package com.android.settings.homepage; import static com.android.settings.homepage.CardContentLoader.CARD_CONTENT_LOADER_ID; import static java.util.stream.Collectors.groupingBy; import android.content.Context; import android.os.Bundle; import android.util.ArrayMap; import android.util.Log; import android.widget.BaseAdapter; Loading @@ -33,6 +36,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; Loading Loading @@ -110,15 +114,12 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade } @Override public void onContextualCardUpdated(List<ContextualCard> updateList) { public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> updateList) { //TODO(b/112245748): Should implement a DiffCallback. //Keep the old list for comparison. final List<ContextualCard> prevCards = mContextualCards; final Set<Integer> cardTypes = updateList .stream() .map(card -> card.getCardType()) .collect(Collectors.toSet()); final Set<Integer> cardTypes = updateList.keySet(); //Remove the existing data that matches the certain cardType before inserting new data. final List<ContextualCard> cardsToKeep = mContextualCards .stream() Loading @@ -126,10 +127,10 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade .collect(Collectors.toList()); final List<ContextualCard> allCards = new ArrayList<>(); allCards.addAll(cardsToKeep); allCards.addAll(updateList); allCards.addAll( updateList.values().stream().flatMap(List::stream).collect(Collectors.toList())); sortCards(allCards); //replace with the new data mContextualCards.clear(); mContextualCards.addAll(allCards); Loading @@ -137,13 +138,15 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade loadCardControllers(); if (mListener != null) { mListener.onContextualCardUpdated(mContextualCards); final Map<Integer, List<ContextualCard>> cardsToUpdate = new ArrayMap<>(); cardsToUpdate.put(ContextualCard.CardType.DEFAULT, mContextualCards); mListener.onContextualCardUpdated(cardsToUpdate); } } @Override public void onFinishCardLoading(List<ContextualCard> contextualCards) { onContextualCardUpdated(contextualCards); public void onFinishCardLoading(List<ContextualCard> cards) { onContextualCardUpdated(cards.stream().collect(groupingBy(ContextualCard::getCardType))); } void setListener(ContextualCardUpdateListener listener) { Loading src/com/android/settings/homepage/ContextualCardUpdateListener.java +10 −6 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ package com.android.settings.homepage; import java.util.List; import java.util.Map; /** * When {@link ContextualCardController} detects changes, it will notify the listeners registered. * In our case, {@link ContextualCardManager} gets noticed. * * After the list of {@link ContextualCard} gets updated in{@link ContextualCardManager}, * {@link ContextualCardManager} will notify the listeners registered, {@link * ContextualCardsAdapter} in this case. */ public interface ContextualCardUpdateListener { void onContextualCardUpdated(List<ContextualCard> updateList); /** * Called when a set of cards are updated. * * @param cards A map of updates grouped by {@link ContextualCard.CardType}. Values can be * null, which means all cards from corresponding {@link * ContextualCard.CardType} are removed. */ void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards); } No newline at end of file src/com/android/settings/homepage/ContextualCardsAdapter.java +3 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; import java.util.Map; public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ContextualCardUpdateListener { Loading Loading @@ -101,7 +102,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi } @Override public void onContextualCardUpdated(List<ContextualCard> contextualCards) { public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards) { final List<ContextualCard> contextualCards = cards.get(ContextualCard.CardType.DEFAULT); //TODO(b/112245748): Should implement a DiffCallback so we can use notifyItemChanged() // instead. if (contextualCards == null) { Loading src/com/android/settings/homepage/conditional/ConditionContextualCardController.java +5 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.homepage.conditional; import android.content.Context; import android.util.ArrayMap; import com.android.settings.homepage.ContextualCard; import com.android.settings.homepage.ContextualCardController; Loading @@ -27,6 +28,7 @@ import com.android.settingslib.core.lifecycle.events.OnStop; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * This controller triggers the loading of conditional cards and monitors state changes to Loading Loading @@ -56,11 +58,6 @@ public class ConditionContextualCardController implements ContextualCardControll return ContextualCard.CardType.CONDITIONAL; } @Override public void onDataUpdated(List<ContextualCard> cardList) { mListener.onContextualCardUpdated(cardList); } @Override public void onStart() { mConditionManager.startMonitoringStateChange(); Loading Loading @@ -105,7 +102,9 @@ public class ConditionContextualCardController implements ContextualCardControll } if (mListener != null) { onDataUpdated(conditionCards); final Map<Integer, List<ContextualCard>> conditionalCards = new ArrayMap<>(); conditionalCards.put(ContextualCard.CardType.CONDITIONAL, conditionCards); mListener.onContextualCardUpdated(conditionalCards); } } } Loading
src/com/android/settings/homepage/ContextualCardController.java +0 −8 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.settings.homepage; import java.util.List; /** * Data controller for {@link ContextualCard}. */ Loading @@ -26,12 +24,6 @@ public interface ContextualCardController { @ContextualCard.CardType int getCardType(); /** * When data is updated or changed, the new data should be passed to ContextualCardManager for * list updating. */ void onDataUpdated(List<ContextualCard> cardList); void onPrimaryClick(ContextualCard card); void onActionClick(ContextualCard card); Loading
src/com/android/settings/homepage/ContextualCardManager.java +13 −10 Original line number Diff line number Diff line Loading @@ -18,8 +18,11 @@ package com.android.settings.homepage; import static com.android.settings.homepage.CardContentLoader.CARD_CONTENT_LOADER_ID; import static java.util.stream.Collectors.groupingBy; import android.content.Context; import android.os.Bundle; import android.util.ArrayMap; import android.util.Log; import android.widget.BaseAdapter; Loading @@ -33,6 +36,7 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; Loading Loading @@ -110,15 +114,12 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade } @Override public void onContextualCardUpdated(List<ContextualCard> updateList) { public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> updateList) { //TODO(b/112245748): Should implement a DiffCallback. //Keep the old list for comparison. final List<ContextualCard> prevCards = mContextualCards; final Set<Integer> cardTypes = updateList .stream() .map(card -> card.getCardType()) .collect(Collectors.toSet()); final Set<Integer> cardTypes = updateList.keySet(); //Remove the existing data that matches the certain cardType before inserting new data. final List<ContextualCard> cardsToKeep = mContextualCards .stream() Loading @@ -126,10 +127,10 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade .collect(Collectors.toList()); final List<ContextualCard> allCards = new ArrayList<>(); allCards.addAll(cardsToKeep); allCards.addAll(updateList); allCards.addAll( updateList.values().stream().flatMap(List::stream).collect(Collectors.toList())); sortCards(allCards); //replace with the new data mContextualCards.clear(); mContextualCards.addAll(allCards); Loading @@ -137,13 +138,15 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade loadCardControllers(); if (mListener != null) { mListener.onContextualCardUpdated(mContextualCards); final Map<Integer, List<ContextualCard>> cardsToUpdate = new ArrayMap<>(); cardsToUpdate.put(ContextualCard.CardType.DEFAULT, mContextualCards); mListener.onContextualCardUpdated(cardsToUpdate); } } @Override public void onFinishCardLoading(List<ContextualCard> contextualCards) { onContextualCardUpdated(contextualCards); public void onFinishCardLoading(List<ContextualCard> cards) { onContextualCardUpdated(cards.stream().collect(groupingBy(ContextualCard::getCardType))); } void setListener(ContextualCardUpdateListener listener) { Loading
src/com/android/settings/homepage/ContextualCardUpdateListener.java +10 −6 Original line number Diff line number Diff line Loading @@ -17,15 +17,19 @@ package com.android.settings.homepage; import java.util.List; import java.util.Map; /** * When {@link ContextualCardController} detects changes, it will notify the listeners registered. * In our case, {@link ContextualCardManager} gets noticed. * * After the list of {@link ContextualCard} gets updated in{@link ContextualCardManager}, * {@link ContextualCardManager} will notify the listeners registered, {@link * ContextualCardsAdapter} in this case. */ public interface ContextualCardUpdateListener { void onContextualCardUpdated(List<ContextualCard> updateList); /** * Called when a set of cards are updated. * * @param cards A map of updates grouped by {@link ContextualCard.CardType}. Values can be * null, which means all cards from corresponding {@link * ContextualCard.CardType} are removed. */ void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards); } No newline at end of file
src/com/android/settings/homepage/ContextualCardsAdapter.java +3 −1 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ import androidx.recyclerview.widget.RecyclerView; import java.util.ArrayList; import java.util.List; import java.util.Map; public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements ContextualCardUpdateListener { Loading Loading @@ -101,7 +102,8 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi } @Override public void onContextualCardUpdated(List<ContextualCard> contextualCards) { public void onContextualCardUpdated(Map<Integer, List<ContextualCard>> cards) { final List<ContextualCard> contextualCards = cards.get(ContextualCard.CardType.DEFAULT); //TODO(b/112245748): Should implement a DiffCallback so we can use notifyItemChanged() // instead. if (contextualCards == null) { Loading
src/com/android/settings/homepage/conditional/ConditionContextualCardController.java +5 −6 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.settings.homepage.conditional; import android.content.Context; import android.util.ArrayMap; import com.android.settings.homepage.ContextualCard; import com.android.settings.homepage.ContextualCardController; Loading @@ -27,6 +28,7 @@ import com.android.settingslib.core.lifecycle.events.OnStop; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * This controller triggers the loading of conditional cards and monitors state changes to Loading Loading @@ -56,11 +58,6 @@ public class ConditionContextualCardController implements ContextualCardControll return ContextualCard.CardType.CONDITIONAL; } @Override public void onDataUpdated(List<ContextualCard> cardList) { mListener.onContextualCardUpdated(cardList); } @Override public void onStart() { mConditionManager.startMonitoringStateChange(); Loading Loading @@ -105,7 +102,9 @@ public class ConditionContextualCardController implements ContextualCardControll } if (mListener != null) { onDataUpdated(conditionCards); final Map<Integer, List<ContextualCard>> conditionalCards = new ArrayMap<>(); conditionalCards.put(ContextualCard.CardType.CONDITIONAL, conditionCards); mListener.onContextualCardUpdated(conditionalCards); } } }