Update summary correctly in Settings dashboard.
Bug: 30490325 SummaryLoader needs DashboardCategory to update summary and it currently ask for it from DashboardAdapter. But DashboardCategory is not always available in DashboardAdapter. When SummaryLoader wants to get category from adapter before adapter is ready, it won't have it, causing summary to appear blank sometimes. The fix is to get category from data source directly. Change-Id: I9d7f676954d1cece42d6e03748ab7aa35357f8b7
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.android.settings.dashboard;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -110,21 +109,6 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
return mSuggestions;
|
||||
}
|
||||
|
||||
public Tile getTile(ComponentName component) {
|
||||
if (mCategories == null) {
|
||||
return null;
|
||||
}
|
||||
for (int i = 0; i < mCategories.size(); i++) {
|
||||
for (int j = 0; j < mCategories.get(i).tiles.size(); j++) {
|
||||
Tile tile = mCategories.get(i).tiles.get(j);
|
||||
if (component.equals(tile.intent.getComponent())) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setCategoriesAndSuggestions(List<DashboardCategory> categories,
|
||||
List<Tile> suggestions) {
|
||||
mSuggestions = suggestions;
|
||||
|
@@ -28,8 +28,10 @@ import android.os.Process;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settingslib.drawer.DashboardCategory;
|
||||
import com.android.settingslib.drawer.SettingsDrawerActivity;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -87,9 +89,24 @@ public class SummaryLoader {
|
||||
public void run() {
|
||||
// Since tiles are not always cached (like on locale change for instance),
|
||||
// we need to always get the latest one.
|
||||
Tile tile = mAdapter.getTile(component);
|
||||
if (tile == null) return;
|
||||
if (DEBUG) Log.d(TAG, "setSummary " + tile.title + " - " + summary);
|
||||
if (!(mActivity instanceof SettingsDrawerActivity)) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Can't get category list.");
|
||||
}
|
||||
return;
|
||||
}
|
||||
final List<DashboardCategory> categories =
|
||||
((SettingsDrawerActivity) mActivity).getDashboardCategories();
|
||||
final Tile tile = getTileFromCategory(categories, component);
|
||||
if (tile == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Can't find tile for " + component);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "setSummary " + tile.title + " - " + summary);
|
||||
}
|
||||
tile.summary = summary;
|
||||
mAdapter.notifyChanged(tile);
|
||||
}
|
||||
@@ -187,6 +204,27 @@ public class SummaryLoader {
|
||||
}
|
||||
}
|
||||
|
||||
private Tile getTileFromCategory(List<DashboardCategory> categories, ComponentName component) {
|
||||
if (categories == null) {
|
||||
if (DEBUG) {
|
||||
Log.d(TAG, "Category is null, can't find tile");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
final int categorySize = categories.size();
|
||||
for (int i = 0; i < categorySize; i++) {
|
||||
final DashboardCategory category = categories.get(i);
|
||||
final int tileCount = category.tiles.size();
|
||||
for (int j = 0; j < tileCount; j++) {
|
||||
final Tile tile = category.tiles.get(j);
|
||||
if (component.equals(tile.intent.getComponent())) {
|
||||
return tile;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface SummaryProvider {
|
||||
void setListening(boolean listening);
|
||||
}
|
||||
|
Reference in New Issue
Block a user