Call SuggestionService.launch when click suggestion.
Bug: 68267490 Test: robotests Change-Id: I8614f256fc1a87395b5c9d41e3621164a2ded5e1
This commit is contained in:
@@ -430,16 +430,16 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
if (position == SUGGESTION_CONDITION_HEADER_POSITION) {
|
||||
if (suggestions != null && suggestions.size() > 0) {
|
||||
conditionOnly = false;
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, (List<Tile>)
|
||||
mDashboardData.getItemEntityByPosition(position),
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
(List<Tile>) mDashboardData.getItemEntityByPosition(position),
|
||||
null, mSuggestionsShownLogged);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, mSuggestionControllerMixin, 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),
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null, (List<Suggestion>) mDashboardData.getItemEntityByPosition(position),
|
||||
mSuggestionsShownLogged);
|
||||
mSuggestionDismissHandler = new SuggestionDismissController(mContext,
|
||||
holder.data, mSuggestionControllerMixin, null /* parser */, mCallback);
|
||||
|
@@ -48,11 +48,13 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
private final List<Suggestion> mSuggestionsV2;
|
||||
private final IconCache mCache;
|
||||
private final List<String> mSuggestionsShownLogged;
|
||||
private final SuggestionControllerMixin mSuggestionControllerMixin;
|
||||
|
||||
public SuggestionAdapter(Context context, List<Tile> suggestions,
|
||||
List<Suggestion> suggestionsV2,
|
||||
public SuggestionAdapter(Context context, SuggestionControllerMixin suggestionControllerMixin,
|
||||
List<Tile> suggestions, List<Suggestion> suggestionsV2,
|
||||
List<String> suggestionsShownLogged) {
|
||||
mContext = context;
|
||||
mSuggestionControllerMixin = suggestionControllerMixin;
|
||||
mSuggestions = suggestions;
|
||||
mSuggestionsV2 = suggestionsV2;
|
||||
mSuggestionsShownLogged = suggestionsShownLogged;
|
||||
@@ -112,6 +114,7 @@ public class SuggestionAdapter extends RecyclerView.Adapter<DashboardItemHolder>
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_SETTINGS_SUGGESTION, id);
|
||||
try {
|
||||
suggestion.getPendingIntent().send();
|
||||
mSuggestionControllerMixin.launchSuggestion(suggestion);
|
||||
} catch (PendingIntent.CanceledException e) {
|
||||
Log.w(TAG, "Failed to start suggestion " + suggestion.getTitle());
|
||||
}
|
||||
|
@@ -122,6 +122,19 @@ public class SuggestionController {
|
||||
}
|
||||
}
|
||||
|
||||
public void launchSuggestion(Suggestion suggestion) {
|
||||
if (!isReady()) {
|
||||
Log.w(TAG, "SuggestionController not ready, cannot launch " + suggestion.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
mRemoteService.launchSuggestion(suggestion);
|
||||
} catch (RemoteException e) {
|
||||
Log.w(TAG, "Error when calling launchSuggestion()", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the manager is ready
|
||||
*/
|
||||
|
@@ -115,4 +115,8 @@ public class SuggestionControllerMixin implements SuggestionController.ServiceCo
|
||||
public void dismissSuggestion(Suggestion suggestion) {
|
||||
mSuggestionController.dismissSuggestions(suggestion);
|
||||
}
|
||||
|
||||
public void launchSuggestion(Suggestion suggestion) {
|
||||
mSuggestionController.launchSuggestion(suggestion);
|
||||
}
|
||||
}
|
||||
|
@@ -67,6 +67,8 @@ public class SuggestionAdapterTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private SettingsActivity mActivity;
|
||||
@Mock
|
||||
private SuggestionControllerMixin mSuggestionControllerMixin;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
private Context mContext;
|
||||
private SuggestionAdapter mSuggestionAdapter;
|
||||
@@ -108,38 +110,38 @@ public class SuggestionAdapterTest {
|
||||
|
||||
@Test
|
||||
public void getItemCount_shouldReturnListSize() {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||
null /* suggestionV2 */, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
||||
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mTwoSuggestions,
|
||||
null /* suggestionV2 */, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
mTwoSuggestions, null /* suggestionV2 */, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemCount_v2_shouldReturnListSize() {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||
mOneSuggestionV2, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null /* suggestions */, mOneSuggestionV2, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(1);
|
||||
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||
mTwoSuggestionsV2, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null /* suggestions */, mTwoSuggestionsV2, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemCount()).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_shouldReturnSuggestionTile() {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||
null /* suggestionV2 */, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||
.isEqualTo(R.layout.suggestion_tile);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getItemViewType_v2_shouldReturnSuggestionTile() {
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||
mOneSuggestionV2, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null /* suggestions */, mOneSuggestionV2, new ArrayList<>());
|
||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||
.isEqualTo(R.layout.suggestion_tile);
|
||||
}
|
||||
@@ -152,8 +154,8 @@ public class SuggestionAdapterTest {
|
||||
.setTitle("123")
|
||||
.setSummary("456")
|
||||
.build());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestions */,
|
||||
suggestions, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null /* suggestions */, suggestions, new ArrayList<>());
|
||||
|
||||
assertThat(mSuggestionAdapter.getItemViewType(0))
|
||||
.isEqualTo(R.layout.suggestion_tile_with_button);
|
||||
@@ -164,8 +166,8 @@ public class SuggestionAdapterTest {
|
||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
||||
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
||||
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mOneSuggestion,
|
||||
null /* suggestionV2 */, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
mOneSuggestion, null /* suggestionV2 */, new ArrayList<>());
|
||||
|
||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||
|
||||
@@ -177,8 +179,8 @@ public class SuggestionAdapterTest {
|
||||
final View view = spy(LayoutInflater.from(mContext).inflate(
|
||||
R.layout.suggestion_tile, new LinearLayout(mContext), true));
|
||||
mSuggestionHolder = new DashboardAdapter.DashboardItemHolder(view);
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, null /* suggestionV1*/,
|
||||
mOneSuggestionV2, new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(mContext, mSuggestionControllerMixin,
|
||||
null /* suggestionV1*/, mOneSuggestionV2, new ArrayList<>());
|
||||
|
||||
// Bind twice
|
||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||
@@ -236,13 +238,14 @@ public class SuggestionAdapterTest {
|
||||
@Test
|
||||
public void onBindViewHolder_v2_itemViewShouldHandleClick()
|
||||
throws PendingIntent.CanceledException {
|
||||
final List<Suggestion> packages = makeSuggestionsV2("pkg1");
|
||||
setupSuggestions(mActivity, null /* suggestionV1 */, packages);
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
setupSuggestions(mActivity, null /* suggestionV1 */, suggestions);
|
||||
|
||||
mSuggestionAdapter.onBindViewHolder(mSuggestionHolder, 0);
|
||||
mSuggestionHolder.itemView.performClick();
|
||||
|
||||
verify(packages.get(0).getPendingIntent()).send();
|
||||
verify(mSuggestionControllerMixin).launchSuggestion(suggestions.get(0));
|
||||
verify(suggestions.get(0).getPendingIntent()).send();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -285,8 +288,8 @@ public class SuggestionAdapterTest {
|
||||
|
||||
private void setupSuggestions(Context context, List<Tile> suggestions,
|
||||
List<Suggestion> suggestionsV2) {
|
||||
mSuggestionAdapter = new SuggestionAdapter(context, suggestions, suggestionsV2,
|
||||
new ArrayList<>());
|
||||
mSuggestionAdapter = new SuggestionAdapter(context, mSuggestionControllerMixin,
|
||||
suggestions, suggestionsV2, new ArrayList<>());
|
||||
mSuggestionHolder = mSuggestionAdapter.onCreateViewHolder(
|
||||
new FrameLayout(RuntimeEnvironment.application),
|
||||
mSuggestionAdapter.getItemViewType(0));
|
||||
|
Reference in New Issue
Block a user