package com.taikor.investment.modules;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;

import com.taikor.investment.R;
import com.taikor.investment.adapter.ProductAdapter;
import com.taikor.investment.base.BaseFragment;
import com.taikor.investment.modules.product.FixedIncomeFragment;
import com.taikor.investment.modules.product.NetVolatilityFragment;
import com.taikor.investment.modules.product.ProductSearchActivity;
import com.taikor.investment.mylibrary.TAnalytics;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * 产品
 * Created by Any on 2017/3/29.
 */
public class ProductFragment extends BaseFragment {

    @BindView(R.id.tab)
    TabLayout tabLayout;//导航标签
    @BindView(R.id.vp_product)
    ViewPager vpProduct;//内容存放

    private String[] titles = {"固定收益类", "净值波动型"};
    private ArrayList<Fragment> fragments = new ArrayList<>();

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_product;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        //初始化两种不同的fragment
        fragments.add(new FixedIncomeFragment());
        fragments.add(new NetVolatilityFragment());

        //设置适配器
        ProductAdapter adapter = new ProductAdapter(getActivity().getSupportFragmentManager(), fragments, titles);
        vpProduct.setAdapter(adapter);
        tabLayout.setupWithViewPager(vpProduct);
    }

    //埋点
    @Override
    public void onHiddenChanged(boolean hidden) {
        if (!hidden) {
            TAnalytics.onPageStart("productPage");
        } else {
            TAnalytics.onPageLoad("productPage", "", "", "");
        }
    }

    //搜索
    @OnClick(R.id.tv_search)
    public void onClick(View view) {
        if (view.getId() == R.id.tv_search) {
            Intent intent = new Intent(getActivity(), ProductSearchActivity.class);
            intent.putExtra("jump_desc", true);
            intent.putExtra("type", "product");
            startActivity(intent);
        }
    }
}
