Bug 1014994 - Part 5: Enable swipe-to-refresh Remote Tabs list. r=margaret

This commit is contained in:
Nick Alexander 2014-09-04 15:32:30 -07:00
parent f54098165f
commit 29d8f87994
2 changed files with 71 additions and 11 deletions

View File

@ -15,13 +15,18 @@ import org.mozilla.gecko.TabsAccessor.RemoteClient;
import org.mozilla.gecko.TabsAccessor.RemoteTab;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.home.HomePager.OnUrlOpenListener;
import org.mozilla.gecko.widget.GeckoSwipeRefreshLayout;
import org.mozilla.gecko.widget.GeckoSwipeRefreshLayout.OnRefreshListener;
import android.accounts.Account;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -40,12 +45,13 @@ import android.widget.TextView;
*/
public class RemoteTabsExpandableListFragment extends HomeFragment {
// Logging tag name.
@SuppressWarnings("unused")
private static final String LOGTAG = "GeckoRemoteTabsExpList";
// Cursor loader ID.
private static final int LOADER_ID_REMOTE_TABS = 0;
private static final String[] STAGES_TO_SYNC_ON_REFRESH = new String[] { "clients", "tabs" };
// Adapter for the list of remote tabs.
private RemoteTabsExpandableListAdapter mAdapter;
@ -58,6 +64,12 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
// Callbacks used for the loader.
private CursorLoaderCallbacks mCursorLoaderCallbacks;
// Child refresh layout view.
private GeckoSwipeRefreshLayout mRefreshLayout;
// Sync listener that stops refreshing when a sync is completed.
private RemoteTabsSyncListener mSyncStatusListener;
public static RemoteTabsExpandableListFragment newInstance() {
return new RemoteTabsExpandableListFragment();
}
@ -73,6 +85,15 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mRefreshLayout = (GeckoSwipeRefreshLayout) view.findViewById(R.id.remote_tabs_refresh_layout);
mRefreshLayout.setColorScheme(
R.color.swipe_refresh_orange, R.color.swipe_refresh_white,
R.color.swipe_refresh_orange, R.color.swipe_refresh_white);
mRefreshLayout.setOnRefreshListener(new RemoteTabsRefreshListener());
mSyncStatusListener = new RemoteTabsSyncListener();
FirefoxAccounts.addSyncStatusListener(mSyncStatusListener);
mList = (ExpandableListView) view.findViewById(R.id.list);
mList.setTag(HomePager.LIST_TAG_REMOTE_TABS);
@ -108,6 +129,11 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
super.onDestroyView();
mList = null;
mEmptyView = null;
if (mSyncStatusListener != null) {
FirefoxAccounts.removeSyncStatusListener(mSyncStatusListener);
mSyncStatusListener = null;
}
}
@Override
@ -181,4 +207,36 @@ public class RemoteTabsExpandableListFragment extends HomeFragment {
mAdapter.replaceClients(null);
}
}
private class RemoteTabsRefreshListener implements OnRefreshListener {
@Override
public void onRefresh() {
if (FirefoxAccounts.firefoxAccountsExist(getActivity())) {
final Account account = FirefoxAccounts.getFirefoxAccount(getActivity());
FirefoxAccounts.requestSync(account, FirefoxAccounts.FORCE, STAGES_TO_SYNC_ON_REFRESH, null);
} else {
Log.wtf(LOGTAG, "No Firefox Account found; this should never happen. Ignoring.");
mRefreshLayout.setRefreshing(false);
}
}
}
private class RemoteTabsSyncListener implements FirefoxAccounts.SyncStatusListener {
@Override
public Context getContext() {
return getActivity();
}
@Override
public Account getAccount() {
return FirefoxAccounts.getFirefoxAccount(getContext());
}
public void onSyncStarted() {
}
public void onSyncFinished() {
mRefreshLayout.setRefreshing(false);
}
}
}

View File

@ -13,16 +13,18 @@
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView android:id="@+id/title"
style="@style/Widget.Home.HistoryPanelTitle"
android:visibility="gone"/>
<org.mozilla.gecko.widget.GeckoSwipeRefreshLayout
android:id="@+id/remote_tabs_refresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ExpandableListView
android:id="@+id/list"
style="@style/Widget.RemoteTabsListView"
android:groupIndicator="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<ExpandableListView
android:id="@+id/list"
style="@style/Widget.RemoteTabsListView"
android:groupIndicator="@android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</org.mozilla.gecko.widget.GeckoSwipeRefreshLayout>
</LinearLayout>