Plumb SuggestionControllerMixin to DismissController.

- The SuggestionControllerMixin is needed to dismiss a suggestion.
- When swipe a suggestion, SuggestionControllerMixin is called, which
  then calls API in SuggestionService to dismiss a suggestion.

Bug: 65065268
Test: robotests
Change-Id: I6a0c5823d60b995ab4a36b1c91777f5cd31a500d
This commit is contained in:
Fan Zhang
2017-09-25 16:44:28 -07:00
parent 9aae9d5d80
commit cd7b13bba5
10 changed files with 80 additions and 21 deletions

View File

@@ -47,6 +47,8 @@ import com.android.settings.dashboard.DashboardData.SuggestionConditionHeaderDat
import com.android.settings.dashboard.conditional.Condition;
import com.android.settings.dashboard.conditional.ConditionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionAdapter;
import com.android.settings.dashboard.suggestions.SuggestionController;
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.SuggestionLogHelper;
@@ -76,6 +78,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
private final IconCache mCache;
private final Context mContext;
private final SuggestionControllerMixin mSuggestionControllerMixin;
private final MetricsFeatureProvider mMetricsFeatureProvider;
private final DashboardFeatureProvider mDashboardFeatureProvider;
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
@@ -100,6 +103,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
public DashboardAdapter(Context context, Bundle savedInstanceState,
List<Condition> conditions, SuggestionParser suggestionParser,
SuggestionControllerMixin suggestionControllerMixin,
SuggestionDismissController.Callback callback) {
// @deprecated In favor of suggestionsV2 below.
@@ -110,6 +114,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
mContext = context;
final FeatureFactory factory = FeatureFactory.getFactory(context);
mSuggestionControllerMixin = suggestionControllerMixin;
mMetricsFeatureProvider = factory.getMetricsFeatureProvider();
mDashboardFeatureProvider = factory.getDashboardFeatureProvider(context);
mSuggestionFeatureProvider = factory.getSuggestionFeatureProvider(context);
@@ -488,7 +493,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
mDashboardData.getItemEntityByPosition(position),
null, mSuggestionsShownLogged);
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
holder.data, mSuggestionParser, mCallback);
holder.data, mSuggestionControllerMixin, mSuggestionParser, mCallback);
holder.data.setAdapter(mSuggestionAdapter);
} else if (suggestionsV2 != null && suggestionsV2.size() > 0) {
conditionOnly = false;
@@ -496,7 +501,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
(List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
mSuggestionsShownLogged);
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
holder.data, null /* parser */, mCallback);
holder.data, mSuggestionControllerMixin, null /* parser */, mCallback);
holder.data.setAdapter(mSuggestionAdapter);
}
}

View File

@@ -91,6 +91,7 @@ public class DashboardSummary extends InstrumentedFragment
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
.getSuggestionFeatureProvider(context);
if (mSuggestionFeatureProvider.isSuggestionV2Enabled(context)) {
Log.d(TAG, "Suggestion v2 is enabled, creating SuggestionControllerMixin");
mSuggestionControllerMixin = new SuggestionControllerMixin(context, this /* host */,
getLifecycle());
}
@@ -207,7 +208,8 @@ public class DashboardSummary extends InstrumentedFragment
mDashboard.setHasFixedSize(true);
mDashboard.setListener(this);
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions(),
mSuggestionParser, this /* SuggestionDismissController.Callback */);
mSuggestionParser, mSuggestionControllerMixin,
this /* SuggestionDismissController.Callback */);
mDashboard.setAdapter(mAdapter);
mDashboard.setItemAnimator(new DashboardItemAnimator());
mSummaryLoader.setSummaryConsumer(mAdapter);
@@ -224,7 +226,7 @@ public class DashboardSummary extends InstrumentedFragment
@VisibleForTesting
void rebuildUI() {
if (!mSuggestionFeatureProvider.isSuggestionEnabled(getContext())) {
Log.d(TAG, "Suggestion feature is disabled, skipping suggestion entirely");
Log.d(TAG, "Suggestion v1 feature is disabled, skipping suggestion v1");
updateCategory();
} else {
new SuggestionLoader().execute();

View File

@@ -110,6 +110,18 @@ public class SuggestionController {
}
}
public void dismissSuggestions(Suggestion suggestion) {
if (!isReady()) {
Log.w(TAG, "SuggestionController not ready, cannot dismiss " + suggestion.getId());
return;
}
try {
mRemoteService.dismissSuggestion(suggestion);
} catch (RemoteException e) {
Log.w(TAG, "Error when calling dismissSuggestion()", e);
}
}
/**
* Whether or not the manager is ready
*/

View File

@@ -111,4 +111,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
public void onLoaderReset(Loader<List<Suggestion>> loader) {
}
public void dismissSuggestion(Suggestion suggestion) {
mSuggestionController.dismissSuggestions(suggestion);
}
}

