Blame view
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
3.28 KB
7f095a929
|
1 |
package com.dinhcv.lifelogpedometer.activity; |
7f095a929
|
2 |
import android.content.Context; |
7f095a929
|
3 4 |
import android.os.Bundle; import android.support.annotation.Nullable; |
0c1f9bf91
|
5 6 |
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; |
7f095a929
|
7 |
import android.view.LayoutInflater; |
7f095a929
|
8 9 |
import android.view.View; import android.view.ViewGroup; |
0c1f9bf91
|
10 |
import android.widget.FrameLayout; |
7f095a929
|
11 12 |
import com.dinhcv.lifelogpedometer.R; |
7f095a929
|
13 |
|
0c1f9bf91
|
14 15 16 17 |
public class TopFragment extends FragmentBase implements SettingFragmentPresenter { public enum TopFragmentTag { TOP_DATE, TOP_TODAY, |
7f095a929
|
18 |
} |
0c1f9bf91
|
19 20 |
private FragmentTransaction mFragmentTransaction; private FragmentManager mFragmentManager; |
7f095a929
|
21 |
|
0c1f9bf91
|
22 23 24 25 |
private View mRootView; private FrameLayout mTopLayout; private TopDateFragment mTopDateFragment; private TopTodayFragment mTopTodayFragment; |
7f095a929
|
26 |
|
0c1f9bf91
|
27 28 |
public static final String TOP_DATE_TAG = "top_date"; public static final String TOP_TODAY_TAG = "top_today"; |
7f095a929
|
29 |
|
0c1f9bf91
|
30 |
public TopFragmentTag mCurrentFragment = TopFragmentTag.TOP_DATE; |
7f095a929
|
31 32 |
@Override |
0c1f9bf91
|
33 34 35 36 37 38 39 40 41 |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment mRootView = inflater.inflate(R.layout.fragment_top, container, false); mFragmentManager = getFragmentManager(); mFragmentTransaction = mFragmentManager.beginTransaction(); initView(); initData(); |
7f095a929
|
42 |
|
0c1f9bf91
|
43 |
return mRootView; |
7f095a929
|
44 45 46 |
} /** |
7f095a929
|
47 |
*/ |
0c1f9bf91
|
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
private void initView() { mTopLayout = (FrameLayout) mRootView.findViewById(R.id.layout_top); mTopDateFragment = new TopDateFragment(); mTopDateFragment.setRootFragment(this); mTopTodayFragment = new TopTodayFragment(); mTopTodayFragment.setRootFragment(this); showContentFragment(); } public void showContentFragment() { ((PedometerActivity) getActivity()).setVisibleIconHome(false); mCurrentFragment = TopFragmentTag.TOP_DATE; mFragmentTransaction = mFragmentManager.beginTransaction(); mFragmentTransaction.replace(mTopLayout.getId(), mTopDateFragment, TOP_DATE_TAG); mFragmentTransaction.commit(); } public void showDetailFragment() { ((PedometerActivity) getActivity()).setVisibleIconHome(true); mCurrentFragment = TopFragmentTag.TOP_TODAY; mFragmentTransaction = mFragmentManager.beginTransaction(); mFragmentTransaction.replace(mTopLayout.getId(), mTopTodayFragment, TOP_TODAY_TAG); mFragmentTransaction.commit(); } public void clickBackToHome(){ switch (mCurrentFragment) { case TOP_DATE: break; case TOP_TODAY: showContentFragment(); break; default: break; |
7f095a929
|
84 85 |
} } |
7f095a929
|
86 |
/** |
0c1f9bf91
|
87 |
* Init data |
7f095a929
|
88 |
*/ |
0c1f9bf91
|
89 |
private void initData() { |
54e5fcd56
|
90 |
|
54e5fcd56
|
91 |
} |
7f095a929
|
92 93 94 95 96 97 |
@Override public void onAttach(Context context) { super.onAttach(context); } |
0c1f9bf91
|
98 99 100 |
/** * Save data */ |
7f095a929
|
101 102 |
@Override public void onSaveData() { |
7f095a929
|
103 104 105 106 107 108 |
} @Override public void onInvalidate(boolean isInit) { initData(); } |
0c1f9bf91
|
109 |
|
7f095a929
|
110 111 112 113 114 115 116 117 |
@Override public void onViewStateRestored(@Nullable Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); initData(); } } |