Merge "Rebuild suggestions when suggestions are dismissed"
This commit is contained in:
@@ -39,7 +39,6 @@ import com.android.settings.SettingsActivity;
|
|||||||
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
import com.android.settings.core.instrumentation.MetricsFeatureProvider;
|
||||||
import com.android.settings.dashboard.conditional.Condition;
|
import com.android.settings.dashboard.conditional.Condition;
|
||||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||||
import com.android.settings.overlay.FeatureFactory;
|
import com.android.settings.overlay.FeatureFactory;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
@@ -49,7 +48,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.DashboardItemHolder>
|
||||||
implements SummaryLoader.SummaryConsumer, SuggestionDismissController.Callback {
|
implements SummaryLoader.SummaryConsumer {
|
||||||
public static final String TAG = "DashboardAdapter";
|
public static final String TAG = "DashboardAdapter";
|
||||||
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
private static final String STATE_SUGGESTION_LIST = "suggestion_list";
|
||||||
private static final String STATE_CATEGORY_LIST = "category_list";
|
private static final String STATE_CATEGORY_LIST = "category_list";
|
||||||
@@ -342,26 +341,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
|||||||
notifyDashboardDataChanged(prevData);
|
notifyDashboardDataChanged(prevData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public Tile getSuggestionForPosition(int position) {
|
|
||||||
return (Tile) mDashboardData.getItemEntityByPosition(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSuggestionDismissed(Tile suggestion) {
|
|
||||||
final List<Tile> suggestions = mDashboardData.getSuggestions();
|
|
||||||
if (suggestions == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
suggestions.remove(suggestion);
|
|
||||||
|
|
||||||
final DashboardData prevData = mDashboardData;
|
|
||||||
mDashboardData = new DashboardData.Builder(prevData)
|
|
||||||
.setSuggestions(suggestions)
|
|
||||||
.build();
|
|
||||||
notifyDashboardDataChanged(prevData);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
void onBindSuggestionHeader(final DashboardItemHolder holder, DashboardData
|
||||||
.SuggestionHeaderData data) {
|
.SuggestionHeaderData data) {
|
||||||
|
|||||||
@@ -34,7 +34,9 @@ import com.android.settings.core.InstrumentedFragment;
|
|||||||
import com.android.settings.dashboard.conditional.Condition;
|
import com.android.settings.dashboard.conditional.Condition;
|
||||||
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
import com.android.settings.dashboard.conditional.ConditionAdapterUtils;
|
||||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
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;
|
||||||
|
import com.android.settings.dashboard.conditional.FocusRecyclerView.FocusListener;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
import com.android.settings.dashboard.suggestions.SuggestionDismissController;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
|
||||||
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
import com.android.settings.dashboard.suggestions.SuggestionsChecks;
|
||||||
@@ -43,14 +45,15 @@ import com.android.settingslib.SuggestionParser;
|
|||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
import com.android.settingslib.drawer.DashboardCategory;
|
import com.android.settingslib.drawer.DashboardCategory;
|
||||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||||
|
import com.android.settingslib.drawer.SettingsDrawerActivity.CategoryListener;
|
||||||
import com.android.settingslib.drawer.Tile;
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class DashboardSummary extends InstrumentedFragment
|
public class DashboardSummary extends InstrumentedFragment
|
||||||
implements SettingsDrawerActivity.CategoryListener, ConditionManager.ConditionListener,
|
implements CategoryListener, ConditionListener,
|
||||||
FocusRecyclerView.FocusListener {
|
FocusListener, SuggestionDismissController.Callback {
|
||||||
public static final boolean DEBUG = false;
|
public static final boolean DEBUG = false;
|
||||||
private static final boolean DEBUG_TIMING = false;
|
private static final boolean DEBUG_TIMING = false;
|
||||||
private static final int MAX_WAIT_MILLIS = 700;
|
private static final int MAX_WAIT_MILLIS = 700;
|
||||||
@@ -195,7 +198,7 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions());
|
mAdapter = new DashboardAdapter(getContext(), bundle, mConditionManager.getConditions());
|
||||||
mDashboard.setAdapter(mAdapter);
|
mDashboard.setAdapter(mAdapter);
|
||||||
mSuggestionDismissHandler = new SuggestionDismissController(
|
mSuggestionDismissHandler = new SuggestionDismissController(
|
||||||
getContext(), mDashboard, mSuggestionParser, mAdapter);
|
getContext(), mDashboard, mSuggestionParser, this);
|
||||||
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
mDashboard.setItemAnimator(new DashboardItemAnimator());
|
||||||
mSummaryLoader.setSummaryConsumer(mAdapter);
|
mSummaryLoader.setSummaryConsumer(mAdapter);
|
||||||
ConditionAdapterUtils.addDismiss(mDashboard);
|
ConditionAdapterUtils.addDismiss(mDashboard);
|
||||||
@@ -236,6 +239,18 @@ public class DashboardSummary extends InstrumentedFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Tile getSuggestionForPosition(int position) {
|
||||||
|
return (Tile) mAdapter.getItem(mAdapter.getItemId(position));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSuggestionDismissed(Tile suggestion) {
|
||||||
|
// Refresh the UI to pick up suggestions that can now be shown because, say, a higher
|
||||||
|
// priority suggestion has been dismissed, or an exclusive suggestion category is emptied.
|
||||||
|
rebuildUI();
|
||||||
|
}
|
||||||
|
|
||||||
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
private class SuggestionLoader extends AsyncTask<Void, Void, List<Tile>> {
|
||||||
@Override
|
@Override
|
||||||
protected List<Tile> doInBackground(Void... params) {
|
protected List<Tile> doInBackground(Void... params) {
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import com.android.settings.TestConfig;
|
|||||||
import com.android.settings.dashboard.conditional.ConditionManager;
|
import com.android.settings.dashboard.conditional.ConditionManager;
|
||||||
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
import com.android.settings.dashboard.conditional.FocusRecyclerView;
|
||||||
import com.android.settingslib.drawer.CategoryKey;
|
import com.android.settingslib.drawer.CategoryKey;
|
||||||
|
import com.android.settingslib.drawer.Tile;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -109,4 +110,11 @@ public class DashboardSummaryTest {
|
|||||||
mSummary.onCategoriesChanged();
|
mSummary.onCategoriesChanged();
|
||||||
verify(mSummary).rebuildUI();
|
verify(mSummary).rebuildUI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onSuggestionDismissed_categoryShouldBeRefreshed() {
|
||||||
|
doNothing().when(mSummary).rebuildUI();
|
||||||
|
mSummary.onSuggestionDismissed(mock(Tile.class));
|
||||||
|
verify(mSummary).rebuildUI();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user