View File

@@ -57,6 +57,7 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
private final Context mContext;
private final SuggestionFeatureProvider mSuggestionFeatureProvider;
private final SuggestionControllerMixin mSuggestionMixin;
/**
* @deprecated in favor of the new Suggestion backend.
@@ -66,8 +67,9 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
private final Callback mCallback;
public SuggestionDismissController(Context context, RecyclerView recyclerView,
SuggestionParser parser, Callback callback) {
SuggestionControllerMixin suggestionMixin, SuggestionParser parser, Callback callback) {
super(0, ItemTouchHelper.START | ItemTouchHelper.END);
mSuggestionMixin = suggestionMixin;
mContext = context;
mSuggestionParser = parser;
mSuggestionFeatureProvider = FeatureFactory.getFactory(context)
@@ -102,7 +104,7 @@ public class SuggestionDismissController extends ItemTouchHelper.SimpleCallback
final int position = viewHolder.getAdapterPosition();
final Suggestion suggestionV2 = mCallback.getSuggestionAt(position);
if (suggestionV2 != null) {
mSuggestionFeatureProvider.dismissSuggestion(mContext, suggestionV2);
mSuggestionFeatureProvider.dismissSuggestion(mContext, mSuggestionMixin, suggestionV2);
mCallback.onSuggestionDismissed(suggestionV2);
} else {
final Tile suggestion = mCallback.getSuggestionForPosition(position);

View File

@@ -79,7 +79,8 @@ public interface SuggestionFeatureProvider {
/**
* Dismisses a suggestion.
*
* @deprecated in favor of {@link #dismissSuggestion(Context, Suggestion)}
* @deprecated in favor of {@link #dismissSuggestion(Context, SuggestionControllerMixin,
* Suggestion)}
*/
@Deprecated
void dismissSuggestion(Context context, SuggestionParser parser, Tile suggestion);
@@ -87,7 +88,8 @@ public interface SuggestionFeatureProvider {
/**
* Dismisses a suggestion.
*/
void dismissSuggestion(Context context, Suggestion suggestion);
void dismissSuggestion(Context context, SuggestionControllerMixin suggestionMixin,
Suggestion suggestion);
/**
* Returns an identifier for the suggestion

View File

@@ -173,14 +173,15 @@ public class SuggestionFeatureProviderImpl implements SuggestionFeatureProvider
}
@Override
public void dismissSuggestion(Context context, Suggestion suggestion) {
if (suggestion == null || context == null) {
public void dismissSuggestion(Context context, SuggestionControllerMixin mixin,
Suggestion suggestion) {
if (mixin == null || suggestion == null || context == null) {
return;
}
mMetricsFeatureProvider.action(
context, MetricsProto.MetricsEvent.ACTION_SETTINGS_DISMISS_SUGGESTION,
suggestion.getId());
// TODO: Call SettingsIntelligence to dismiss suggestion.
mixin.dismissSuggestion(suggestion);
}
@Override