Bug 1100904 - Ensure panel updates don't happen during transitions (r=margaret)

This commit is contained in:
Lucas Rocha 2014-11-24 15:13:23 +00:00
Родитель 3243e93dc5
Коммит 4f9175bbc2
8 изменённых файлов: 81 добавлений и 14 удалений

Просмотреть файл

@ -216,7 +216,7 @@ public class BookmarksPanel extends HomeFragment {
/**
* Loader callbacks for the LoaderManager of this fragment.
*/
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
if (args == null) {
@ -229,7 +229,7 @@ public class BookmarksPanel extends HomeFragment {
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
BookmarksLoader bl = (BookmarksLoader) loader;
mListAdapter.swapCursor(c, bl.getFolderInfo(), bl.getRefreshType());
updateUiFromCursor(c);
@ -237,6 +237,8 @@ public class BookmarksPanel extends HomeFragment {
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
if (mList != null) {
mListAdapter.swapCursor(null);
}

Просмотреть файл

@ -352,7 +352,7 @@ public class DynamicPanel extends HomeFragment {
/**
* LoaderCallbacks implementation that interacts with the LoaderManager.
*/
private class PanelLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class PanelLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
final DatasetRequest request = (DatasetRequest) args.getParcelable(DATASET_REQUEST);
@ -362,7 +362,7 @@ public class DynamicPanel extends HomeFragment {
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor cursor) {
final DatasetRequest request = getRequestFromLoader(loader);
Log.d(LOGTAG, "Finished loader for request: " + request);
@ -373,6 +373,8 @@ public class DynamicPanel extends HomeFragment {
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
final DatasetRequest request = getRequestFromLoader(loader);
Log.d(LOGTAG, "Resetting loader for request: " + request);

Просмотреть файл

@ -471,20 +471,21 @@ public class HistoryPanel extends HomeFragment {
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new HistoryCursorLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
mAdapter.swapCursor(null);
}
}

Просмотреть файл

@ -197,20 +197,21 @@ public class ReadingListPanel extends HomeFragment {
/**
* LoaderCallbacks implementation that interacts with the LoaderManager.
*/
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new ReadingListLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
mAdapter.swapCursor(null);
}
}

Просмотреть файл

@ -404,20 +404,21 @@ public class RecentTabsPanel extends HomeFragment
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new RecentTabsCursorLoader(getActivity(), mClosedTabs);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
mAdapter.swapCursor(c);
updateUiFromCursor(c);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
mAdapter.swapCursor(null);
}
}

Просмотреть файл

@ -392,14 +392,14 @@ public class RemoteTabsExpandableListFragment extends HomeFragment implements Re
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new RemoteTabsCursorLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
public void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
final List<RemoteClient> clients = TabsAccessor.getClientsFromCursor(c);
// Filter the hidden clients out of the clients list. The clients
@ -421,6 +421,7 @@ public class RemoteTabsExpandableListFragment extends HomeFragment implements Re
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
mAdapter.replaceClients(null);
}
}

Просмотреть файл

@ -689,7 +689,7 @@ public class TopSitesPanel extends HomeFragment {
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private class CursorLoaderCallbacks extends TransitionAwareCursorLoaderCallbacks {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
trace("Creating TopSitesLoader: " + id);
@ -707,7 +707,7 @@ public class TopSitesPanel extends HomeFragment {
* Why that is... dunno.
*/
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
protected void onLoadFinishedAfterTransitions(Loader<Cursor> loader, Cursor c) {
debug("onLoadFinished: " + c.getCount() + " rows.");
mListAdapter.swapCursor(c);
@ -752,6 +752,8 @@ public class TopSitesPanel extends HomeFragment {
@Override
public void onLoaderReset(Loader<Cursor> loader) {
super.onLoaderReset(loader);
if (mListAdapter != null) {
mListAdapter.swapCursor(null);
}

Просмотреть файл

@ -0,0 +1,57 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.mozilla.gecko.home;
import android.database.Cursor;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import org.mozilla.gecko.animation.TransitionsTracker;
/**
* A {@link LoaderCallbacks} implementation that avoids running its
* {@link #onLoadFinished(Loader, Cursor)} method during animations as it's
* likely to trigger a layout traversal as a result of a cursor swap in the
* target adapter.
*/
public abstract class TransitionAwareCursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
private OnLoadFinishedRunnable onLoadFinishedRunnable;
@Override
public void onLoadFinished(Loader loader, Cursor c) {
if (onLoadFinishedRunnable != null) {
TransitionsTracker.cancelPendingAction(onLoadFinishedRunnable);
}
onLoadFinishedRunnable = new OnLoadFinishedRunnable(loader, c);
TransitionsTracker.runAfterTransitions(onLoadFinishedRunnable);
}
protected abstract void onLoadFinishedAfterTransitions(Loader<Cursor> loade, Cursor c);
@Override
public void onLoaderReset(Loader<Cursor> loader) {
if (onLoadFinishedRunnable != null) {
TransitionsTracker.cancelPendingAction(onLoadFinishedRunnable);
onLoadFinishedRunnable = null;
}
}
private class OnLoadFinishedRunnable implements Runnable {
private final Loader<Cursor> loader;
private final Cursor cursor;
public OnLoadFinishedRunnable(Loader<Cursor> loader, Cursor cursor) {
this.loader = loader;
this.cursor = cursor;
}
@Override
public void run() {
onLoadFinishedAfterTransitions(loader, cursor);
onLoadFinishedRunnable = null;
}
}
}