Create custom card controller/render as soon as possible.

Custom cards might need to monitor lifecycle events, waiting for
onFinishLoading is too late.

Also make sure custom cards cannot change card type.

Test: manual
Change-Id: Ib8f8e6e48926a63c9d241ed9e9843c025e3f634a
This commit is contained in:
Fan Zhang
2018-09-12 15:27:03 -07:00
parent 089ed21526
commit a93743f9c4
5 changed files with 69 additions and 15 deletions

View File

@@ -20,6 +20,7 @@ import static com.android.settings.homepage.CardContentLoader.CARD_CONTENT_LOADE
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.widget.BaseAdapter;
import androidx.annotation.NonNull;
@@ -60,12 +61,15 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
private ContextualCardUpdateListener mListener;
public ContextualCardManager(Context context, Lifecycle lifecycle) {
mContext = context;
mLifecycle = lifecycle;
mContextualCards = new ArrayList<>();
mControllerRendererPool = new ControllerRendererPool();
//for data provided by Settings
for (int cardType : SETTINGS_CARDS) {
setupController(cardType);
}
}
void loadContextualCards(PersonalSettingsFragment fragment) {
@@ -82,22 +86,19 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
setupController(card.getCardType());
}
}
//for data provided by Settings
for (int cardType : SETTINGS_CARDS) {
setupController(cardType);
}
}
private void setupController(int cardType) {
final ContextualCardController controller = mControllerRendererPool.getController(mContext,
cardType);
if (controller != null) {
controller.setCardUpdateListener(this);
if (controller instanceof LifecycleObserver) {
if (mLifecycle != null) {
mLifecycle.addObserver((LifecycleObserver) controller);
}
if (controller == null) {
Log.w(TAG, "Cannot find ContextualCardController for type " + cardType);
return;
}
controller.setCardUpdateListener(this);
if (controller instanceof LifecycleObserver) {
if (mLifecycle != null) {
mLifecycle.addObserver((LifecycleObserver) controller);
}
}
}