michael@0: /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.home; michael@0: michael@0: import org.mozilla.gecko.R; michael@0: import org.mozilla.gecko.widget.IconTabWidget; michael@0: michael@0: import android.content.res.Configuration; michael@0: import android.os.Bundle; michael@0: import android.support.v4.app.Fragment; michael@0: import android.view.LayoutInflater; michael@0: import android.view.View; michael@0: import android.view.ViewGroup; michael@0: michael@0: public class HistoryPanel extends HomeFragment michael@0: implements IconTabWidget.OnTabChangedListener { michael@0: // Logging tag name michael@0: private static final String LOGTAG = "GeckoHistoryPanel"; michael@0: private IconTabWidget mTabWidget; michael@0: private int mSelectedTab; michael@0: private boolean initializeRecentPanel; michael@0: michael@0: @Override michael@0: public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { michael@0: return inflater.inflate(R.layout.home_history_panel, container, false); michael@0: } michael@0: michael@0: @Override michael@0: public void onViewCreated(View view, Bundle savedInstanceState) { michael@0: super.onViewCreated(view, savedInstanceState); michael@0: michael@0: mTabWidget = (IconTabWidget) view.findViewById(R.id.tab_icon_widget); michael@0: michael@0: mTabWidget.addTab(R.drawable.icon_most_recent, R.string.home_most_recent_title); michael@0: mTabWidget.addTab(R.drawable.icon_last_tabs, R.string.home_last_tabs_title); michael@0: michael@0: mTabWidget.setTabSelectionListener(this); michael@0: mTabWidget.setCurrentTab(mSelectedTab); michael@0: michael@0: loadIfVisible(); michael@0: } michael@0: michael@0: @Override michael@0: public void load() { michael@0: // Show most recent panel as the initial panel. michael@0: // Since we detach/attach on config change, this prevents from replacing current fragment. michael@0: if (!initializeRecentPanel) { michael@0: showMostRecentPanel(); michael@0: initializeRecentPanel = true; michael@0: } michael@0: } michael@0: michael@0: @Override michael@0: public void onTabChanged(int index) { michael@0: if (index == mSelectedTab) { michael@0: return; michael@0: } michael@0: michael@0: if (index == 0) { michael@0: showMostRecentPanel(); michael@0: } else if (index == 1) { michael@0: showLastTabsPanel(); michael@0: } michael@0: michael@0: mTabWidget.setCurrentTab(index); michael@0: mSelectedTab = index; michael@0: } michael@0: michael@0: @Override michael@0: public void onConfigurationChanged(Configuration newConfig) { michael@0: super.onConfigurationChanged(newConfig); michael@0: michael@0: // Rotation should detach and re-attach to use a different layout. michael@0: if (isVisible()) { michael@0: getFragmentManager().beginTransaction() michael@0: .detach(this) michael@0: .attach(this) michael@0: .commitAllowingStateLoss(); michael@0: } michael@0: } michael@0: michael@0: private void showSubPanel(Fragment subPanel) { michael@0: final Bundle args = new Bundle(); michael@0: args.putBoolean(HomePager.CAN_LOAD_ARG, getCanLoadHint()); michael@0: subPanel.setArguments(args); michael@0: michael@0: getChildFragmentManager().beginTransaction() michael@0: .addToBackStack(null).replace(R.id.history_panel_container, subPanel) michael@0: .commitAllowingStateLoss(); michael@0: } michael@0: michael@0: private void showMostRecentPanel() { michael@0: final MostRecentPanel mostRecentPanel = MostRecentPanel.newInstance(); michael@0: showSubPanel(mostRecentPanel); michael@0: } michael@0: michael@0: private void showLastTabsPanel() { michael@0: final LastTabsPanel lastTabsPanel = LastTabsPanel.newInstance(); michael@0: showSubPanel(lastTabsPanel); michael@0: } michael@0: }