package com.wasu.cs.ui;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.View;

import com.wasu.common.WError;
import com.wasu.cs.anim.DepthPageTransformer;
import com.wasu.module.log.WLog;

import java.util.ArrayList;
import java.util.List;

import cn.com.wasu.main.ErrorMap;
import cn.com.wasu.main.IntentConstant;
import cn.com.wasu.main.R;

/**
 * Created by chenming on 2016/8/1.
 *
 * @author chenming
 * @Description: 网易新闻专区CS模板,注释部分为二期需求
 * @email chenming@wasu.com
 * @date  2016/8/1.
 */

public class ActivityNeteaseNews extends ActivityBase implements View.OnClickListener {

	private String TAG = "ActivityNeteaseNews";

	private FragmentNeteaseNewsBody fragmengbody;
	//private FragmentNeteasePicText fragmentpictext;//二期需求预留
	private List<Fragment> fragmentList;
	private ViewPager mviewPager;
	private NeteasePagerAdapter mpageradapter;
	//private Button btnwyxw, btntwbb;
	private String CAT_URL;//="http://120.26.137.228/?s=2002&p=sjctNetEase&k=1&v=2&type=21&subjectId=57&indCatId=220195";
	private int keyCode = 0;

	protected void doCreate(Bundle savedInstanceState) {
		WLog.i(TAG,"doCreate()");

		setContentView(R.layout.activity_neteasenews);

		CAT_URL = getIntent().getStringExtra(IntentConstant.DATAURI.value());
		if (TextUtils.isEmpty(CAT_URL)) {
			showErrorExitDlg(ErrorMap.mapError(this, WError.ERROR_UNSUPPORT, null));
			return;
		}

		initviews();
	}

	private void initviews() {

		mviewPager = (ViewPager) findViewById(R.id.netease_body_viewpager);
		mpageradapter = new NeteasePagerAdapter(getSupportFragmentManager());
		mviewPager.setAdapter(mpageradapter);
		mviewPager.setPageTransformer(true, new DepthPageTransformer());
		/*btnwyxw = (Button) findViewById(R.id.btn_wyxw);
		btntwbb = (Button) findViewById(R.id.btn_twbb);
		btnwyxw.setOnClickListener(this);
		btntwbb.setOnClickListener(this);
		btnwyxw.requestFocus();*/

		//fragmengbody = new FragmentNeteaseNewsBodyTest();
		fragmengbody = new FragmentNeteaseNewsBody();
		//fragmentpictext = new FragmentNeteasePicText();
		fragmentList = new ArrayList<>();
		fragmentList.add(fragmengbody);
		//fragmentList.add(fragmentpictext);


	}

	public String getCAT_URL() {
		return CAT_URL;
	}

	@Override
	public void onClick(View v) {
		/*switch (v.getId()) {
			case R.id.btn_wyxw:
				mviewPager.setCurrentItem(0);
				break;
			case R.id.btn_twbb:
				mviewPager.setCurrentItem(1);
				break;
			default:
				break;
		}*/

	}



	/*@Override
	public void onBackPressed() {
		if (mviewPager.getCurrentItem() == 0) {
			super.onBackPressed();

		} else {
			mviewPager.setCurrentItem(mviewPager.getCurrentItem() - 1);
		}

	}*/


	private class NeteasePagerAdapter extends FragmentStatePagerAdapter {

		public NeteasePagerAdapter(FragmentManager fm) {
			super(fm);
		}


		@Override
		public Fragment getItem(int position) {

			return fragmentList.get(position);
		}

		@Override
		public int getCount() {
			return 1;
		}
	}
}
