167 lines
4.8 KiB
Java
167 lines
4.8 KiB
Java
package com.gh.gamecenter.kaifu;
|
|
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v4.app.Fragment;
|
|
import android.support.v4.view.ViewPager;
|
|
import android.view.View;
|
|
import android.widget.CheckedTextView;
|
|
import android.widget.LinearLayout;
|
|
|
|
import com.gh.base.AppController;
|
|
import com.gh.base.adapter.FragmentAdapter;
|
|
import com.gh.base.fragment.BaseFragment;
|
|
import com.gh.gamecenter.R;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import butterknife.BindView;
|
|
import butterknife.OnClick;
|
|
|
|
/**
|
|
* Created by khy on 20/08/17.
|
|
*/
|
|
|
|
public class KaiFuFragment extends BaseFragment {
|
|
|
|
@BindView(R.id.kaifu_tabbar_today)
|
|
CheckedTextView mKaifuTabbarToday;
|
|
@BindView(R.id.kaifu_tabbar_tomorrow)
|
|
CheckedTextView mKaifuTabbarTomorrow;
|
|
@BindView(R.id.kaifu_tabbar_future)
|
|
CheckedTextView mKaifuTabbarFuture;
|
|
@BindView(R.id.kaifu_tabbar)
|
|
LinearLayout mKaifuTabbar;
|
|
@BindView(R.id.kaifu_content_vp)
|
|
ViewPager mKaifuContentVp;
|
|
|
|
private List<Fragment> mFragments;
|
|
|
|
|
|
@Override
|
|
protected int getLayoutId() {
|
|
return R.layout.fragment_kaifu;
|
|
}
|
|
|
|
@Override
|
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
|
|
mFragments = new ArrayList<>();
|
|
for (int i = 0; i < 3; i++) {
|
|
KaiFuVpFragment kaiFuVpFragment = new KaiFuVpFragment();
|
|
Bundle arguments;
|
|
if (getArguments() != null) {
|
|
arguments = (Bundle) getArguments().clone();
|
|
} else {
|
|
arguments = new Bundle();
|
|
}
|
|
String day;
|
|
switch (i) {
|
|
case 0:
|
|
day = "today";
|
|
break;
|
|
case 1:
|
|
day = "tomorrow";
|
|
break;
|
|
default:
|
|
day = "after";
|
|
break;
|
|
}
|
|
arguments.putString("day", day);
|
|
kaiFuVpFragment.setArguments(arguments);
|
|
mFragments.add(kaiFuVpFragment);
|
|
}
|
|
FragmentAdapter fragmentAdapter = new FragmentAdapter(getChildFragmentManager(), mFragments);
|
|
|
|
setTabbarPosition(0);
|
|
mKaifuContentVp.setAdapter(fragmentAdapter);
|
|
mKaifuContentVp.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
|
|
@Override
|
|
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
|
|
}
|
|
|
|
@Override
|
|
public void onPageSelected(int position) {
|
|
setTabbarPosition(position);
|
|
}
|
|
|
|
@Override
|
|
public void onPageScrollStateChanged(final int state) {
|
|
setPageScrollState(state);
|
|
}
|
|
});
|
|
}
|
|
|
|
@Override
|
|
public void onPause() {
|
|
super.onPause();
|
|
for (Fragment fragment : mFragments) {
|
|
fragment.onPause();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
for (Fragment fragment : mFragments) {
|
|
fragment.onResume();
|
|
}
|
|
}
|
|
|
|
@OnClick({R.id.kaifu_tabbar_today, R.id.kaifu_tabbar_tomorrow, R.id.kaifu_tabbar_future})
|
|
public void onViewClicked(View view) {
|
|
int index = 0;
|
|
switch (view.getId()) {
|
|
case R.id.kaifu_tabbar_today:
|
|
index = 0;
|
|
break;
|
|
case R.id.kaifu_tabbar_tomorrow:
|
|
index = 1;
|
|
break;
|
|
case R.id.kaifu_tabbar_future:
|
|
index = 2;
|
|
break;
|
|
}
|
|
|
|
setTabbarPosition(index);
|
|
mKaifuContentVp.setCurrentItem(index);
|
|
setPageScrollState(1);
|
|
}
|
|
|
|
private void setPageScrollState(final int state) {
|
|
AppController.MAIN_EXECUTOR.execute(new Runnable() {
|
|
@Override
|
|
public void run() {
|
|
for (Fragment fragment : mFragments) {
|
|
if (fragment.getUserVisibleHint() && fragment instanceof KaiFuVpFragment) {
|
|
((KaiFuVpFragment) fragment).vpScrollState(state);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
private void setTabbarPosition(int index) {
|
|
switch (index) {
|
|
case 0:
|
|
mKaifuTabbarToday.setChecked(true);
|
|
mKaifuTabbarFuture.setChecked(false);
|
|
mKaifuTabbarTomorrow.setChecked(false);
|
|
break;
|
|
case 1:
|
|
mKaifuTabbarToday.setChecked(false);
|
|
mKaifuTabbarFuture.setChecked(false);
|
|
mKaifuTabbarTomorrow.setChecked(true);
|
|
break;
|
|
case 2:
|
|
mKaifuTabbarToday.setChecked(false);
|
|
mKaifuTabbarFuture.setChecked(true);
|
|
mKaifuTabbarTomorrow.setChecked(false);
|
|
break;
|
|
}
|
|
}
|
|
}
|