package com.navinfo.outdoor.fragment;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.navinfo.outdoor.R;
import com.navinfo.outdoor.base.BaseFragment;
import com.navinfo.outdoor.util.NoSlideViewPager;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;

/**
 * 记录的Fragment
 * 2021-5-25
 */
public class RecordFragment extends BaseFragment implements View.OnClickListener {


    private TabLayout tabRecord;
    private NoSlideViewPager vpRecord;
    private final String[] names = {"待提交", "已提交"};
    private StaySubmitFragment staySubmitFragment; // 待提交
    private HasSubmitFragment hasSubmitFragment;// 已提交

    public static RecordFragment newInstance(Bundle bundle) {
        RecordFragment fragment = new RecordFragment();
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected int getLayout() {
        return R.layout.record_fragment;
    }

    @Override
    protected void initView() {
        super.initView();
        tabRecord = (TabLayout) findViewById(R.id.tab_record);
        vpRecord = (NoSlideViewPager) findViewById(R.id.vp_record);

        ArrayList<Fragment> fragments = new ArrayList<>();
        new StaySubmitFragment();
        staySubmitFragment = new StaySubmitFragment();
        fragments.add(staySubmitFragment);
        hasSubmitFragment = new HasSubmitFragment();
        fragments.add(hasSubmitFragment);
        vpRecord.setAdapter(new FragmentPagerAdapter(getFragmentManager()) {
            @NonNull
            @NotNull
            @Override
            public Fragment getItem(int position) {
                return fragments.get(position);
            }

            @Override
            public int getCount() {
                return fragments.size();
            }
        });

        tabRecord.setupWithViewPager(vpRecord);
        tabRecord.getTabAt(0).setText(names[0]);
        tabRecord.getTabAt(1).setText(names[1]);

    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    public void onClick(View v) {

    }

    /**
     * 刷新fragment内的所有数据
     * */
    public void refreshData() {
        if (staySubmitFragment!=null) {
            staySubmitFragment.refreshData();
        }
//        if (hasSubmitFragment!=null) {
//            hasSubmitFragment.refreshData();
//        }
    }
}