Blame view
app/src/main/java/com/dinhcv/lifelogpedometer/activity/TopFragment.java
3.62 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; |
|
cb2ba72a7
|
13 |
import com.dinhcv.lifelogpedometer.utils.Debug; |
|
7f095a929
|
14 |
|
|
0c1f9bf91
|
15 16 17 18 |
public class TopFragment extends FragmentBase implements SettingFragmentPresenter {
public enum TopFragmentTag {
TOP_DATE,
TOP_TODAY,
|
|
7f095a929
|
19 |
} |
|
0c1f9bf91
|
20 21 |
private FragmentTransaction mFragmentTransaction;
private FragmentManager mFragmentManager;
|
|
7f095a929
|
22 |
|
|
0c1f9bf91
|
23 24 25 26 |
private View mRootView;
private FrameLayout mTopLayout;
private TopDateFragment mTopDateFragment;
private TopTodayFragment mTopTodayFragment;
|
|
7f095a929
|
27 |
|
|
0c1f9bf91
|
28 29 |
public static final String TOP_DATE_TAG = "top_date";
public static final String TOP_TODAY_TAG = "top_today";
|
|
7f095a929
|
30 |
|
|
0c1f9bf91
|
31 |
public TopFragmentTag mCurrentFragment = TopFragmentTag.TOP_DATE; |
|
7f095a929
|
32 33 |
@Override
|
|
0c1f9bf91
|
34 35 36 37 38 39 40 41 42 |
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
|
43 |
|
|
0c1f9bf91
|
44 |
return mRootView; |
|
7f095a929
|
45 46 47 |
}
/**
|
|
7f095a929
|
48 |
*/ |
|
0c1f9bf91
|
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 84 |
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
|
85 86 |
}
}
|
|
7f095a929
|
87 |
/** |
|
0c1f9bf91
|
88 |
* Init data |
|
7f095a929
|
89 |
*/ |
|
0c1f9bf91
|
90 |
private void initData() {
|
|
cb2ba72a7
|
91 92 93 94 95 96 |
Debug.normal("Current fragment : "+ mCurrentFragment);
if (mCurrentFragment == TopFragmentTag.TOP_DATE){
((PedometerActivity) getActivity()).setVisibleIconHome(false);
}else {
((PedometerActivity) getActivity()).setVisibleIconHome(true);
}
|
|
54e5fcd56
|
97 |
} |
|
7f095a929
|
98 99 100 101 102 103 |
@Override
public void onAttach(Context context) {
super.onAttach(context);
}
|
|
0c1f9bf91
|
104 105 106 |
/**
* Save data
*/
|
|
7f095a929
|
107 108 |
@Override
public void onSaveData() {
|
|
7f095a929
|
109 110 111 112 113 114 |
}
@Override
public void onInvalidate(boolean isInit) {
initData();
}
|
|
0c1f9bf91
|
115 |
|
|
7f095a929
|
116 117 118 119 120 121 122 123 |
@Override
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
initData();
}
}
|