Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*- |
michael@0 | 2 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | package org.mozilla.gecko.home; |
michael@0 | 7 | |
michael@0 | 8 | import org.mozilla.gecko.R; |
michael@0 | 9 | import org.mozilla.gecko.widget.IconTabWidget; |
michael@0 | 10 | |
michael@0 | 11 | import android.content.res.Configuration; |
michael@0 | 12 | import android.os.Bundle; |
michael@0 | 13 | import android.support.v4.app.Fragment; |
michael@0 | 14 | import android.view.LayoutInflater; |
michael@0 | 15 | import android.view.View; |
michael@0 | 16 | import android.view.ViewGroup; |
michael@0 | 17 | |
michael@0 | 18 | public class HistoryPanel extends HomeFragment |
michael@0 | 19 | implements IconTabWidget.OnTabChangedListener { |
michael@0 | 20 | // Logging tag name |
michael@0 | 21 | private static final String LOGTAG = "GeckoHistoryPanel"; |
michael@0 | 22 | private IconTabWidget mTabWidget; |
michael@0 | 23 | private int mSelectedTab; |
michael@0 | 24 | private boolean initializeRecentPanel; |
michael@0 | 25 | |
michael@0 | 26 | @Override |
michael@0 | 27 | public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { |
michael@0 | 28 | return inflater.inflate(R.layout.home_history_panel, container, false); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | @Override |
michael@0 | 32 | public void onViewCreated(View view, Bundle savedInstanceState) { |
michael@0 | 33 | super.onViewCreated(view, savedInstanceState); |
michael@0 | 34 | |
michael@0 | 35 | mTabWidget = (IconTabWidget) view.findViewById(R.id.tab_icon_widget); |
michael@0 | 36 | |
michael@0 | 37 | mTabWidget.addTab(R.drawable.icon_most_recent, R.string.home_most_recent_title); |
michael@0 | 38 | mTabWidget.addTab(R.drawable.icon_last_tabs, R.string.home_last_tabs_title); |
michael@0 | 39 | |
michael@0 | 40 | mTabWidget.setTabSelectionListener(this); |
michael@0 | 41 | mTabWidget.setCurrentTab(mSelectedTab); |
michael@0 | 42 | |
michael@0 | 43 | loadIfVisible(); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | @Override |
michael@0 | 47 | public void load() { |
michael@0 | 48 | // Show most recent panel as the initial panel. |
michael@0 | 49 | // Since we detach/attach on config change, this prevents from replacing current fragment. |
michael@0 | 50 | if (!initializeRecentPanel) { |
michael@0 | 51 | showMostRecentPanel(); |
michael@0 | 52 | initializeRecentPanel = true; |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | @Override |
michael@0 | 57 | public void onTabChanged(int index) { |
michael@0 | 58 | if (index == mSelectedTab) { |
michael@0 | 59 | return; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | if (index == 0) { |
michael@0 | 63 | showMostRecentPanel(); |
michael@0 | 64 | } else if (index == 1) { |
michael@0 | 65 | showLastTabsPanel(); |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | mTabWidget.setCurrentTab(index); |
michael@0 | 69 | mSelectedTab = index; |
michael@0 | 70 | } |
michael@0 | 71 | |
michael@0 | 72 | @Override |
michael@0 | 73 | public void onConfigurationChanged(Configuration newConfig) { |
michael@0 | 74 | super.onConfigurationChanged(newConfig); |
michael@0 | 75 | |
michael@0 | 76 | // Rotation should detach and re-attach to use a different layout. |
michael@0 | 77 | if (isVisible()) { |
michael@0 | 78 | getFragmentManager().beginTransaction() |
michael@0 | 79 | .detach(this) |
michael@0 | 80 | .attach(this) |
michael@0 | 81 | .commitAllowingStateLoss(); |
michael@0 | 82 | } |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | private void showSubPanel(Fragment subPanel) { |
michael@0 | 86 | final Bundle args = new Bundle(); |
michael@0 | 87 | args.putBoolean(HomePager.CAN_LOAD_ARG, getCanLoadHint()); |
michael@0 | 88 | subPanel.setArguments(args); |
michael@0 | 89 | |
michael@0 | 90 | getChildFragmentManager().beginTransaction() |
michael@0 | 91 | .addToBackStack(null).replace(R.id.history_panel_container, subPanel) |
michael@0 | 92 | .commitAllowingStateLoss(); |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | private void showMostRecentPanel() { |
michael@0 | 96 | final MostRecentPanel mostRecentPanel = MostRecentPanel.newInstance(); |
michael@0 | 97 | showSubPanel(mostRecentPanel); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | private void showLastTabsPanel() { |
michael@0 | 101 | final LastTabsPanel lastTabsPanel = LastTabsPanel.newInstance(); |
michael@0 | 102 | showSubPanel(lastTabsPanel); |
michael@0 | 103 | } |
michael@0 | 104 | } |