package com.yutou.jianr_mg.views;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import com.alibaba.fastjson.JSON;
import com.umeng.analytics.MobclickAgent;
import com.yutou.jianr_mg.Adapters.ViewPagerAdapter;
import com.yutou.jianr_mg.Data.MAppMg;
import com.yutou.jianr_mg.Fragments.ModListFragment_0;
import com.yutou.jianr_mg.Fragments.ModListFragment_1;
import com.yutou.jianr_mg.Fragments.ModListFragment_2;
import com.yutou.jianr_mg.R;
import com.yutou.jianr_mg.Tools.Log;


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

import me.majiajie.pagerbottomtabstrip.NavigationController;
import me.majiajie.pagerbottomtabstrip.PageNavigationView;
import me.majiajie.pagerbottomtabstrip.listener.OnTabItemSelectedListener;

/**
 * Created by 58381 on 2018/1/25.
 */

public class ModListActivity extends  AppCompatActivity{
    private PageNavigationView tab;
    private ViewPager viewPager;
    private NavigationController navigationController;
    private List<Fragment> list;
    private MAppMg appMg;
    private Context context;
    private Intent intent;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mod_list);
        this.context = context;
        intent=getIntent();
        appMg = JSON.parseObject(intent.getStringExtra("mg"), MAppMg.class);
        Log.i("接受到的魔改：" + appMg.toString());
        initViews();
    }
    private void initViews() {
        tab = findViewById(R.id.tab);
        viewPager = findViewById(R.id.pager);
        list=new ArrayList<>();
        list.add(ModListFragment_0.init(appMg));
        list.add(ModListFragment_1.init(appMg));
        list.add(ModListFragment_2.init(appMg));
        ViewPagerAdapter adapter=new ViewPagerAdapter(getSupportFragmentManager(),list);
        viewPager.setAdapter(adapter);
        viewPager.setCurrentItem(0);
        navigationController = tab.material()
                .addItem(R.drawable.icon_mod_new, "最新")
                .addItem(R.drawable.icon_mod_lh,"仅立绘")
                .addItem(R.drawable.icon_mod_q,"仅Q版")
                .build();
        navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
            @Override
            public void onSelected(int index, int old) {
                viewPager.setCurrentItem(index);

            }

            @Override
            public void onRepeat(int index) {

            }
        });
        navigationController.setupWithViewPager(viewPager);
        navigationController.setSelect(0);

    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
}
