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