зеркало из https://github.com/mozilla/gecko-dev.git
Bug 994734 - Handle dataset refreshes in HomePanelsManager (r=margaret)
This commit is contained in:
Родитель
c0f9d23fd4
Коммит
0d3f0a78f1
|
@ -56,8 +56,7 @@ import android.widget.FrameLayout;
|
|||
* See {@code PanelLayout} for more details on how {@code DynamicPanel}
|
||||
* receives dataset requests and delivers them back to the {@code PanelLayout}.
|
||||
*/
|
||||
public class DynamicPanel extends HomeFragment
|
||||
implements GeckoEventListener {
|
||||
public class DynamicPanel extends HomeFragment {
|
||||
private static final String LOGTAG = "GeckoDynamicPanel";
|
||||
|
||||
// Dataset ID to be used by the loader
|
||||
|
@ -154,7 +153,6 @@ public class DynamicPanel extends HomeFragment
|
|||
}
|
||||
|
||||
mPanelAuthCache.setOnChangeListener(new PanelAuthChangeListener());
|
||||
GeckoAppShell.registerEventListener("HomePanels:RefreshDataset", this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -165,7 +163,6 @@ public class DynamicPanel extends HomeFragment
|
|||
mPanelAuthLayout = null;
|
||||
|
||||
mPanelAuthCache.setOnChangeListener(null);
|
||||
GeckoAppShell.unregisterEventListener("HomePanels:RefreshDataset", this);
|
||||
|
||||
if (mAuthStateTask != null) {
|
||||
mAuthStateTask.cancel(true);
|
||||
|
@ -289,42 +286,6 @@ public class DynamicPanel extends HomeFragment
|
|||
mUIMode = mode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMessage(String event, final JSONObject message) {
|
||||
if (event.equals("HomePanels:RefreshDataset")) {
|
||||
ThreadUtils.postToUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
handleDatasetRefreshRequest(message);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles a dataset refresh request from Gecko. This is usually
|
||||
* triggered by a HomeStorage.save() call in an add-on.
|
||||
*/
|
||||
private void handleDatasetRefreshRequest(JSONObject message) {
|
||||
final String datasetId;
|
||||
try {
|
||||
datasetId = message.getString("datasetId");
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "Failed to handle dataset refresh", e);
|
||||
return;
|
||||
}
|
||||
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(LOGTAG, "Refresh request for dataset: " + datasetId);
|
||||
|
||||
final ContentResolver cr = activity.getContentResolver();
|
||||
cr.notifyChange(HomeProvider.getDatasetNotificationUri(datasetId), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by the PanelLayout to make load and reset requests to
|
||||
* the holding fragment.
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
|
|||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.mozilla.gecko.db.HomeProvider;
|
||||
import org.mozilla.gecko.GeckoAppShell;
|
||||
import org.mozilla.gecko.home.HomeConfig.PanelConfig;
|
||||
import org.mozilla.gecko.home.PanelInfoManager.PanelInfo;
|
||||
|
@ -23,6 +24,7 @@ import org.mozilla.gecko.home.PanelInfoManager.RequestCallback;
|
|||
import org.mozilla.gecko.util.GeckoEventListener;
|
||||
import org.mozilla.gecko.util.ThreadUtils;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
|
@ -38,6 +40,7 @@ public class HomePanelsManager implements GeckoEventListener {
|
|||
private static final String EVENT_HOMEPANELS_INSTALL = "HomePanels:Install";
|
||||
private static final String EVENT_HOMEPANELS_UNINSTALL = "HomePanels:Uninstall";
|
||||
private static final String EVENT_HOMEPANELS_UPDATE = "HomePanels:Update";
|
||||
private static final String EVENT_HOMEPANELS_REFRESH = "HomePanels:RefreshDataset";
|
||||
|
||||
private static final String JSON_KEY_PANEL = "panel";
|
||||
private static final String JSON_KEY_PANEL_ID = "id";
|
||||
|
@ -85,6 +88,7 @@ public class HomePanelsManager implements GeckoEventListener {
|
|||
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_INSTALL, this);
|
||||
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_UNINSTALL, this);
|
||||
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_UPDATE, this);
|
||||
GeckoAppShell.getEventDispatcher().registerEventListener(EVENT_HOMEPANELS_REFRESH, this);
|
||||
}
|
||||
|
||||
public void onLocaleReady(final String locale) {
|
||||
|
@ -112,6 +116,9 @@ public class HomePanelsManager implements GeckoEventListener {
|
|||
} else if (event.equals(EVENT_HOMEPANELS_UPDATE)) {
|
||||
Log.d(LOGTAG, EVENT_HOMEPANELS_UPDATE);
|
||||
handlePanelUpdate(createPanelConfigFromMessage(message));
|
||||
} else if (event.equals(EVENT_HOMEPANELS_REFRESH)) {
|
||||
Log.d(LOGTAG, EVENT_HOMEPANELS_REFRESH);
|
||||
handleDatasetRefresh(message);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Log.e(LOGTAG, "Failed to handle event " + event, e);
|
||||
|
@ -175,6 +182,28 @@ public class HomePanelsManager implements GeckoEventListener {
|
|||
scheduleInvalidation(InvalidationMode.IMMEDIATE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles a dataset refresh request from Gecko. This is usually
|
||||
* triggered by a HomeStorage.save() call in an add-on.
|
||||
*
|
||||
* Runs in the gecko thread.
|
||||
*/
|
||||
private void handleDatasetRefresh(JSONObject message) {
|
||||
final String datasetId;
|
||||
try {
|
||||
datasetId = message.getString("datasetId");
|
||||
} catch (JSONException e) {
|
||||
Log.e(LOGTAG, "Failed to handle dataset refresh", e);
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(LOGTAG, "Refresh request for dataset: " + datasetId);
|
||||
|
||||
final ContentResolver cr = mContext.getContentResolver();
|
||||
cr.notifyChange(HomeProvider.getDatasetNotificationUri(datasetId), null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs in the gecko or main thread.
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче