Misc clean up
- Rename a few more things from Homepage* to ContextualCard* - Fixed a wrong parameter that GridLayoutManager was using Test: rebuild Change-Id: I7986b1caf63158e876295de6d31dbbe05581664d
This commit is contained in:
@@ -28,14 +28,14 @@ import java.util.List;
|
|||||||
/**
|
/**
|
||||||
* This is a centralized manager of multiple {@link ContextualCardController}.
|
* This is a centralized manager of multiple {@link ContextualCardController}.
|
||||||
*
|
*
|
||||||
* {@link ContextualCardManager} first loads data from {@link CardContentLoader} and gets back a list of
|
* {@link ContextualCardManager} first loads data from {@link CardContentLoader} and gets back a
|
||||||
* {@link ContextualCard}. All subclasses of {@link ContextualCardController} are loaded here, which
|
* list of {@link ContextualCard}. All subclasses of {@link ContextualCardController} are loaded
|
||||||
* will then trigger the {@link ContextualCardController} to load its data and listen to
|
* here, which will then trigger the {@link ContextualCardController} to load its data and listen to
|
||||||
* corresponding changes. When every single {@link ContextualCardController} updates its data, the
|
* corresponding changes. When every single {@link ContextualCardController} updates its data, the
|
||||||
* data will be passed here, then going through some sorting mechanisms. The
|
* data will be passed here, then going through some sorting mechanisms. The
|
||||||
* {@link ContextualCardController} will end up building a list of {@link ContextualCard} for {@link
|
* {@link ContextualCardController} will end up building a list of {@link ContextualCard} for
|
||||||
* ContextualCardsAdapter} and {@link BaseAdapter#notifyDataSetChanged()} will be called to get the page
|
* {@link ContextualCardsAdapter} and {@link BaseAdapter#notifyDataSetChanged()} will be called to
|
||||||
* refreshed.
|
* get the page refreshed.
|
||||||
*/
|
*/
|
||||||
public class ContextualCardManager implements CardContentLoader.CardContentLoaderListener,
|
public class ContextualCardManager implements CardContentLoader.CardContentLoaderListener,
|
||||||
ContextualCardUpdateListener {
|
ContextualCardUpdateListener {
|
||||||
@@ -48,8 +48,8 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ControllerRendererPool mControllerRendererPool;
|
private final ControllerRendererPool mControllerRendererPool;
|
||||||
private final Lifecycle mLifecycle;
|
private final Lifecycle mLifecycle;
|
||||||
|
private final List<ContextualCard> mContextualCards;
|
||||||
|
|
||||||
private List<ContextualCard> mContextualCards;
|
|
||||||
private ContextualCardUpdateListener mListener;
|
private ContextualCardUpdateListener mListener;
|
||||||
|
|
||||||
|
|
||||||
@@ -97,7 +97,7 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHomepageCardUpdated(int cardType, List<ContextualCard> updateList) {
|
public void onContextualCardUpdated(int cardType, List<ContextualCard> updateList) {
|
||||||
//TODO(b/112245748): Should implement a DiffCallback.
|
//TODO(b/112245748): Should implement a DiffCallback.
|
||||||
//Keep the old list for comparison.
|
//Keep the old list for comparison.
|
||||||
final List<ContextualCard> prevCards = mContextualCards;
|
final List<ContextualCard> prevCards = mContextualCards;
|
||||||
@@ -115,13 +115,16 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
|
|||||||
sortCards();
|
sortCards();
|
||||||
|
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.onHomepageCardUpdated(ContextualCard.CardType.INVALID, mContextualCards);
|
mListener.onContextualCardUpdated(ContextualCard.CardType.INVALID, mContextualCards);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinishCardLoading(List<ContextualCard> contextualCards) {
|
public void onFinishCardLoading(List<ContextualCard> contextualCards) {
|
||||||
mContextualCards = contextualCards;
|
mContextualCards.clear();
|
||||||
|
if (contextualCards != null) {
|
||||||
|
mContextualCards.addAll(contextualCards);
|
||||||
|
}
|
||||||
|
|
||||||
//Force card sorting here in case CardControllers of custom view have nothing to update
|
//Force card sorting here in case CardControllers of custom view have nothing to update
|
||||||
// for the first launch.
|
// for the first launch.
|
||||||
|
@@ -19,13 +19,13 @@ package com.android.settings.homepage;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When {@link ContextualCardController} detects changes, it will notify the listeners registered. In
|
* When {@link ContextualCardController} detects changes, it will notify the listeners registered.
|
||||||
* our case, {@link ContextualCardManager} gets noticed.
|
* In our case, {@link ContextualCardManager} gets noticed.
|
||||||
*
|
*
|
||||||
* After the list of {@link ContextualCard} gets updated in{@link ContextualCardManager},
|
* After the list of {@link ContextualCard} gets updated in{@link ContextualCardManager},
|
||||||
* {@link ContextualCardManager} will notify the listeners registered, {@link ContextualCardsAdapter} in this
|
* {@link ContextualCardManager} will notify the listeners registered, {@link
|
||||||
* case.
|
* ContextualCardsAdapter} in this case.
|
||||||
*/
|
*/
|
||||||
public interface ContextualCardUpdateListener {
|
public interface ContextualCardUpdateListener {
|
||||||
void onHomepageCardUpdated(int cardType, List<ContextualCard> updateList);
|
void onContextualCardUpdated(int cardType, List<ContextualCard> updateList);
|
||||||
}
|
}
|
@@ -37,8 +37,7 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
|||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final ControllerRendererPool mControllerRendererPool;
|
private final ControllerRendererPool mControllerRendererPool;
|
||||||
|
private final List<ContextualCard> mContextualCards;
|
||||||
private List<ContextualCard> mContextualCards;
|
|
||||||
|
|
||||||
public ContextualCardsAdapter(Context context, ContextualCardManager manager) {
|
public ContextualCardsAdapter(Context context, ContextualCardManager manager) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -102,13 +101,14 @@ public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.Vi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHomepageCardUpdated(int cardType, List<ContextualCard> contextualCards) {
|
public void onContextualCardUpdated(int cardType, List<ContextualCard> contextualCards) {
|
||||||
//TODO(b/112245748): Should implement a DiffCallback so we can use notifyItemChanged()
|
//TODO(b/112245748): Should implement a DiffCallback so we can use notifyItemChanged()
|
||||||
// instead.
|
// instead.
|
||||||
if (contextualCards == null) {
|
if (contextualCards == null) {
|
||||||
mContextualCards.clear();
|
mContextualCards.clear();
|
||||||
} else {
|
} else {
|
||||||
mContextualCards = contextualCards;
|
mContextualCards.clear();
|
||||||
|
mContextualCards.addAll(contextualCards);
|
||||||
}
|
}
|
||||||
notifyDataSetChanged();
|
notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,6 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.GridLayoutManager;
|
import androidx.recyclerview.widget.GridLayoutManager;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||||
@@ -50,11 +49,10 @@ public class PersonalSettingsFragment extends InstrumentedFragment {
|
|||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
final View rootView = inflater.inflate(R.layout.settings_homepage,
|
final View rootView = inflater.inflate(R.layout.settings_homepage, container, false);
|
||||||
container, false);
|
|
||||||
mCardsContainer = rootView.findViewById(R.id.card_container);
|
mCardsContainer = rootView.findViewById(R.id.card_container);
|
||||||
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT,
|
mLayoutManager = new GridLayoutManager(getActivity(), SPAN_COUNT,
|
||||||
LinearLayoutManager.VERTICAL, false /* reverseLayout */);
|
GridLayoutManager.VERTICAL, false /* reverseLayout */);
|
||||||
mCardsContainer.setLayoutManager(mLayoutManager);
|
mCardsContainer.setLayoutManager(mLayoutManager);
|
||||||
mContextualCardsAdapter = new ContextualCardsAdapter(getContext(), mContextualCardManager);
|
mContextualCardsAdapter = new ContextualCardsAdapter(getContext(), mContextualCardManager);
|
||||||
mCardsContainer.setAdapter(mContextualCardsAdapter);
|
mCardsContainer.setAdapter(mContextualCardsAdapter);
|
||||||
|
@@ -58,7 +58,7 @@ public class ConditionContextualCardController implements ContextualCardControll
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDataUpdated(List<ContextualCard> cardList) {
|
public void onDataUpdated(List<ContextualCard> cardList) {
|
||||||
mListener.onHomepageCardUpdated(getCardType(), cardList);
|
mListener.onContextualCardUpdated(getCardType(), cardList);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user