Bug 958889 - Part 2.8: Add RemoteTabsPanel. r=nalexander

This commit is contained in:
Michael Comella 2014-05-22 18:38:03 -07:00
Родитель 450e0dfa4f
Коммит f76d5f9623
8 изменённых файлов: 147 добавлений и 36 удалений

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

@ -361,8 +361,9 @@ gbjar.sources += [
'Tab.java',
'Tabs.java',
'TabsAccessor.java',
'tabspanel/RemoteTabsContainer.java',
'tabspanel/RemoteTabsContainerPanel.java',
'tabspanel/RemoteTabsList.java',
'tabspanel/RemoteTabsPanel.java',
'tabspanel/TabsPanel.java',
'tabspanel/TabsTray.java',
'Telemetry.java',

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

@ -48,20 +48,11 @@
android:visibility="gone"
gecko:tabs="tabs_private"/>
<org.mozilla.gecko.tabspanel.RemoteTabsContainer android:id="@+id/synced_tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone">
<org.mozilla.gecko.tabspanel.RemoteTabsList android:id="@+id/synced_tabs_list"
style="@style/RemoteTabsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/tabs_panel_list_padding"
android:paddingRight="@dimen/tabs_panel_list_padding"
android:scrollbarStyle="outsideOverlay"/>
</org.mozilla.gecko.tabspanel.RemoteTabsContainer>
<org.mozilla.gecko.tabspanel.RemoteTabsPanel
android:id="@+id/remote_tabs"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
</view>

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

@ -0,0 +1,20 @@
<?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.tabspanel.RemoteTabsContainerPanel
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone">
<org.mozilla.gecko.tabspanel.RemoteTabsList
style="@style/RemoteTabsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/tabs_panel_list_padding"
android:paddingRight="@dimen/tabs_panel_list_padding"
android:scrollbarStyle="outsideOverlay"/>
</org.mozilla.gecko.tabspanel.RemoteTabsContainerPanel>

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

@ -47,20 +47,11 @@
android:visibility="gone"
gecko:tabs="tabs_private"/>
<org.mozilla.gecko.tabspanel.RemoteTabsContainer android:id="@+id/synced_tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="gone">
<org.mozilla.gecko.tabspanel.RemoteTabsList android:id="@+id/synced_tabs"
style="@style/RemoteTabsList"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="@dimen/tabs_panel_list_padding"
android:paddingRight="@dimen/tabs_panel_list_padding"
android:scrollbarStyle="outsideOverlay"/>
</org.mozilla.gecko.tabspanel.RemoteTabsContainer>
<org.mozilla.gecko.tabspanel.RemoteTabsPanel
android:id="@+id/remote_tabs"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:visibility="gone"/>
</view>

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

@ -21,7 +21,7 @@ import android.view.ViewGroup;
* Provides a container to wrap the list of synced tabs and provide swipe-to-refresh support. The
* only child view should be an instance of {@link RemoteTabsList}.
*/
public class RemoteTabsContainer extends GeckoSwipeRefreshLayout
public class RemoteTabsContainerPanel extends GeckoSwipeRefreshLayout
implements TabsPanel.PanelView {
private static final String[] STAGES_TO_SYNC_ON_REFRESH = new String[] { "tabs" };
@ -29,7 +29,7 @@ public class RemoteTabsContainer extends GeckoSwipeRefreshLayout
private final RemoteTabsSyncObserver syncListener;
private RemoteTabsList list;
public RemoteTabsContainer(Context context, AttributeSet attrs) {
public RemoteTabsContainerPanel(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
this.syncListener = new RemoteTabsSyncObserver();
@ -67,14 +67,14 @@ public class RemoteTabsContainer extends GeckoSwipeRefreshLayout
@Override
public void show() {
setVisibility(VISIBLE);
setVisibility(View.VISIBLE);
TabsAccessor.getTabs(context, list);
FirefoxAccounts.addSyncStatusListener(syncListener);
}
@Override
public void hide() {
setVisibility(GONE);
setVisibility(View.GONE);
FirefoxAccounts.removeSyncStatusListener(syncListener);
}
@ -96,7 +96,7 @@ public class RemoteTabsContainer extends GeckoSwipeRefreshLayout
private class RemoteTabsSyncObserver implements FirefoxAccounts.SyncStatusListener {
@Override
public Context getContext() {
return RemoteTabsContainer.this.getContext();
return RemoteTabsContainerPanel.this.getContext();
}
@Override

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

@ -23,7 +23,7 @@ import android.widget.ExpandableListView;
import android.widget.SimpleExpandableListAdapter;
/**
* The actual list of synced tabs. This serves as the only child view of {@link RemoteTabsContainer}
* The actual list of synced tabs. This serves as the only child view of {@link RemoteTabsContainerPanel}
* so it can be refreshed using a swipe-to-refresh gesture.
*/
class RemoteTabsList extends ExpandableListView

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

@ -0,0 +1,108 @@
/* 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.tabspanel;
import org.mozilla.gecko.R;
import org.mozilla.gecko.fxa.FirefoxAccounts;
import org.mozilla.gecko.fxa.login.State;
import org.mozilla.gecko.tabspanel.TabsPanel.PanelView;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
/**
* This panel, which is a {@link TabsPanel.PanelView}, chooses which underlying
* PanelView to show based on the current account state, and forwards the appropriate
* calls to the currently visible panel.
*/
class RemoteTabsPanel extends FrameLayout implements PanelView {
private enum RemotePanelType {
SETUP,
VERIFICATION,
CONTAINER
}
private PanelView currentPanel;
private RemotePanelType currentPanelType;
private TabsPanel tabsPanel;
public RemoteTabsPanel(Context context, AttributeSet attrs) {
super(context, attrs);
updateCurrentPanel();
}
@Override
public void setTabsPanel(TabsPanel panel) {
tabsPanel = panel;
currentPanel.setTabsPanel(panel);
}
@Override
public void show() {
updateCurrentPanel();
currentPanel.show();
setVisibility(View.VISIBLE);
}
@Override
public void hide() {
setVisibility(View.GONE);
currentPanel.hide();
}
@Override
public boolean shouldExpand() {
return currentPanel.shouldExpand();
}
private void updateCurrentPanel() {
final RemotePanelType newPanelType = getPanelTypeFromAccountState();
if (newPanelType != currentPanelType) {
// The current panel should be null the first time this is called.
if (currentPanel != null) {
currentPanel.hide();
}
removeAllViews();
currentPanelType = newPanelType;
currentPanel = inflatePanel(currentPanelType);
currentPanel.setTabsPanel(tabsPanel);
addView((View) currentPanel);
}
}
private RemotePanelType getPanelTypeFromAccountState() {
final State accountState = FirefoxAccounts.getFirefoxAccountState(getContext());
if (accountState == null) {
return RemotePanelType.SETUP;
}
if (accountState.getNeededAction() == State.Action.NeedsVerification) {
return RemotePanelType.VERIFICATION;
}
return RemotePanelType.CONTAINER;
}
private PanelView inflatePanel(final RemotePanelType panelType) {
final LayoutInflater inflater = LayoutInflater.from(getContext());
final View inflatedView;
switch (panelType) {
case CONTAINER:
inflatedView = inflater.inflate(R.layout.remote_tabs_container_panel, null);
break;
default:
throw new IllegalArgumentException("Unknown panelType, " + panelType);
}
return (PanelView) inflatedView;
}
}

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

@ -102,7 +102,7 @@ public class TabsPanel extends LinearLayout
mPanelPrivate = (PanelView) findViewById(R.id.private_tabs);
mPanelPrivate.setTabsPanel(this);
mPanelRemote = (PanelView) findViewById(R.id.synced_tabs);
mPanelRemote = (PanelView) findViewById(R.id.remote_tabs);
mPanelRemote.setTabsPanel(this);
mFooter = (RelativeLayout) findViewById(R.id.tabs_panel_footer);