package com.ycgis.macall.personalcenter.v.fragment;

import android.os.Bundle;


import android.util.Log;
import android.view.View;
import android.view.ViewOutlineProvider;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.google.android.material.appbar.AppBarLayout;
import com.rs.macall.androidx.basemodel.base.BaseViewBindFragment;

import com.rs.macall.androidx.basemodel.utils.DimensionConvert;
import com.ycgis.macall.personalcenter.databinding.FragmentHomeBinding;
import com.ycgis.macall.personalcenter.v.adapter.SimStringListAdapter;

import java.util.Arrays;

/**
 */
public class HomeFragment extends BaseViewBindFragment<FragmentHomeBinding> {

    public HomeFragment() {
        // Required empty public constructor
    }

     public static HomeFragment getInstance(int position) {
         Bundle bundle  = new Bundle();
         bundle.putInt("position",position);
         HomeFragment homeFragment = new HomeFragment();
         homeFragment.setArguments(bundle);
         return homeFragment;
    }

    @Override
    protected FragmentHomeBinding getViewBinding() {
        return FragmentHomeBinding.inflate(getLayoutInflater());
    }

    @Override
    protected void lazyLoad() {
        Log.w(TAG,"lazyLoad");
    }

    @Override
    protected void readInstanceState(Bundle savedInstanceState) {

    }

    float pxz = 0.0096666666666666666666666666667f;

    @Override
    protected void initView(View view) {
        LinearLayoutManager manager = new LinearLayoutManager(getContext(),LinearLayoutManager.VERTICAL,false);
        viewBinding.rvList.setLayoutManager(manager);
        String st = "你好！欢迎大家来到欢乐大测试,请认真阅读游戏规则,并自愿遵,守游戏规则,规则如下:,1、所有人初始状态为0级,2、初始状态下无技能,3、游戏开始后所有人进入发育期,4、这是个比手速的游戏,5、每提升五级随机获取一个技能," +
                "6、拥有技能后可向其他玩家发起攻击,7、技能冷却时间5分钟,8、场地只有最后一人时游戏结束，玩家胜出。,如果游戏中有人违反规则,我们将给予惩罚,lasdjfls,alsjdfl,fasdkglalsjg,asdkgas";
        SimStringListAdapter adapter = new SimStringListAdapter(getContext(), Arrays.asList(st.split(",")));
        viewBinding.rvList.setAdapter(adapter);
        viewBinding.appBar.setOutlineProvider(null);
        viewBinding.toolbarLayout.setOutlineProvider(ViewOutlineProvider.BOUNDS);
        viewBinding.appBar.addOnOffsetChangedListener((appBarLayout, verticalOffset) -> {
            int i = -DimensionConvert.px2dip(getContext(), verticalOffset);
            if (i<60){
                viewBinding.mainMyTitle.getRoot().setAlpha(0);
                viewBinding.mainFoldRegion.getRoot().setAlpha(1);
            }else if (i<150){
                float v = i * pxz;
                viewBinding.mainMyTitle.getRoot().setAlpha(v);
                viewBinding.mainFoldRegion.getRoot().setAlpha(1-v);
            }else {
                float v = i * 0.1f;
                viewBinding.mainFoldRegion.getRoot().setAlpha(0);
                viewBinding.mainMyTitle.getRoot().setAlpha(v);
            }
        });
    }

    @Override
    protected void startView(View view) {

    }

    @Override
    public void onResume() {
        super.onResume();
    }
}