Fix nits in contextual card package.
We missed to catch a few nits in previous CLs. This change cleans up some of it. Test: manual Change-Id: Ibd3466f781952f998e1183a49f56e812cbce99a1
This commit is contained in:
@@ -19,7 +19,7 @@ package com.android.settings.homepage;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.settingslib.utils.AsyncLoaderCompat;
|
import com.android.settingslib.utils.AsyncLoaderCompat;
|
||||||
|
|
||||||
@@ -45,28 +45,22 @@ public class CardContentLoader extends AsyncLoaderCompat<List<ContextualCard>> {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public List<ContextualCard> loadInBackground() {
|
public List<ContextualCard> loadInBackground() {
|
||||||
List<ContextualCard> result;
|
final List<ContextualCard> result = new ArrayList<>();
|
||||||
try (Cursor cursor = CardDatabaseHelper.getInstance(mContext).getAllContextualCards()) {
|
try (Cursor cursor = CardDatabaseHelper.getInstance(mContext).getContextualCards()) {
|
||||||
if (cursor.getCount() == 0) {
|
if (cursor.getCount() == 0) {
|
||||||
//TODO(b/113372471): Load Default static cards and return 3 static cards
|
//TODO(b/113372471): Load Default static cards and return 3 static cards
|
||||||
return new ArrayList<>();
|
return result;
|
||||||
}
|
}
|
||||||
result = buildContextualCardList(cursor);
|
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
||||||
}
|
final ContextualCard card = new ContextualCard(cursor);
|
||||||
return result;
|
if (card.isCustomCard()) {
|
||||||
}
|
//TODO(b/114688391): Load and generate custom card,then add into list
|
||||||
|
} else {
|
||||||
private List<ContextualCard> buildContextualCardList(Cursor cursor) {
|
result.add(card);
|
||||||
final List<ContextualCard> result = new ArrayList<>();
|
}
|
||||||
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
|
|
||||||
final ContextualCard card = new ContextualCard(cursor);
|
|
||||||
if (card.isCustomCard()) {
|
|
||||||
//TODO(b/114688391): Load and generate custom card,then add into list
|
|
||||||
} else {
|
|
||||||
result.add(card);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@@ -192,7 +192,7 @@ public class CardDatabaseHelper extends SQLiteOpenHelper {
|
|||||||
return sCardDatabaseHelper;
|
return sCardDatabaseHelper;
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor getAllContextualCards() {
|
Cursor getContextualCards() {
|
||||||
final SQLiteDatabase db = this.getReadableDatabase();
|
final SQLiteDatabase db = this.getReadableDatabase();
|
||||||
Cursor cursor = db.query(CARD_TABLE, null /* columns */, null /* selection */,
|
Cursor cursor = db.query(CARD_TABLE, null /* columns */, null /* selection */,
|
||||||
null /* selectionArgs */, null /* groupBy */, null /* having */,
|
null /* selectionArgs */, null /* groupBy */, null /* having */,
|
||||||
|
@@ -27,8 +27,8 @@ public interface ContextualCardController {
|
|||||||
int getCardType();
|
int getCardType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When data is updated or changed, the new data should be passed to ContextualCardManager for list
|
* When data is updated or changed, the new data should be passed to ContextualCardManager for
|
||||||
* updating.
|
* list updating.
|
||||||
*/
|
*/
|
||||||
void onDataUpdated(List<ContextualCard> cardList);
|
void onDataUpdated(List<ContextualCard> cardList);
|
||||||
|
|
||||||
|
@@ -68,7 +68,7 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
|
|||||||
mControllerRendererPool = new ControllerRendererPool();
|
mControllerRendererPool = new ControllerRendererPool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void startCardContentLoading(PersonalSettingsFragment fragment) {
|
void loadContextualCards(PersonalSettingsFragment fragment) {
|
||||||
final CardContentLoaderCallbacks cardContentLoaderCallbacks =
|
final CardContentLoaderCallbacks cardContentLoaderCallbacks =
|
||||||
new CardContentLoaderCallbacks(mContext);
|
new CardContentLoaderCallbacks(mContext);
|
||||||
cardContentLoaderCallbacks.setListener(this);
|
cardContentLoaderCallbacks.setListener(this);
|
||||||
@@ -152,7 +152,6 @@ public class ContextualCardManager implements CardContentLoader.CardContentLoade
|
|||||||
return mControllerRendererPool;
|
return mControllerRendererPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static class CardContentLoaderCallbacks implements
|
static class CardContentLoaderCallbacks implements
|
||||||
LoaderManager.LoaderCallbacks<List<ContextualCard>> {
|
LoaderManager.LoaderCallbacks<List<ContextualCard>> {
|
||||||
|
|
||||||
|
@@ -31,15 +31,15 @@ public interface ContextualCardRenderer {
|
|||||||
int getViewType();
|
int getViewType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When {@link ContextualCardsAdapter} calls {@link ContextualCardsAdapter#onCreateViewHolder(ViewGroup,
|
* When {@link ContextualCardsAdapter} calls {@link ContextualCardsAdapter#onCreateViewHolder},
|
||||||
* int)}, this method will be called to retrieve the corresponding
|
* this method will be called to retrieve the corresponding
|
||||||
* {@link androidx.recyclerview.widget.RecyclerView.ViewHolder}.
|
* {@link androidx.recyclerview.widget.RecyclerView.ViewHolder}.
|
||||||
*/
|
*/
|
||||||
RecyclerView.ViewHolder createViewHolder(View view);
|
RecyclerView.ViewHolder createViewHolder(View view);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When {@link ContextualCardsAdapter} calls {@link ContextualCardsAdapter#onBindViewHolder(RecyclerView
|
* When {@link ContextualCardsAdapter} calls {@link ContextualCardsAdapter#onBindViewHolder},
|
||||||
* .ViewHolder, int)}, this method will be called to bind data to the
|
* this method will be called to bind data to the
|
||||||
* {@link androidx.recyclerview.widget.RecyclerView.ViewHolder}.
|
* {@link androidx.recyclerview.widget.RecyclerView.ViewHolder}.
|
||||||
*/
|
*/
|
||||||
void bindView(RecyclerView.ViewHolder holder, ContextualCard card);
|
void bindView(RecyclerView.ViewHolder holder, ContextualCard card);
|
||||||
|
@@ -27,8 +27,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements
|
public class ContextualCardsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
|
||||||
ContextualCardUpdateListener {
|
implements ContextualCardUpdateListener {
|
||||||
static final int SPAN_COUNT = 2;
|
static final int SPAN_COUNT = 2;
|
||||||
|
|
||||||
private static final String TAG = "ContextualCardsAdapter";
|
private static final String TAG = "ContextualCardsAdapter";
|
||||||
|
@@ -43,7 +43,7 @@ public class PersonalSettingsFragment extends InstrumentedFragment {
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mContextualCardManager = new ContextualCardManager(getContext(), getSettingsLifecycle());
|
mContextualCardManager = new ContextualCardManager(getContext(), getSettingsLifecycle());
|
||||||
mContextualCardManager.startCardContentLoading(this);
|
mContextualCardManager.loadContextualCards(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user