OSDN Git Service

Fix missing summaries
authorJason Monk <jmonk@google.com>
Thu, 31 Mar 2016 17:59:46 +0000 (13:59 -0400)
committerJason Monk <jmonk@google.com>
Thu, 31 Mar 2016 17:59:46 +0000 (13:59 -0400)
Handle non-cached tiles by doing lookup from component name.

Change-Id: I979e2df2eed4a065f290c5c0e66276d08b4fb0af
Fixes: 27942733

src/com/android/settings/dashboard/DashboardAdapter.java
src/com/android/settings/dashboard/SummaryLoader.java

index 8082f62..292244c 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.android.settings.dashboard;
 
+import android.content.ComponentName;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.support.v7.widget.PopupMenu;
@@ -96,6 +97,18 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
         recountItems();
     }
 
+    public Tile getTile(ComponentName component) {
+        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 setCategories(List<DashboardCategory> categories) {
         mCategories = categories;
 
index e6c1243..86cffde 100644 (file)
@@ -16,6 +16,7 @@
 package com.android.settings.dashboard;
 
 import android.app.Activity;
+import android.content.ComponentName;
 import android.os.Bundle;
 import android.os.Handler;
 import android.os.HandlerThread;
@@ -38,7 +39,7 @@ public class SummaryLoader {
     public static final String SUMMARY_PROVIDER_FACTORY = "SUMMARY_PROVIDER_FACTORY";
 
     private final Activity mActivity;
-    private final ArrayMap<SummaryProvider, Tile> mSummaryMap = new ArrayMap<>();
+    private final ArrayMap<SummaryProvider, ComponentName> mSummaryMap = new ArrayMap<>();
     private final List<Tile> mTiles = new ArrayList<>();
 
     private final Worker mWorker;
@@ -74,10 +75,15 @@ public class SummaryLoader {
     }
 
     public void setSummary(SummaryProvider provider, final CharSequence summary) {
-        final Tile tile = mSummaryMap.get(provider);
+        final ComponentName component= mSummaryMap.get(provider);
         mHandler.post(new Runnable() {
             @Override
             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);
                 tile.summary = summary;
                 mAdapter.notifyChanged(tile);
             }
@@ -138,7 +144,7 @@ public class SummaryLoader {
         SummaryProvider provider = getSummaryProvider(tile);
         if (provider != null) {
             if (DEBUG) Log.d(TAG, "Creating " + tile);
-            mSummaryMap.put(provider, tile);
+            mSummaryMap.put(provider, tile.intent.getComponent());
             if (mListening) {
                 // If we are somehow already listening, put the provider in that state.
                 provider.setListening(true);