Load suggestions through SettingsIntelligence.
- Add flag to switch between old/new implementation - Add SuggestionLoader to load using Loader (instead of AsyncTask) - Update DashboardAdapater/SuggestionAdapter to take List<Suggestion> - Marked old getter/setters as @Deprecated and added comment - Update tests to cover suggestionV2 adapter changes. TODO: - Handler for dismissing suggestion not set up yet. - Suggestion data structure is incomplete (missing icon, remote view, etc) - Need to extend Suggestion data strcture to support icon and remote view binding Bug: 65065268 Test: robotests Change-Id: I2378ef4c9edee972d5de93c3868068e2cde23f56
This commit is contained in:
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -35,6 +36,7 @@ import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.service.settings.suggestions.Suggestion;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Pair;
|
||||
@@ -557,6 +559,33 @@ public class DashboardAdapterTest {
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindConditionAndSuggestion_v2_shouldSetSuggestionAdapterAndNoCrash() {
|
||||
mDashboardAdapter = new DashboardAdapter(mContext, null, null, null, null);
|
||||
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
|
||||
final DashboardCategory category = mock(DashboardCategory.class);
|
||||
final List<Tile> tiles = new ArrayList<>();
|
||||
tiles.add(mock(Tile.class));
|
||||
category.tiles = tiles;
|
||||
|
||||
mDashboardAdapter.setSuggestionsV2(suggestions);
|
||||
|
||||
final RecyclerView data = mock(RecyclerView.class);
|
||||
when(data.getResources()).thenReturn(mResources);
|
||||
when(data.getContext()).thenReturn(mContext);
|
||||
when(mResources.getDisplayMetrics()).thenReturn(mock(DisplayMetrics.class));
|
||||
final View itemView = mock(View.class);
|
||||
when(itemView.findViewById(R.id.data)).thenReturn(data);
|
||||
final DashboardAdapter.SuggestionAndConditionContainerHolder holder =
|
||||
new DashboardAdapter.SuggestionAndConditionContainerHolder(itemView);
|
||||
|
||||
mDashboardAdapter.onBindConditionAndSuggestion(
|
||||
holder, DashboardAdapter.SUGGESTION_CONDITION_HEADER_POSITION);
|
||||
|
||||
verify(data).setAdapter(any(SuggestionAdapter.class));
|
||||
// should not crash
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBindConditionAndSuggestion_emptySuggestion_shouldSetConditionAdpater() {
|
||||
final Bundle savedInstance = new Bundle();
|
||||
@@ -598,6 +627,17 @@ public class DashboardAdapterTest {
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
|
||||
final List<Suggestion> suggestions = new ArrayList<>();
|
||||
for (String pkgName : pkgNames) {
|
||||
final Suggestion suggestion = new Suggestion.Builder(pkgName)
|
||||
.setPendingIntent(mock(PendingIntent.class))
|
||||
.build();
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
return suggestions;
|
||||
}
|
||||
|
||||
private void setupSuggestions(List<Tile> suggestions) {
|
||||
mDashboardAdapter.setCategoriesAndSuggestions(null /* category */, suggestions);
|
||||
final Context context = RuntimeEnvironment.application;
|
||||
@@ -605,4 +645,6 @@ public class DashboardAdapterTest {
|
||||
LayoutInflater.from(context).inflate(
|
||||
R.layout.suggestion_condition_header, new RelativeLayout(context), true));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user