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