Merge "Load suggestions through SettingsIntelligence."
This commit is contained in:
committed by
Android (Google) Code Review
commit
530de5be78
@@ -23,6 +23,7 @@ import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
@@ -62,6 +63,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
implements SummaryLoader.SummaryConsumer {
|
||||
public static final String TAG = "DashboardAdapter";
|
||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||
private static final String STATE_SUGGESTION_LIST_V2 = "suggestion_list_v2";
|
||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||
private static final String STATE_SUGGESTIONS_SHOWN_LOGGED = "suggestions_shown_logged";
|
||||
|
||||
@@ -99,7 +101,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
public DashboardAdapter(Context context, Bundle savedInstanceState,
|
||||
List<Condition> conditions, SuggestionParser suggestionParser,
|
||||
SuggestionDismissController.Callback callback) {
|
||||
|
||||
// @deprecated In favor of suggestionsV2 below.
|
||||
List<Tile> suggestions = null;
|
||||
List<Suggestion> suggestionsV2 = null;
|
||||
DashboardCategory category = null;
|
||||
int suggestionConditionMode = DashboardData.HEADER_MODE_DEFAULT;
|
||||
|
||||
@@ -116,6 +121,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
suggestions = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST);
|
||||
suggestionsV2 = savedInstanceState.getParcelableArrayList(STATE_SUGGESTION_LIST_V2);
|
||||
category = savedInstanceState.getParcelable(STATE_CATEGORY_LIST);
|
||||
suggestionConditionMode = savedInstanceState.getInt(
|
||||
STATE_SUGGESTION_CONDITION_MODE, suggestionConditionMode);
|
||||
@@ -128,6 +134,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
mDashboardData = new DashboardData.Builder()
|
||||
.setConditions(conditions)
|
||||
.setSuggestions(suggestions)
|
||||
.setSuggestionsV2(suggestionsV2)
|
||||
.setCategory(category)
|
||||
.setSuggestionConditionMode(suggestionConditionMode)
|
||||
.build();
|
||||
@@ -137,8 +144,12 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mDashboardData.getSuggestions();
|
||||
}
|
||||
|
||||
public void setCategoriesAndSuggestions(DashboardCategory category,
|
||||
List<Tile> suggestions) {
|
||||
/**
|
||||
* @deprecated in favor of {@link #setCategory(DashboardCategory)} and
|
||||
* {@link #setSuggestionsV2(List)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void setCategoriesAndSuggestions(DashboardCategory category, List<Tile> suggestions) {
|
||||
tintIcons(category, suggestions);
|
||||
|
||||
final DashboardData prevData = mDashboardData;
|
||||
@@ -168,6 +179,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
}
|
||||
|
||||
public void setSuggestionsV2(List<Suggestion> data) {
|
||||
// TODO: Tint icon
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestionsV2(data)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
// TODO: Replicate the metrics logging from setCategoriesAndSuggestions()
|
||||
}
|
||||
|
||||
public void setCategory(DashboardCategory category) {
|
||||
tintIcons(category, null);
|
||||
final DashboardData prevData = mDashboardData;
|
||||
@@ -187,6 +208,10 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
notifyDashboardDataChanged(prevData);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public void onSuggestionDismissed(Tile suggestion) {
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
if (suggestions == null || suggestions.isEmpty()) {
|
||||
@@ -205,6 +230,24 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
}
|
||||
|
||||
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||
final List<Suggestion> list = mDashboardData.getSuggestionsV2();
|
||||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
if (list.size() == 1) {
|
||||
// The only suggestion is dismissed, and the the empty suggestion container will
|
||||
// remain as the dashboard item. Need to refresh the dashboard list.
|
||||
final DashboardData prevData = mDashboardData;
|
||||
mDashboardData = new DashboardData.Builder(prevData)
|
||||
.setSuggestionsV2(null)
|
||||
.build();
|
||||
notifyDashboardDataChanged(prevData);
|
||||
} else {
|
||||
mSuggestionAdapter.removeSuggestion(suggestion);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifySummaryChanged(Tile tile) {
|
||||
final int position = mDashboardData.getPositionByTile(tile);
|
||||
@@ -303,10 +346,18 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mDashboardData.getItemEntityById(itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #getSuggestionV2(int)}.
|
||||
*/
|
||||
@Deprecated
|
||||
public Tile getSuggestion(int position) {
|
||||
return mSuggestionAdapter.getSuggestion(position);
|
||||
}
|
||||
|
||||
public Suggestion getSuggestionV2(int position) {
|
||||
return mSuggestionAdapter.getSuggestionsV2(position);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
void notifyDashboardDataChanged(DashboardData prevData) {
|
||||
if (mFirstFrameDrawn && prevData != null) {
|
||||
@@ -426,15 +477,30 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
int position) {
|
||||
// If there is suggestions to show, it will be at position 0 as we don't show the suggestion
|
||||
// header anymore.
|
||||
final List<Suggestion> suggestionsV2 = mDashboardData.getSuggestionsV2();
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
if (position == SUGGESTION_CONDITION_HEADER_POSITION
|
||||
&& suggestions != null && suggestions.size() > 0) {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
||||
mDashboardData.getItemEntityByPosition(position), mSuggestionsShownLogged);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, mSuggestionParser, mCallback);
|
||||
holder.data.setAdapter(mSuggestionAdapter);
|
||||
} else {
|
||||
|
||||
boolean conditionOnly = true;
|
||||
if (position == SUGGESTION_CONDITION_HEADER_POSITION) {
|
||||
if (suggestions != null && suggestions.size() > 0) {
|
||||
conditionOnly = false;
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
||||
mDashboardData.getItemEntityByPosition(position),
|
||||
null, mSuggestionsShownLogged);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, mSuggestionParser, mCallback);
|
||||
holder.data.setAdapter(mSuggestionAdapter);
|
||||
} else if (suggestionsV2 != null && suggestionsV2.size() > 0) {
|
||||
conditionOnly = false;
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null,
|
||||
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
|
||||
mSuggestionsShownLogged);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, null /* parser */, mCallback);
|
||||
holder.data.setAdapter(mSuggestionAdapter);
|
||||
}
|
||||
}
|
||||
if (conditionOnly) {
|
||||
ConditionAdapter adapter = new ConditionAdapter(mContext,
|
||||
(List<Condition>) mDashboardData.getItemEntityByPosition(position),
|
||||
mDashboardData.getSuggestionConditionMode());
|
||||
@@ -482,11 +548,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
}
|
||||
|
||||
void onSaveInstanceState(Bundle outState) {
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
final DashboardCategory category = mDashboardData.getCategory();
|
||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
||||
final List<Suggestion> suggestionV2 = mDashboardData.getSuggestionsV2();
|
||||
if (suggestions != null) {
|
||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST, new ArrayList<>(suggestions));
|
||||
}
|
||||
if (suggestionV2 != null) {
|
||||
outState.putParcelableArrayList(STATE_SUGGESTION_LIST_V2,
|
||||
new ArrayList<>(suggestionV2));
|
||||
}
|
||||
if (category != null) {
|
||||
outState.putParcelable(STATE_CATEGORY_LIST, category);
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.dashboard;
|
||||
|
||||
import android.annotation.IntDef;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.util.DiffUtil;
|
||||
import android.text.TextUtils;
|
||||
@@ -69,6 +70,7 @@ public class DashboardData {
|
||||
private final DashboardCategory mCategory;
|
||||
private final List<Condition> mConditions;
|
||||
private final List<Tile> mSuggestions;
|
||||
private final List<Suggestion> mSuggestionsV2;
|
||||
@HeaderMode
|
||||
private final int mSuggestionConditionMode;
|
||||
|
||||
@@ -76,6 +78,7 @@ public class DashboardData {
|
||||
mCategory = builder.mCategory;
|
||||
mConditions = builder.mConditions;
|
||||
mSuggestions = builder.mSuggestions;
|
||||
mSuggestionsV2 = builder.mSuggestionsV2;
|
||||
mSuggestionConditionMode = builder.mSuggestionConditionMode;
|
||||
|
||||
mItems = new ArrayList<>();
|
||||
@@ -124,6 +127,10 @@ public class DashboardData {
|
||||
return mSuggestions;
|
||||
}
|
||||
|
||||
public List<Suggestion> getSuggestionsV2() {
|
||||
return mSuggestionsV2;
|
||||
}
|
||||
|
||||
public int getSuggestionConditionMode() {
|
||||
return mSuggestionConditionMode;
|
||||
}
|
||||
@@ -190,13 +197,22 @@ public class DashboardData {
|
||||
* and mIsShowingAll, mSuggestionConditionMode flag.
|
||||
*/
|
||||
private void buildItemsData() {
|
||||
final boolean hasSuggestions = sizeOf(mSuggestions) > 0;
|
||||
final boolean useSuggestionV2 = mSuggestionsV2 != null;
|
||||
final boolean hasSuggestions = useSuggestionV2
|
||||
? sizeOf(mSuggestionsV2) > 0
|
||||
: sizeOf(mSuggestions) > 0;
|
||||
final List<Condition> conditions = getConditionsToShow(mConditions);
|
||||
final boolean hasConditions = sizeOf(conditions) > 0;
|
||||
|
||||
final List<Tile> suggestions = getSuggestionsToShow(mSuggestions);
|
||||
final int hiddenSuggestion =
|
||||
hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
||||
final List<Suggestion> suggestionsV2 = getSuggestionsV2ToShow(mSuggestionsV2);
|
||||
|
||||
final int hiddenSuggestion;
|
||||
if (useSuggestionV2) {
|
||||
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestionsV2) - sizeOf(suggestionsV2) : 0;
|
||||
} else {
|
||||
hiddenSuggestion = hasSuggestions ? sizeOf(mSuggestions) - sizeOf(suggestions) : 0;
|
||||
}
|
||||
|
||||
final boolean hasSuggestionAndCollapsed = hasSuggestions
|
||||
&& mSuggestionConditionMode == HEADER_MODE_COLLAPSED;
|
||||
@@ -215,10 +231,15 @@ public class DashboardData {
|
||||
R.layout.suggestion_condition_header,
|
||||
STABLE_ID_SUGGESTION_CONDITION_MIDDLE_HEADER, onlyHasConditionAndCollapsed);
|
||||
|
||||
/* Suggestion container. This is the card view that contains the list of suggestions.
|
||||
* This will be added whenever the suggestion list is not empty */
|
||||
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
||||
if (useSuggestionV2) {
|
||||
addToItemList(suggestionsV2, R.layout.suggestion_condition_container,
|
||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestionsV2) > 0);
|
||||
} else {
|
||||
/* Suggestion container. This is the card view that contains the list of suggestions.
|
||||
* This will be added whenever the suggestion list is not empty */
|
||||
addToItemList(suggestions, R.layout.suggestion_condition_container,
|
||||
STABLE_ID_SUGGESTION_CONTAINER, sizeOf(suggestions) > 0);
|
||||
}
|
||||
|
||||
/* Second suggestion/condition header. This will be added when there is at least one
|
||||
* suggestion or condition that is not currently displayed, and the user can expand the
|
||||
@@ -246,7 +267,7 @@ public class DashboardData {
|
||||
&& !hasConditions
|
||||
&& hiddenSuggestion == 0);
|
||||
|
||||
if(mCategory != null) {
|
||||
if (mCategory != null) {
|
||||
for (int j = 0; j < mCategory.tiles.size(); j++) {
|
||||
final Tile tile = mCategory.tiles.get(j);
|
||||
addToItemList(tile, R.layout.dashboard_tile, Objects.hash(tile.title),
|
||||
@@ -274,6 +295,10 @@ public class DashboardData {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #getSuggestionsV2ToShow}.
|
||||
*/
|
||||
@Deprecated
|
||||
private List<Tile> getSuggestionsToShow(List<Tile> suggestions) {
|
||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||
return null;
|
||||
@@ -285,6 +310,17 @@ public class DashboardData {
|
||||
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
||||
}
|
||||
|
||||
private List<Suggestion> getSuggestionsV2ToShow(List<Suggestion> suggestions) {
|
||||
if (suggestions == null || mSuggestionConditionMode == HEADER_MODE_COLLAPSED) {
|
||||
return null;
|
||||
}
|
||||
if (mSuggestionConditionMode != HEADER_MODE_DEFAULT
|
||||
|| suggestions.size() <= DEFAULT_SUGGESTION_COUNT) {
|
||||
return suggestions;
|
||||
}
|
||||
return suggestions.subList(0, DEFAULT_SUGGESTION_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Builder used to build the ItemsData
|
||||
* <p>
|
||||
@@ -296,7 +332,12 @@ public class DashboardData {
|
||||
|
||||
private DashboardCategory mCategory;
|
||||
private List<Condition> mConditions;
|
||||
/**
|
||||
* @deprecated in favor of SuggestionList
|
||||
*/
|
||||
@Deprecated
|
||||
private List<Tile> mSuggestions;
|
||||
private List<Suggestion> mSuggestionsV2;
|
||||
|
||||
public Builder() {
|
||||
}
|
||||
@@ -305,6 +346,7 @@ public class DashboardData {
|
||||
mCategory = dashboardData.mCategory;
|
||||
mConditions = dashboardData.mConditions;
|
||||
mSuggestions = dashboardData.mSuggestions;
|
||||
mSuggestionsV2 = dashboardData.mSuggestionsV2;
|
||||
mSuggestionConditionMode = dashboardData.mSuggestionConditionMode;
|
||||
}
|
||||
|
||||
@@ -318,11 +360,20 @@ public class DashboardData {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #setSuggestionsV2(List)})}
|
||||
*/
|
||||
@Deprecated
|
||||
public Builder setSuggestions(List<Tile> suggestions) {
|
||||
this.mSuggestions = suggestions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSuggestionsV2(List<Suggestion> suggestions) {
|
||||
this.mSuggestionsV2 = suggestions;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setSuggestionConditionMode(@HeaderMode int mode) {
|
||||
this.mSuggestionConditionMode = mode;
|
||||
return this;
|
||||
|
@@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.util.Log;
|
||||
@@ -36,9 +37,9 @@ import com.android.settings.dashboard.conditional.ConditionManager;
|
||||
import com.android.settings.dashboard.conditional.ConditionManager.ConditionListener;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionControllerMixin;
|
||||
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settings.widget.ActionBarShadowController;
|
||||
@@ -55,7 +56,8 @@ import java.util.List;
|
||||
|
||||
public class DashboardSummary extends InstrumentedFragment
|
||||
implements CategoryListener, ConditionListener,
|
||||
FocusListener, SuggestionDismissController.Callback {
|
||||
FocusListener, SuggestionDismissController.Callback,
|
||||
SuggestionControllerMixin.SuggestionControllerHost {
|
||||
public static final boolean DEBUG = false;
|
||||
private static final boolean DEBUG_TIMING = false;
|
||||
private static final int MAX_WAIT_MILLIS = 700;
|
||||
@@ -86,7 +88,12 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
mSuggestionControllerMixin = new SuggestionControllerMixin(context, getLifecycle());
|
||||
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
|
||||
.getSuggestionFeatureProvider(context);
|
||||
if (mSuggestionFeatureProvider.isSuggestionV2Enabled(context)) {
|
||||
mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
|
||||
getLifecycle());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -96,8 +103,6 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
final Activity activity = getActivity();
|
||||
mDashboardFeatureProvider = FeatureFactory.getFactory(activity)
|
||||
.getDashboardFeatureProvider(activity);
|
||||
mSuggestionFeatureProvider = FeatureFactory.getFactory(activity)
|
||||
.getSuggestionFeatureProvider(activity);
|
||||
|
||||
mSummaryLoader = new SummaryLoader(activity, CategoryKey.CATEGORY_HOMEPAGE);
|
||||
|
||||
@@ -109,8 +114,7 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mSuggestionsChecks = new SuggestionsChecks(getContext());
|
||||
}
|
||||
if (DEBUG_TIMING) {
|
||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime)
|
||||
+ " ms");
|
||||
Log.d(TAG, "onCreate took " + (System.currentTimeMillis() - startTime) + " ms");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,12 +225,12 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
void rebuildUI() {
|
||||
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
|
||||
Log.d(TAG, "Suggestion feature is disabled, skipping suggestion entirely");
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
updateCategory();
|
||||
} else {
|
||||
new SuggestionLoader().execute();
|
||||
// Set categories on their own if loading suggestions takes too long.
|
||||
mHandler.postDelayed(() -> {
|
||||
updateCategoryAndSuggestion(null /* tiles */);
|
||||
updateCategory();
|
||||
}, MAX_WAIT_MILLIS);
|
||||
}
|
||||
}
|
||||
@@ -263,6 +267,11 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Suggestion getSuggestionAt(int position) {
|
||||
return mAdapter.getSuggestionV2(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Tile getSuggestionForPosition(int position) {
|
||||
return mAdapter.getSuggestion(position);
|
||||
@@ -273,6 +282,20 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
mAdapter.onSuggestionDismissed(suggestion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuggestionDismissed(Suggestion suggestion) {
|
||||
mAdapter.onSuggestionDismissed(suggestion);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuggestionReady(List<Suggestion> suggestions) {
|
||||
mAdapter.setSuggestionsV2(suggestions);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of the real SuggestionLoader.
|
||||
*/
|
||||
@Deprecated
|
||||
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
||||
@Override
|
||||
protected List<Tile> doInBackground(Void... params) {
|
||||
@@ -311,6 +334,17 @@ public class DashboardSummary extends InstrumentedFragment
|
||||
}
|
||||
}
|
||||
|
||||
void updateCategory() {
|
||||
final DashboardCategory category = mDashboardFeatureProvider.getTilesForCategory(
|
||||
CategoryKey.CATEGORY_HOMEPAGE);
|
||||
mSummaryLoader.updateSummaryToCache(category);
|
||||
mAdapter.setCategory(category);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor of SuggestionControllerMixin.
|
||||
*/
|
||||
@Deprecated
|
||||
@VisibleForTesting
|
||||
void updateCategoryAndSuggestion(List<Tile> suggestions) {
|
||||
final Activity activity = getActivity();
|
||||
|
@@ -15,13 +15,17 @@
|
||||
*/
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsActivity;
|
||||
@@ -40,14 +44,18 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
private final Context mContext;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||
private List<Tile> mSuggestions;
|
||||
@Deprecated // in favor of mNewSuggestions
|
||||
private final List<Tile> mSuggestions;
|
||||
private final List<Suggestion> mSuggestionsV2;
|
||||
private final IconCache mCache;
|
||||
private final List<String> mSuggestionsShownLogged;
|
||||
|
||||
public SuggestionAdapter(Context context, List<Tile> suggestions,
|
||||
List<Suggestion> suggestionsV2,
|
||||
List<String> suggestionsShownLogged) {
|
||||
mContext = context;
|
||||
mSuggestions = suggestions;
|
||||
mSuggestionsV2 = suggestionsV2;
|
||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||
mCache = new IconCache(context);
|
||||
final FeatureFactory factory = FeatureFactory.getFactory(context);
|
||||
@@ -65,6 +73,68 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(DashboardItemHolder holder, int position) {
|
||||
if (mSuggestions != null) {
|
||||
bindSuggestionTile(holder, position);
|
||||
} else {
|
||||
bindSuggestion(holder, position);
|
||||
}
|
||||
}
|
||||
|
||||
private void bindSuggestion(DashboardItemHolder holder, int position) {
|
||||
final Suggestion suggestion = mSuggestionsV2.get(position);
|
||||
final String id = suggestion.getId();
|
||||
if (!mSuggestionsShownLogged.contains(id)) {
|
||||
mMetricsFeatureProvider.action(
|
||||
mContext, MetricsEvent.ACTION_SHOW_SETTINGS_SUGGESTION, id);
|
||||
mSuggestionsShownLogged.add(id);
|
||||
}
|
||||
// TODO: Add remote view field in Suggestion, and enable this.
|
||||
// if (suggestion.remoteViews != null) {
|
||||
// final ViewGroup itemView = (ViewGroup) holder.itemView;
|
||||
// itemView.removeAllViews();
|
||||
// itemView.addView(suggestion.remoteViews.apply(itemView.getContext(),
|
||||
// itemView));
|
||||
// } else
|
||||
{
|
||||
// TODO: Add icon field in Suggestion, and enable this.
|
||||
// holder.icon.setImageDrawable(mCache.getIcon(suggestion.icon));
|
||||
holder.title.setText(suggestion.getTitle());
|
||||
final CharSequence summary = suggestion.getSummary();
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
holder.summary.setText(summary);
|
||||
holder.summary.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
holder.summary.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
final View divider = holder.itemView.findViewById(R.id.divider);
|
||||
if (divider != null) {
|
||||
divider.setVisibility(position < mSuggestionsV2.size() - 1 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
View clickHandler = holder.itemView;
|
||||
// If a view with @android:id/primary is defined, use that as the click handler
|
||||
// instead.
|
||||
final View primaryAction = holder.itemView.findViewById(android.R.id.primary);
|
||||
if (primaryAction != null) {
|
||||
clickHandler = primaryAction;
|
||||
// set the item view to disabled to remove any touch effects
|
||||
holder.itemView.setEnabled(false);
|
||||
}
|
||||
clickHandler.setOnClickListener(v -> {
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_SUGGESTION, id);
|
||||
try {
|
||||
suggestion.getPendingIntent().send();
|
||||
} catch (PendingIntent.CanceledException e) {
|
||||
Log.w(TAG, "Failed to start suggestion " + suggestion.getTitle());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated in favor {@link #bindSuggestion(DashboardItemHolder, int)}.
|
||||
*/
|
||||
@Deprecated
|
||||
private void bindSuggestionTile(DashboardItemHolder holder, int position) {
|
||||
final Tile suggestion = (Tile) mSuggestions.get(position);
|
||||
final String suggestionId = mSuggestionFeatureProvider.getSuggestionIdentifier(
|
||||
mContext, suggestion);
|
||||
@@ -113,20 +183,39 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return Objects.hash(mSuggestions.get(position).title);
|
||||
if (mSuggestions != null) {
|
||||
return Objects.hash(mSuggestions.get(position).title);
|
||||
} else {
|
||||
return Objects.hash(mSuggestionsV2.get(position).getId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
Tile suggestion = getSuggestion(position);
|
||||
return suggestion.remoteViews != null
|
||||
? R.layout.suggestion_tile_remote_container
|
||||
: R.layout.suggestion_tile;
|
||||
if (mSuggestions != null) {
|
||||
Tile suggestion = getSuggestion(position);
|
||||
|
||||
return suggestion.remoteViews != null
|
||||
? R.layout.suggestion_tile_remote_container
|
||||
: R.layout.suggestion_tile;
|
||||
} else {
|
||||
|
||||
return R.layout.suggestion_tile;
|
||||
// TODO: Add remote view field in Suggestion, and enable this.
|
||||
// Suggestion suggestion = getSuggestionsV2(position);
|
||||
// return suggestion.remoteViews != null
|
||||
// ? R.layout.suggestion_tile_remote_container
|
||||
// : R.layout.suggestion_tile;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mSuggestions.size();
|
||||
if (mSuggestions != null) {
|
||||
return mSuggestions.size();
|
||||
} else {
|
||||
return mSuggestionsV2.size();
|
||||
}
|
||||
}
|
||||
|
||||
public Tile getSuggestion(int position) {
|
||||
@@ -139,6 +228,16 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
return null;
|
||||
}
|
||||
|
||||
public Suggestion getSuggestionsV2(int position) {
|
||||
final long itemId = getItemId(position);
|
||||
for (Suggestion suggestion : mSuggestionsV2) {
|
||||
if (Objects.hash(suggestion.getId()) == itemId) {
|
||||
return suggestion;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeSuggestion(Tile suggestion) {
|
||||
mSuggestions.remove(suggestion);
|
||||
notifyDataSetChanged();
|
||||
@@ -149,4 +248,8 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
mSuggestionFeatureProvider.isSmartSuggestionEnabled(mContext));
|
||||
}
|
||||
|
||||
public void removeSuggestion(Suggestion suggestion) {
|
||||
mSuggestionsV2.remove(suggestion);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
@@ -16,11 +16,12 @@
|
||||
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.app.LoaderManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Loader;
|
||||
import android.os.Bundle;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
@@ -34,23 +35,32 @@ import java.util.List;
|
||||
* Manages IPC communication to SettingsIntelligence for suggestion related services.
|
||||
*/
|
||||
public class SuggestionControllerMixin implements SuggestionController.ServiceConnectionListener,
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
LifecycleObserver, OnStart, OnStop, LoaderManager.LoaderCallbacks<List<Suggestion>> {
|
||||
|
||||
public interface SuggestionControllerHost {
|
||||
/**
|
||||
* Called when suggestion data fetching is ready.
|
||||
*/
|
||||
void onSuggestionReady(List<Suggestion> data);
|
||||
|
||||
/**
|
||||
* Returns {@link LoaderManager} associated with the host.
|
||||
*/
|
||||
LoaderManager getLoaderManager();
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static final String FEATURE_FLAG = "new_settings_suggestion";
|
||||
private static final String TAG = "SuggestionCtrlMixin";
|
||||
private static final boolean DEBUG = false;
|
||||
|
||||
private final Context mContext;
|
||||
private final SuggestionController mSuggestionController;
|
||||
private final SuggestionControllerHost mHost;
|
||||
|
||||
public static boolean isEnabled() {
|
||||
return FeatureFlagUtils.isEnabled(FEATURE_FLAG);
|
||||
}
|
||||
|
||||
public SuggestionControllerMixin(Context context, Lifecycle lifecycle) {
|
||||
public SuggestionControllerMixin(Context context, SuggestionControllerHost host,
|
||||
Lifecycle lifecycle) {
|
||||
mContext = context.getApplicationContext();
|
||||
mSuggestionController = new SuggestionController(context,
|
||||
mHost = host;
|
||||
mSuggestionController = new SuggestionController(mContext,
|
||||
new ComponentName(
|
||||
"com.android.settings.intelligence",
|
||||
"com.android.settings.intelligence.suggestions.SuggestionService"),
|
||||
@@ -62,10 +72,6 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (!isEnabled()) {
|
||||
Log.w(TAG, "Feature not enabled, skipping");
|
||||
return;
|
||||
}
|
||||
mSuggestionController.start();
|
||||
}
|
||||
|
||||
@@ -76,11 +82,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
|
||||
@Override
|
||||
public void onServiceConnected() {
|
||||
// TODO: Call API to get data from a loader instead of in current thread.
|
||||
final List<Suggestion> data = mSuggestionController.getSuggestions();
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "data size " + (data == null ? 0 : data.size()));
|
||||
}
|
||||
mHost.getLoaderManager().restartLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS,
|
||||
null /* args */, this /* callback */);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -88,5 +91,24 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "SuggestionService disconnected");
|
||||
}
|
||||
mHost.getLoaderManager().destroyLoader(SuggestionLoader.LOADER_ID_SUGGESTIONS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<List<Suggestion>> onCreateLoader(int id, Bundle args) {
|
||||
if (id == SuggestionLoader.LOADER_ID_SUGGESTIONS) {
|
||||
return new SuggestionLoader(mContext, mSuggestionController);
|
||||
}
|
||||
throw new IllegalArgumentException("This loader id is not supported " + id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<List<Suggestion>> loader, List<Suggestion> data) {
|
||||
mHost.onSuggestionReady(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<List<Suggestion>> loader) {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.helper.ItemTouchHelper;
|
||||
|
||||
@@ -30,18 +31,37 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
||||
public interface Callback {
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #getSuggestionAt(int)}
|
||||
* Returns suggestion tile data from the callback
|
||||
*/
|
||||
@Deprecated
|
||||
Tile getSuggestionForPosition(int position);
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link #onSuggestionDismissed(Suggestion)}
|
||||
* Called when a suggestion is dismissed.
|
||||
*/
|
||||
@Deprecated
|
||||
void onSuggestionDismissed(Tile suggestion);
|
||||
|
||||
/**
|
||||
* Returns suggestion tile data from the callback
|
||||
*/
|
||||
Suggestion getSuggestionAt(int position);
|
||||
|
||||
/**
|
||||
* Called when a suggestion is dismissed.
|
||||
*/
|
||||
void onSuggestionDismissed(Tile suggestion);
|
||||
void onSuggestionDismissed(Suggestion suggestion);
|
||||
}
|
||||
|
||||
private final Context mContext;
|
||||
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of the new Suggestion backend.
|
||||
*/
|
||||
@Deprecated
|
||||
private final SuggestionParser mSuggestionParser;
|
||||
private final Callback mCallback;
|
||||
|
||||
@@ -79,8 +99,15 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
|
||||
if (mCallback == null) {
|
||||
return;
|
||||
}
|
||||
final Tile suggestion = mCallback.getSuggestionForPosition(viewHolder.getAdapterPosition());
|
||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionParser, suggestion);
|
||||
mCallback.onSuggestionDismissed(suggestion);
|
||||
final int position = viewHolder.getAdapterPosition();
|
||||
final Suggestion suggestionV2 = mCallback.getSuggestionAt(position);
|
||||
if (suggestionV2 != null) {
|
||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, suggestionV2);
|
||||
mCallback.onSuggestionDismissed(suggestionV2);
|
||||
} else {
|
||||
final Tile suggestion = mCallback.getSuggestionForPosition(position);
|
||||
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionParser, suggestion);
|
||||
mCallback.onSuggestionDismissed(suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ package com.android.settings.dashboard.suggestions;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
@@ -31,9 +32,16 @@ public interface SuggestionFeatureProvider {
|
||||
|
||||
/**
|
||||
* Whether or not the whole suggestion feature is enabled.
|
||||
* @deprecated in favor of {@link #isSuggestionV2Enabled(Context)}
|
||||
*/
|
||||
@Deprecated
|
||||
boolean isSuggestionEnabled(Context context);
|
||||
|
||||
/**
|
||||
* Whether or not the suggestion v2 feature is enabled.
|
||||
*/
|
||||
boolean isSuggestionV2Enabled(Context context);
|
||||
|
||||
/**
|
||||
* Returns true if smart suggestion should be used instead of xml based SuggestionParser.
|
||||
*/
|
||||
@@ -52,7 +60,9 @@ public interface SuggestionFeatureProvider {
|
||||
*
|
||||
* @param suggestions List of suggestion Tiles
|
||||
* @param suggestionIds List of suggestion ids corresponding to the suggestion tiles.
|
||||
* @deprecated in favor of SettingsIntelligence
|
||||
*/
|
||||
@Deprecated
|
||||
void rankSuggestions(final List<Tile> suggestions, List<String> suggestionIds);
|
||||
|
||||
/**
|
||||
@@ -62,9 +72,17 @@ public interface SuggestionFeatureProvider {
|
||||
|
||||
/**
|
||||
* Dismisses a suggestion.
|
||||
*
|
||||
* @deprecated in favor of {@link #dismissSuggestion(Context, Suggestion)}
|
||||
*/
|
||||
@Deprecated
|
||||
void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion);
|
||||
|
||||
/**
|
||||
* Dismisses a suggestion.
|
||||
*/
|
||||
void dismissSuggestion(Context context, Suggestion suggestion);
|
||||
|
||||
/**
|
||||
* Returns an identifier for the suggestion
|
||||
*/
|
||||
|
@@ -23,11 +23,14 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.provider.Settings.Secure;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.FeatureFlagUtils;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.Settings.AmbientDisplayPickupSuggestionActivity;
|
||||
import com.android.settings.Settings.AmbientDisplaySuggestionActivity;
|
||||
@@ -46,7 +49,6 @@ import com.android.settings.support.NewDeviceIntroSuggestionActivity;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
import com.android.settingslib.suggestions.SuggestionParser;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider {
|
||||
@@ -55,6 +57,8 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
private static final int EXCLUSIVE_SUGGESTION_MAX_COUNT = 3;
|
||||
|
||||
private static final String SHARED_PREF_FILENAME = "suggestions";
|
||||
@VisibleForTesting
|
||||
static final String FEATURE_FLAG_SUGGESTIONS_V2 = "new_settings_suggestion";
|
||||
|
||||
private final SuggestionRanker mSuggestionRanker;
|
||||
private final MetricsFeatureProvider mMetricsFeatureProvider;
|
||||
@@ -63,7 +67,20 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
public boolean isSuggestionEnabled(Context context) {
|
||||
final ActivityManager am =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
return !am.isLowRamDevice();
|
||||
boolean isLowRamDevice = am.isLowRamDevice();
|
||||
return !isLowRamDevice && !isV2Enabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSuggestionV2Enabled(Context context) {
|
||||
final ActivityManager am =
|
||||
(ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
||||
boolean isLowRamDevice = am.isLowRamDevice();
|
||||
return !isLowRamDevice && isV2Enabled();
|
||||
}
|
||||
|
||||
private static boolean isV2Enabled() {
|
||||
return FeatureFlagUtils.isEnabled(FEATURE_FLAG_SUGGESTIONS_V2);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -148,6 +165,17 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
|
||||
PackageManager.DONT_KILL_APP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismissSuggestion(Context context, Suggestion suggestion) {
|
||||
if (suggestion == null || context == null) {
|
||||
return;
|
||||
}
|
||||
mMetricsFeatureProvider.action(
|
||||
context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
|
||||
suggestion.getId());
|
||||
// TODO: Call SettingsIntelligence to dismiss suggestion.
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSuggestionIdentifier(Context context, Tile suggestion) {
|
||||
if (suggestion.intent == null || suggestion.intent.getComponent() == null
|
||||
|
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.dashboard.suggestions;
|
||||
|
||||
import android.content.Context;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.utils.AsyncLoader;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class SuggestionLoader extends AsyncLoader<List<Suggestion>> {
|
||||
|
||||
public static final int LOADER_ID_SUGGESTIONS = 42;
|
||||
private static final String TAG = "SuggestionLoader";
|
||||
|
||||
private final SuggestionController mSuggestionController;
|
||||
|
||||
public SuggestionLoader(Context context, SuggestionController controller) {
|
||||
super(context);
|
||||
mSuggestionController = controller;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDiscardResult(List<Suggestion> result) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Suggestion> loadInBackground() {
|
||||
final List<Suggestion> data = mSuggestionController.getSuggestions();
|
||||
if (data == null) {
|
||||
Log.d(TAG, "data is null");
|
||||
} else {
|
||||
Log.d(TAG, "data size " + data.size());
|
||||
}
|
||||
return data;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user