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:
Fan Zhang
2018-09-12 14:07:12 -07:00
parent de3ff1eee1
commit 089ed21526
7 changed files with 23 additions and 30 deletions

View File

@@ -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,28 +45,22 @@ 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<>();
return result;
}
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()) {
//TODO(b/114688391): Load and generate custom card,then add into list
} else {
result.add(card);
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;

View File

@@ -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 */,

View File

@@ -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);

View File

@@ -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>> {

View File

@@ -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);

View File

@@ -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";

View File

@@ -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