Bug 1014994 - Part 4: Display list of Remote Tabs when possible. r=margaret

This commit is contained in:
Nick Alexander 2014-09-04 15:32:29 -07:00
parent 644d11aded
commit f54098165f
10 changed files with 279 additions and 3 deletions

View File

@ -0,0 +1,184 @@
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
* 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 java.util.EnumSet;
import java.util.List;
import org.mozilla.gecko.R;
import org.mozilla.gecko.RemoteTabsExpandableListAdapter;
import org.mozilla.gecko.TabsAccessor;
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.home.HomePager.OnUrlOpenListener;
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.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Fragment that displays tabs from other devices in an <code>ExpandableListView<code>.
* <p>
* This is intended to be used on phones, and possibly in portrait mode on tablets.
*/
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;
// Adapter for the list of remote tabs.
private RemoteTabsExpandableListAdapter mAdapter;
// The view shown by the fragment.
private ExpandableListView mList;
// Reference to the View to display when there are no results.
private View mEmptyView;
// Callbacks used for the loader.
private CursorLoaderCallbacks mCursorLoaderCallbacks;
public static RemoteTabsExpandableListFragment newInstance() {
return new RemoteTabsExpandableListFragment();
}
public RemoteTabsExpandableListFragment() {
super();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.home_remote_tabs_list_panel, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
mList = (ExpandableListView) view.findViewById(R.id.list);
mList.setTag(HomePager.LIST_TAG_REMOTE_TABS);
mList.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
final ExpandableListAdapter adapter = parent.getExpandableListAdapter();
final RemoteTab tab = (RemoteTab) adapter.getChild(groupPosition, childPosition);
if (tab == null) {
return false;
}
Telemetry.sendUIEvent(TelemetryContract.Event.LOAD_URL, TelemetryContract.Method.LIST_ITEM);
// This item is a TwoLinePageRow, so we allow switch-to-tab.
mUrlOpenListener.onUrlOpen(tab.url, EnumSet.of(OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
return true;
}
});
mList.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
// Since we don't indicate the expansion state yet, don't allow
// collapsing groups at all.
return true;
}
});
}
@Override
public void onDestroyView() {
super.onDestroyView();
mList = null;
mEmptyView = null;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// Intialize adapter
mAdapter = new RemoteTabsExpandableListAdapter(R.layout.home_remote_tabs_group, R.layout.home_remote_tabs_child, null);
mList.setAdapter(mAdapter);
// Create callbacks before the initial loader is started
mCursorLoaderCallbacks = new CursorLoaderCallbacks();
loadIfVisible();
}
private void updateUiFromClients(List<RemoteClient> clients) {
if (clients != null && !clients.isEmpty()) {
for (int i = 0; i < mList.getExpandableListAdapter().getGroupCount(); i++) {
mList.expandGroup(i);
}
return;
}
// Cursor is empty, so set the empty view if it hasn't been set already.
if (mEmptyView == null) {
// Set empty panel view. We delay this so that the empty view won't flash.
final ViewStub emptyViewStub = (ViewStub) getView().findViewById(R.id.home_empty_view_stub);
mEmptyView = emptyViewStub.inflate();
final ImageView emptyIcon = (ImageView) mEmptyView.findViewById(R.id.home_empty_image);
emptyIcon.setImageResource(R.drawable.icon_remote_tabs_empty);
final TextView emptyText = (TextView) mEmptyView.findViewById(R.id.home_empty_text);
emptyText.setText(R.string.home_remote_tabs_empty);
mList.setEmptyView(mEmptyView);
}
}
@Override
protected void load() {
getLoaderManager().initLoader(LOADER_ID_REMOTE_TABS, null, mCursorLoaderCallbacks);
}
private static class RemoteTabsCursorLoader extends SimpleCursorLoader {
public RemoteTabsCursorLoader(Context context) {
super(context);
}
@Override
public Cursor loadCursor() {
return TabsAccessor.getRemoteTabsCursor(getContext());
}
}
private class CursorLoaderCallbacks implements LoaderCallbacks<Cursor> {
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
return new RemoteTabsCursorLoader(getActivity());
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
final List<RemoteClient> clients = TabsAccessor.getClientsFromCursor(c);
mAdapter.replaceClients(clients);
updateUiFromClients(clients);
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.replaceClients(null);
}
}
}

View File

@ -145,9 +145,7 @@ public class RemoteTabsPanel extends HomeFragment {
switch (action) {
case None:
// This is only here to allow splitting commits. It will be replaced
// with the list of Remote Tabs in the next commits.
return RemoteTabsStaticFragment.newInstance(R.layout.remote_tabs_needs_upgrade);
return new RemoteTabsExpandableListFragment();
case NeedsVerification:
return RemoteTabsStaticFragment.newInstance(R.layout.remote_tabs_needs_verification);
case NeedsPassword:

View File

@ -297,6 +297,7 @@ gbjar.sources += [
'home/ReadingListPanel.java',
'home/ReadingListRow.java',
'home/RecentTabsPanel.java',
'home/RemoteTabsExpandableListFragment.java',
'home/RemoteTabsPanel.java',
'home/RemoteTabsStaticFragment.java',
'home/SearchEngine.java',

Binary file not shown.

After

Width:  |  Height:  |  Size: 744 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 645 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 947 B

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<org.mozilla.gecko.home.TwoLinePageRow xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Widget.RemoteTabsItemView"
android:layout_width="match_parent"
android:layout_height="@dimen/page_row_height"
android:minHeight="@dimen/page_row_height"/>

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
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/.
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:gecko="http://schemas.android.com/apk/res-auto"
style="@style/Widget.RemoteTabsClientView"
android:layout_width="match_parent"
android:layout_height="@dimen/page_row_height"
android:gravity="center_vertical"
android:minHeight="@dimen/page_row_height" >
<ImageView
android:id="@+id/device_type"
android:layout_width="@dimen/favicon_bg"
android:layout_height="@dimen/favicon_bg"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dip"
android:orientation="vertical" >
<org.mozilla.gecko.widget.FadedTextView
android:id="@+id/client"
style="@style/Widget.TwoLinePageRow.Title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
gecko:fadeWidth="30dp" />
<TextView
android:id="@+id/last_synced"
style="@style/Widget.TwoLinePageRow.Url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawablePadding="5dp"
android:maxLength="1024" />
</LinearLayout>
</LinearLayout>

View File

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ViewStub android:id="@+id/home_empty_view_stub"
android:layout="@layout/home_empty_panel"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView android:id="@+id/title"
style="@style/Widget.Home.HistoryPanelTitle"
android:visibility="gone"/>
<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"/>
</LinearLayout>

View File

@ -576,6 +576,16 @@
<item name="android:layout_height">wrap_content</item>
</style>
<style name="Widget.RemoteTabsItemView" parent="Widget.TwoLinePageRow"/>
<style name="Widget.RemoteTabsClientView" parent="Widget.TwoLinePageRow">
<item name="android:background">#fff5f7f9</item>
</style>
<style name="Widget.RemoteTabsListView" parent="Widget.HomeListView">
<item name="android:childDivider">#E7ECF0</item>
</style>
<!-- TabsTray Row -->
<style name="TabRowTextAppearance">
<item name="android:textColor">#FFFFFFFF</item>